add search dialog and pane

This commit is contained in:
2020-10-29 07:48:35 +01:00
parent 38a046aaef
commit 6be1f018b1
9 changed files with 412 additions and 105 deletions

View File

@@ -1,13 +1,14 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH 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:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
/*******************************************************************************
* 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;
@@ -24,51 +25,61 @@ 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;
import org.osgi.framework.Bundle;
import com.minres.scviewer.e4.application.Messages;
/**
* Utility class for managing OS resources associated with SWT/JFace controls such as colors, fonts, images,
* etc.
* Utility class for managing OS resources associated with SWT/JFace controls
* such as colors, fonts, images, etc.
*
* !!! IMPORTANT !!! 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 (e.g. on application shutdown)
* 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 {
////////////////////////////////////////////////////////////////////////////
//
// Image
//
////////////////////////////////////////////////////////////////////////////
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.
* 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.
* @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.
* @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) {
@@ -78,11 +89,11 @@ public class ResourceManager extends SWTResourceManager {
return null;
}
}
/**
* Returns an {@link Image} based on the specified {@link ImageDescriptor}.
*
* @param descriptor
* the {@link ImageDescriptor} for the {@link Image}.
* @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) {
@@ -96,23 +107,24 @@ public class ResourceManager extends SWTResourceManager {
}
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.
* @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.
*
@@ -149,13 +161,13 @@ public class ResourceManager extends SWTResourceManager {
protected void drawCompositeImage(int width, int height) {
drawImage(createCachedImageDataProvider(baseImage), 0, 0);
if (corner == TOP_LEFT) {
drawImage(createCachedImageDataProvider(decorator), 0, 0);
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()) , 0, 0);
} else if (corner == TOP_RIGHT) {
drawImage(createCachedImageDataProvider(decorator), bib.width - dib.width, 0);
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, 0);
} else if (corner == BOTTOM_LEFT) {
drawImage(createCachedImageDataProvider(decorator), 0, bib.height - dib.height);
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), 0, bib.height - dib.height);
} else if (corner == BOTTOM_RIGHT) {
drawImage(createCachedImageDataProvider(decorator), bib.width - dib.width, bib.height - dib.height);
drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, bib.height - dib.height);
}
}
@Override
@@ -169,6 +181,12 @@ public class ResourceManager extends SWTResourceManager {
}
return result;
}
private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) {
return zoom -> zoom == 100 ? imageData : null;
}
/**
* Dispose all of the cached images.
*/
@@ -202,6 +220,7 @@ public class ResourceManager extends SWTResourceManager {
m_URLImageMap.clear();
}
}
////////////////////////////////////////////////////////////////////////////
//
// Plugin images support
@@ -211,23 +230,25 @@ public class ResourceManager extends SWTResourceManager {
* 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.
* 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
* @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.
@@ -244,13 +265,12 @@ public class ResourceManager extends SWTResourceManager {
}
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.
* @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) {
@@ -264,6 +284,7 @@ public class ResourceManager extends SWTResourceManager {
}
return null;
}
/**
* Returns an {@link Image} based on given {@link URL}.
*/
@@ -290,13 +311,12 @@ public class ResourceManager extends SWTResourceManager {
}
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.
* @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.
@@ -315,14 +335,15 @@ public class ResourceManager extends SWTResourceManager {
}
return null;
}
/**
* Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource entry path.
* 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.
* @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 {
@@ -335,6 +356,7 @@ public class ResourceManager extends SWTResourceManager {
}
return null;
}
/**
* Returns an {@link URL} based on a {@link Bundle} and resource entry path.
*/
@@ -353,13 +375,12 @@ public class ResourceManager extends SWTResourceManager {
// 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.
* @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
*/
@@ -373,13 +394,13 @@ public class ResourceManager extends SWTResourceManager {
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});
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});
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
@@ -390,24 +411,26 @@ public class ResourceManager extends SWTResourceManager {
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});
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});
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).
* 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();