Skip to content

Commit 8052ffb

Browse files
committed
disabled icon logic
1 parent 6328554 commit 8052ffb

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public ImageData getImageData(int zoom) {
126126
InputStream in = getStream(zoom);
127127
if (in != null) {
128128
try (BufferedInputStream stream = new BufferedInputStream(in)) {
129-
return new ImageData(stream, zoom);
129+
return new ImageData(stream, zoom, SWT.IMAGE_COPY);
130130
} catch (SWTException e) {
131131
if (e.code != SWT.ERROR_INVALID_IMAGE) {
132132
throw e;

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java

+41-7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ public ImageData getImageData(int zoom) {
9999
return URLImageDescriptor.getImageData(url, zoom);
100100
}
101101

102+
@Override
103+
public ImageData getCustomizedImageData(int zoom, int flag) {
104+
return URLImageDescriptor.getCustomizedImageData(url, zoom, flag);
105+
}
106+
107+
@Override
108+
public boolean supportsRasterizationFlag(int flag) {
109+
boolean supportsFlag = flag == SWT.IMAGE_DISABLE || flag == SWT.IMAGE_GRAY || flag == SWT.IMAGE_COPY;
110+
URL tempURL = getURL(url);
111+
if (tempURL != null) {
112+
if (tempURL.toString().endsWith(".svg") && supportsFlag) { //$NON-NLS-1$
113+
return true;
114+
}
115+
}
116+
return false;
117+
}
102118
}
103119

104120
private static long cumulativeTime;
@@ -143,14 +159,14 @@ private static ImageData getImageData(String url, int zoom) {
143159
URL tempURL = getURL(url);
144160
if (tempURL != null) {
145161
if (tempURL.toString().endsWith(".svg")) { //$NON-NLS-1$
146-
return getImageData(tempURL, zoom);
162+
return getImageData(tempURL, zoom, SWT.IMAGE_COPY);
147163
}
148164
if (zoom == 100) {
149-
return getImageData(tempURL, zoom);
165+
return getImageData(tempURL);
150166
}
151167
URL xUrl = getxURL(tempURL, zoom);
152168
if (xUrl != null) {
153-
ImageData xdata = getImageData(xUrl, zoom);
169+
ImageData xdata = getImageData(xUrl);
154170
if (xdata != null) {
155171
return xdata;
156172
}
@@ -159,22 +175,35 @@ private static ImageData getImageData(String url, int zoom) {
159175
if (xpath != null) {
160176
URL xPathUrl = getURL(xpath);
161177
if (xPathUrl != null) {
162-
return getImageData(xPathUrl, zoom);
178+
return getImageData(xPathUrl);
163179
}
164180
}
165181
}
166182
return null;
167183
}
168184

169185
private static ImageData getImageData(URL url) {
170-
return getImageData(url, 0);
186+
ImageData result = null;
187+
try (InputStream in = getStream(url)) {
188+
if (in != null) {
189+
result = new ImageData(in);
190+
}
191+
} catch (SWTException e) {
192+
if (e.code != SWT.ERROR_INVALID_IMAGE) {
193+
throw e;
194+
// fall through otherwise
195+
}
196+
} catch (IOException e) {
197+
Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, e.getLocalizedMessage(), e));
198+
}
199+
return result;
171200
}
172201

173-
private static ImageData getImageData(URL url, int zoom) {
202+
private static ImageData getImageData(URL url, int zoom, int flag) {
174203
ImageData result = null;
175204
try (InputStream in = getStream(url)) {
176205
if (in != null) {
177-
result = new ImageData(in, zoom);
206+
result = new ImageData(in, zoom, flag);
178207
}
179208
} catch (SWTException e) {
180209
if (e.code != SWT.ERROR_INVALID_IMAGE) {
@@ -187,6 +216,11 @@ private static ImageData getImageData(URL url, int zoom) {
187216
return result;
188217
}
189218

219+
private static ImageData getCustomizedImageData(String url, int zoom, int flag) {
220+
URL tempURL = getURL(url);
221+
return getImageData(tempURL, zoom, flag);
222+
}
223+
190224
/**
191225
* Returns a stream on the image contents. Returns null if a stream could
192226
* not be opened.

0 commit comments

Comments
 (0)