Skip to content

Commit 807ec4a

Browse files
committed
Add SVG images for Draw2D and Zest icons
This moves the SVG check from GEF to Draw2D so that it can be re-used, also for Zest. Both bundles have been adapted to also use SVG icons if supported by the active version of SWT.
1 parent 2e46a0b commit 807ec4a

File tree

18 files changed

+104
-78
lines changed

18 files changed

+104
-78
lines changed

icons/.project

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

icons/.settings/org.eclipse.core.resources.prefs

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

icons/build.sh

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

org.eclipse.draw2d/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ Require-Bundle: org.eclipse.swt;bundle-version="[3.126.0,4.0.0)";visibility:=ree
2222
Bundle-ActivationPolicy: lazy
2323
Bundle-RequiredExecutionEnvironment: JavaSE-17
2424
Automatic-Module-Name: org.eclipse.draw2d
25+
Require-Capability: eclipse.swt;filter:="(image.format=svg)";resolution:=optional
2526

org.eclipse.draw2d/src/org/eclipse/draw2d/CheckBox.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -24,8 +24,8 @@
2424
public final class CheckBox extends Toggle {
2525
private Label label = null;
2626

27-
static final Image UNCHECKED = FileImageDataProvider.createImage(CheckBox.class, "images/checkboxenabledoff.png"); //$NON-NLS-1$
28-
static final Image CHECKED = FileImageDataProvider.createImage(CheckBox.class, "images/checkboxenabledon.png"); //$NON-NLS-1$
27+
static final Image UNCHECKED = FileImageDataProvider.createImage(CheckBox.class, "images/checkboxenabledoff.svg"); //$NON-NLS-1$
28+
static final Image CHECKED = FileImageDataProvider.createImage(CheckBox.class, "images/checkboxenabledon.svg"); //$NON-NLS-1$
2929

3030
/**
3131
* Constructs a CheckBox with no text.
File renamed without changes.
File renamed without changes.

org.eclipse.draw2d/src/org/eclipse/draw2d/internal/FileImageDataProvider.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2024 Patrick Ziegler and others.
2+
* Copyright (c) 2024, 2025 Patrick Ziegler and others.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -43,7 +43,7 @@ public FileImageDataProvider(Class<?> clazz, String path) {
4343

4444
@Override
4545
public ImageData getImageData(int zoom) {
46-
if (zoom == 100) {
46+
if (zoom == 100 || "svg".equals(fileExtension)) { //$NON-NLS-1$
4747
return createImageData(basePath + '.' + fileExtension);
4848
}
4949
if (zoom == 200) {
@@ -67,6 +67,6 @@ private ImageData createImageData(String name) {
6767
* at an appropriate time.
6868
*/
6969
public static Image createImage(Class<?> clazz, String name) {
70-
return new Image(null, new FileImageDataProvider(clazz, name));
70+
return new Image(null, new FileImageDataProvider(clazz, ImageUtils.getEffectiveFileName(name)));
7171
}
7272
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Patrick Ziegler and others.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Patrick Ziegler - initial API and implementation
12+
*******************************************************************************/
13+
14+
package org.eclipse.draw2d.internal;
15+
16+
import java.io.ByteArrayInputStream;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.nio.charset.StandardCharsets;
20+
21+
import org.eclipse.swt.SWTException;
22+
import org.eclipse.swt.graphics.ImageLoader;
23+
24+
/**
25+
* This utility class is used to handle the migration from GIF/PNG to SVG-based
26+
* images. If {@link #getEffectiveFileName(String)} called with a {@code .svg}
27+
* file, the file extension is automatically changed to {@code .png} if SVGs are
28+
* not yet supported by the active SWT instance. This allows Draw2D to be
29+
* executed in both the latest and older Eclipse releases.
30+
*/
31+
public final class ImageUtils {
32+
private static Boolean isSvgSupported;
33+
34+
private ImageUtils() {
35+
throw new IllegalStateException("Must never be instantiated"); //$NON-NLS-1$
36+
}
37+
38+
/**
39+
* If {@code fileName} ends with {@code .svg}, the extension is changed to
40+
* {@code .png} if not yet supported by SWT.
41+
*/
42+
public static String getEffectiveFileName(String fileName) {
43+
// If the SWT version doesn't yet support SVGs, fall back to PNG
44+
if (!isSvgSupported() && fileName.endsWith(".svg")) { //$NON-NLS-1$
45+
return fileName.replaceFirst("\\.svg$", ".png"); //$NON-NLS-1$ //$NON-NLS-2$
46+
}
47+
return fileName;
48+
}
49+
50+
/**
51+
* Convenience method to check whether SVGs are supported by the current
52+
* application. This method returns {@code true}, if there is at least one
53+
* active bundle that satisfies the (optional) {@code (image.format=svg)}
54+
* capability.
55+
*/
56+
public static boolean isSvgSupported() {
57+
if (isSvgSupported != null) {
58+
return isSvgSupported;
59+
}
60+
String svg = """
61+
<?xml version="1.0" encoding="UTF-8"?>
62+
<svg width="1" height="1" version="1.1" viewBox="0 0 0 0" xmlns="http://www.w3.org/2000/svg"></svg>
63+
"""; //$NON-NLS-1$
64+
try (InputStream is = new ByteArrayInputStream(svg.getBytes(StandardCharsets.UTF_8))) {
65+
new ImageLoader().load(is);
66+
isSvgSupported = true;
67+
} catch (IOException ignore) {
68+
// Should never happen
69+
isSvgSupported = false;
70+
} catch (SWTException e) {
71+
// SVGs unsupported
72+
isSvgSupported = false;
73+
}
74+
return isSvgSupported;
75+
}
76+
}

org.eclipse.gef/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Plugin.name
44
Bundle-SymbolicName: org.eclipse.gef; singleton:=true
5-
Bundle-Version: 3.22.100.qualifier
5+
Bundle-Version: 3.23.0.qualifier
66
Bundle-Activator: org.eclipse.gef.internal.InternalGEFPlugin
77
Bundle-Vendor: %Plugin.providerName
88
Bundle-Localization: plugin
@@ -31,7 +31,7 @@ Export-Package: org.eclipse.gef,
3131
org.eclipse.gef.ui.rulers,
3232
org.eclipse.gef.ui.views.palette,
3333
org.eclipse.gef.util
34-
Require-Bundle: org.eclipse.draw2d;visibility:=reexport;bundle-version="[3.13.0,4.0.0)",
34+
Require-Bundle: org.eclipse.draw2d;visibility:=reexport;bundle-version="[3.20.100,4.0.0)",
3535
org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
3636
org.eclipse.ui.views;resolution:=optional;bundle-version="[3.2.0,4.0.0)",
3737
org.eclipse.ui.workbench;bundle-version="[3.133.0,4.0.0)",

0 commit comments

Comments
 (0)