Skip to content

Commit bd58803

Browse files
committed
[FIXUP] Replace FileImageDescriptor by URLImageDescriptor
1 parent 762649b commit bd58803

File tree

3 files changed

+25
-328
lines changed

3 files changed

+25
-328
lines changed

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

Lines changed: 0 additions & 325 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected ImageDescriptor() {
8484
* @return a new image descriptor
8585
*/
8686
public static ImageDescriptor createFromFile(Class<?> location, String filename) {
87-
return new FileImageDescriptor(location, filename);
87+
return createFromURL(location.getResource(filename));
8888
}
8989

9090
/**

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.net.URL;
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
27+
import java.util.regex.Matcher;
28+
import java.util.regex.Pattern;
2729

2830
import org.eclipse.core.runtime.FileLocator;
2931
import org.eclipse.core.runtime.IAdaptable;
@@ -69,7 +71,7 @@ public String getImagePath(int zoom) {
6971
return xResult;
7072
}
7173
}
72-
String xpath = FileImageDescriptor.getxPath(url, zoom);
74+
String xpath = getxPath(url, zoom);
7375
if (xpath != null) {
7476
URL xPathUrl = getURL(xpath);
7577
if (xPathUrl != null) {
@@ -148,7 +150,7 @@ private static ImageData getImageData(String url, int zoom) {
148150
return xdata;
149151
}
150152
}
151-
String xpath = FileImageDescriptor.getxPath(url, zoom);
153+
String xpath = getxPath(url, zoom);
152154
if (xpath != null) {
153155
URL xPathUrl = getURL(xpath);
154156
if (xPathUrl != null) {
@@ -159,6 +161,26 @@ private static ImageData getImageData(String url, int zoom) {
159161
return null;
160162
}
161163

164+
private static final Pattern XPATH_PATTERN = Pattern.compile("(\\d+)x(\\d+)"); //$NON-NLS-1$
165+
166+
private static String getxPath(String name, int zoom) {
167+
Matcher matcher = XPATH_PATTERN.matcher(name);
168+
if (matcher.find()) {
169+
try {
170+
int currentWidth = Integer.parseInt(matcher.group(1));
171+
int desiredWidth = Math.round((zoom / 100f) * currentWidth);
172+
int currentHeight = Integer.parseInt(matcher.group(2));
173+
int desiredHeight = Math.round((zoom / 100f) * currentHeight);
174+
String lead = name.substring(0, matcher.start(1));
175+
String tail = name.substring(matcher.end(2));
176+
return lead + desiredWidth + "x" + desiredHeight + tail; //$NON-NLS-1$
177+
} catch (RuntimeException e) {
178+
// should never happen but if then we can't use the alternative name...
179+
}
180+
}
181+
return null;
182+
}
183+
162184
private static ImageData getImageData(URL url) {
163185
ImageData result = null;
164186
try (InputStream in = getStream(url)) {

0 commit comments

Comments
 (0)