add sliuder variant

This commit is contained in:
Eyck Jentzsch 2022-01-03 14:15:59 +01:00
parent 5a372d0f90
commit 93a8c067fc
20 changed files with 1737 additions and 444 deletions

View File

@ -56,13 +56,13 @@ import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout; import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
@ -71,7 +71,6 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Slider;
import org.eclipse.swt.widgets.Widget; import org.eclipse.swt.widgets.Widget;
import org.eclipse.wb.swt.SWTResourceManager; import org.eclipse.wb.swt.SWTResourceManager;
@ -94,6 +93,8 @@ import com.minres.scviewer.database.ui.IWaveformStyleProvider;
import com.minres.scviewer.database.ui.IWaveformView; import com.minres.scviewer.database.ui.IWaveformView;
import com.minres.scviewer.database.ui.IWaveformZoom; import com.minres.scviewer.database.ui.IWaveformZoom;
import com.minres.scviewer.database.ui.TrackEntry; import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.swt.internal.slider.ImageButton;
import com.minres.scviewer.database.ui.swt.internal.slider.RangeSlider;
import com.minres.scviewer.database.ui.swt.sb.FlatScrollBar; import com.minres.scviewer.database.ui.swt.sb.FlatScrollBar;
public class WaveformView implements IWaveformView { public class WaveformView implements IWaveformView {
@ -345,10 +346,36 @@ public class WaveformView implements IWaveformView {
waveformCanvas = new WaveformCanvas(waveformPane, SWT.NONE | SWT.V_SCROLL /*| SWT.H_SCROLL*/, styleProvider); waveformCanvas = new WaveformCanvas(waveformPane, SWT.NONE | SWT.V_SCROLL /*| SWT.H_SCROLL*/, styleProvider);
waveformCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); waveformCanvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
Composite timeSliderPane = new WaveformSlider(waveformPane, SWT.NONE);
GridData gd_timeSlider = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1); //Composite timeSliderPane = new WaveformSlider(waveformPane, SWT.NONE);
gd_timeSlider.heightHint = 18; Composite timeSliderPane = new Composite(waveformPane, SWT.NONE);
timeSliderPane.setLayoutData(gd_timeSlider); // timeSliderPane.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
GridData gd_timeSliderPane = new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1);
// gd_timeSliderPane.heightHint = 22;
timeSliderPane.setLayoutData(gd_timeSliderPane);
GridLayout gl_timeSliderPane = new GridLayout(3, false);
gl_timeSliderPane.marginHeight=0;
gl_timeSliderPane.marginWidth=0;
gl_timeSliderPane.horizontalSpacing=0;
gl_timeSliderPane.verticalSpacing=0;
timeSliderPane.setLayout(gl_timeSliderPane);
ImageButton b1 = new ImageButton(timeSliderPane, SWT.NONE);
GridData gd_b1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_b1.widthHint=18;
gd_b1.heightHint=18;
b1.setLayoutData(gd_b1);
b1.setImage(SWTResourceManager.getImage(RangeSlider.class, "bullet_left.png"));
Composite timeSlider = new RangeSlider(timeSliderPane, SWT.ON|SWT.HIGH|SWT.SMOOTH|SWT.CONTROL);
GridData gd_timeSlide = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
timeSlider.setLayoutData(gd_timeSlide);
ImageButton b2 = new ImageButton(timeSliderPane, SWT.NONE);
GridData gd_b2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_b2.widthHint=18;
gd_b2.heightHint=18;
b2.setLayoutData(gd_b2);
b2.setImage(SWTResourceManager.getImage(RangeSlider.class, "bullet_right.png"));
// create the name pane // create the name pane
createTextPane(namePane, "Name"); createTextPane(namePane, "Name");

View File

@ -0,0 +1,129 @@
package com.minres.scviewer.database.ui.swt.internal.slider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
public class ImageButton extends Composite
{
private Color textColor;
private Image image;
private Image grayImage;
private ImageData imageData;
private String text = "";
private int width;
private int height;
private boolean hover;
public ImageButton(Composite parent, int style)
{
super(parent, style);
textColor = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
/* Add dispose listener for the image */
addListener(SWT.Dispose, event -> {
if (image != null)
image.dispose();
});
/* Add custom paint listener that paints the stars */
addListener(SWT.Paint, event -> {
paintControl(event);
});
/* Listen for click events */
addListener(SWT.MouseDown, event -> {
System.out.println("Click");
});
addListener(SWT.MouseDown, event -> {
});
addListener(SWT.MouseUp, event -> {
});
addListener(SWT.MouseMove, event -> {
hover=false;
redraw();
});
addListener(SWT.MouseWheel, event -> {
});
addListener(SWT.MouseHover, event -> {
hover=true;
redraw();
});
addListener(SWT.MouseDoubleClick, event -> {
});
}
private void paintControl(Event event) {
GC gc = event.gc;
if (image != null)
{
// gc.drawImage(image, 1, 1);
// if(hover) {
// Rectangle rect = image.getBounds ();
// Transform tr = new Transform (event.display);
// tr.setElements (1, 0, 0, -1, 1, 2*(1+rect.height));
// gc.setTransform (tr);
// gc.drawImage (image, 1, 1);
// gc.setTransform (null);
// }
if(hover) {
gc.drawImage(image, 1, 1);
} else {
gc.drawImage(grayImage, 1, 1);
}
Point textSize = gc.textExtent(text);
gc.setForeground(textColor);
gc.drawText(text, (width - textSize.x) / 2 + 1, (height - textSize.y) / 2 + 1, true);
}
}
public void setImage(Image img)
{
image = new Image(Display.getDefault(), img, SWT.IMAGE_COPY);
grayImage = new Image(Display.getDefault(),img,SWT.IMAGE_GRAY);
width = img.getBounds().width;
height = img.getBounds().height;
imageData = img.getImageData();
redraw();
}
public void setText(String text)
{
this.text = text;
redraw();
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed)
{
int overallWidth = width;
int overallHeight = height;
/* Consider hints */
if (wHint != SWT.DEFAULT && wHint < overallWidth)
overallWidth = wHint;
if (hHint != SWT.DEFAULT && hHint < overallHeight)
overallHeight = hHint;
/* Return computed dimensions plus border */
return new Point(overallWidth + 2, overallHeight + 2);
}
}

View File

@ -0,0 +1,48 @@
package com.minres.scviewer.database.ui.swt.internal.slider;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ReflectionUtils {
/**
* Call a method using introspection (so ones can call a private or protected method)
* @param object object on which the method will be called
* @param methodName method name
* @param args arguments of this method (can be null)
* @return the value returned by this method (if this method returns a value)
*/
public static Object callMethod(final Object object, final String methodName, final Object... args) {
if (object == null) {
return null;
}
final Class<?>[] array = new Class<?>[args == null ? 0 : args.length];
int index = 0;
if (args != null) {
for (final Object o : args) {
array[index++] = o == null ? Object.class : o.getClass();
}
}
return callMethodWithClassType(object, methodName, array, args);
}
private static Object callMethodWithClassType(final Object object, final String methodName, final Class<?>[] array, final Object... args) {
Class<?> currentClass = object.getClass();
Method method = null;
while (currentClass != null) {
try {
method = currentClass.getDeclaredMethod(methodName, array);
break;
} catch (final NoSuchMethodException nsme) {
currentClass = currentClass.getSuperclass();
}
}
try {
method.setAccessible(true);
return method.invoke(object, args);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,74 @@
package com.minres.scviewer.database.ui.swt.internal.slider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TypedListener;
public class SelectionListenerUtil {
/**
* Add a <code>SelectionListener</code> to a given Control
*
* @param control control on which the selection listener is added
* @param listener listener to add
*/
public static void addSelectionListener(final Control control, final SelectionListener listener) {
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
TypedListener typedListener = new TypedListener(listener);
control.addListener(SWT.Selection, typedListener);
}
/**
* Remove a <code>SelectionListener</code> of a given Control
*
* @param control control on which the selection listener is removed
* @param listener listener to remove
*/
public static void removeSelectionListener(final Control control, final SelectionListener listener) {
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final Listener[] listeners = control.getListeners(SWT.Selection);
for (Listener l : listeners) {
if (l instanceof TypedListener) {
TypedListener typedListener = (TypedListener) l;
if (typedListener.getEventListener() == listener) {
ReflectionUtils.callMethod(control, "removeListener", SWT.Selection, ((TypedListener) l).getEventListener());
return;
}
}
}
}
/**
* Fire the selection listeners of a given control
*
* @param control the control that fires the event
* @param sourceEvent mouse event
* @return true if the selection could be changed, false otherwise
*/
public static boolean fireSelectionListeners(final Control control, final Event sourceEvent) {
for (final Listener listener : control.getListeners(SWT.Selection)) {
final Event event = new Event();
event.button = sourceEvent==null?1:sourceEvent.button;
event.display = control.getDisplay();
event.item = null;
event.widget = control;
event.data = sourceEvent == null ? null : sourceEvent.data;
event.time = sourceEvent == null ? 0 : sourceEvent.time;
event.x = sourceEvent == null ? 0 : sourceEvent.x;
event.y = sourceEvent == null ? 0 : sourceEvent.y;
event.type = SWT.Selection;
listener.handleEvent(event);
if (!event.doit) {
return false;
}
}
return true;
}
}

View File

@ -1,438 +0,0 @@
/*******************************************************************************
* 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 <code>dispose()</code> 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.
* <p>
*
* @author scheglov_ke
* @author Dan Rubel
* @author Wim Jongman
*/
public class ResourceManager extends SWTResourceManager {
/**
* The map where we store our images.
*/
private static Map<ImageDescriptor, Image> m_descriptorImageMap = new HashMap<ImageDescriptor, Image>();
/**
* 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<Image, Map<Image, Image>>[] 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<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
if (cornerDecoratedImageMap == null) {
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
m_decoratedImageMap[corner] = cornerDecoratedImageMap;
}
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
if (decoratedMap == null) {
decoratedMap = new HashMap<Image, Image>();
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<Image> 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<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
if (cornerDecoratedImageMap != null) {
for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
for (Image image : decoratedMap.values()) {
image.dispose();
}
decoratedMap.clear();
}
cornerDecoratedImageMap.clear();
}
}
// dispose plugin images
{
for (Iterator<Image> I = m_URLImageMap.values().iterator(); I.hasNext();) {
I.next().dispose();
}
m_URLImageMap.clear();
}
}
////////////////////////////////////////////////////////////////////////////
//
// Plugin images support
//
////////////////////////////////////////////////////////////////////////////
/**
* Maps URL to images.
*/
private static Map<String, Image> m_URLImageMap = new HashMap<String, Image>();
/**
* 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();
}
}