add dynamic update of waveform list
This commit is contained in:
@@ -13,8 +13,6 @@ 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;
|
||||
@@ -61,7 +59,7 @@ public class ResourceManager extends SWTResourceManager {
|
||||
/**
|
||||
* The map where we store our images.
|
||||
*/
|
||||
private static Map<ImageDescriptor, Image> m_descriptorImageMap = new HashMap<ImageDescriptor, Image>();
|
||||
private static Map<ImageDescriptor, Image> descriptorImageMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Returns an {@link ImageDescriptor} stored in the file at the specified path
|
||||
@@ -97,22 +95,16 @@ public class ResourceManager extends SWTResourceManager {
|
||||
* @return the {@link Image} based on the specified {@link ImageDescriptor}.
|
||||
*/
|
||||
public static Image getImage(ImageDescriptor descriptor) {
|
||||
if (descriptor == null) {
|
||||
if (descriptor == null)
|
||||
return null;
|
||||
}
|
||||
Image image = m_descriptorImageMap.get(descriptor);
|
||||
if (image == null) {
|
||||
image = descriptor.createImage();
|
||||
m_descriptorImageMap.put(descriptor, image);
|
||||
}
|
||||
return image;
|
||||
return descriptorImageMap.computeIfAbsent(descriptor, ImageDescriptor::createImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps images to decorated images.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
|
||||
private static Map<Image, Map<Image, Image>>[] decoratedImageMap = new Map[LAST_CORNER_KEY];
|
||||
|
||||
/**
|
||||
* Returns an {@link Image} composed of a base image decorated by another image.
|
||||
@@ -140,17 +132,12 @@ public class ResourceManager extends SWTResourceManager {
|
||||
if (corner <= 0 || corner >= LAST_CORNER_KEY) {
|
||||
throw new IllegalArgumentException(Messages.ResourceManager_0);
|
||||
}
|
||||
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
|
||||
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = decoratedImageMap[corner];
|
||||
if (cornerDecoratedImageMap == null) {
|
||||
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
|
||||
m_decoratedImageMap[corner] = cornerDecoratedImageMap;
|
||||
cornerDecoratedImageMap = new HashMap<>();
|
||||
decoratedImageMap[corner] = cornerDecoratedImageMap;
|
||||
}
|
||||
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
|
||||
if (decoratedMap == null) {
|
||||
decoratedMap = new HashMap<Image, Image>();
|
||||
cornerDecoratedImageMap.put(baseImage, decoratedMap);
|
||||
}
|
||||
//
|
||||
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.computeIfAbsent(baseImage, k -> new HashMap<Image, Image>());
|
||||
Image result = decoratedMap.get(decorator);
|
||||
if (result == null) {
|
||||
final Rectangle bib = baseImage.getBounds();
|
||||
@@ -181,7 +168,7 @@ public class ResourceManager extends SWTResourceManager {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) {
|
||||
return zoom -> zoom == 100 ? imageData : null;
|
||||
}
|
||||
@@ -193,15 +180,13 @@ public class ResourceManager extends SWTResourceManager {
|
||||
public static void disposeImages() {
|
||||
SWTResourceManager.disposeImages();
|
||||
// dispose ImageDescriptor images
|
||||
{
|
||||
for (Iterator<Image> I = m_descriptorImageMap.values().iterator(); I.hasNext();) {
|
||||
I.next().dispose();
|
||||
}
|
||||
m_descriptorImageMap.clear();
|
||||
for (Iterator<Image> I = descriptorImageMap.values().iterator(); I.hasNext();) {
|
||||
I.next().dispose();
|
||||
}
|
||||
descriptorImageMap.clear();
|
||||
// dispose decorated images
|
||||
for (int i = 0; i < m_decoratedImageMap.length; i++) {
|
||||
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
|
||||
for (int i = 0; i < decoratedImageMap.length; i++) {
|
||||
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = decoratedImageMap[i];
|
||||
if (cornerDecoratedImageMap != null) {
|
||||
for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
|
||||
for (Image image : decoratedMap.values()) {
|
||||
@@ -213,12 +198,10 @@ public class ResourceManager extends SWTResourceManager {
|
||||
}
|
||||
}
|
||||
// dispose plugin images
|
||||
{
|
||||
for (Iterator<Image> I = m_URLImageMap.values().iterator(); I.hasNext();) {
|
||||
I.next().dispose();
|
||||
}
|
||||
m_URLImageMap.clear();
|
||||
for (Iterator<Image> I = urlImageMap.values().iterator(); I.hasNext();) {
|
||||
I.next().dispose();
|
||||
}
|
||||
urlImageMap.clear();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@@ -229,7 +212,7 @@ public class ResourceManager extends SWTResourceManager {
|
||||
/**
|
||||
* Maps URL to images.
|
||||
*/
|
||||
private static Map<String, Image> m_URLImageMap = new HashMap<String, Image>();
|
||||
private static Map<String, Image> urlImageMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Provider for plugin resources, used by WindowBuilder at design time.
|
||||
@@ -242,29 +225,7 @@ public class ResourceManager extends SWTResourceManager {
|
||||
* 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;
|
||||
}
|
||||
private static PluginResourceProvider designTimePluginResourceProvider = null;
|
||||
|
||||
/**
|
||||
* Returns an {@link Image} based on a {@link Bundle} and resource entry path.
|
||||
@@ -279,7 +240,7 @@ public class ResourceManager extends SWTResourceManager {
|
||||
if (url != null) {
|
||||
return getPluginImageFromUrl(url);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
// Ignore any exceptions
|
||||
}
|
||||
return null;
|
||||
@@ -290,47 +251,19 @@ public class ResourceManager extends SWTResourceManager {
|
||||
*/
|
||||
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();
|
||||
}
|
||||
String key = url.toExternalForm();
|
||||
Image image = urlImageMap.get(key);
|
||||
if (image == null) {
|
||||
InputStream stream = url.openStream();
|
||||
try {
|
||||
image = getImage(stream);
|
||||
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) {
|
||||
return image;
|
||||
} catch (Exception e) {
|
||||
// Ignore any exceptions
|
||||
}
|
||||
return null;
|
||||
@@ -351,7 +284,7 @@ public class ResourceManager extends SWTResourceManager {
|
||||
if (url != null) {
|
||||
return ImageDescriptor.createFromURL(url);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
// Ignore any exceptions
|
||||
}
|
||||
return null;
|
||||
@@ -362,66 +295,18 @@ public class ResourceManager extends SWTResourceManager {
|
||||
*/
|
||||
private static URL getPluginImageURL(String symbolicName, String path) {
|
||||
// try runtime plugins
|
||||
{
|
||||
Bundle bundle = Platform.getBundle(symbolicName);
|
||||
if (bundle != null) {
|
||||
return bundle.getEntry(path);
|
||||
}
|
||||
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);
|
||||
if (designTimePluginResourceProvider != null) {
|
||||
return 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
|
||||
|
Reference in New Issue
Block a user