listeners, Listener untypedListener ) {
+ for( SelectionListener listener : listeners ) {
+ if( isAdapterType( listener ) && matches( untypedListener, listener ) ) {
+ return listener;
+ }
+ }
+ return null;
+ }
+
+ private static boolean isAdapterType( SelectionListener listener ) {
+ return listener instanceof UntypedSelectionAdapter;
+ }
+
+ private static boolean matches( Listener untypedListener, SelectionListener listener ) {
+ return ( ( UntypedSelectionAdapter )listener ).listener == untypedListener;
+ }
+}
\ No newline at end of file
diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/sb/ViewComponent.java b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/sb/ViewComponent.java
new file mode 100644
index 0000000..af1779c
--- /dev/null
+++ b/plugins/com.minres.scviewer.database.ui.swt/src/com/minres/scviewer/database/ui/swt/sb/ViewComponent.java
@@ -0,0 +1,7 @@
+package com.minres.scviewer.database.ui.swt.sb;
+
+import org.eclipse.swt.widgets.Control;
+
+public interface ViewComponent {
+ Control getControl();
+}
\ No newline at end of file
diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/ResourceManager.java b/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/ResourceManager.java
new file mode 100644
index 0000000..8e96dfe
--- /dev/null
+++ b/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/ResourceManager.java
@@ -0,0 +1,438 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Google, Inc. and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Google, Inc. - initial API and implementation
+ * Wim Jongman - 1.8 and higher compliance
+ *******************************************************************************/
+package org.eclipse.wb.swt;
+
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.resource.CompositeImageDescriptor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageDataProvider;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.osgi.framework.Bundle;
+
+/**
+ * Utility class for managing OS resources associated with SWT/JFace controls
+ * such as colors, fonts, images, etc.
+ *
+ * This class is created automatically when you fiddle around with images and
+ * colors in WB. You might want to prevent your application from using this
+ * class and provide your own more effective means of resource caching.
+ *
+ * Even though this class can be used to manage these resources, if they are
+ * here for the duration of the application and not used then you still have an
+ * effective resource leak.
+ *
+ * Application code must explicitly invoke the dispose()
method to
+ * release the operating system resources managed by cached objects when those
+ * objects and OS resources are no longer needed.
+ *
+ * This class may be freely distributed as part of any application or plugin.
+ *
+ *
+ * @author scheglov_ke
+ * @author Dan Rubel
+ * @author Wim Jongman
+ */
+public class ResourceManager extends SWTResourceManager {
+
+ /**
+ * The map where we store our images.
+ */
+ private static Map m_descriptorImageMap = new HashMap();
+
+ /**
+ * Returns an {@link ImageDescriptor} stored in the file at the specified path
+ * relative to the specified class.
+ *
+ * @param clazz the {@link Class} relative to which to find the image
+ * descriptor.
+ * @param path the path to the image file.
+ * @return the {@link ImageDescriptor} stored in the file at the specified path.
+ */
+ public static ImageDescriptor getImageDescriptor(Class> clazz, String path) {
+ return ImageDescriptor.createFromFile(clazz, path);
+ }
+
+ /**
+ * Returns an {@link ImageDescriptor} stored in the file at the specified path.
+ *
+ * @param path the path to the image file.
+ * @return the {@link ImageDescriptor} stored in the file at the specified path.
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ try {
+ return ImageDescriptor.createFromURL(new File(path).toURI().toURL());
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns an {@link Image} based on the specified {@link ImageDescriptor}.
+ *
+ * @param descriptor the {@link ImageDescriptor} for the {@link Image}.
+ * @return the {@link Image} based on the specified {@link ImageDescriptor}.
+ */
+ public static Image getImage(ImageDescriptor descriptor) {
+ if (descriptor == null) {
+ return null;
+ }
+ Image image = m_descriptorImageMap.get(descriptor);
+ if (image == null) {
+ image = descriptor.createImage();
+ m_descriptorImageMap.put(descriptor, image);
+ }
+ return image;
+ }
+
+ /**
+ * Maps images to decorated images.
+ */
+ @SuppressWarnings("unchecked")
+ private static Map>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
+
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage the base {@link Image} that should be decorated.
+ * @param decorator the {@link Image} to decorate the base image.
+ * @return {@link Image} The resulting decorated image.
+ */
+ public static Image decorateImage(Image baseImage, Image decorator) {
+ return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
+ }
+
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated.
+ * @param decorator
+ * the {@link Image} to decorate the base image.
+ * @param corner
+ * the corner to place decorator image.
+ * @return the resulting decorated {@link Image}.
+ */
+ public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
+ if (corner <= 0 || corner >= LAST_CORNER_KEY) {
+ throw new IllegalArgumentException("Wrong decorate corner");
+ }
+ Map> cornerDecoratedImageMap = m_decoratedImageMap[corner];
+ if (cornerDecoratedImageMap == null) {
+ cornerDecoratedImageMap = new HashMap>();
+ m_decoratedImageMap[corner] = cornerDecoratedImageMap;
+ }
+ Map decoratedMap = cornerDecoratedImageMap.get(baseImage);
+ if (decoratedMap == null) {
+ decoratedMap = new HashMap();
+ cornerDecoratedImageMap.put(baseImage, decoratedMap);
+ }
+ //
+ Image result = decoratedMap.get(decorator);
+ if (result == null) {
+ final Rectangle bib = baseImage.getBounds();
+ final Rectangle dib = decorator.getBounds();
+ final Point baseImageSize = new Point(bib.width, bib.height);
+ CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
+ @Override
+ protected void drawCompositeImage(int width, int height) {
+ drawImage(createCachedImageDataProvider(baseImage), 0, 0);
+ if (corner == TOP_LEFT) {
+ drawImage(getUnzoomedImageDataProvider(decorator.getImageData()) , 0, 0);
+ } else if (corner == TOP_RIGHT) {
+ drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, 0);
+ } else if (corner == BOTTOM_LEFT) {
+ drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), 0, bib.height - dib.height);
+ } else if (corner == BOTTOM_RIGHT) {
+ drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, bib.height - dib.height);
+ }
+ }
+ @Override
+ protected Point getSize() {
+ return baseImageSize;
+ }
+ };
+ //
+ result = compositImageDesc.createImage();
+ decoratedMap.put(decorator, result);
+ }
+ return result;
+ }
+
+ private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) {
+ return zoom -> zoom == 100 ? imageData : null;
+ }
+
+
+ /**
+ * Dispose all of the cached images.
+ */
+ public static void disposeImages() {
+ SWTResourceManager.disposeImages();
+ // dispose ImageDescriptor images
+ {
+ for (Iterator I = m_descriptorImageMap.values().iterator(); I.hasNext();) {
+ I.next().dispose();
+ }
+ m_descriptorImageMap.clear();
+ }
+ // dispose decorated images
+ for (int i = 0; i < m_decoratedImageMap.length; i++) {
+ Map> cornerDecoratedImageMap = m_decoratedImageMap[i];
+ if (cornerDecoratedImageMap != null) {
+ for (Map decoratedMap : cornerDecoratedImageMap.values()) {
+ for (Image image : decoratedMap.values()) {
+ image.dispose();
+ }
+ decoratedMap.clear();
+ }
+ cornerDecoratedImageMap.clear();
+ }
+ }
+ // dispose plugin images
+ {
+ for (Iterator I = m_URLImageMap.values().iterator(); I.hasNext();) {
+ I.next().dispose();
+ }
+ m_URLImageMap.clear();
+ }
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Plugin images support
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps URL to images.
+ */
+ private static Map m_URLImageMap = new HashMap();
+
+ /**
+ * Provider for plugin resources, used by WindowBuilder at design time.
+ */
+ public interface PluginResourceProvider {
+ URL getEntry(String symbolicName, String path);
+ }
+
+ /**
+ * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design
+ * time.
+ */
+ private static PluginResourceProvider m_designTimePluginResourceProvider = null;
+
+ /**
+ * Returns an {@link Image} based on a plugin and file path.
+ *
+ * @param plugin the plugin {@link Object} containing the image
+ * @param name the path to the image within the plugin
+ * @return the {@link Image} stored in the file at the specified path
+ *
+ * @deprecated Use {@link #getPluginImage(String, String)} instead.
+ */
+ @Deprecated
+ public static Image getPluginImage(Object plugin, String name) {
+ try {
+ URL url = getPluginImageURL(plugin, name);
+ if (url != null) {
+ return getPluginImageFromUrl(url);
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+
+ /**
+ * Returns an {@link Image} based on a {@link Bundle} and resource entry path.
+ *
+ * @param symbolicName the symbolic name of the {@link Bundle}.
+ * @param path the path of the resource entry.
+ * @return the {@link Image} stored in the file at the specified path.
+ */
+ public static Image getPluginImage(String symbolicName, String path) {
+ try {
+ URL url = getPluginImageURL(symbolicName, path);
+ if (url != null) {
+ return getPluginImageFromUrl(url);
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+
+ /**
+ * Returns an {@link Image} based on given {@link URL}.
+ */
+ private static Image getPluginImageFromUrl(URL url) {
+ try {
+ try {
+ String key = url.toExternalForm();
+ Image image = m_URLImageMap.get(key);
+ if (image == null) {
+ InputStream stream = url.openStream();
+ try {
+ image = getImage(stream);
+ m_URLImageMap.put(key, image);
+ } finally {
+ stream.close();
+ }
+ }
+ return image;
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+
+ /**
+ * Returns an {@link ImageDescriptor} based on a plugin and file path.
+ *
+ * @param plugin the plugin {@link Object} containing the image.
+ * @param name the path to th eimage within the plugin.
+ * @return the {@link ImageDescriptor} stored in the file at the specified path.
+ *
+ * @deprecated Use {@link #getPluginImageDescriptor(String, String)} instead.
+ */
+ @Deprecated
+ public static ImageDescriptor getPluginImageDescriptor(Object plugin, String name) {
+ try {
+ try {
+ URL url = getPluginImageURL(plugin, name);
+ return ImageDescriptor.createFromURL(url);
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+
+ /**
+ * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource
+ * entry path.
+ *
+ * @param symbolicName the symbolic name of the {@link Bundle}.
+ * @param path the path of the resource entry.
+ * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource
+ * entry path.
+ */
+ public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) {
+ try {
+ URL url = getPluginImageURL(symbolicName, path);
+ if (url != null) {
+ return ImageDescriptor.createFromURL(url);
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ return null;
+ }
+
+ /**
+ * Returns an {@link URL} based on a {@link Bundle} and resource entry path.
+ */
+ private static URL getPluginImageURL(String symbolicName, String path) {
+ // try runtime plugins
+ {
+ Bundle bundle = Platform.getBundle(symbolicName);
+ if (bundle != null) {
+ return bundle.getEntry(path);
+ }
+ }
+ // try design time provider
+ if (m_designTimePluginResourceProvider != null) {
+ return m_designTimePluginResourceProvider.getEntry(symbolicName, path);
+ }
+ // no such resource
+ return null;
+ }
+
+ /**
+ * Returns an {@link URL} based on a plugin and file path.
+ *
+ * @param plugin the plugin {@link Object} containing the file path.
+ * @param name the file path.
+ * @return the {@link URL} representing the file at the specified path.
+ * @throws Exception
+ */
+ private static URL getPluginImageURL(Object plugin, String name) throws Exception {
+ // try to work with 'plugin' as with OSGI BundleContext
+ try {
+ Class> BundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$
+ Class> BundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$
+ if (BundleContextClass.isAssignableFrom(plugin.getClass())) {
+ Method getBundleMethod = BundleContextClass.getMethod("getBundle", new Class[0]); //$NON-NLS-1$
+ Object bundle = getBundleMethod.invoke(plugin, new Object[0]);
+ //
+ Class> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$
+ Constructor> pathConstructor = PathClass.getConstructor(new Class[] { String.class });
+ Object path = pathConstructor.newInstance(new Object[] { name });
+ //
+ Class> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$
+ Class> PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$
+ Method findMethod = PlatformClass.getMethod("find", new Class[] { BundleClass, IPathClass }); //$NON-NLS-1$
+ return (URL) findMethod.invoke(null, new Object[] { bundle, path });
+ }
+ } catch (Throwable e) {
+ // Ignore any exceptions
+ }
+ // else work with 'plugin' as with usual Eclipse plugin
+ {
+ Class> PluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$
+ if (PluginClass.isAssignableFrom(plugin.getClass())) {
+ //
+ Class> PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$
+ Constructor> pathConstructor = PathClass.getConstructor(new Class[] { String.class });
+ Object path = pathConstructor.newInstance(new Object[] { name });
+ //
+ Class> IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$
+ Method findMethod = PluginClass.getMethod("find", new Class[] { IPathClass }); //$NON-NLS-1$
+ return (URL) findMethod.invoke(plugin, new Object[] { path });
+ }
+ }
+ return null;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // General
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Dispose of cached objects and their underlying OS resources. This should only
+ * be called when the cached objects are no longer needed (e.g. on application
+ * shutdown).
+ */
+ public static void dispose() {
+ disposeColors();
+ disposeFonts();
+ disposeImages();
+ }
+}
\ No newline at end of file
diff --git a/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java b/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java
index 0024a03..d8a2858 100644
--- a/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java
+++ b/plugins/com.minres.scviewer.database.ui.swt/src/org/eclipse/wb/swt/SWTResourceManager.java
@@ -29,17 +29,14 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
/**
- * Utility class for managing OS resources associated with SWT controls such as
- * colors, fonts, images, etc.
+ * Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc.
*
- * !!! IMPORTANT !!! Application code must explicitly invoke the
- * dispose()
method to release the operating system resources
- * managed by cached objects when those objects and OS resources are no longer
+ * !!! IMPORTANT !!! Application code must explicitly invoke the dispose()
method to release the
+ * operating system resources managed by cached objects when those objects and OS resources are no longer
* needed (e.g. on application shutdown)
*
* This class may be freely distributed as part of any application or plugin.
*
- *
* @author scheglov_ke
* @author Dan Rubel
*/
@@ -49,54 +46,57 @@ public class SWTResourceManager {
// Color
//
////////////////////////////////////////////////////////////////////////////
- private static Map colorMap = new HashMap<>();
-
- private SWTResourceManager() {}
-
+ private static Map m_colorMap = new HashMap();
/**
* Returns the system {@link Color} matching the specific ID.
*
- * @param systemColorID the ID value for the color
+ * @param systemColorID
+ * the ID value for the color
* @return the system {@link Color} matching the specific ID
*/
public static Color getColor(int systemColorID) {
Display display = Display.getCurrent();
return display.getSystemColor(systemColorID);
}
-
/**
* Returns a {@link Color} given its red, green and blue component values.
*
- * @param r the red component of the color
- * @param g the green component of the color
- * @param b the blue component of the color
- * @return the {@link Color} matching the given red, green and blue component
- * values
+ * @param r
+ * the red component of the color
+ * @param g
+ * the green component of the color
+ * @param b
+ * the blue component of the color
+ * @return the {@link Color} matching the given red, green and blue component values
*/
public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b));
}
-
/**
* Returns a {@link Color} given its RGB value.
*
- * @param rgb the {@link RGB} value of the color
+ * @param rgb
+ * the {@link RGB} value of the color
* @return the {@link Color} matching the RGB value
*/
public static Color getColor(RGB rgb) {
- return colorMap.computeIfAbsent(rgb, k -> new Color(Display.getCurrent(), rgb));
+ Color color = m_colorMap.get(rgb);
+ if (color == null) {
+ Display display = Display.getCurrent();
+ color = new Color(display, rgb);
+ m_colorMap.put(rgb, color);
+ }
+ return color;
}
-
/**
* Dispose of all the cached {@link Color}'s.
*/
public static void disposeColors() {
- for (Color color : colorMap.values()) {
+ for (Color color : m_colorMap.values()) {
color.dispose();
}
- colorMap.clear();
+ m_colorMap.clear();
}
-
////////////////////////////////////////////////////////////////////////////
//
// Image
@@ -105,12 +105,12 @@ public class SWTResourceManager {
/**
* Maps image paths to images.
*/
- private static Map imageMap = new HashMap<>();
-
+ private static Map m_imageMap = new HashMap();
/**
* Returns an {@link Image} encoded by the specified {@link InputStream}.
*
- * @param stream the {@link InputStream} encoding the image data
+ * @param stream
+ * the {@link InputStream} encoding the image data
* @return the {@link Image} encoded by the specified input stream
*/
protected static Image getImage(InputStream stream) throws IOException {
@@ -125,55 +125,52 @@ public class SWTResourceManager {
stream.close();
}
}
-
/**
* Returns an {@link Image} stored in the file at the specified path.
*
- * @param path the path to the image file
+ * @param path
+ * the path to the image file
* @return the {@link Image} stored in the file at the specified path
*/
public static Image getImage(String path) {
- Image image = imageMap.get(path);
+ Image image = m_imageMap.get(path);
if (image == null) {
try {
image = getImage(new FileInputStream(path));
- imageMap.put(path, image);
+ m_imageMap.put(path, image);
} catch (Exception e) {
image = getMissingImage();
- imageMap.put(path, image);
+ m_imageMap.put(path, image);
}
}
return image;
}
-
/**
- * Returns an {@link Image} stored in the file at the specified path relative to
- * the specified class.
+ * Returns an {@link Image} stored in the file at the specified path relative to the specified class.
*
- * @param clazz the {@link Class} relative to which to find the image
- * @param path the path to the image file, if starts with '/'
+ * @param clazz
+ * the {@link Class} relative to which to find the image
+ * @param path
+ * the path to the image file, if starts with '/'
* @return the {@link Image} stored in the file at the specified path
*/
public static Image getImage(Class> clazz, String path) {
String key = clazz.getName() + '|' + path;
- Image image = imageMap.get(key);
+ Image image = m_imageMap.get(key);
if (image == null) {
try {
image = getImage(clazz.getResourceAsStream(path));
- imageMap.put(key, image);
+ m_imageMap.put(key, image);
} catch (Exception e) {
image = getMissingImage();
- imageMap.put(key, image);
+ m_imageMap.put(key, image);
}
}
return image;
}
-
private static final int MISSING_IMAGE_SIZE = 10;
-
/**
- * @return the small {@link Image} that can be used as placeholder for missing
- * image.
+ * @return the small {@link Image} that can be used as placeholder for missing image.
*/
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
@@ -185,7 +182,6 @@ public class SWTResourceManager {
//
return image;
}
-
/**
* Style constant for placing decorator image in top left corner of base image.
*/
@@ -195,13 +191,11 @@ public class SWTResourceManager {
*/
public static final int TOP_RIGHT = 2;
/**
- * Style constant for placing decorator image in bottom left corner of base
- * image.
+ * Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/**
- * Style constant for placing decorator image in bottom right corner of base
- * image.
+ * Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/**
@@ -212,77 +206,83 @@ public class SWTResourceManager {
* Maps images to decorated images.
*/
@SuppressWarnings("unchecked")
- private static Map>[] decoratedImageMap = new Map[LAST_CORNER_KEY];
-
+ private static Map>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
- * @param baseImage the base {@link Image} that should be decorated
- * @param decorator the {@link Image} to decorate the base image
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
* @return {@link Image} The resulting decorated image
*/
public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
}
-
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
- * @param baseImage the base {@link Image} that should be decorated
- * @param decorator the {@link Image} to decorate the base image
- * @param corner the corner to place decorator image
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @param corner
+ * the corner to place decorator image
* @return the resulting decorated {@link Image}
*/
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
if (corner <= 0 || corner >= LAST_CORNER_KEY) {
throw new IllegalArgumentException("Wrong decorate corner");
}
- Map> cornerDecoratedImageMap = decoratedImageMap[corner];
+ Map> cornerDecoratedImageMap = m_decoratedImageMap[corner];
if (cornerDecoratedImageMap == null) {
- cornerDecoratedImageMap = new HashMap<>();
- decoratedImageMap[corner] = cornerDecoratedImageMap;
+ cornerDecoratedImageMap = new HashMap>();
+ m_decoratedImageMap[corner] = cornerDecoratedImageMap;
}
- Map decoratedMap = cornerDecoratedImageMap.computeIfAbsent(baseImage,
- k -> new HashMap());
- return decoratedMap.computeIfAbsent(decorator, k -> {
+ Map decoratedMap = cornerDecoratedImageMap.get(baseImage);
+ if (decoratedMap == null) {
+ decoratedMap = new HashMap();
+ cornerDecoratedImageMap.put(baseImage, decoratedMap);
+ }
+ //
+ Image result = decoratedMap.get(decorator);
+ if (result == null) {
Rectangle bib = baseImage.getBounds();
Rectangle dib = decorator.getBounds();
- Image result = new Image(Display.getCurrent(), bib.width, bib.height);
+ //
+ result = new Image(Display.getCurrent(), bib.width, bib.height);
+ //
GC gc = new GC(result);
gc.drawImage(baseImage, 0, 0);
- switch (corner) {
- case TOP_LEFT:
+ if (corner == TOP_LEFT) {
gc.drawImage(decorator, 0, 0);
- break;
- case TOP_RIGHT:
+ } else if (corner == TOP_RIGHT) {
gc.drawImage(decorator, bib.width - dib.width, 0);
- break;
- case BOTTOM_LEFT:
+ } else if (corner == BOTTOM_LEFT) {
gc.drawImage(decorator, 0, bib.height - dib.height);
- break;
- case BOTTOM_RIGHT:
+ } else if (corner == BOTTOM_RIGHT) {
gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
- break;
- default:
- // do nothing
}
gc.dispose();
- return result;
- });
+ //
+ decoratedMap.put(decorator, result);
+ }
+ return result;
}
-
/**
* Dispose all of the cached {@link Image}'s.
*/
public static void disposeImages() {
// dispose loaded images
- for (Image image : imageMap.values()) {
- image.dispose();
+ {
+ for (Image image : m_imageMap.values()) {
+ image.dispose();
+ }
+ m_imageMap.clear();
}
- imageMap.clear();
// dispose decorated images
- for (int i = 0; i < decoratedImageMap.length; i++) {
- Map> cornerDecoratedImageMap = decoratedImageMap[i];
+ for (int i = 0; i < m_decoratedImageMap.length; i++) {
+ Map> cornerDecoratedImageMap = m_decoratedImageMap[i];
if (cornerDecoratedImageMap != null) {
for (Map decoratedMap : cornerDecoratedImageMap.values()) {
for (Image image : decoratedMap.values()) {
@@ -294,7 +294,6 @@ public class SWTResourceManager {
}
}
}
-
////////////////////////////////////////////////////////////////////////////
//
// Font
@@ -303,39 +302,45 @@ public class SWTResourceManager {
/**
* Maps font names to fonts.
*/
- private static Map fontMap = new HashMap<>();
+ private static Map m_fontMap = new HashMap();
/**
* Maps fonts to their bold versions.
*/
- private static Map fontToBoldFontMap = new HashMap<>();
-
+ private static Map m_fontToBoldFontMap = new HashMap();
/**
* Returns a {@link Font} based on its name, height and style.
*
- * @param name the name of the font
- * @param height the height of the font
- * @param style the style of the font
+ * @param name
+ * the name of the font
+ * @param height
+ * the height of the font
+ * @param style
+ * the style of the font
* @return {@link Font} The font matching the name, height and style
*/
public static Font getFont(String name, int height, int style) {
return getFont(name, height, style, false, false);
}
-
/**
- * Returns a {@link Font} based on its name, height and style. Windows-specific
- * strikeout and underline flags are also supported.
+ * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
+ * flags are also supported.
*
- * @param name the name of the font
- * @param size the size of the font
- * @param style the style of the font
- * @param strikeout the strikeout flag (warning: Windows only)
- * @param underline the underline flag (warning: Windows only)
- * @return {@link Font} The font matching the name, height, style, strikeout and
- * underline
+ * @param name
+ * the name of the font
+ * @param size
+ * the size of the font
+ * @param style
+ * the style of the font
+ * @param strikeout
+ * the strikeout flag (warning: Windows only)
+ * @param underline
+ * the underline flag (warning: Windows only)
+ * @return {@link Font} The font matching the name, height, style, strikeout and underline
*/
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
- return fontMap.computeIfAbsent(fontName, k -> {
+ Font font = m_fontMap.get(fontName);
+ if (font == null) {
FontData fontData = new FontData(name, size, style);
if (strikeout || underline) {
try {
@@ -349,45 +354,47 @@ public class SWTResourceManager {
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
}
}
- } catch (Exception e) {
+ } catch (Throwable e) {
+ System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
- return new Font(Display.getCurrent(), fontData);
-
- });
-
+ font = new Font(Display.getCurrent(), fontData);
+ m_fontMap.put(fontName, font);
+ }
+ return font;
}
-
/**
* Returns a bold version of the given {@link Font}.
*
- * @param baseFont the {@link Font} for which a bold version is desired
+ * @param baseFont
+ * the {@link Font} for which a bold version is desired
* @return the bold version of the given {@link Font}
*/
public static Font getBoldFont(Font baseFont) {
- return fontToBoldFontMap.computeIfAbsent(baseFont, k -> {
- FontData[] fontDatas = baseFont.getFontData();
+ Font font = m_fontToBoldFontMap.get(baseFont);
+ if (font == null) {
+ FontData fontDatas[] = baseFont.getFontData();
FontData data = fontDatas[0];
- return new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
- });
+ font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
+ m_fontToBoldFontMap.put(baseFont, font);
+ }
+ return font;
}
-
/**
* Dispose all of the cached {@link Font}'s.
*/
public static void disposeFonts() {
// clear fonts
- for (Font font : fontMap.values()) {
+ for (Font font : m_fontMap.values()) {
font.dispose();
}
- fontMap.clear();
+ m_fontMap.clear();
// clear bold fonts
- for (Font font : fontToBoldFontMap.values()) {
+ for (Font font : m_fontToBoldFontMap.values()) {
font.dispose();
}
- fontToBoldFontMap.clear();
+ m_fontToBoldFontMap.clear();
}
-
////////////////////////////////////////////////////////////////////////////
//
// Cursor
@@ -396,38 +403,40 @@ public class SWTResourceManager {
/**
* Maps IDs to cursors.
*/
- private static Map idToCursorMap = new HashMap<>();
-
+ private static Map m_idToCursorMap = new HashMap();
/**
* Returns the system cursor matching the specific ID.
*
- * @param id int The ID value for the cursor
+ * @param id
+ * int The ID value for the cursor
* @return Cursor The system cursor matching the specific ID
*/
public static Cursor getCursor(int id) {
Integer key = Integer.valueOf(id);
- return idToCursorMap.computeIfAbsent(key, k -> new Cursor(Display.getDefault(), id));
+ Cursor cursor = m_idToCursorMap.get(key);
+ if (cursor == null) {
+ cursor = new Cursor(Display.getDefault(), id);
+ m_idToCursorMap.put(key, cursor);
+ }
+ return cursor;
}
-
/**
* Dispose all of the cached cursors.
*/
public static void disposeCursors() {
- for (Cursor cursor : idToCursorMap.values()) {
+ for (Cursor cursor : m_idToCursorMap.values()) {
cursor.dispose();
}
- idToCursorMap.clear();
+ m_idToCursorMap.clear();
}
-
////////////////////////////////////////////////////////////////////////////
//
// General
//
////////////////////////////////////////////////////////////////////////////
/**
- * Dispose of cached objects and their underlying OS resources. This should only
- * be called when the cached objects are no longer needed (e.g. on application
- * shutdown).
+ * Dispose of cached objects and their underlying OS resources. This should only be called when the cached
+ * objects are no longer needed (e.g. on application shutdown).
*/
public static void dispose() {
disposeColors();
diff --git a/products/com.minres.scviewer.e4.product/scviewer.product b/products/com.minres.scviewer.e4.product/scviewer.product
index 3e2be35..fb43cfd 100644
--- a/products/com.minres.scviewer.e4.product/scviewer.product
+++ b/products/com.minres.scviewer.e4.product/scviewer.product
@@ -80,7 +80,6 @@
-