Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah Graham2018-11-20 11:20:42 -0500
committerJonah Graham2018-11-22 16:47:02 -0500
commit170e654b4796bad1453ae85a427b97317d67a69a (patch)
tree6ca9b8a8fedd5fd25f97eb79c408312e256ff981 /visualizer
parent35996a5c5ca5c254959ba48241eaada6dbf8628d (diff)
downloadorg.eclipse.cdt-170e654b4796bad1453ae85a427b97317d67a69a.tar.gz
org.eclipse.cdt-170e654b4796bad1453ae85a427b97317d67a69a.tar.xz
org.eclipse.cdt-170e654b4796bad1453ae85a427b97317d67a69a.zip
Bug 540373: Cleanup: Format & Remove trailing whitespace
This was done by selecting all projects in Eclipse then Source -> Clean Up... -> choosing: - Format source code - Remove trailing white spaces on all lines and completing the wizard Change-Id: I63685372c6bcc67719bcf145123bcb72e5b00394
Diffstat (limited to 'visualizer')
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java62
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java113
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java80
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java39
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/VisualizerExamplesPlugin.java25
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/BarGraphicObject.java2
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ProblemVisualizer.java33
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ResizableGraphicCanvas.java2
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphControl.java121
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphVisualizer.java67
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizer.java61
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizerViewer.java47
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/Visualizer.java99
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerAction.java25
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerView.java186
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerViewer.java322
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/BufferedCanvas.java115
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvas.java53
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvasVisualizer.java66
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicObject.java274
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/IGraphicObject.java16
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/VirtualBoundsGraphicObject.java55
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/IVisualizerViewerListener.java8
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/VisualizerViewerEvent.java35
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/plugin/CDTVisualizerUIPlugin.java53
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvas.java34
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvasVisualizer.java58
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Colors.java70
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Event.java43
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/GUIUtils.java158
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ListenerList.java50
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/MouseMonitor.java255
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/RunnableWithResult.java66
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ScrollPanel.java51
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionManager.java150
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionProviderAdapter.java39
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionUtils.java166
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Timer.java84
-rw-r--r--visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Todo.java27
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/UIResourceManager.java465
-rwxr-xr-xvisualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/WorkbenchSelectionAdapter.java78
41 files changed, 1704 insertions, 2049 deletions
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java
index 34576be373..ee566d3f62 100644
--- a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/Extension.java
@@ -21,75 +21,63 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
-
// ---------------------------------------------------------------------------
// Extension
// ---------------------------------------------------------------------------
/** Facade/utility class for dealing with Eclipse extensions. */
-public class Extension extends ExtensionElement
-{
+public class Extension extends ExtensionElement {
// --- static methods ---
-
- /** Gets extension point declaration with specified full ID (including plugin ID prefix). */
- public static IExtensionPoint getExtensionPoint(String extensionPointID)
- {
- IExtensionPoint extensionPoint =
- Platform.getExtensionRegistry().getExtensionPoint(
- extensionPointID);
+
+ /** Gets extension point declaration with specified full ID (including plugin ID prefix). */
+ public static IExtensionPoint getExtensionPoint(String extensionPointID) {
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(extensionPointID);
return extensionPoint;
- }
-
- /** Gets extension point declaration with specified name defined by specified plugin. */
- public static IExtensionPoint getExtensionPoint(String pluginID, String extensionPointName)
- {
- IExtensionPoint extensionPoint =
- Platform.getExtensionRegistry().getExtensionPoint(
- pluginID, extensionPointName);
+ }
+
+ /** Gets extension point declaration with specified name defined by specified plugin. */
+ public static IExtensionPoint getExtensionPoint(String pluginID, String extensionPointName) {
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(pluginID,
+ extensionPointName);
return extensionPoint;
- }
+ }
/** Gets list of extensions for specified extension point ID (including plugin ID prefix). */
- public static List<Extension> getExtensions(String extensionPointID)
- {
+ public static List<Extension> getExtensions(String extensionPointID) {
IExtensionPoint extensionPoint = getExtensionPoint(extensionPointID);
return getExtensions(extensionPoint);
}
/** Gets list of extensions for specified plugin and extension point name. */
- public static List<Extension> getExtensions(String pluginID, String extensionPointName)
- {
+ public static List<Extension> getExtensions(String pluginID, String extensionPointName) {
IExtensionPoint extensionPoint = getExtensionPoint(pluginID, extensionPointName);
return getExtensions(extensionPoint);
}
-
+
/** Gets list of extensions for specified plugin and extension point name. */
- public static List<Extension> getExtensions(IExtensionPoint extensionPoint)
- {
- return (extensionPoint == null) ? null :
- Extension.wrapExtensions(extensionPoint.getConfigurationElements());
+ public static List<Extension> getExtensions(IExtensionPoint extensionPoint) {
+ return (extensionPoint == null) ? null : Extension.wrapExtensions(extensionPoint.getConfigurationElements());
}
/** Wraps list of raw extension declarations. */
- public static List<Extension> wrapExtensions(IConfigurationElement[] elements)
- {
+ public static List<Extension> wrapExtensions(IConfigurationElement[] elements) {
int count = (elements == null) ? 0 : elements.length;
List<Extension> result = new ArrayList<Extension>(count);
- for (int i=0; i<count; ++i) {
+ for (int i = 0; i < count; ++i) {
result.add(new Extension(elements[i]));
}
return result;
}
-
- // --- members ---
-
+
+ // --- members ---
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public Extension(IConfigurationElement element) {
super(element);
}
-
+
// --- methods ---
-
+
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java
index 5c9d1afad6..7bedb65711 100755
--- a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ExtensionElement.java
@@ -27,80 +27,69 @@ import org.eclipse.core.runtime.IContributor;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
-
// ---------------------------------------------------------------------------
// ExtensionElement
// ---------------------------------------------------------------------------
/** Facade/utility class for dealing with Eclipse extensions. */
public class ExtensionElement {
-
+
// --- static methods ---
-
+
/** Wraps list of raw extension declarations. */
- public static List<ExtensionElement> wrapExtensionElements(IConfigurationElement[] elements)
- {
+ public static List<ExtensionElement> wrapExtensionElements(IConfigurationElement[] elements) {
int count = (elements == null) ? 0 : elements.length;
List<ExtensionElement> result = new ArrayList<ExtensionElement>(count);
- for (int i=0; i<count; ++i) {
+ for (int i = 0; i < count; ++i) {
result.add(new ExtensionElement(elements[i]));
}
return result;
}
-
- // --- members ---
-
+ // --- members ---
+
/** Actual extension description loaded from extension point. */
protected IConfigurationElement m_element = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public ExtensionElement(IConfigurationElement element) {
m_element = element;
}
-
-
+
// --- methods ---
-
+
/** Gets string value of specified attribute. */
- public String getAttribute(String attributeName)
- {
+ public String getAttribute(String attributeName) {
return m_element.getAttribute(attributeName);
}
-
+
/** Creates and returns instance of implementing class, using class name found in "class" attribute. */
- public <T> T getClassAttribute()
- {
+ public <T> T getClassAttribute() {
return getClassAttribute("class");
}
-
+
/** Creates and returns instance of implementing class, using class name found in specified attribute. */
@SuppressWarnings("unchecked")
- public <T> T getClassAttribute(String attributeName)
- {
+ public <T> T getClassAttribute(String attributeName) {
T result = null;
try {
// TODO: Hmm... is there a right way to do this, without an unchecked cast?
result = (T) m_element.createExecutableExtension(attributeName);
- }
- catch (ClassCastException ex) {
+ } catch (ClassCastException ex) {
// For now, eat it, and don't return this extension.
// TODO: decide how to log this
- }
- catch (CoreException ex) {
+ } catch (CoreException ex) {
// For now, eat it, and don't return this extension.
// TODO: decide how to log this
}
return result;
- }
-
+ }
+
/** Creates and returns instance of implementing class, using class name found in specified attribute. */
@SuppressWarnings("unchecked")
- public <T> T getClassAttribute(String attributeName, Object... arguments)
- {
+ public <T> T getClassAttribute(String attributeName, Object... arguments) {
// Make sure we default to zero-argument form if we can.
if (arguments == null || arguments.length == 0)
return getClassAttribute(attributeName);
@@ -109,55 +98,45 @@ public class ExtensionElement {
T result = null;
try {
// Get name of class we're trying to load from attribute.
- String className = getAttribute(attributeName);
-
- // Attempt to load class using the source plugin's class loader.
- // TODO: is there a better way?
- IContributor contributor = m_element.getContributor();
- String pluginID = contributor.getName();
- Bundle plugin = Platform.getBundle(pluginID);
- Class<?> instance = plugin.loadClass(className);
-
- // Select appropriate constructor for provided argument(s).
- int argumentsLength = (arguments == null) ? 0 : arguments.length;
+ String className = getAttribute(attributeName);
+
+ // Attempt to load class using the source plugin's class loader.
+ // TODO: is there a better way?
+ IContributor contributor = m_element.getContributor();
+ String pluginID = contributor.getName();
+ Bundle plugin = Platform.getBundle(pluginID);
+ Class<?> instance = plugin.loadClass(className);
+
+ // Select appropriate constructor for provided argument(s).
+ int argumentsLength = (arguments == null) ? 0 : arguments.length;
Class<?>[] argumentTypes = new Class<?>[argumentsLength];
- for (int i=0; i<argumentsLength; ++i) {
- argumentTypes[i] =
- (arguments[i] == null) ? NullType.class : arguments[i].getClass();
+ for (int i = 0; i < argumentsLength; ++i) {
+ argumentTypes[i] = (arguments[i] == null) ? NullType.class : arguments[i].getClass();
}
- Constructor<?> constructor = (Constructor<?>)
- instance.getConstructor(argumentTypes);
+ Constructor<?> constructor = (Constructor<?>) instance.getConstructor(argumentTypes);
- // Invoke the constructor.
- result = (T) constructor.newInstance(arguments);
- }
- catch (ClassNotFoundException ex) {
+ // Invoke the constructor.
+ result = (T) constructor.newInstance(arguments);
+ } catch (ClassNotFoundException ex) {
// TODO: decide how to log this
- }
- catch (NoSuchMethodException ex) {
+ } catch (NoSuchMethodException ex) {
// TODO: decide how to log this
- }
- catch (InvocationTargetException ex) {
+ } catch (InvocationTargetException ex) {
// TODO: decide how to log this
- }
- catch (IllegalAccessException ex) {
+ } catch (IllegalAccessException ex) {
// TODO: decide how to log this
- }
- catch (InstantiationException ex) {
+ } catch (InstantiationException ex) {
// TODO: decide how to log this
- }
- catch (ClassCastException ex) {
+ } catch (ClassCastException ex) {
// TODO: decide how to log this
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
// TODO: decide how to log this
}
return result;
- }
-
+ }
+
/** Returns child elements of this element. */
- public List<ExtensionElement> getChildren()
- {
+ public List<ExtensionElement> getChildren() {
return wrapExtensionElements(m_element.getChildren());
}
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java
index 54d4197f7d..4770ee4635 100755
--- a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/ResourceManager.java
@@ -21,7 +21,6 @@ import java.util.ResourceBundle;
import org.eclipse.core.runtime.Plugin;
-
// ---------------------------------------------------------------------------
// ResourceManager
// ---------------------------------------------------------------------------
@@ -31,28 +30,27 @@ import org.eclipse.core.runtime.Plugin;
* This class should be instanced in the plugin's "start()" method,
* and disposed in the "stop()" method.
*/
-public class ResourceManager{
-
+public class ResourceManager {
+
// --- members ---
-
+
/** Plugin ID */
protected String m_pluginID = null;
-
+
/** Plugin */
protected Plugin m_plugin = null;
-
+
/** Parent resource manager, if any */
protected ResourceManager m_parentManager = null;
-
+
/** String resource manager */
protected ResourceBundle m_stringResources = null;
-
+
/** String resource property file name */
protected String m_stringResourceFilename = null;
-
-
+
// --- constructors/destructors ---
-
+
/**
* Constructor,
* Assumes string resources are in the file "messages.properties".
@@ -68,7 +66,7 @@ public class ResourceManager{
m_stringResourceFilename = stringResourceFilename;
getStringRegistry(); // creates registry object
}
-
+
/** Dispose method */
public void dispose() {
disposeStringRegistry();
@@ -76,18 +74,16 @@ public class ResourceManager{
m_plugin = null;
m_pluginID = null;
}
-
-
+
// --- accessors ---
-
+
/** Returns plugin we're associated with */
public Plugin getPlugin() {
return m_plugin;
}
-
-
+
// --- parent manager management ---
-
+
/** Sets parent resource manager, if any */
public void setParentManager(ResourceManager parentManager) {
m_parentManager = parentManager;
@@ -98,7 +94,6 @@ public class ResourceManager{
return m_parentManager;
}
-
// --- string resource management ---
/** Creates/returns string registry */
@@ -109,40 +104,33 @@ public class ResourceManager{
// The ".properties" extension is assumed, so we trim it here
String propertiesExtension = ".properties";
if (filename.endsWith(propertiesExtension)) {
- filename = filename.substring(0, filename.length() -
- propertiesExtension.length());
+ filename = filename.substring(0, filename.length() - propertiesExtension.length());
}
-
+
// NOTE: We have to be careful to pick up the class loader
// from the plugin class, otherwise we default to the classloader
// of the ResourceManager class, which is the classloader
// for the plugin the ResourceManager comes from.
ClassLoader classLoader = m_plugin.getClass().getClassLoader();
Locale locale = Locale.getDefault();
-
+
// we'll check for .properties file first
// in the same directory as the plugin activator class
String propertyFileName1 = m_pluginID + ".plugin." + filename;
try {
- m_stringResources =
- ResourceBundle.getBundle(propertyFileName1,
- locale, classLoader);
- }
- catch (MissingResourceException e) {
+ m_stringResources = ResourceBundle.getBundle(propertyFileName1, locale, classLoader);
+ } catch (MissingResourceException e) {
// TODO: log this exception (probably a .properties file is missing)
m_stringResources = null;
}
-
- // if not found, we try in the default package
+
+ // if not found, we try in the default package
// (that is, the top-level "src" or "resources" folder)
String propertyFileName2 = filename;
if (m_stringResources == null) {
try {
- m_stringResources =
- ResourceBundle.getBundle(propertyFileName2,
- locale, classLoader);
- }
- catch (MissingResourceException e) {
+ m_stringResources = ResourceBundle.getBundle(propertyFileName2, locale, classLoader);
+ } catch (MissingResourceException e) {
// TODO: log this exception (probably a .properties file is missing)
m_stringResources = null;
}
@@ -150,29 +138,28 @@ public class ResourceManager{
}
return m_stringResources;
}
-
+
/** Disposes of string registry */
protected void disposeStringRegistry() {
m_stringResources = null;
}
-
+
/** Returns string resource for specified key */
public String getString(String key) {
String result = null;
- if (key == null) return "(null resource)";
-
+ if (key == null)
+ return "(null resource)";
+
// get string registry, look up key
ResourceBundle strings = getStringRegistry();
if (strings == null) {
// if we can't get the registry, display the key instead,
// so we know what's missing (e.g. the .properties file)
result = "(" + key + ")";
- }
- else {
+ } else {
try {
result = strings.getString(key);
- }
- catch (MissingResourceException e) {
+ } catch (MissingResourceException e) {
// we fail, but don't throw an exception
// so we don't screw any UI setup that depends
// on this string resource
@@ -184,13 +171,14 @@ public class ResourceManager{
if (result == null && m_parentManager != null) {
result = m_parentManager.getString(key);
}
-
+
// if we still fail, display the key instead,
// so we know what's missing
- if (result == null) result = "[" + key + "]";
+ if (result == null)
+ result = "[" + key + "]";
return result;
}
-
+
/** Formats string resource with specified argument(s) */
public String getString(String key, Object... arguments) {
return MessageFormat.format(getString(key), arguments);
diff --git a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java
index 1a1f8cd961..5a38244499 100755
--- a/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java
+++ b/visualizer/org.eclipse.cdt.visualizer.core/src/org/eclipse/cdt/visualizer/core/plugin/CDTVisualizerCorePlugin.java
@@ -20,24 +20,21 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
-
// ----------------------------------------------------------------------------
// CDTVisualizerCorePlugin
// ----------------------------------------------------------------------------
/**
* CDT visualizer core plugin class.
- *
+ *
* This plugin contains the non-UI components of the visualizer framework.
*/
-public class CDTVisualizerCorePlugin extends AbstractUIPlugin
-{
+public class CDTVisualizerCorePlugin extends AbstractUIPlugin {
// --- constants ---
-
+
/** The plug-in ID */
public static final String PLUGIN_ID = "org.eclipse.cdt.visualizer.core"; //$NON-NLS-1$
-
// --- static members ---
/** Singleton instance */
@@ -51,25 +48,23 @@ public class CDTVisualizerCorePlugin extends AbstractUIPlugin
/** Resource manager */
protected static ResourceManager s_resources = null;
-
// --- constructors/destructors ---
-
+
/** Constructor */
public CDTVisualizerCorePlugin() {
}
-
// --- plugin startup/shutdown methods ---
/** Invoked when plugin is loaded. */
public void start(BundleContext context) throws Exception {
super.start(context);
s_plugin = this;
-
+
// touch activator classes of any plugins we depend on,
// to ensure their start() methods are called first
// (None for now.)
-
+
// initialize resource management (strings, images, fonts, colors, etc.)
getPluginResources();
}
@@ -78,28 +73,25 @@ public class CDTVisualizerCorePlugin extends AbstractUIPlugin
public void stop(BundleContext context) throws Exception {
// clean up resource management
cleanupPluginResources();
-
+
s_plugin = null;
super.stop(context);
}
-
-
+
// --- logging ---
-
- /**
+
+ /**
* Writes message to Eclipse log.
* Severity can be one of:
* Status.OK, Status.ERROR, Status.INFO, Status.WARNING, Status.CANCEL
*/
- public static void log(int severity, String text)
- {
+ public static void log(int severity, String text) {
Status status = new Status(severity, PLUGIN_ID, text);
ResourcesPlugin.getPlugin().getLog().log(status);
}
-
// --- resource management ---
-
+
/** Returns resource manager for this plugin */
public ResourceManager getPluginResources() {
if (s_resources == null) {
@@ -107,21 +99,22 @@ public class CDTVisualizerCorePlugin extends AbstractUIPlugin
}
return s_resources;
}
-
+
/** Releases resource manager for this plugin. */
public void cleanupPluginResources() {
s_resources.dispose();
}
-
+
/** Convenience method for getting plugin resource manager */
public static ResourceManager getResources() {
return getDefault().getPluginResources();
}
-
+
/** Convenience method for looking up string resources */
public static String getString(String key) {
return getDefault().getPluginResources().getString(key);
}
+
/** Convenience method for looking up string resources */
public static String getString(String key, Object... arguments) {
return getDefault().getPluginResources().getString(key, arguments);
diff --git a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/VisualizerExamplesPlugin.java b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/VisualizerExamplesPlugin.java
index 8317465496..d0fb630d07 100644
--- a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/VisualizerExamplesPlugin.java
+++ b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/VisualizerExamplesPlugin.java
@@ -32,10 +32,10 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
// The shared instance
private static VisualizerExamplesPlugin plugin;
-
+
/** Resource manager */
protected static UIResourceManager s_resources = null;
-
+
/**
* The constructor
*/
@@ -50,7 +50,7 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
-
+
// initialize resource management (strings, images, fonts, colors, etc.)
getPluginResources();
}
@@ -63,7 +63,7 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
public void stop(BundleContext context) throws Exception {
// clean up resource management
cleanupPluginResources();
-
+
plugin = null;
super.stop(context);
}
@@ -78,49 +78,52 @@ public class VisualizerExamplesPlugin extends AbstractUIPlugin {
}
// --- resource management ---
-
+
/** Returns resource manager for this plugin */
public UIResourceManager getPluginResources() {
if (s_resources == null) {
s_resources = new UIResourceManager(this);
s_resources.setParentManager(CDTVisualizerUIPlugin.getResources());
}
-
+
return s_resources;
}
-
+
/** Releases resource manager for this plugin. */
public void cleanupPluginResources() {
s_resources.dispose();
}
-
+
/** Convenience method for getting plugin resource manager */
public static UIResourceManager getResources() {
return getDefault().getPluginResources();
}
-
+
/** Convenience method for looking up string resources */
public static String getString(String key) {
return getDefault().getPluginResources().getString(key);
}
+
/** Convenience method for looking up string resources */
public static String getString(String key, Object... arguments) {
return getDefault().getPluginResources().getString(key, arguments);
}
-
+
/** Convenience method for looking up image resources */
public static Image getImage(String key) {
return getDefault().getPluginResources().getImage(key);
}
+
/** Convenience method for looking up image resources */
public static ImageDescriptor getImageDescriptor(String key) {
return getDefault().getPluginResources().getImageDescriptor(key);
}
-
+
/** Convenience method for looking up font resources */
public static Font getFont(String fontName, int height) {
return getDefault().getPluginResources().getFont(fontName, height);
}
+
/** Convenience method for looking up font resources */
public static Font getFont(String fontName, int height, int style) {
return getDefault().getPluginResources().getFont(fontName, height, style);
diff --git a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/BarGraphicObject.java b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/BarGraphicObject.java
index 3999413a72..5684ecf133 100644
--- a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/BarGraphicObject.java
+++ b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/BarGraphicObject.java
@@ -71,7 +71,7 @@ public class BarGraphicObject extends VirtualBoundsGraphicObject {
gc.setForeground(Colors.BLACK);
int text_indent = 6;
- int tx = m_bounds.x + m_bounds.width - text_indent;
+ int tx = m_bounds.x + m_bounds.width - text_indent;
int ty = m_bounds.y + m_bounds.height - text_indent;
GUIUtils.drawTextAligned(gc, m_label, m_bounds, tx, ty, false, false);
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ProblemVisualizer.java b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ProblemVisualizer.java
index 6ec59bacdc..af132a192b 100644
--- a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ProblemVisualizer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ProblemVisualizer.java
@@ -41,10 +41,9 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
private static final int BAR_VIRTUAL_WIDTH = 1;
private static final int BAR_VIRTUAL_HEIGHT = 4;
/** Virtual bounds of each of the bars, relative to their container */
- private static final int[][] BARS_VIRTUAL_BOUNDS = {
- { 0, 13, BAR_VIRTUAL_WIDTH, BAR_VIRTUAL_HEIGHT }, // infos
- { 0, 7, BAR_VIRTUAL_WIDTH, BAR_VIRTUAL_HEIGHT }, // warnings
- { 0, 1, BAR_VIRTUAL_WIDTH, BAR_VIRTUAL_HEIGHT } // errors
+ private static final int[][] BARS_VIRTUAL_BOUNDS = { { 0, 13, BAR_VIRTUAL_WIDTH, BAR_VIRTUAL_HEIGHT }, // infos
+ { 0, 7, BAR_VIRTUAL_WIDTH, BAR_VIRTUAL_HEIGHT }, // warnings
+ { 0, 1, BAR_VIRTUAL_WIDTH, BAR_VIRTUAL_HEIGHT } // errors
};
/** The canvas on which we'll draw our bars */
@@ -60,16 +59,12 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
private int[] m_markerCount = new int[NUM_SEVERITY];
/** Labels for the different marker severity levels*/
- private String[] m_markerSeverityLabels = {
- Messages.ProblemCountVisualizer_Infos,
- Messages.ProblemCountVisualizer_Warnings,
- Messages.ProblemCountVisualizer_Errors,
- };
+ private String[] m_markerSeverityLabels = { Messages.ProblemCountVisualizer_Infos,
+ Messages.ProblemCountVisualizer_Warnings, Messages.ProblemCountVisualizer_Errors, };
public ProblemVisualizer() {
- super(Messages.ProblemCountVisualizer_Name,
- Messages.ProblemCountVisualizer_DisplayName,
- Messages.ProblemCountVisualizer_Description);
+ super(Messages.ProblemCountVisualizer_Name, Messages.ProblemCountVisualizer_DisplayName,
+ Messages.ProblemCountVisualizer_Description);
}
@Override
@@ -85,8 +80,7 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
}
@Override
- public void disposeCanvas()
- {
+ public void disposeCanvas() {
if (m_canvas != null) {
m_canvas.dispose();
m_canvas = null;
@@ -119,7 +113,8 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
// Find the maximum marker count to dictate the width
int maxCount = Math.max(m_markerCount[0], m_markerCount[1]);
maxCount = Math.max(maxCount, m_markerCount[2]);
- if (maxCount == 0) maxCount = 1; // Set to anything but 0. It will be multiplied by 0 and not matter.
+ if (maxCount == 0)
+ maxCount = 1; // Set to anything but 0. It will be multiplied by 0 and not matter.
// go from high severity to low
for (int severity = IMarker.SEVERITY_ERROR; severity >= IMarker.SEVERITY_INFO; severity--) {
@@ -130,12 +125,12 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
m_container.addChildObject("bar" + severity, bar); //$NON-NLS-1$
}
- // set real bounds on parent "container" object - real bounds of
+ // set real bounds on parent "container" object - real bounds of
// bars will be recursively computed in proportion of their virtual
// bounds, relative to their container
m_container.setBounds(m_canvas.getBounds());
// Add container object to canvas - when canvas draws the container,
- // the bars will automatically be drawn too, so no need to add them
+ // the bars will automatically be drawn too, so no need to add them
// to canvas.
m_canvas.add(m_container);
}
@@ -165,7 +160,7 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
try {
Object attrValue = problem.getAttribute(IMarker.SEVERITY);
if (attrValue != null && attrValue instanceof Integer) {
- int severity = (Integer)attrValue;
+ int severity = (Integer) attrValue;
m_markerCount[severity]++;
}
} catch (CoreException e) {
@@ -210,7 +205,7 @@ public class ProblemVisualizer extends GraphicCanvasVisualizer {
for (Object sel : selections) {
if (sel instanceof IResource) {
// Update the data
- addToMarkerCount((IResource)sel);
+ addToMarkerCount((IResource) sel);
}
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ResizableGraphicCanvas.java b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ResizableGraphicCanvas.java
index d353c1b46a..a206612a0a 100644
--- a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ResizableGraphicCanvas.java
+++ b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/problemvisualizer/ResizableGraphicCanvas.java
@@ -24,7 +24,7 @@ public class ResizableGraphicCanvas extends GraphicCanvas {
super(parent);
m_problemVisualizer = problemVisualizer;
}
-
+
@Override
public void resized(Rectangle bounds) {
m_problemVisualizer.refresh();
diff --git a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphControl.java b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphControl.java
index e36c4c8b42..9843aa983d 100644
--- a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphControl.java
+++ b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphControl.java
@@ -41,37 +41,36 @@ import org.osgi.framework.Bundle;
// ---------------------------------------------------------------------------
/** Simple control that displays a graph based on a source text selection. */
-public class SourceGraphControl extends BufferedCanvas
-{
+public class SourceGraphControl extends BufferedCanvas {
// --- constants ---
-
+
/** Margin used in drawing graph and computing control height. */
- public static final int MARGIN = 10;
-
+ public static final int MARGIN = 10;
+
/** Line height used in drawing graph and computing control height. */
- public static final int LINE_HEIGHT = 20;
-
+ public static final int LINE_HEIGHT = 20;
+
/** Path for the banner image, relative to plug-in root path */
protected static final String BANNER_FILE = "images/sgv-banner.png"; //$NON-NLS-1$
protected static final int BANNER_HEIGHT = 50;
-
+
// --- members ---
-
+
/** Text we're currently displaying. */
protected String m_sourceText = ""; //$NON-NLS-1$
-
+
protected GraphicObject m_banner;
-
+
/** Data structure used to hold character stats. */
- class CharStat
- implements Comparable<CharStat>
- {
+ class CharStat implements Comparable<CharStat> {
public String characters;
public int count;
+
public CharStat(String c) {
characters = c;
count = 0;
}
+
@Override
public int compareTo(CharStat o) {
int c1 = count;
@@ -79,70 +78,65 @@ public class SourceGraphControl extends BufferedCanvas
int cmp = (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
// we want to sort in descending order, so negate result
return -cmp;
- };
+ };
};
-
+
/** List of characters we discovered and their occurrences. */
ArrayList<CharStat> m_characters;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public SourceGraphControl(Composite parent) {
super(parent);
m_characters = new ArrayList<CharStat>();
m_banner = new GraphicObject();
}
-
+
/** Dispose method. */
@Override
public void dispose() {
super.dispose();
}
-
// --- accessors ---
-
+
/** Sets source text to graph. */
- public void setSourceText(String text)
- {
+ public void setSourceText(String text) {
processText(text);
SourceGraphControl.this.update();
}
-
// --- text processing methods ---
-
+
/** Processes text into digested display form. */
- public void processText(String text)
- {
- if (text == null) text = ""; //$NON-NLS-1$
+ public void processText(String text) {
+ if (text == null)
+ text = ""; //$NON-NLS-1$
m_sourceText = text;
// TODO: reuse the array/hashtable and stat objects
-
- Hashtable<String, CharStat> characters =
- new Hashtable<String, CharStat>();
-
+
+ Hashtable<String, CharStat> characters = new Hashtable<String, CharStat>();
+
int len = m_sourceText.length();
int fragment_length = 2;
if (len >= fragment_length) {
- for (int i = 0; i<len-fragment_length+1; ++i) {
- String c = m_sourceText.substring(i,i+fragment_length);
-
+ for (int i = 0; i < len - fragment_length + 1; ++i) {
+ String c = m_sourceText.substring(i, i + fragment_length);
+
// Don't bother with fragments containing spaces
// and non-printing chars.
boolean skip = false;
- for (int j=0; j<c.length(); ++j)
- {
+ for (int j = 0; j < c.length(); ++j) {
if (c.charAt(j) <= 32 || c.charAt(j) > 127) {
skip = true;
break;
}
}
- if (skip) continue;
-
+ if (skip)
+ continue;
+
CharStat cs = characters.get(c);
if (cs == null) {
cs = new CharStat(c);
@@ -151,24 +145,24 @@ public class SourceGraphControl extends BufferedCanvas
++cs.count;
}
}
-
+
m_characters.clear();
m_characters.addAll(characters.values());
Collections.sort(m_characters);
-
+
characters.clear();
-
+
Rectangle bounds = getBounds();
int height = MARGIN * 2 + m_characters.size() * LINE_HEIGHT;
-
+
// reserve space for banner at the top
height = height + BANNER_HEIGHT;
-
+
bounds.height = height;
setBounds(bounds);
-
+
}
-
+
// --- painting methods ---
/** Invoked when canvas repaint event is raised.
@@ -182,35 +176,35 @@ public class SourceGraphControl extends BufferedCanvas
clearCanvas(gc);
int margin = MARGIN;
- int tw = 90;
+ int tw = 90;
int tw2 = 45;
int lh = LINE_HEIGHT;
-
+
int x = margin;
- // skip banner space
+ // skip banner space
int y = BANNER_HEIGHT + margin;
-
+
Rectangle area = getClientArea();
- int w = area.width - margin*2 - tw;
-
+ int w = area.width - margin * 2 - tw;
+
// position and size banner container object
m_banner.setBounds(new Rectangle(x - margin, margin, area.width, BANNER_HEIGHT - margin));
-
+
// draw banner
try {
m_banner.drawImage(gc, getAbsFilePath(BANNER_FILE), GraphicObject.ImageSizeAndPosition.MAXSIZE);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
-
+
int maxcount = 0;
- for (CharStat cs : m_characters)
- {
+ for (CharStat cs : m_characters) {
// We're sorted in descending order, so first element
// that we draw will always have the largest count.
- if (maxcount == 0) maxcount = cs.count;
-
- gc.drawText("[" + cs.characters + "]", x, y); //$NON-NLS-1$ //$NON-NLS-2$
+ if (maxcount == 0)
+ maxcount = cs.count;
+
+ gc.drawText("[" + cs.characters + "]", x, y); //$NON-NLS-1$ //$NON-NLS-2$
gc.drawText("(" + cs.count + ")", x + tw2, y); //$NON-NLS-1$ //$NON-NLS-2$
double proportion = cs.count * 1.0 / maxcount;
@@ -220,16 +214,15 @@ public class SourceGraphControl extends BufferedCanvas
gc.setBackground(Colors.GREEN);
else if (proportion > .40)
gc.setBackground(Colors.YELLOW);
- else
+ else
gc.setBackground(Colors.RED);
- gc.fillRectangle(x + tw, y, bw, lh-5);
+ gc.fillRectangle(x + tw, y, bw, lh - 5);
gc.setBackground(oldb);
y += lh;
}
}
-
// --- update methods ---
/**
@@ -246,7 +239,7 @@ public class SourceGraphControl extends BufferedCanvas
public void resized(Rectangle bounds) {
refresh();
}
-
+
/** Get the absolute path of a file, from the path relative to plugin root. */
private String getAbsFilePath(String relPath) {
Bundle bundle = Platform.getBundle(VisualizerExamplesPlugin.PLUGIN_ID);
diff --git a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphVisualizer.java b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphVisualizer.java
index a96977a4ec..ec2cb9173a 100644
--- a/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphVisualizer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.examples/src/org/eclipse/cdt/visualizer/examples/sourcegraph/SourceGraphVisualizer.java
@@ -32,32 +32,28 @@ import org.eclipse.swt.widgets.Control;
// SourceGraphVisualizer
//---------------------------------------------------------------------------
-public class SourceGraphVisualizer extends Visualizer
-{
+public class SourceGraphVisualizer extends Visualizer {
// --- constants ---
-
+
/** Eclipse ID for this view */
public static final String ECLIPSE_ID = "org.eclipse.cdt.visualizer.examples.sourcegraph"; //$NON-NLS-1$
-
// --- members ---
-
+
/** ScrollPanel container for visualizer control. */
ScrollPanel m_scrollPanel = null;
-
+
/** visualizer control (downcast reference) */
SourceGraphControl m_sourceGraphControl = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
- public SourceGraphVisualizer()
- {
- super(VisualizerExamplesPlugin.getString("SourceGraphVisualizer.name"), //$NON-NLS-1$
- VisualizerExamplesPlugin.getString("SourceGraphVisualizer.displayName"), //$NON-NLS-1$
- VisualizerExamplesPlugin.getString("SourceGraphVisualizer.description") //$NON-NLS-1$
- );
+ public SourceGraphVisualizer() {
+ super(VisualizerExamplesPlugin.getString("SourceGraphVisualizer.name"), //$NON-NLS-1$
+ VisualizerExamplesPlugin.getString("SourceGraphVisualizer.displayName"), //$NON-NLS-1$
+ VisualizerExamplesPlugin.getString("SourceGraphVisualizer.description") //$NON-NLS-1$
+ );
}
/** Dispose method. */
@@ -66,13 +62,11 @@ public class SourceGraphVisualizer extends Visualizer
super.dispose();
}
-
// --- control management ---
-
+
/** Creates and returns visualizer control on specified parent. */
@Override
- public Control createControl(Composite parent)
- {
+ public Control createControl(Composite parent) {
if (m_sourceGraphControl == null) {
m_scrollPanel = new ScrollPanel(parent);
@@ -90,11 +84,10 @@ public class SourceGraphVisualizer extends Visualizer
}
return getControl();
}
-
+
/** Invoked when visualizer control should be disposed. */
@Override
- public void disposeControl()
- {
+ public void disposeControl() {
if (m_sourceGraphControl != null) {
setControl(null);
m_sourceGraphControl.dispose();
@@ -109,14 +102,13 @@ public class SourceGraphVisualizer extends Visualizer
@Override
public void visualizerDeselected() {
}
-
+
@Override
public void visualizerSelected() {
}
-
// --- update methods ---
-
+
/**
* Refresh the visualizer display based on the existing data.
*/
@@ -125,14 +117,15 @@ public class SourceGraphVisualizer extends Visualizer
}
// --- selection handling ---
-
+
/** Invoked when selection changes, to determine whether this
* visualizer knows how to display the current selection.
*/
@Override
public int handlesSelection(ISelection selection) {
Object s = SelectionUtils.getSelectedObject(selection);
- if (s instanceof TextSelection) return 1;
+ if (s instanceof TextSelection)
+ return 1;
return 0;
}
@@ -149,30 +142,28 @@ public class SourceGraphVisualizer extends Visualizer
m_sourceGraphControl.setSourceText(""); //$NON-NLS-1$
}
}
-
+
public SelectionManager getSelectionManager() {
return m_selectionManager;
- }
+ }
-
// --- menu/toolbar management ---
/** Invoked when visualizer is selected, to populate the toolbar. */
@Override
- public void populateToolBar(IToolBarManager toolBarManager)
- {}
+ public void populateToolBar(IToolBarManager toolBarManager) {
+ }
/** Invoked when visualizer is selected, to populate the toolbar's menu. */
@Override
- public void populateMenu(IMenuManager menuManager)
- {}
+ public void populateMenu(IMenuManager menuManager) {
+ }
-
// --- context menu handling ---
-
+
/** Invoked when visualizer view's context menu is invoked, to populate it. */
@Override
- public void populateContextMenu(IMenuManager menuManager)
- {}
+ public void populateContextMenu(IMenuManager menuManager) {
+ }
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizer.java
index 2958161e71..7e504c8752 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizer.java
@@ -22,60 +22,56 @@ import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-
// ----------------------------------------------------------------------------
// IVisualizer
// ----------------------------------------------------------------------------
/**
* CDT Visualizer interface.
- *
+ *
* An IVisualizer encapsulates a specific graphic presentation of the
* currently selected object (launch, target, etc.).
- *
+ *
* It knows how to create a Control to draw on, which is displayed by
* the Visualizer Viewer, and also knows how to draw its presentation on
* that control.
- *
+ *
* A visualizer can be generic (e.g. knows how to draw any kind of
* launch) or specific (e.g. specialized for a particular type of
* launch or execution target). The viewer automatically chooses
* the most specific IVisualizer that reports it is able to render
* the current selection.
*/
-public interface IVisualizer
- extends ISelectionProvider
-{
+public interface IVisualizer extends ISelectionProvider {
// --- init methods ---
-
+
/** Invoked when visualizer is created, to permit any initialization. */
public void initializeVisualizer();
-
+
/** Invoked when visualizer is disposed, to permit any cleanup. */
public void disposeVisualizer();
-
// --- accessors ---
/** Sets non-localized name. */
public void setName(String name);
+
/** Gets non-localized name. */
-
+
public String getName();
/** Sets localized display name. */
public void setDisplayName(String displayName);
-
+
/** Gets localized display name. */
public String getDisplayName();
/** Sets localized description string. */
public void setDescription(String description);
-
+
/** Gets localized description string. */
public String getDescription();
-
// --- viewer management ---
/** Called by viewer when visualizer is added to it. */
@@ -83,17 +79,15 @@ public interface IVisualizer
/** Returns viewer control for this visualizer. */
public IVisualizerViewer getViewer();
-
-
+
// --- visualizer selection management ---
-
+
/** Invoked when visualizer has been selected. */
public void visualizerSelected();
-
+
/** Invoked when another visualizer has been selected, hiding this one. */
public void visualizerDeselected();
-
// --- control management ---
/** Creates and returns visualizer's UI control on specified parent control. */
@@ -103,8 +97,7 @@ public interface IVisualizer
* Returns null if createControl() has not yet been called.
*/
public Control getControl();
-
-
+
// --- menu/toolbar management ---
/**
@@ -130,33 +123,31 @@ public interface IVisualizer
* There is no need to invoke update on the toolbar, the viewer handles that.
*/
public void populateContextMenu(IMenuManager menuManager);
-
-
+
// --- workbench selection management ---
- /**
- * Tests whether if the IVisualizer can display the selection
- * (or something reachable from it).
- *
+ /**
+ * Tests whether if the IVisualizer can display the selection
+ * (or something reachable from it).
+ *
* Returns a positive "weight" if true, and zero otherwise.
* If multiple visualizers can handle a given selection,
* the one reporting the highest weight value "wins".
* In case of ties, an arbitrary visualizer is selected.
- *
+ *
* The weight should reflect the specificity of the visualizer;
* in other words, a "default" visualization for a given selection
* should have a low weight, and a special case should have
* a higher weight; this allows the visualizer view to "fall back"
* to the default visualization in the general case.
- */
+ */
public int handlesSelection(ISelection selection);
- /**
- * Invoked by VisualizerViewer when workbench selection changes.
- */
+ /**
+ * Invoked by VisualizerViewer when workbench selection changes.
+ */
public void workbenchSelectionChanged(ISelection selection);
-
-
+
// --- selection changed event handling ---
/** Adds external listener for selection change events. */
@@ -164,7 +155,7 @@ public interface IVisualizer
/** Removes external listener for selection change events. */
public void removeSelectionChangedListener(ISelectionChangedListener listener);
-
+
/** Gets current externally-visible selection. */
public ISelection getSelection();
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizerViewer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizerViewer.java
index 024e61e0ce..51cfbc84e8 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizerViewer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/IVisualizerViewer.java
@@ -22,51 +22,45 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Control;
-
// ----------------------------------------------------------------------------
// IVisualizerViewer
// ----------------------------------------------------------------------------
/**
* CDT Visualizer Viewer interface.
- *
+ *
* An IVisualizerViewer is a simple container for multiple
* IVisualizers, where the currently selected IVisualizer
* determines which IVisualizer control is displayed in the viewer.
*/
-public interface IVisualizerViewer
-{
+public interface IVisualizerViewer {
// --- accessors ---
/** Gets containing view. */
public VisualizerView getView();
-
+
/** Returns non-localized unique name for selected visualizer. */
public String getVisualizerName();
/** Returns localized name to display for selected visualizer. */
public String getVisualizerDisplayName();
-
+
/** Returns localized tooltip text to display for selected visualizer. */
public String getVisualizerDescription();
-
-
-
+
// --- control management ---
-
+
/** Gets viewer control. */
public Control getControl();
-
// --- focus handling ---
-
+
/**
* Invoked by VisualizerView when currently selected presentation,
* if any, should take the focus.
*/
public boolean setFocus();
-
// --- menu/toolbar management ---
/** Invoked when visualizer is selected, to populate the toolbar. */
@@ -75,40 +69,37 @@ public interface IVisualizerViewer
/** Invoked when visualizer is selected, to populate the toolbar's menu. */
public void populateMenu(IMenuManager menuManager);
-
// --- context menu handling ---
-
+
/** Invoked when context menu is about to be shown. */
public void populateContextMenu(IMenuManager m);
/** Gets context menu location. */
public Point getContextMenuLocation();
-
-
+
// --- selection handling ---
-
- /**
- * Invoked by VisualizerView when workbench selection changes,
- * and the change was made by some other view.
- */
+
+ /**
+ * Invoked by VisualizerView when workbench selection changes,
+ * and the change was made by some other view.
+ */
public void workbenchSelectionChanged(ISelection selection);
-
+
/** Adds external listener for selection change events. */
public void addSelectionChangedListener(ISelectionChangedListener listener);
/** Removes external listener for selection change events. */
public void removeSelectionChangedListener(ISelectionChangedListener listener);
-
+
/** Gets current externally-visible selection. */
public ISelection getSelection();
-
// --- events ---
-
+
/** Adds listener for viewer events. */
public void addVisualizerViewerListener(IVisualizerViewerListener listener);
-
+
/** Removes listener for viewer events. */
public void removeVisualizerViewerListener(IVisualizerViewerListener listener);
-
+
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/Visualizer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/Visualizer.java
index 605f35b50f..d7e820eaca 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/Visualizer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/Visualizer.java
@@ -24,7 +24,6 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-
// ---------------------------------------------------------------------------
// Visualizer
// ---------------------------------------------------------------------------
@@ -32,11 +31,9 @@ import org.eclipse.swt.widgets.Control;
/**
* Base class for IVisualizer implementations.
*/
-abstract public class Visualizer
- implements IVisualizer, ISelectionProvider, ISelectionChangedListener
-{
+abstract public class Visualizer implements IVisualizer, ISelectionProvider, ISelectionChangedListener {
// --- members ---
-
+
/** Visualizer's non-localized name. */
protected String m_name;
@@ -48,22 +45,21 @@ abstract public class Visualizer
/** The parent view control. */
protected IVisualizerViewer m_viewer;
-
+
/** The visualizer control. */
protected Control m_control;
-
+
/** Externally visible selection manager. */
protected SelectionManager m_selectionManager;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public Visualizer() {
// TODO: internationalize these strings.
this("visualizer", "Visualizer", "Displays graphic representation of selection.");
}
-
+
/** Constructor. */
public Visualizer(String name, String displayName, String description) {
setName(name);
@@ -71,7 +67,7 @@ abstract public class Visualizer
setDescription(description);
m_selectionManager = new SelectionManager(this, "Visualizer selection manager");
}
-
+
/** Dispose method. */
public void dispose() {
m_name = null;
@@ -85,31 +81,28 @@ abstract public class Visualizer
}
}
-
// --- init methods ---
-
+
/** Invoked when visualizer is created, to permit any initialization.
* Intended to be overridden. Default implementation does nothing.
*/
- public void initializeVisualizer()
- {
+ public void initializeVisualizer() {
}
-
+
/** Invoked when visualizer is disposed, to permit any cleanup.
* Intended to be overridden. Default implementation calls dispose().
*/
- public void disposeVisualizer()
- {
+ public void disposeVisualizer() {
dispose();
}
-
-
+
// --- accessors ---
/** Sets non-localized name. */
public void setName(String name) {
m_name = name;
}
+
/** Gets non-localized name. */
public String getName() {
return m_name;
@@ -119,6 +112,7 @@ abstract public class Visualizer
public void setDisplayName(String displayName) {
m_displayName = displayName;
}
+
/** Gets localized display name. */
public String getDisplayName() {
return m_displayName;
@@ -128,12 +122,12 @@ abstract public class Visualizer
public void setDescription(String description) {
m_description = description;
}
+
/** Gets localized description string. */
public String getDescription() {
return m_description;
}
-
// --- viewer management ---
/** Sets viewer we're associated with. */
@@ -145,27 +139,25 @@ abstract public class Visualizer
public IVisualizerViewer getViewer() {
return m_viewer;
}
-
// --- visualizer selection management ---
-
+
/** Invoked when visualizer has been selected. */
public void visualizerSelected() {
};
-
+
/** Invoked when another visualizer has been selected, hiding this one. */
public void visualizerDeselected() {
};
-
// --- control management ---
-
+
/** Creates and returns visualizer's UI control on specified parent control. */
abstract public Control createControl(Composite parent);
/** Invoked when visualizer control should be disposed. */
abstract public void disposeControl();
-
+
/**
* Sets visualizer control.
* Intended to be called from createControl();
@@ -181,7 +173,6 @@ abstract public class Visualizer
return m_control;
}
-
// --- menu/toolbar management ---
/** Invoked by VisualizerViewer when toolbar needs to be populated. */
@@ -192,39 +183,34 @@ abstract public class Visualizer
public void populateMenu(IMenuManager menuManager) {
}
-
// --- context menu handling ---
-
+
/** Invoked by VisualizerViewer when context menu needs to be populated. */
public void populateContextMenu(IMenuManager menuManager) {
}
-
// --- workbench selection management ---
- /**
- * Tests whether if the IVisualizer can display the selection
- * (or something reachable from it).
- */
- public int handlesSelection(ISelection selection)
- {
+ /**
+ * Tests whether if the IVisualizer can display the selection
+ * (or something reachable from it).
+ */
+ public int handlesSelection(ISelection selection) {
// Default implementation doesn't know how to display anything.
return 0;
}
- /**
- * Invoked by VisualizerViewer when workbench selection changes.
- */
- public void workbenchSelectionChanged(ISelection selection)
- {
+ /**
+ * Invoked by VisualizerViewer when workbench selection changes.
+ */
+ public void workbenchSelectionChanged(ISelection selection) {
// Default implementation does nothing.
}
-
// --- ISelectionProvider implementation ---
-
+
// Delegate to selection manager.
-
+
/** Adds external listener for selection change events. */
public void addSelectionChangedListener(ISelectionChangedListener listener) {
m_selectionManager.addSelectionChangedListener(listener);
@@ -234,37 +220,32 @@ abstract public class Visualizer
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
m_selectionManager.removeSelectionChangedListener(listener);
}
-
+
/** Raises selection changed event. */
public void raiseSelectionChangedEvent() {
m_selectionManager.raiseSelectionChangedEvent();
}
-
+
/** Gets current externally-visible selection. */
- public ISelection getSelection()
- {
+ public ISelection getSelection() {
return m_selectionManager.getSelection();
}
-
+
/** Sets externally-visible selection. */
- public void setSelection(ISelection selection)
- {
+ public void setSelection(ISelection selection) {
m_selectionManager.setSelection(selection);
}
/** Sets externally-visible selection. */
- public void setSelection(ISelection selection, boolean raiseEvent)
- {
+ public void setSelection(ISelection selection, boolean raiseEvent) {
m_selectionManager.setSelection(selection, raiseEvent);
}
/** Returns true if we currently have a non-empty selection. */
- public boolean hasSelection()
- {
+ public boolean hasSelection() {
return m_selectionManager.hasSelection();
}
-
-
+
// --- ISelectionChangedListener implementation ---
/**
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerAction.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerAction.java
index abd260ac19..5b3edb8af1 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerAction.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerAction.java
@@ -19,7 +19,6 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Event;
-
// ---------------------------------------------------------------------------
// VisualizerAction
// ---------------------------------------------------------------------------
@@ -28,19 +27,18 @@ import org.eclipse.swt.widgets.Event;
* (Viewers are not required to use this class. This is simply a
* convenience wrapper for the standard Action class.)
*/
-public class VisualizerAction extends Action
-{
+public class VisualizerAction extends Action {
// --- members ---
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
protected VisualizerAction() {
// NOTE: this constructor is only intended for deriving classes
// that need to construct the text/description/image attributes
// programmatically.
}
-
+
/** Constructor. */
public VisualizerAction(String text, int style) {
super(text, style);
@@ -51,27 +49,24 @@ public class VisualizerAction extends Action
super(text);
setDescription(description);
}
-
+
/** Constructor. */
- public VisualizerAction(String text, String description,
- ImageDescriptor image) {
+ public VisualizerAction(String text, String description, ImageDescriptor image) {
super(text, image);
setDescription(description);
}
-
+
/** Constructor. */
- public VisualizerAction(String text, String description,
- ImageDescriptor enabledImage, ImageDescriptor disabledImage) {
+ public VisualizerAction(String text, String description, ImageDescriptor enabledImage,
+ ImageDescriptor disabledImage) {
super(text, enabledImage);
setDescription(description);
setDisabledImageDescriptor(disabledImage);
}
/** Dispose method. */
- public void dispose()
- {
+ public void dispose() {
}
-
// --- methods ---
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerView.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerView.java
index 1452fef4ec..61a62ae251 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerView.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerView.java
@@ -45,54 +45,48 @@ import org.eclipse.cdt.visualizer.ui.util.SelectionProviderAdapter;
import org.eclipse.cdt.visualizer.ui.util.SelectionUtils;
import org.eclipse.cdt.visualizer.ui.util.WorkbenchSelectionAdapter;
-
// ----------------------------------------------------------------------------
// VisualizerView
// ----------------------------------------------------------------------------
/**
* CDT Visualizer View class.
- *
+ *
* This is the default implementation of the Visualizer View.
* It can also serve as a base class for custom visualizer views.
- *
+ *
* The Visualizer View is a simple container with a toolbar,
* which presents an instance of an IVisualizerViewer,
* and mediates passing of selections to and from the viewer.
- *
+ *
* The intent of the VisualizerView class is to encapsulate the
* standard Eclipse workbench view support, so the viewer does
* not have to worry about such things.
*/
-public class VisualizerView
- extends ViewPart
- implements IVisualizerViewerListener,
- ISelectionChangedListener
-{
+public class VisualizerView extends ViewPart implements IVisualizerViewerListener, ISelectionChangedListener {
// --- members ---
-
+
/** Whether view has been initialized */
protected boolean m_initialized = false;
-
+
/** Parent control of view. */
protected Composite m_parentControl = null;
/** Contained IVisualizerViewer control. */
protected IVisualizerViewer m_viewer = null;
-
+
/** Selection change event manager */
protected WorkbenchSelectionAdapter m_workbenchSelectionAdapter = null;
- /** Context menu manager. */
- protected MenuManager m_contextMenuManager = null;
-
- /** Last context menu display location. */
- protected Point m_contextMenuLocation = null;
+ /** Context menu manager. */
+ protected MenuManager m_contextMenuManager = null;
+
+ /** Last context menu display location. */
+ protected Point m_contextMenuLocation = null;
+
+ /** Open New View action */
+ private OpenNewViewAction m_openNewViewAction = null;
- /** Open New View action */
- private OpenNewViewAction m_openNewViewAction = null;
-
-
// --- constructors/destructors ---
/** Constructor */
@@ -109,41 +103,35 @@ public class VisualizerView
disposeSelectionHandling();
}
-
// --- accessors ---
-
+
/** Returns whether view has been initialized. */
- public boolean isInitialized()
- {
+ public boolean isInitialized() {
return m_initialized;
}
/** Gets contained viewer control. */
- public IVisualizerViewer getViewer()
- {
+ public IVisualizerViewer getViewer() {
return m_viewer;
}
-
+
/** Sets contained viewer control. */
- public void setViewer(IVisualizerViewer viewer)
- {
+ public void setViewer(IVisualizerViewer viewer) {
if (m_viewer != null) {
m_viewer.removeSelectionChangedListener(this);
m_viewer.removeVisualizerViewerListener(this);
}
-
+
m_viewer = viewer;
-
- if (m_viewer != null)
- {
+
+ if (m_viewer != null) {
m_viewer.addVisualizerViewerListener(this);
m_viewer.addSelectionChangedListener(this);
updateUI();
populateMenu();
}
}
-
-
+
// --- ViewPart implementation ---
// IMPORTANT: a view may be loaded before the plugins, etc.
@@ -155,11 +143,11 @@ public class VisualizerView
// of its createPartControl() method, and any methods that touch/repaint/update
// the view's controls, etc. should call isInitialized() to be sure
// these controls have been created.
-
+
/** Invoked when UI controls need to be created */
public void createPartControl(Composite parent) {
m_parentControl = parent;
-
+
// Reminder: Don't muck with the toolbar or toolbar menu here.
// (I.e. don't try to clean them out or set initial items.)
// VisualizerViewer's selection handling code
@@ -168,37 +156,36 @@ public class VisualizerView
// set up context menu support
initializeContextMenu();
-
+
// setup the view menu
initializeMenu();
-
+
// set up selection handling
initializeSelectionHandling();
-
+
// initialize viewer control
initializeViewer();
-
+
m_initialized = true;
}
-
+
/** Invoked when view should take the focus.
* Note: this can be invoked before the view is fully initialized
* (for example, when loading views from workspace memento information),
* in which case it should silently do nothing.
*/
public void setFocus() {
- if (m_viewer != null) m_viewer.setFocus();
+ if (m_viewer != null)
+ m_viewer.setFocus();
}
-
// --- initialization support ---
-
+
/**
* Creates and returns VisualizerViewer control.
* Intended to be overridden by derived types.
*/
- protected IVisualizerViewer createViewer(Composite parent)
- {
+ protected IVisualizerViewer createViewer(Composite parent) {
return (m_viewer != null) ? m_viewer : new VisualizerViewer(this, parent);
}
@@ -211,22 +198,18 @@ public class VisualizerView
setViewer(viewer);
}
-
// --- tab name management ---
-
+
/** Sets displayed tab name and description for this view. */
- public void setTabName(String displayName)
- {
+ public void setTabName(String displayName) {
setPartName(displayName);
}
/** Sets displayed tab name and description for this view. */
- public void setTabDescription(String description)
- {
+ public void setTabDescription(String description) {
setTitleToolTip(description);
}
-
// --- selection handling ---
/** Initializes selection handling for this view. */
@@ -278,7 +261,7 @@ public class VisualizerView
// tell viewer about workbench selection
ISelection selection = event.getSelection();
setWorkbenchSelection(selection);
-
+
// update toolbar/menu to reflect changed selection
updateUI();
}
@@ -288,7 +271,7 @@ public class VisualizerView
// Do nothing.
}
// if the source is another instance of VisualizerView
- // it's a selection in another (cloned) view. The
+ // it's a selection in another (cloned) view. The
// workbench selection has or will be updated by the
// instance of the view where the selection originated,
// so no need to do anything
@@ -300,7 +283,7 @@ public class VisualizerView
else {
ISelection selection = event.getSelection();
workbenchSelectionChanged(selection);
-
+
// update toolbar/menu to reflect changed selection
updateUI();
}
@@ -315,8 +298,7 @@ public class VisualizerView
m_viewer.workbenchSelectionChanged(selection);
}
}
-
-
+
// --- IVisulizerViewerListener implementation ---
/** Invoked when visualizer in view has changed. */
@@ -329,16 +311,15 @@ public class VisualizerView
showContextMenu(event.x, event.y);
}
}
-
-
+
// --- update methods ---
-
+
/** Updates tab name, toolbar, etc. from viewer. */
public void updateUI() {
// Update tab name/tooltip
// TODO: internationalize these default strings
- String name = "Visualizer View";
+ String name = "Visualizer View";
String description = "Displays visualizations of launches.";
if (m_viewer != null) {
name = m_viewer.getVisualizerDisplayName();
@@ -352,43 +333,42 @@ public class VisualizerView
// Update toolbar & toolbar menu
if (m_viewer != null) {
IActionBars actionBars = getViewSite().getActionBars();
-
+
// Allow presentation to set the displayed toolbar content, if any
IToolBarManager toolBarManager = actionBars.getToolBarManager();
toolBarManager.removeAll();
m_viewer.populateToolBar(toolBarManager);
-
+
// Add the "open new view" button on the Visualizer toolbar,
// after any viewer-specific buttons.
toolBarManager.add(m_openNewViewAction);
toolBarManager.update(true);
-
+
// Note: when context menu is invoked,
// the populateContextMenu() method is called by the view,
// which in turn delegates to the current visualizer
// to populate the context menu.
-
+
// Note2: when view menu is invoked,
// the populateMenu() method is called by the view,
// which in turn delegates to the current visualizer
// to populate the view menu.
-
+
// Propagate the changes
actionBars.updateActionBars();
}
}
-
-
+
// --- view menu support ---
-
- /** Utility method that returns the menu manager for the view menu
+
+ /** Utility method that returns the menu manager for the view menu
* @since 1.2*/
protected IMenuManager getViewMenuManager() {
IActionBars actionBars = getViewSite().getActionBars();
return actionBars.getMenuManager();
}
-
- /** Initialize the view menu
+
+ /** Initialize the view menu
* @since 1.2*/
protected void initializeMenu() {
IMenuManager menuManager = getViewMenuManager();
@@ -396,45 +376,44 @@ public class VisualizerView
public void menuAboutToShow(IMenuManager m) {
viewMenuShow(m);
}
+
public void menuAboutToHide(IMenuManager m) {
viewMenuHide(m);
}
});
}
-
+
/** Invoked when the viewer is set to do an initial populating of the view
- * menu. Without this, the view menu would not appear.
+ * menu. Without this, the view menu would not appear.
* @since 1.2*/
protected void populateMenu() {
IMenuManager menuManager = getViewMenuManager();
viewMenuShow(menuManager);
}
-
- /** Invoked when view menu is about to be shown.
+
+ /** Invoked when view menu is about to be shown.
* @since 1.2*/
- protected void viewMenuShow(IMenuManager m)
- {
+ protected void viewMenuShow(IMenuManager m) {
m.removeAll();
m_viewer.populateMenu(m);
m.update();
}
-
- /** Invoked when view menu is about to be hidden.
+
+ /** Invoked when view menu is about to be hidden.
* @since 1.2*/
- protected void viewMenuHide(IMenuManager m)
- {
+ protected void viewMenuHide(IMenuManager m) {
}
-
-
+
// --- context menu support ---
-
+
/** Sets up context menu support. */
protected void initializeContextMenu() {
- m_contextMenuManager = new MenuManager();
+ m_contextMenuManager = new MenuManager();
m_contextMenuManager.addMenuListener(new IMenuListener2() {
public void menuAboutToShow(IMenuManager m) {
VisualizerView.this.contextMenuShow(m);
}
+
public void menuAboutToHide(IMenuManager m) {
VisualizerView.this.contextMenuHide(m);
}
@@ -443,44 +422,41 @@ public class VisualizerView
// We associate the view's context menu with the parent control.
// Viewer has the option of calling showContextMenu()
// to display the view's context menu.
- Menu menu= m_contextMenuManager.createContextMenu(m_parentControl);
- m_parentControl.setMenu(menu);
+ Menu menu = m_contextMenuManager.createContextMenu(m_parentControl);
+ m_parentControl.setMenu(menu);
}
-
+
/** Invoked when context menu is about to be shown. */
- protected void contextMenuShow(IMenuManager m)
- {
+ protected void contextMenuShow(IMenuManager m) {
m.removeAll();
m_viewer.populateContextMenu(m);
m.update();
}
-
+
/** Invoked when context menu is about to be hidden. */
- protected void contextMenuHide(IMenuManager m)
- {
+ protected void contextMenuHide(IMenuManager m) {
}
-
+
/** Shows view's context menu at specified position. */
- public void showContextMenu(int x, int y)
- {
+ public void showContextMenu(int x, int y) {
Menu menu = m_parentControl.getMenu();
if (menu != null) {
menu.setLocation(x, y);
-
+
// capture context menu location in relative coordinates
- m_contextMenuLocation = m_parentControl.toControl(x,y);
-
+ m_contextMenuLocation = m_parentControl.toControl(x, y);
+
// Note: showing menu implicitly invokes populateContextMenu()
// to populate context menu items.
menu.setVisible(true);
-
+
// Make sure we have the focus now
// so we'll still have it when the menu goes away,
// and user doesn't have to click twice.
setFocus();
}
}
-
+
/** Gets context menu location. */
public Point getContextMenuLocation() {
// Just asking the menu for its own location doesn't work,
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerViewer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerViewer.java
index 50ccecf038..5e9958bce4 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerViewer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/VisualizerViewer.java
@@ -47,72 +47,67 @@ import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.part.PageBook;
-
// ----------------------------------------------------------------------------
// VisualizerViewer
// ----------------------------------------------------------------------------
/**
* CDT Visualizer Viewer class.
- *
+ *
* This is the default implementation of IVisualizerViewer.
* It can also serve as a base class for custom visualizer viewers.
- *
+ *
* The Visualizer Viewer is a simple container for multiple
* IVisualizers, where the currently selected IVisualizer
* determines which IVisualizer control is displayed in the viewer.
- *
- * The base implementation simply displays a single IVisualizer at a time.
+ *
+ * The base implementation simply displays a single IVisualizer at a time.
* One can programmatically switch selections, but there are no user
* controls for doing so. (The intent is that derived types can add
* various kinds of switching controls, like a combo box, etc.)
*/
public class VisualizerViewer extends PageBook
- implements IVisualizerViewer, MenuDetectListener,
- ISelectionProvider, ISelectionChangedListener
-{
+ implements IVisualizerViewer, MenuDetectListener, ISelectionProvider, ISelectionChangedListener {
// --- constants ---
-
+
/** Extension point name for list of IVisualizer types. */
- public static final String VISUALIZER_EXTENSION_POINT_NAME = "visualizer"; //$NON-NLS-1$
-
-
+ public static final String VISUALIZER_EXTENSION_POINT_NAME = "visualizer"; //$NON-NLS-1$
+
// --- members ---
-
- /** Containing view. */
- protected VisualizerView m_view = null;
-
- /** Parent control. */
- protected Composite m_parent = null;
-
+
+ /** Containing view. */
+ protected VisualizerView m_view = null;
+
+ /** Parent control. */
+ protected Composite m_parent = null;
+
/** List of registered visualizer types. */
- protected Map<String, IVisualizer> m_visualizers = null;
-
+ protected Map<String, IVisualizer> m_visualizers = null;
+
/** Currently selected visualizer. */
protected IVisualizer m_currentVisualizer = null;
-
+
/** Event listeners. */
protected ListenerList m_listeners = null;
-
+
/** Viewer selection manager. */
protected SelectionManager m_selectionManager = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public VisualizerViewer(VisualizerView view, Composite parent) {
super(parent, SWT.NONE);
initVisualizerViewer(view, parent);
// so we're notified when the widget is disposed
- addDisposeListener(new DisposeListener() {
- @Override
- public void widgetDisposed(DisposeEvent e) {
- dispose();
- }
- });
- }
-
+ addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ }
+ });
+ }
+
/** Dispose method. */
public void dispose() {
cleanupVisualizerViewer();
@@ -125,23 +120,19 @@ public class VisualizerViewer extends PageBook
// (Superclass implementation throws "Subclassing not allowed" exception.)
}
-
// --- init methods ---
-
+
/** Initializes control */
protected void initVisualizerViewer(VisualizerView view, Composite parent) {
m_view = view;
m_parent = parent;
-
+
// Event listener support
- m_listeners = new ListenerList(this, "VisualizerViewer event listeners")
- {
+ m_listeners = new ListenerList(this, "VisualizerViewer event listeners") {
public void raise(Object listener, Object event) {
- if (listener instanceof IVisualizerViewerListener &&
- event instanceof VisualizerViewerEvent)
- {
+ if (listener instanceof IVisualizerViewerListener && event instanceof VisualizerViewerEvent) {
IVisualizerViewerListener typedListener = (IVisualizerViewerListener) listener;
- VisualizerViewerEvent typedEvent = (VisualizerViewerEvent) event;
+ VisualizerViewerEvent typedEvent = (VisualizerViewerEvent) event;
typedListener.visualizerEvent(VisualizerViewer.this, typedEvent);
}
}
@@ -149,7 +140,7 @@ public class VisualizerViewer extends PageBook
// Selection change listener support
m_selectionManager = new SelectionManager(this, "Visualizer Viewer selection manager");
-
+
// Set default colors for empty viewer.
Display display = getDisplay();
setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
@@ -165,144 +156,130 @@ public class VisualizerViewer extends PageBook
// Load any visualizers defined through extension point.
loadVisualizers();
}
-
+
/** Cleans up control */
protected void cleanupVisualizerViewer() {
// perform any cleanup here
- disposeVisualizers();
- if (m_selectionManager != null) {
- m_selectionManager.dispose();
- m_selectionManager = null;
- }
- }
-
-
+ disposeVisualizers();
+ if (m_selectionManager != null) {
+ m_selectionManager.dispose();
+ m_selectionManager = null;
+ }
+ }
+
// --- accessors ---
-
+
/** Gets containing view. */
public VisualizerView getView() {
return m_view;
}
-
+
/** Returns non-localized unique name for selected visualizer. */
- public String getVisualizerName()
- {
+ public String getVisualizerName() {
String result = "visualizer";
- if (m_currentVisualizer != null) result = m_currentVisualizer.getName();
+ if (m_currentVisualizer != null)
+ result = m_currentVisualizer.getName();
return result;
}
/** Returns localized name to display for selected visualizer. */
- public String getVisualizerDisplayName()
- {
+ public String getVisualizerDisplayName() {
String result = "Visualizer";
- if (m_currentVisualizer != null) result = m_currentVisualizer.getDisplayName();
+ if (m_currentVisualizer != null)
+ result = m_currentVisualizer.getDisplayName();
return result;
}
-
+
/** Returns localized tooltip text to display for selected visualizer. */
- public String getVisualizerDescription()
- {
+ public String getVisualizerDescription() {
String result = "Visualizer";
- if (m_currentVisualizer != null) result = m_currentVisualizer.getDescription();
+ if (m_currentVisualizer != null)
+ result = m_currentVisualizer.getDescription();
return result;
}
-
// --- control management ---
-
+
/** Gets viewer control. */
public Control getControl() {
return this;
}
-
-
+
// --- focus handling ---
-
+
/**
* Invoked by VisualizerView when currently selected presentation,
* if any, should take the focus.
*/
- public boolean setFocus()
- {
+ public boolean setFocus() {
boolean result = false;
if (m_currentVisualizer != null) {
// Tell current visualizer's control to take the focus.
m_currentVisualizer.getControl().setFocus();
- }
- else {
+ } else {
// Otherwise, let viewer take the focus.
result = super.setFocus();
}
return result;
}
-
// --- viewer events ---
-
+
/** Adds listener for viewer events. */
- public void addVisualizerViewerListener(IVisualizerViewerListener listener)
- {
+ public void addVisualizerViewerListener(IVisualizerViewerListener listener) {
m_listeners.addListener(listener);
}
-
+
/** Removes listener for viewer events. */
- public void removeVisualizerViewerListener(IVisualizerViewerListener listener)
- {
+ public void removeVisualizerViewerListener(IVisualizerViewerListener listener) {
m_listeners.removeListener(listener);
}
/** Raises change event for all listeners. */
- public void raiseVisualizerChangedEvent()
- {
- VisualizerViewerEvent event =
- new VisualizerViewerEvent(this, VisualizerViewerEvent.VISUALIZER_CHANGED);
+ public void raiseVisualizerChangedEvent() {
+ VisualizerViewerEvent event = new VisualizerViewerEvent(this, VisualizerViewerEvent.VISUALIZER_CHANGED);
m_listeners.raise(event);
}
/** Raises context menu event for all listeners. */
- public void raiseContextMenuEvent(int x, int y)
- {
- VisualizerViewerEvent event =
- new VisualizerViewerEvent(this, VisualizerViewerEvent.VISUALIZER_CONTEXT_MENU, x, y);
+ public void raiseContextMenuEvent(int x, int y) {
+ VisualizerViewerEvent event = new VisualizerViewerEvent(this, VisualizerViewerEvent.VISUALIZER_CONTEXT_MENU, x,
+ y);
m_listeners.raise(event);
}
-
// --- visualizer management ---
/** Loads initial set of visualizers and constructs viewer controls. */
- protected void loadVisualizers()
- {
+ protected void loadVisualizers() {
// TODO: add error checking, logging for errors in extension declarations
// TODO: do we need to worry about this being called more than once?
-
- m_visualizers = new Hashtable<String, IVisualizer>();
-
- List<Extension> visualizers = Extension.getExtensions(
- CDTVisualizerUIPlugin.FEATURE_ID, VISUALIZER_EXTENSION_POINT_NAME);
-
- if (visualizers != null) {
- for(Extension e : visualizers) {
- String id = e.getAttribute("id");
- IVisualizer visualizerInstance = e.getClassAttribute();
- if (id != null && visualizerInstance != null) {
- // Add visualizer's control to viewer's "pagebook" of controls.
- visualizerInstance.setViewer(this);
- visualizerInstance.initializeVisualizer();
- visualizerInstance.createControl(this);
- m_visualizers.put(id, visualizerInstance);
- }
- }
- }
-
+
+ m_visualizers = new Hashtable<String, IVisualizer>();
+
+ List<Extension> visualizers = Extension.getExtensions(CDTVisualizerUIPlugin.FEATURE_ID,
+ VISUALIZER_EXTENSION_POINT_NAME);
+
+ if (visualizers != null) {
+ for (Extension e : visualizers) {
+ String id = e.getAttribute("id");
+ IVisualizer visualizerInstance = e.getClassAttribute();
+ if (id != null && visualizerInstance != null) {
+ // Add visualizer's control to viewer's "pagebook" of controls.
+ visualizerInstance.setViewer(this);
+ visualizerInstance.initializeVisualizer();
+ visualizerInstance.createControl(this);
+ m_visualizers.put(id, visualizerInstance);
+ }
+ }
+ }
+
// select initial visualization
- selectDefaultVisualizer();
+ selectDefaultVisualizer();
}
-
+
/** Cleans up visualizers. */
- protected void disposeVisualizers()
- {
+ protected void disposeVisualizers() {
for (String id : m_visualizers.keySet()) {
IVisualizer v = m_visualizers.get(id);
Control c = v.getControl();
@@ -312,36 +289,35 @@ public class VisualizerViewer extends PageBook
m_visualizers.clear();
}
-
/** Selects default visualizer.
* Default implementation displays visualizer that can handle
* the current selection.
*/
- public void selectDefaultVisualizer()
- {
+ public void selectDefaultVisualizer() {
// fake a workbench selection changed event
updateVisualizerFromWorkbenchSelection();
}
-
+
/** Selects specified visualizer, makes its control visible. */
- public void selectVisualizer(IVisualizer visualizer)
- {
- if (visualizer == null) return;
- if (visualizer == m_currentVisualizer) return;
+ public void selectVisualizer(IVisualizer visualizer) {
+ if (visualizer == null)
+ return;
+ if (visualizer == m_currentVisualizer)
+ return;
if (m_currentVisualizer != null) {
// let the visualizer know it's being hidden
m_currentVisualizer.visualizerDeselected();
-
+
// stop listening for context menu events
m_currentVisualizer.getControl().removeMenuDetectListener(this);
-
+
// stop listening for selection changed events
m_currentVisualizer.removeSelectionChangedListener(this);
}
-
+
m_currentVisualizer = visualizer;
-
+
if (m_currentVisualizer != null) {
// We've added visualizer's control in loadVisualizers(),
// so all we need to do here is select it.
@@ -356,10 +332,10 @@ public class VisualizerViewer extends PageBook
// raise visualizer changed event, so view knows
// it should update tab name, toolbar, etc.
raiseVisualizerChangedEvent();
-
+
// make sure workbench knows about current visualizer selection
updateWorkbenchFromVisualizerSelection();
-
+
// no need to update visualizer from workbench selection,
// we already do that whenever the workbench selection changes
@@ -367,33 +343,28 @@ public class VisualizerViewer extends PageBook
m_currentVisualizer.visualizerSelected();
}
}
-
+
/** Gets current visualizer. */
- public IVisualizer getVisualizer()
- {
+ public IVisualizer getVisualizer() {
return m_currentVisualizer;
}
-
// --- menu/toolbar management ---
/** Invoked when visualizer is selected, to populate the toolbar. */
- public void populateToolBar(IToolBarManager toolBarManager)
- {
+ public void populateToolBar(IToolBarManager toolBarManager) {
if (m_currentVisualizer != null)
m_currentVisualizer.populateToolBar(toolBarManager);
}
/** Invoked when visualizer is selected, to populate the toolbar's menu. */
- public void populateMenu(IMenuManager menuManager)
- {
+ public void populateMenu(IMenuManager menuManager) {
if (m_currentVisualizer != null)
m_currentVisualizer.populateMenu(menuManager);
}
-
// --- context menu handling ---
-
+
/** Invoked when context menu gesture happens on current
* visualizer control.
*/
@@ -403,41 +374,36 @@ public class VisualizerViewer extends PageBook
}
/** Invoked when context menu is about to be shown. */
- public void populateContextMenu(IMenuManager m)
- {
+ public void populateContextMenu(IMenuManager m) {
if (m_currentVisualizer != null) {
m_currentVisualizer.populateContextMenu(m);
}
}
-
+
/** Gets context menu location. */
public Point getContextMenuLocation() {
return m_view.getContextMenuLocation();
}
-
-
+
// --- paint methods ---
-
+
/**
* Invoked when viewer needs to be repainted.
- * May be overridden by derived classes.
+ * May be overridden by derived classes.
* Default implementation displays "No visualizers defined." message
*/
- public void paint(GC gc)
- {
+ public void paint(GC gc) {
gc.fillRectangle(getClientArea());
if (m_visualizers == null || m_visualizers.size() == 0) {
- String noVisualizersMessage =
- CDTVisualizerUIPlugin.getString("VisualizerViewer.no.visualizers.defined");
+ String noVisualizersMessage = CDTVisualizerUIPlugin.getString("VisualizerViewer.no.visualizers.defined");
gc.drawString("(" + noVisualizersMessage + ")", 10, 10);
}
}
-
-
+
// --- ISelectionProvider implementation ---
-
+
// Delegate to selection manager.
-
+
/** Adds external listener for selection change events. */
public void addSelectionChangedListener(ISelectionChangedListener listener) {
m_selectionManager.addSelectionChangedListener(listener);
@@ -445,29 +411,26 @@ public class VisualizerViewer extends PageBook
/** Removes external listener for selection change events. */
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
- if(m_selectionManager != null) {
+ if (m_selectionManager != null) {
m_selectionManager.removeSelectionChangedListener(listener);
}
}
-
+
/** Raises selection changed event. */
public void raiseSelectionChangedEvent() {
m_selectionManager.raiseSelectionChangedEvent();
}
-
+
/** Gets current externally-visible selection. */
- public ISelection getSelection()
- {
+ public ISelection getSelection() {
return m_selectionManager.getSelection();
}
-
+
/** Sets externally-visible selection. */
- public void setSelection(ISelection selection)
- {
+ public void setSelection(ISelection selection) {
m_selectionManager.setSelection(selection);
}
-
// --- workbench selection handling ---
/**
@@ -481,20 +444,19 @@ public class VisualizerViewer extends PageBook
workbenchSelectionChanged(selection);
}
- /**
- * Invoked by VisualizerView when workbench selection changes,
- * and change's source is not this view.
- *
- * Selects visualizer (if any) that knows how to display current
- * selection. Also invokes workbenchSelectionChanged() on visualizer
- * so it can update itself accordingly.
- */
- public void workbenchSelectionChanged(ISelection selection)
- {
+ /**
+ * Invoked by VisualizerView when workbench selection changes,
+ * and change's source is not this view.
+ *
+ * Selects visualizer (if any) that knows how to display current
+ * selection. Also invokes workbenchSelectionChanged() on visualizer
+ * so it can update itself accordingly.
+ */
+ public void workbenchSelectionChanged(ISelection selection) {
// See if we need to change visualizers to handle selection type.
IVisualizer handles = null;
int weight = 0;
-
+
// First, see if the current visualizer can handle the new selection.
// (This gives it automatic precedence if there's a tie.)
if (m_currentVisualizer != null) {
@@ -508,20 +470,21 @@ public class VisualizerViewer extends PageBook
// Next, check the list of other visualizers, to see if any
// of them is more specific than the current one.
for (IVisualizer v : m_visualizers.values()) {
- if (v == m_currentVisualizer) continue; // already checked
+ if (v == m_currentVisualizer)
+ continue; // already checked
int w = v.handlesSelection(selection);
if (w > weight) {
handles = v;
weight = w;
}
}
-
+
// If NOBODY claims ownership, and we don't have a visualizer yet,
// then pick somebody and let them take a whack at it.
if (handles == null && m_visualizers.size() > 0) {
handles = m_visualizers.values().iterator().next();
}
-
+
// If we need to change visualizers, select the new one.
// Note: this also reports the new visualizer's selection to the workbench
if (handles != null && handles != m_currentVisualizer) {
@@ -536,9 +499,8 @@ public class VisualizerViewer extends PageBook
}
}
-
// --- visualizer selection handling ---
-
+
/** Updates workbench selection from current visualizer selection.
* Note: normally the viewer keeps the selection in synch,
* so you should not need to call this method except in special cases.
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/BufferedCanvas.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/BufferedCanvas.java
index d2162efe41..9ce04c690e 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/BufferedCanvas.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/BufferedCanvas.java
@@ -27,41 +27,36 @@ import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-
// ---------------------------------------------------------------------------
// BufferedCanvas
// ---------------------------------------------------------------------------
/** Canvas control with double-buffering support. */
-public class BufferedCanvas extends Canvas
- implements PaintListener, ControlListener
-{
+public class BufferedCanvas extends Canvas implements PaintListener, ControlListener {
// --- members ---
-
+
/** double-buffering image */
protected Image m_doubleBuffer = null;
-
+
/** buffer GC */
protected GC m_doubleBufferGC = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public BufferedCanvas(Composite parent) {
- super(parent,
- SWT.NO_BACKGROUND | // don't automatically clear background on paint event
- SWT.NO_REDRAW_RESIZE // don't automatically repaint on resize event
- );
+ super(parent, SWT.NO_BACKGROUND | // don't automatically clear background on paint event
+ SWT.NO_REDRAW_RESIZE // don't automatically repaint on resize event
+ );
initBufferedCanvas();
}
-
+
/** Dispose method. */
public void dispose() {
super.dispose();
cleanupBufferedCanvas();
}
-
+
// --- init methods ---
/** Initializes control. */
@@ -69,10 +64,10 @@ public class BufferedCanvas extends Canvas
addControlListener(this);
addPaintListener(this);
}
-
+
/** Cleans up control. */
protected void cleanupBufferedCanvas() {
- if(!this.isDisposed()) {
+ if (!this.isDisposed()) {
removePaintListener(this);
removeControlListener(this);
}
@@ -81,10 +76,9 @@ public class BufferedCanvas extends Canvas
m_doubleBuffer = null;
}
}
-
-
+
// --- event handlers ---
-
+
/** Invoked when control is moved/resized */
public void controlMoved(ControlEvent e) {
// do nothing, we don't care
@@ -94,28 +88,26 @@ public class BufferedCanvas extends Canvas
public void controlResized(ControlEvent e) {
resized(getBounds());
}
-
-
+
// --- resize methods ---
-
+
/** Invoked when control is resized.
* Default implementation does nothing,
* intended to be overridden by derived types.
*/
public void resized(Rectangle bounds) {
-
+
}
-
-
+
// --- GC management ---
-
+
/** Gets/creates GC for current background buffer.
* NOTE: The GC is disposed whenever the canvas size changes,
* so caller should not retain a reference to this GC.
*/
protected synchronized GC getBufferedGC() {
if (m_doubleBufferGC == null) {
-
+
m_doubleBufferGC = new GC(m_doubleBuffer);
}
return m_doubleBufferGC;
@@ -129,57 +121,53 @@ public class BufferedCanvas extends Canvas
}
}
-
// --- paint methods ---
-
+
/** Invoked when control needs to be repainted */
public void paintControl(PaintEvent e) {
// Handle last paint event of a cluster.
- if (e.count<=1) {
+ if (e.count <= 1) {
Display display = e.display;
GC gc = e.gc;
paintDoubleBuffered(display, gc);
}
}
-
+
/** Internal -- handles double-buffering support, calls paintCanvas() */
// NOTE: need display to create image buffer, not for painting code
protected void paintDoubleBuffered(Display display, GC gc) {
- // get/create background image buffer
+ // get/create background image buffer
Rectangle clientArea = getClientArea();
int width = clientArea.width;
int height = clientArea.height;
- if (m_doubleBuffer == null
- || m_doubleBuffer.getBounds().width < width
- || m_doubleBuffer.getBounds().height < height)
- {
+ if (m_doubleBuffer == null || m_doubleBuffer.getBounds().width < width
+ || m_doubleBuffer.getBounds().height < height) {
m_doubleBuffer = new Image(display, width, height);
disposeBufferedGC();
- }
-
- // create graphics context for buffer
- GC bgc = getBufferedGC();
-
- // copy current GC properties into it as defaults
- bgc.setBackground(gc.getBackground());
- bgc.setForeground(gc.getForeground());
- bgc.setFont(gc.getFont());
- bgc.setAlpha(255);
-
- // invoke paintCanvas() method to paint into the buffer
- try {
- paintCanvas(bgc);
- }
- catch (Throwable t) {
- // Throwing an exception in painting code can hang Eclipse,
- // so catch any exceptions here.
- System.err.println("BufferedCanvas: Exception thrown in painting code: \n" + t);
- }
-
- // then copy image buffer to actual canvas (reduces repaint flickering)
- gc.drawImage(m_doubleBuffer, 0,0);
+ }
+
+ // create graphics context for buffer
+ GC bgc = getBufferedGC();
+
+ // copy current GC properties into it as defaults
+ bgc.setBackground(gc.getBackground());
+ bgc.setForeground(gc.getForeground());
+ bgc.setFont(gc.getFont());
+ bgc.setAlpha(255);
+
+ // invoke paintCanvas() method to paint into the buffer
+ try {
+ paintCanvas(bgc);
+ } catch (Throwable t) {
+ // Throwing an exception in painting code can hang Eclipse,
+ // so catch any exceptions here.
+ System.err.println("BufferedCanvas: Exception thrown in painting code: \n" + t);
+ }
+
+ // then copy image buffer to actual canvas (reduces repaint flickering)
+ gc.drawImage(m_doubleBuffer, 0, 0);
}
-
+
/** Invoked when canvas repaint event is raised.
* Default implementation clears canvas to background color.
*/
@@ -193,14 +181,13 @@ public class BufferedCanvas extends Canvas
gc.fillRectangle(bounds);
}
-
// --- update methods ---
-
+
/** Redraws control */
public void update() {
// guard against update events that happen
// after app has shut down
- if (! isDisposed()) {
+ if (!isDisposed()) {
redraw();
}
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvas.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvas.java
index 565a4c3ac3..b23b9f3d64 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvas.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvas.java
@@ -23,7 +23,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
-
// ---------------------------------------------------------------------------
// GraphicCanvas
// ---------------------------------------------------------------------------
@@ -31,21 +30,19 @@ import org.eclipse.swt.widgets.Listener;
/**
* Viewer canvas -- base class for canvas that displays a collection
* of persistent, repositionable graphic objects.
- *
+ *
* Note: painting is done in order objects were added,
* so objects added last are drawn "on top" of others.
* Use raise/lower methods to change the object z-ordering, if needed.
*/
-public class GraphicCanvas extends BufferedCanvas
-{
+public class GraphicCanvas extends BufferedCanvas {
// --- members ---
-
+
/** Viewer elements. */
protected ArrayList<IGraphicObject> m_objects = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public GraphicCanvas(Composite parent) {
super(parent);
@@ -67,7 +64,7 @@ public class GraphicCanvas extends BufferedCanvas
addListener(SWT.MouseMove, mouseListener);
addListener(SWT.MouseEnter, mouseListener);
}
-
+
/** Dispose method. */
public void dispose() {
if (m_objects != null) {
@@ -76,28 +73,27 @@ public class GraphicCanvas extends BufferedCanvas
}
super.dispose();
}
-
-
+
// --- object management methods ---
/** Removes all elements */
public void clear() {
m_objects.clear();
}
-
+
/** Adds an element */
public IGraphicObject add(IGraphicObject element) {
- if (! m_objects.contains(element)) {
+ if (!m_objects.contains(element)) {
m_objects.add(element);
}
return element;
}
-
+
/** Removes an element */
public void remove(IGraphicObject element) {
m_objects.remove(element);
}
-
+
/** Raises an element to top of repaint z-ordering */
public void raiseToFront(IGraphicObject element) {
if (m_objects.contains(element)) {
@@ -105,7 +101,7 @@ public class GraphicCanvas extends BufferedCanvas
m_objects.add(element);
}
}
-
+
/** Lowers an element to bottom of repaint z-ordering */
public void lowerToBack(IGraphicObject element) {
if (m_objects.contains(element)) {
@@ -114,14 +110,13 @@ public class GraphicCanvas extends BufferedCanvas
}
}
-
// --- painting methods ---
-
+
/** Paints elements on canvas. */
public void paintCanvas(GC gc) {
// paint background first
clearCanvas(gc);
-
+
// we paint object list from start to end,
// so end of the list is "top" in z-ordering
@@ -136,10 +131,9 @@ public class GraphicCanvas extends BufferedCanvas
gobj.paint(gc, true);
}
}
-
-
+
// --- point-to-object accessors ---
-
+
/** Returns first graphic object found under specified point */
public IGraphicObject getGraphicObject(int x, int y) {
return getGraphicObject(null, x, y);
@@ -150,27 +144,28 @@ public class GraphicCanvas extends BufferedCanvas
*/
public IGraphicObject getGraphicObject(Class<?> type, int x, int y) {
IGraphicObject result = null;
-
+
// note: have to search list in reverse order we draw it,
// so we hit items "on top" in the z-ordering first
int count = (m_objects == null) ? 0 : m_objects.size();
- for (int i=count-1; i>=0; i--) {
+ for (int i = count - 1; i >= 0; i--) {
IGraphicObject gobj = m_objects.get(i);
if (gobj.contains(x, y)) {
if (type != null) {
Class<?> objType = gobj.getClass();
- if (! type.isAssignableFrom(objType)) continue;
+ if (!type.isAssignableFrom(objType))
+ continue;
}
result = gobj;
break;
}
}
-
+
return result;
}
-
+
// --- model data accessors ---
-
+
/** Returns graphic object (if any) that has specified data value. */
public IGraphicObject getGraphicObjectFor(Object value) {
IGraphicObject result = null;
@@ -182,7 +177,7 @@ public class GraphicCanvas extends BufferedCanvas
}
return result;
}
-
+
/** Returns data value (if any) for the specified graphic element. */
public Object getDataFor(IGraphicObject IGraphicObject) {
return (IGraphicObject == null) ? null : IGraphicObject.getData();
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvasVisualizer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvasVisualizer.java
index 44ee9858fa..8eedd081c7 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvasVisualizer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicCanvasVisualizer.java
@@ -20,7 +20,6 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-
// ---------------------------------------------------------------------------
// GraphicCanvasVisualizer
// ---------------------------------------------------------------------------
@@ -28,25 +27,22 @@ import org.eclipse.swt.widgets.Control;
/**
* Viewer canvas -- base class for canvas that displays a collection
* of persistent, repositionable graphic objects.
- *
+ *
* Note: painting is done in order objects were added,
* so objects added last are drawn "on top" of others.
* Use raise/lower methods to change the object z-ordering, if needed.
*/
-public class GraphicCanvasVisualizer extends Visualizer
-{
+public class GraphicCanvasVisualizer extends Visualizer {
// --- members ---
-
// --- constructors/destructors ---
-
+
/** Constructor. */
- public GraphicCanvasVisualizer()
- {
+ public GraphicCanvasVisualizer() {
// TODO: internationalize these strings.
super("canvas", "Canvas Visualizer", "Displays graphic representation of selection.");
}
-
+
/** Constructor specifying name and such information. */
public GraphicCanvasVisualizer(String name, String displayName, String description) {
super(name, displayName, description);
@@ -57,12 +53,10 @@ public class GraphicCanvasVisualizer extends Visualizer
super.dispose();
}
-
// --- control management ---
-
+
/** Creates and returns visualizer control on specified parent. */
- public Control createControl(Composite parent)
- {
+ public Control createControl(Composite parent) {
if (m_control == null) {
GraphicCanvas canvas = createCanvas(parent);
canvas.setMenu(parent.getMenu());
@@ -71,61 +65,53 @@ public class GraphicCanvasVisualizer extends Visualizer
}
return getControl();
}
-
+
/** Invoked when visualizer control should be disposed. */
- public void disposeControl()
- {
+ public void disposeControl() {
if (m_control != null) {
disposeCanvas();
m_control.dispose();
setControl(null);
}
}
-
-
+
// --- canvas management ---
-
+
/** Creates and returns visualizer canvas control. */
- public GraphicCanvas createCanvas(Composite parent)
- {
+ public GraphicCanvas createCanvas(Composite parent) {
return new GraphicCanvas(parent);
}
/** Invoked when canvas control should be disposed. */
- public void disposeCanvas()
- {
-
+ public void disposeCanvas() {
+
}
-
+
/** Invoked after visualizer control creation,
* to allow derived classes to do any initialization of canvas.
*/
- protected void initializeCanvas(GraphicCanvas canvas)
- {
+ protected void initializeCanvas(GraphicCanvas canvas) {
}
-
+
/** Gets downcast reference to canvas control. */
- public GraphicCanvas getCanvas()
- {
+ public GraphicCanvas getCanvas() {
return (GraphicCanvas) getControl();
}
-
// --- menu/toolbar management ---
/** Invoked when visualizer is selected, to populate the toolbar. */
- public void populateToolBar(IToolBarManager toolBarManager)
- {}
+ public void populateToolBar(IToolBarManager toolBarManager) {
+ }
/** Invoked when visualizer is selected, to populate the toolbar's menu. */
- public void populateMenu(IMenuManager menuManager)
- {}
+ public void populateMenu(IMenuManager menuManager) {
+ }
-
// --- context menu handling ---
-
+
/** Invoked when visualizer view's context menu is invoked, to populate it. */
- public void populateContextMenu(IMenuManager menuManager)
- {}
-
+ public void populateContextMenu(IMenuManager menuManager) {
+ }
+
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicObject.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicObject.java
index 44c25aeea9..41f822dfa8 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicObject.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/GraphicObject.java
@@ -24,7 +24,6 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
-
// ---------------------------------------------------------------------------
// GraphicObject
// ---------------------------------------------------------------------------
@@ -33,32 +32,29 @@ import org.eclipse.swt.graphics.Rectangle;
* Graphic object base class.
* Base class for objects that can be displayed and manipulated on a GraphicCanvas.
*/
-public class GraphicObject
- implements IGraphicObject, ITooltipProvider
-{
+public class GraphicObject implements IGraphicObject, ITooltipProvider {
// --- members ---
/** Data object, if any, associated with this graphic object. */
protected Object m_data = null;
-
+
/** Bounding rectangle of this element. */
- protected Rectangle m_bounds = new Rectangle(0,0,0,0);
-
+ protected Rectangle m_bounds = new Rectangle(0, 0, 0, 0);
+
/** Whether this element is visible. */
protected boolean m_visible = true;
-
+
/** Whether this element is selected. */
protected boolean m_selected = false;
-
+
/** Foreground color (null means inherit from canvas) */
protected Color m_foreground = null;
-
+
/** Background color (null means inherit from canvas) */
protected Color m_background = null;
-
-
+
// --- enums ---
-
+
/**
* Pre-defined sizes/positions for super-imposing images on graphic objects.
* @since 1.3
@@ -69,7 +65,7 @@ public class GraphicObject
/** Image occupies upper-right quadrant of graphic object's area */
UPPER_RIGHT_QUADRANT(new Rectangle(50, 0, 50, 50)),
/** Image occupies lower-left quadrant of graphic object's area */
- LOWER_LEFT_QUADRANT(new Rectangle(0, 50, 50, 50)),
+ LOWER_LEFT_QUADRANT(new Rectangle(0, 50, 50, 50)),
/** Image occupies lower-right quadrant of graphic object's area */
LOWER_RIGHT_QUADRANT(new Rectangle(50, 50, 50, 50)),
/** Image occupies lower-right 1/8 of graphic object's area */
@@ -78,23 +74,24 @@ public class GraphicObject
UPPER_LEFT_SEVENTH_HEIGHTH(new Rectangle(0, 0, 75, 75)),
/** Image completely occupies the graphic object's area */
MAXSIZE(new Rectangle(0, 0, 100, 100));
-
+
private Rectangle value;
+
private ImageSizeAndPosition(Rectangle sizeAndPos) {
value = sizeAndPos;
}
+
public Rectangle getValue() {
return value;
}
}
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public GraphicObject() {
}
-
+
/** Constructor. */
public GraphicObject(int x, int y, int width, int height) {
m_bounds.x = x;
@@ -102,7 +99,7 @@ public class GraphicObject
m_bounds.width = width;
m_bounds.height = height;
}
-
+
/** Constructor. */
public GraphicObject(Rectangle bounds) {
m_bounds.x = bounds.x;
@@ -110,12 +107,12 @@ public class GraphicObject
m_bounds.width = bounds.width;
m_bounds.height = bounds.height;
}
-
+
/** Constructor. */
public GraphicObject(Object data) {
m_data = data;
}
-
+
/** Constructor. */
public GraphicObject(int x, int y, int width, int height, Object data) {
m_bounds.x = x;
@@ -124,73 +121,90 @@ public class GraphicObject
m_bounds.height = height;
m_data = data;
}
-
/** Constructor. */
- public GraphicObject(Rectangle bounds, Object data)
- {
+ public GraphicObject(Rectangle bounds, Object data) {
m_bounds.x = bounds.x;
m_bounds.y = bounds.y;
m_bounds.width = bounds.width;
m_bounds.height = bounds.height;
m_data = data;
}
-
+
/** Dispose method. */
public void dispose() {
m_data = null;
}
-
// --- accessors ---
-
+
/** Gets data object associated with this view element. */
public Object getData() {
return m_data;
}
+
/** Sets data object associated with this view element. */
public void setData(Object data) {
m_data = data;
}
-
-
+
/** Gets x location of this element */
- public int getX() { return m_bounds.x; }
+ public int getX() {
+ return m_bounds.x;
+ }
+
/** Sets x location of this element */
- public void setX(int x) {
- m_bounds.x = x;
+ public void setX(int x) {
+ m_bounds.x = x;
}
/** Gets y location of this element */
- public int getY() { return m_bounds.y; }
+ public int getY() {
+ return m_bounds.y;
+ }
+
/** Sets y location of this element */
- public void setY(int y) { m_bounds.y = y; }
-
+ public void setY(int y) {
+ m_bounds.y = y;
+ }
+
/** Sets x/y position of this element */
public void setPosition(int x, int y) {
- m_bounds.x = x; m_bounds.y = y;
+ m_bounds.x = x;
+ m_bounds.y = y;
}
-
-
+
/** Gets width of this element */
- public int getWidth() { return m_bounds.width; }
+ public int getWidth() {
+ return m_bounds.width;
+ }
+
/** Sets width of this element */
- public void setWidth(int w) { m_bounds.width = w; }
+ public void setWidth(int w) {
+ m_bounds.width = w;
+ }
/** Gets y location of this element */
- public int getHeight() { return m_bounds.height; }
+ public int getHeight() {
+ return m_bounds.height;
+ }
+
/** Sets y location of this element */
- public void setHeight(int h) { m_bounds.height = h; }
-
+ public void setHeight(int h) {
+ m_bounds.height = h;
+ }
+
/** Sets width/height of this element */
public void setSize(int w, int h) {
- m_bounds.width = w; m_bounds.height = h;
+ m_bounds.width = w;
+ m_bounds.height = h;
}
-
+
/** Gets bounding rectangle of this element. */
public Rectangle getBounds() {
return m_bounds;
}
+
/** Sets bounding rectangle of this element. */
public void setBounds(int x, int y, int w, int h) {
m_bounds.x = x;
@@ -198,6 +212,7 @@ public class GraphicObject
m_bounds.width = w;
m_bounds.height = h;
}
+
/** Sets bounding rectangle of this element. */
public void setBounds(Rectangle bounds) {
m_bounds.x = bounds.x;
@@ -205,19 +220,19 @@ public class GraphicObject
m_bounds.width = bounds.width;
m_bounds.height = bounds.height;
}
-
+
/** Returns true if element bounds contains point. */
public boolean contains(int x, int y) {
- return m_bounds.contains(x,y);
+ return m_bounds.contains(x, y);
}
+
/** Returns true if element bounds are within specified rectangle. */
public boolean isWithin(Rectangle region) {
- return (region.x <= m_bounds.x &&
- region.y <= m_bounds.y &&
- region.x + region.width >= m_bounds.x + m_bounds.width &&
- region.y + region.height >= m_bounds.y + m_bounds.height);
+ return (region.x <= m_bounds.x && region.y <= m_bounds.y
+ && region.x + region.width >= m_bounds.x + m_bounds.width
+ && region.y + region.height >= m_bounds.y + m_bounds.height);
}
-
+
/** Gets whether this element is visible. */
public boolean isVisible() {
return m_visible;
@@ -227,7 +242,7 @@ public class GraphicObject
public void setVisible(boolean visible) {
m_visible = visible;
}
-
+
/** Gets whether this element is selected. */
public boolean isSelected() {
return m_selected;
@@ -237,11 +252,12 @@ public class GraphicObject
public void setSelected(boolean selected) {
m_selected = selected;
}
-
+
/** Sets foreground color (null means inherit from container) */
public void setForeground(Color color) {
m_foreground = color;
}
+
/** Gets foreground color (null means inherit from container) */
public Color getForeground() {
return m_foreground;
@@ -251,14 +267,14 @@ public class GraphicObject
public void setBackground(Color color) {
m_background = color;
}
+
/** Gets background color (null means inherit from container) */
public Color getBackground() {
return m_background;
}
-
// --- methods ---
-
+
/** Invoked to allow element to paint itself on the viewer canvas */
public void paint(GC gc, boolean decorations) {
if (isVisible()) {
@@ -275,17 +291,19 @@ public class GraphicObject
}
// Paint the object.
- if (! decorations)
+ if (!decorations)
paintContent(gc);
else
paintDecorations(gc);
// Restore old state.
- if (m_foreground != null) gc.setForeground(oldForeground);
- if (m_background != null) gc.setBackground(oldBackground);
+ if (m_foreground != null)
+ gc.setForeground(oldForeground);
+ if (m_background != null)
+ gc.setBackground(oldBackground);
}
}
-
+
/**
* Paints content of graphic object.
* GC has already been set to this object's
@@ -295,22 +313,26 @@ public class GraphicObject
public void paintContent(GC gc) {
// Draw boundary rectangle of object.
gc.drawRectangle(m_bounds);
-
+
// Display selection as thicker boundary.
if (isSelected()) {
int x = m_bounds.x + 1;
int y = m_bounds.y + 1;
- int width = m_bounds.width - 2; if (width < 0) width = 0;
- int height = m_bounds.height - 2; if (height < 0) height = 0;
- gc.drawRectangle(x,y,width,height);
+ int width = m_bounds.width - 2;
+ if (width < 0)
+ width = 0;
+ int height = m_bounds.height - 2;
+ if (height < 0)
+ height = 0;
+ gc.drawRectangle(x, y, width, height);
}
}
-
+
/** Returns true if object has decorations to paint. */
public boolean hasDecorations() {
return false;
}
-
+
/** Invoked to allow element to paint decorations
* on top of other items drawn on top of it.
*/
@@ -324,111 +346,105 @@ public class GraphicObject
public String getTooltip(int x, int y) {
return null;
}
-
-
+
/**
* Draws an image on the current canvas graphic element. Where the image is
- * located, relative to the graphic object and it's horizontal and vertical
- * scale is configurable.
- *
+ * located, relative to the graphic object and it's horizontal and vertical
+ * scale is configurable.
+ *
* @param gc
* @param imgPath : Absolute path and name of image to display
* by this margin, in each dimension.
- * @param imgRelPositionAndScale : Rectangle object, where x, y are in % and
+ * @param imgRelPositionAndScale : Rectangle object, where x, y are in % and
* represent the relative position where the upper left corner of the image
- * will be positioned, relative to the parent graphic object.
+ * will be positioned, relative to the parent graphic object.
* The width and height are in % and represent the scale of the object relative
- * to the parent object. For example. a relative width and height of 25 means
- * that the image will be scaled to be 1/4 of the width and height of the parent
- * graphic object.
- * @throws FileNotFoundException
+ * to the parent object. For example. a relative width and height of 25 means
+ * that the image will be scaled to be 1/4 of the width and height of the parent
+ * graphic object.
+ * @throws FileNotFoundException
* @since 1.3
*/
- public void drawImage(GC gc, String imgPath, Rectangle imgRelPositionAndScale)
- throws FileNotFoundException
- {
+ public void drawImage(GC gc, String imgPath, Rectangle imgRelPositionAndScale) throws FileNotFoundException {
// by default no margin
drawImageWithMargin(gc, imgPath, imgRelPositionAndScale, 0);
}
-
- /**
+
+ /**
* Draws an image on the current canvas graphic element. Where the image is
- * located, relative to the graphic object and it's horizontal and vertical
- * scale is configurable.
- *
+ * located, relative to the graphic object and it's horizontal and vertical
+ * scale is configurable.
+ *
* @param gc
* @param imgPath : Absolute path and name of image to draw
* @param sizeAndpos : ImageSizeAndPosition enum value
* represent the relative position where the upper left corner of the image
- * will be positioned, relative to the parent graphic object.
+ * will be positioned, relative to the parent graphic object.
* The width and height are in % and represent the scale of the object relative
- * to the parent object. For example. a relative width and height of 25 means
- * that the image will be scaled to be 1/4 of the width and height of the parent
- * graphic object.
- * @throws FileNotFoundException
+ * to the parent object. For example. a relative width and height of 25 means
+ * that the image will be scaled to be 1/4 of the width and height of the parent
+ * graphic object.
+ * @throws FileNotFoundException
* @since 1.3
*/
- public void drawImage(GC gc, String imgPath, ImageSizeAndPosition sizeAndpos)
- throws FileNotFoundException
- {
+ public void drawImage(GC gc, String imgPath, ImageSizeAndPosition sizeAndpos) throws FileNotFoundException {
drawImageWithMargin(gc, imgPath, sizeAndpos.getValue(), 0);
}
-
- /**
+
+ /**
* Draws an image on the current canvas graphic element. Where the image is
- * located, relative to the graphic object and it's horizontal and vertical
+ * located, relative to the graphic object and it's horizontal and vertical
* scale is configurable. This version of the method allows to specify a margin,
- * in pixels, that is to be left, by reducing the size of the image
- *
+ * in pixels, that is to be left, by reducing the size of the image
+ *
* @param gc
* @param imgPath : Absolute path and name of image to draw
* @param sizeAndpos : ImageSizeAndPosition enum value
* represent the relative position where the upper left corner of the image
- * will be positioned, relative to the parent graphic object.
+ * will be positioned, relative to the parent graphic object.
* The width and height are in % and represent the scale of the object relative
- * to the parent object. For example. a relative width and height of 25 means
- * that the image will be scaled to be 1/4 of the width and height of the parent
- * graphic object.
+ * to the parent object. For example. a relative width and height of 25 means
+ * that the image will be scaled to be 1/4 of the width and height of the parent
+ * graphic object.
* @param margin: margin in pixels: the image will be reduced in size
* by this margin, in each dimension.
- * @throws FileNotFoundException
+ * @throws FileNotFoundException
* @since 1.3
*/
- public void drawImageWithMargin(GC gc, String imgPath, ImageSizeAndPosition sizeAndpos, int margin)
- throws FileNotFoundException
- {
+ public void drawImageWithMargin(GC gc, String imgPath, ImageSizeAndPosition sizeAndpos, int margin)
+ throws FileNotFoundException {
drawImageWithMargin(gc, imgPath, sizeAndpos.getValue(), margin);
}
-
- /**
+
+ /**
* Draws an image on the current canvas graphic element. Where the image is
- * located, relative to the graphic object and it's horizontal and vertical
+ * located, relative to the graphic object and it's horizontal and vertical
* scale is configurable. This version of the method allows to specify a margin,
- * in pixels, that is to be left, by reducing the size of the image
- *
+ * in pixels, that is to be left, by reducing the size of the image
+ *
* @param gc
* @param imgPath : Absolute path and name of image to draw
- * @param imgRelPositionAndScale : Rectangle object, where x, y are in % and
+ * @param imgRelPositionAndScale : Rectangle object, where x, y are in % and
* represent the relative position where the upper left corner of the image
- * will be positioned, relative to the parent graphic object.
+ * will be positioned, relative to the parent graphic object.
* The width and height are in % and represent the scale of the object relative
- * to the parent object. For example. a relative width and height of 25 means
- * that the image will be scaled to be 1/4 of the width and height of the parent
- * graphic object.
+ * to the parent object. For example. a relative width and height of 25 means
+ * that the image will be scaled to be 1/4 of the width and height of the parent
+ * graphic object.
* @param margin: margin in pixels: the image will be reduced in size
* by this margin, in each dimension.
- * @throws FileNotFoundException
+ * @throws FileNotFoundException
* @since 1.3
*/
- public void drawImageWithMargin(GC gc, String imgPath, Rectangle imgRelPositionAndScale, int margin)
- throws FileNotFoundException
- {
+ public void drawImageWithMargin(GC gc, String imgPath, Rectangle imgRelPositionAndScale, int margin)
+ throws FileNotFoundException {
File file = new File(imgPath);
if (!file.exists()) {
throw new FileNotFoundException();
}
- if (margin < 0) margin = 0;
-
+ if (margin < 0)
+ margin = 0;
+
// extract params
int imgPosX = imgRelPositionAndScale.x;
int imgPosY = imgRelPositionAndScale.y;
@@ -436,14 +452,14 @@ public class GraphicObject
int imgScaleH = imgRelPositionAndScale.height;
// compute wanted image pixel position and size
- float posX = (m_bounds.x + (float) m_bounds.width * imgPosX / 100) + margin;
- float posY = (m_bounds.y + (float) m_bounds.height * imgPosY / 100) + margin;
+ float posX = (m_bounds.x + (float) m_bounds.width * imgPosX / 100) + margin;
+ float posY = (m_bounds.y + (float) m_bounds.height * imgPosY / 100) + margin;
float width = ((float) m_bounds.width * imgScaleW / 100) - 2 * margin;
float height = ((float) m_bounds.height * imgScaleH / 100) - 2 * margin;
-
- Image img = new Image(gc.getDevice(),imgPath);
+
+ Image img = new Image(gc.getDevice(), imgPath);
// draw image
- gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height,
- Math.round(posX), Math.round(posY), Math.round(width), Math.round(height));
+ gc.drawImage(img, 0, 0, img.getBounds().width, img.getBounds().height, Math.round(posX), Math.round(posY),
+ Math.round(width), Math.round(height));
}
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/IGraphicObject.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/IGraphicObject.java
index 5d60e89252..c833ae0e74 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/IGraphicObject.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/IGraphicObject.java
@@ -17,7 +17,6 @@ package org.eclipse.cdt.visualizer.ui.canvas;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
-
// ---------------------------------------------------------------------------
// IGraphicObject
// ---------------------------------------------------------------------------
@@ -25,28 +24,27 @@ import org.eclipse.swt.graphics.Rectangle;
/**
* An object that can be displayed and manipulated on a GraphicCanvas.
*/
-public interface IGraphicObject
-{
+public interface IGraphicObject {
// --- methods ---
-
+
/** Paints object using specified graphics context.
* If decorations is false, draws ordinary object content.
* If decorations is true, paints optional "decorations" layer.
*/
public void paint(GC gc, boolean decorations);
-
+
/** Returns true if object has decorations to paint. */
public boolean hasDecorations();
-
+
/** Gets model data (if any) associated with this graphic object */
public Object getData();
-
+
/** Sets model data (if any) associated with this graphic object */
public void setData(Object data);
-
+
/** Whether graphic object contains the specified point. */
public boolean contains(int x, int y);
-
+
/** Returns true if element bounds are within specified rectangle. */
public boolean isWithin(Rectangle region);
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/VirtualBoundsGraphicObject.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/VirtualBoundsGraphicObject.java
index 20e555214e..acb692ae51 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/VirtualBoundsGraphicObject.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/canvas/VirtualBoundsGraphicObject.java
@@ -37,15 +37,13 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
* Holds the virtual position and size of graphical object.
* Position is relative to parent object
*/
- protected Rectangle m_virtualBounds = new Rectangle(0,0,0,0);
+ protected Rectangle m_virtualBounds = new Rectangle(0, 0, 0, 0);
/** List of children objects contained in this one */
- protected ArrayList<VirtualBoundsGraphicObject> m_childrenObjects =
- new ArrayList<VirtualBoundsGraphicObject>();
+ protected ArrayList<VirtualBoundsGraphicObject> m_childrenObjects = new ArrayList<VirtualBoundsGraphicObject>();
/** Map of contained objects and their identifying labels. for quick look-up */
- protected HashMap<String, VirtualBoundsGraphicObject> m_childrenObjectsMap =
- new HashMap<String, VirtualBoundsGraphicObject>();
+ protected HashMap<String, VirtualBoundsGraphicObject> m_childrenObjectsMap = new HashMap<String, VirtualBoundsGraphicObject>();
/** Whether the container's boundaries should be drawn */
protected boolean m_drawContainerBounds = true;
@@ -62,7 +60,6 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
/** Default for the margin in pixels */
protected static final int MARGIN_PIXELS_DEFAULT = 1;
-
// --- constructors/destructors ---
/** Constructor */
@@ -95,22 +92,16 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
}
}
-
// --- Object methods ---
/** Returns string representation. */
@Override
public String toString() {
- return String.format("Class: %s, Real bounds: %s, Virtual bounds: %s" +
- ", Draw container bounds: %s ",
- this.getClass().getSimpleName(),
- this.getBounds().toString(),
- m_virtualBounds.toString(),
- m_drawContainerBounds
- );
+ return String.format("Class: %s, Real bounds: %s, Virtual bounds: %s" + ", Draw container bounds: %s ",
+ this.getClass().getSimpleName(), this.getBounds().toString(), m_virtualBounds.toString(),
+ m_drawContainerBounds);
}
-
// --- accessors ---
/**
@@ -150,7 +141,6 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
// --- methods ---
-
/**
* Sets the absolute bounds (in pixels) of this container object. If it has
* children objects, recursively set their absolute bounds.
@@ -169,7 +159,7 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
@Override
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x, y, w, h);
- for(VirtualBoundsGraphicObject o : m_childrenObjects) {
+ for (VirtualBoundsGraphicObject o : m_childrenObjects) {
o.setBounds(virtualToRealBounds(o.getVirtualBounds()));
}
}
@@ -244,14 +234,12 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
float ow = 0.0f;
float oh = 0.0f;
- ox = (float) this.getBounds().x + childsVirtualBounds.x
- * ( (float) this.getBounds().width / (this.getVirtualBounds().width) );
- oy = (float) this.getBounds().y + childsVirtualBounds.y
- * ( (float) this.getBounds().height / this.getVirtualBounds().height );
- ow = ( (float) childsVirtualBounds.width
- / this.getVirtualBounds().width) * this.getBounds().width;
- oh = ( (float) childsVirtualBounds.height
- / this.getVirtualBounds().height) * this.getBounds().height;
+ ox = (float) this.getBounds().x
+ + childsVirtualBounds.x * ((float) this.getBounds().width / (this.getVirtualBounds().width));
+ oy = (float) this.getBounds().y
+ + childsVirtualBounds.y * ((float) this.getBounds().height / this.getVirtualBounds().height);
+ ow = ((float) childsVirtualBounds.width / this.getVirtualBounds().width) * this.getBounds().width;
+ oh = ((float) childsVirtualBounds.height / this.getVirtualBounds().height) * this.getBounds().height;
// add margin
ox += m_childMargin;
@@ -265,7 +253,6 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
return new Rectangle(Math.round(ox), Math.round(oy), Math.round(ow), Math.round(oh));
}
-
/** Add children graphical object in this container. Provided label can be used to later retrieve object */
public VirtualBoundsGraphicObject addChildObject(String label, VirtualBoundsGraphicObject obj) {
m_childrenObjects.add(obj);
@@ -278,7 +265,7 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
ArrayList<VirtualBoundsGraphicObject> objs = new ArrayList<VirtualBoundsGraphicObject>();
for (VirtualBoundsGraphicObject o : this.getAllObjects(recurse)) {
- if(type.isInstance(o) ) {
+ if (type.isInstance(o)) {
objs.add(o);
}
}
@@ -286,7 +273,7 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
}
/** Searches recursively for a child object matching a label.
- Returns null if object is not found */
+ Returns null if object is not found */
public VirtualBoundsGraphicObject getObject(String label) {
return getObject(label, true);
}
@@ -296,9 +283,8 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
public VirtualBoundsGraphicObject getObject(String label, boolean recurse) {
if (m_childrenObjectsMap.containsKey(label)) {
return m_childrenObjectsMap.get(label);
- }
- else if (recurse) {
- for(VirtualBoundsGraphicObject o : m_childrenObjects) {
+ } else if (recurse) {
+ for (VirtualBoundsGraphicObject o : m_childrenObjects) {
if (o.getObject(label) != null) {
return o.getObject(label, true);
}
@@ -344,7 +330,6 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
return false;
}
-
// --- paint methods ---
/**
@@ -370,8 +355,7 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
if (isVisible()) {
paintContent(gc);
}
- }
- else {
+ } else {
// Paint decorations
if (isVisible() && hasDecorations()) {
paintDecorations(gc);
@@ -400,8 +384,7 @@ public class VirtualBoundsGraphicObject extends GraphicObject {
if (m_drawContainerBounds) {
if (isSelected() && m_selectedColor != null) {
gc.setForeground(m_selectedColor);
- }
- else {
+ } else {
gc.setForeground(m_foreground);
}
gc.setBackground(m_background);
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/IVisualizerViewerListener.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/IVisualizerViewerListener.java
index 96fef7dc8c..118ae12912 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/IVisualizerViewerListener.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/IVisualizerViewerListener.java
@@ -16,7 +16,6 @@ package org.eclipse.cdt.visualizer.ui.events;
import org.eclipse.cdt.visualizer.ui.IVisualizerViewer;
-
// ---------------------------------------------------------------------------
// IVisualizerViewerListener
// ---------------------------------------------------------------------------
@@ -24,11 +23,10 @@ import org.eclipse.cdt.visualizer.ui.IVisualizerViewer;
/**
* IVisualizerViewer event listener.
*/
-public interface IVisualizerViewerListener
-{
+public interface IVisualizerViewerListener {
// --- methods ---
-
+
/** Invoked when VisualizerViewer's selected IVisualizer changes. */
public void visualizerEvent(IVisualizerViewer source, VisualizerViewerEvent event);
-
+
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/VisualizerViewerEvent.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/VisualizerViewerEvent.java
index 20d228e781..5554c8c8ba 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/VisualizerViewerEvent.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/events/VisualizerViewerEvent.java
@@ -17,7 +17,6 @@ package org.eclipse.cdt.visualizer.ui.events;
import org.eclipse.cdt.visualizer.ui.IVisualizerViewer;
import org.eclipse.cdt.visualizer.ui.util.Event;
-
// ---------------------------------------------------------------------------
// VisualizerViewerEvent
// ---------------------------------------------------------------------------
@@ -25,56 +24,54 @@ import org.eclipse.cdt.visualizer.ui.util.Event;
/**
* IVisualizerViewer event
*/
-public class VisualizerViewerEvent extends Event
-{
+public class VisualizerViewerEvent extends Event {
// --- event types ---
-
+
/** Event type constant */
public static final int VISUALIZER_CHANGED = 1;
-
+
/** Event type constant */
public static final int VISUALIZER_CONTEXT_MENU = 2;
-
// --- members ---
-
+
/** X coordinate, for menu events. */
public int x;
-
+
/** Y coordinate, for menu events. */
public int y;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public VisualizerViewerEvent(IVisualizerViewer source, int eventType) {
super(source, eventType);
}
-
+
/** Constructor. */
public VisualizerViewerEvent(IVisualizerViewer source, int eventType, int x, int y) {
super(source, eventType);
this.x = x;
this.y = y;
}
-
+
/** Dispose method. */
public void dispose() {
super.dispose();
}
// --- Object methods ---
-
+
/** Converts event type to string */
public String typeToString(int type) {
String result = "";
switch (type) {
- case VISUALIZER_CHANGED:
- result = "VISUALIZER_CHANGED"; break;
- default:
- result = super.typeToString(type);
- break;
+ case VISUALIZER_CHANGED:
+ result = "VISUALIZER_CHANGED";
+ break;
+ default:
+ result = super.typeToString(type);
+ break;
}
return result;
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/plugin/CDTVisualizerUIPlugin.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/plugin/CDTVisualizerUIPlugin.java
index 5399958694..4f867be9d4 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/plugin/CDTVisualizerUIPlugin.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/plugin/CDTVisualizerUIPlugin.java
@@ -25,27 +25,24 @@ import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
-
// ----------------------------------------------------------------------------
// CDTVisualizerUIPlugin
// ----------------------------------------------------------------------------
/**
* CDT visualizer UI plugin class.
- *
+ *
* This plugin contains the UI components of the visualizer framework.
*/
-public class CDTVisualizerUIPlugin extends AbstractUIPlugin
-{
+public class CDTVisualizerUIPlugin extends AbstractUIPlugin {
// --- constants ---
-
- /** Feature ID (used as prefix for extension points, etc). */
- public static final String FEATURE_ID = "org.eclipse.cdt.visualizer.ui"; //$NON-NLS-1$
-
+
+ /** Feature ID (used as prefix for extension points, etc). */
+ public static final String FEATURE_ID = "org.eclipse.cdt.visualizer.ui"; //$NON-NLS-1$
+
/** The plug-in ID */
public static final String PLUGIN_ID = "org.eclipse.cdt.visualizer.ui"; //$NON-NLS-1$
-
// --- static members ---
/** Singleton instance */
@@ -59,27 +56,25 @@ public class CDTVisualizerUIPlugin extends AbstractUIPlugin
/** Resource manager */
protected static UIResourceManager s_resources = null;
-
// --- constructors/destructors ---
-
+
/**
* Constructor
*/
public CDTVisualizerUIPlugin() {
}
-
// --- plugin startup/shutdown methods ---
/** Invoked when plugin is loaded. */
public void start(BundleContext context) throws Exception {
super.start(context);
s_plugin = this;
-
+
// touch activator classes of any plugins we depend on,
// to ensure their start() methods are called first
// (None for now.)
-
+
// initialize resource management (strings, images, fonts, colors, etc.)
getPluginResources();
}
@@ -88,28 +83,25 @@ public class CDTVisualizerUIPlugin extends AbstractUIPlugin
public void stop(BundleContext context) throws Exception {
// clean up resource management
cleanupPluginResources();
-
+
s_plugin = null;
super.stop(context);
}
-
-
+
// --- logging ---
-
- /**
+
+ /**
* Writes message to Eclipse log.
* Severity can be one of:
* Status.OK, Status.ERROR, Status.INFO, Status.WARNING, Status.CANCEL
*/
- public static void log(int severity, String text)
- {
+ public static void log(int severity, String text) {
Status status = new Status(severity, PLUGIN_ID, text);
ResourcesPlugin.getPlugin().getLog().log(status);
}
-
// --- resource management ---
-
+
/** Returns resource manager for this plugin */
public UIResourceManager getPluginResources() {
if (s_resources == null) {
@@ -119,42 +111,45 @@ public class CDTVisualizerUIPlugin extends AbstractUIPlugin
// initialize Colors class, now that UIResources object is available.
Colors.initialize(s_resources);
}
-
+
return s_resources;
}
-
+
/** Releases resource manager for this plugin. */
public void cleanupPluginResources() {
s_resources.dispose();
}
-
+
/** Convenience method for getting plugin resource manager */
public static UIResourceManager getResources() {
return getDefault().getPluginResources();
}
-
+
/** Convenience method for looking up string resources */
public static String getString(String key) {
return getDefault().getPluginResources().getString(key);
}
+
/** Convenience method for looking up string resources */
public static String getString(String key, Object... arguments) {
return getDefault().getPluginResources().getString(key, arguments);
}
-
+
/** Convenience method for looking up image resources */
public static Image getImage(String key) {
return getDefault().getPluginResources().getImage(key);
}
+
/** Convenience method for looking up image resources */
public static ImageDescriptor getImageDescriptor(String key) {
return getDefault().getPluginResources().getImageDescriptor(key);
}
-
+
/** Convenience method for looking up font resources */
public static Font getFont(String fontName, int height) {
return getDefault().getPluginResources().getFont(fontName, height);
}
+
/** Convenience method for looking up font resources */
public static Font getFont(String fontName, int height, int style) {
return getDefault().getPluginResources().getFont(fontName, height, style);
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvas.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvas.java
index 2b46d68644..40a83e2d75 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvas.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvas.java
@@ -18,7 +18,6 @@ import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvas;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
-
// ---------------------------------------------------------------------------
// TestCanvas
// ---------------------------------------------------------------------------
@@ -26,52 +25,46 @@ import org.eclipse.swt.widgets.Composite;
/**
* Default canvas control, used by TestCanvasVisualizer.
*/
-public class TestCanvas extends GraphicCanvas
-{
+public class TestCanvas extends GraphicCanvas {
// --- members ---
-
+
/** Text string to display. */
String m_text = null;
-
// --- constructors/destructors ---
-
+
/** Constructor. */
public TestCanvas(Composite parent) {
super(parent);
initDefaultCanvas(parent);
}
-
+
/** Dispose method. */
public void dispose() {
cleanupDefaultCanvas();
super.dispose();
}
-
// --- init methods ---
-
+
/** Initializes control */
protected void initDefaultCanvas(Composite parent) {
// perform any initialization here
}
-
+
/** Cleans up control */
protected void cleanupDefaultCanvas() {
}
-
// --- accessors ---
-
+
/** Sets text string to display. */
- public void setText(String text)
- {
+ public void setText(String text) {
m_text = text;
}
-
// --- methods ---
-
+
/** Invoked when canvas repaint event is raised.
* Default implementation clears canvas to background color.
*/
@@ -82,25 +75,24 @@ public class TestCanvas extends GraphicCanvas
drawStringWrapNewlines(gc, m_text, margin, margin);
}
-
// --- utilities ---
-
+
/** Gets line height of text, based on current font */
public static int getTextHeight(GC gc) {
return gc.getFontMetrics().getHeight();
}
-
+
/** Draw string, wrapping if there are any newline chars. */
public static void drawStringWrapNewlines(GC gc, String text, int x, int y) {
int lineHeight = getTextHeight(gc);
drawStringWrapNewlines(gc, text, x, y, lineHeight);
}
-
+
/** Draw string, wrapping if there are any newline chars. */
public static void drawStringWrapNewlines(GC gc, String text, int x, int y, int lineHeight) {
if (text != null) {
String[] lines = text.split("\n");
- for (int i=0; i<lines.length; i++) {
+ for (int i = 0; i < lines.length; i++) {
gc.drawString(lines[i], x, y, true); // transparent
y += lineHeight;
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvasVisualizer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvasVisualizer.java
index c54f9b4e5c..ec735c8798 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvasVisualizer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/test/TestCanvasVisualizer.java
@@ -22,94 +22,82 @@ import org.eclipse.cdt.visualizer.ui.canvas.GraphicCanvasVisualizer;
import org.eclipse.cdt.visualizer.ui.util.SelectionUtils;
import org.eclipse.jface.viewers.ISelection;
-
// ---------------------------------------------------------------------------
// TestCanvasVisualizer
// ---------------------------------------------------------------------------
/**
* Default visualizer, used only for testing framework.
- *
+ *
* This view uses the CDT Visualizer framework.
*/
-public class TestCanvasVisualizer extends GraphicCanvasVisualizer
-{
+public class TestCanvasVisualizer extends GraphicCanvasVisualizer {
// --- constants ---
-
+
/** Eclipse ID for this visualizer */
public static final String ECLIPSE_ID = "org.eclipse.cdt.visualizer.ui.test.TestCanvasVisualizer";
-
// --- members ---
-
+
/** Visualizer control. */
TestCanvas m_canvas = null;
-
// --- constructors/destructors ---
-
-
+
// --- accessors ---
-
+
/** Gets canvas control. */
- public TestCanvas getDefaultCanvas()
- {
+ public TestCanvas getDefaultCanvas() {
return m_canvas;
}
-
// --- IVisualizer implementation ---
-
+
/** Returns non-localized unique name for this visualizer. */
public String getName() {
return "default";
}
-
+
/** Returns localized name to display for this visualizer. */
public String getDisplayName() {
// TODO: use a string resource here.
return "Test Visualizer";
}
-
+
/** Returns localized tooltip text to display for this visualizer. */
public String getDescription() {
// TODO: use a string resource here.
return "Test visualizer (for debugging only).";
}
-
+
/** Creates and returns visualizer canvas control. */
- public GraphicCanvas createCanvas(Composite parent)
- {
+ public GraphicCanvas createCanvas(Composite parent) {
m_canvas = new TestCanvas(parent);
return m_canvas;
}
-
+
/** Invoked after visualizer control creation, */
- protected void initializeCanvas(GraphicCanvas canvas)
- {
+ protected void initializeCanvas(GraphicCanvas canvas) {
m_canvas.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_WHITE));
m_canvas.setForeground(canvas.getDisplay().getSystemColor(SWT.COLOR_BLACK));
}
-
// --- workbench selection management ---
- /**
- * Tests whether if the IVisualizer can display the selection
- * (or something reachable from it).
- */
- public int handlesSelection(ISelection selection)
- {
+ /**
+ * Tests whether if the IVisualizer can display the selection
+ * (or something reachable from it).
+ */
+ public int handlesSelection(ISelection selection) {
// By default, we don't support anything.
// Changing this to return 1 enables the test canvas.
return 0;
}
- /**
- * Invoked by VisualizerViewer when workbench selection changes.
- */
- public void workbenchSelectionChanged(ISelection selection)
- {
+ /**
+ * Invoked by VisualizerViewer when workbench selection changes.
+ */
+ public void workbenchSelectionChanged(ISelection selection) {
String text = SelectionUtils.toString(selection);
m_canvas.setText(text);
m_canvas.redraw();
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Colors.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Colors.java
index 5d24a14632..3425aaf589 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Colors.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Colors.java
@@ -17,14 +17,13 @@ package org.eclipse.cdt.visualizer.ui.util;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
-
// ---------------------------------------------------------------------------
// Colors
// ---------------------------------------------------------------------------
/**
* Standard color constants.
- *
+ *
* This is basically a set of cached color resources
* for commonly-used colors.
* These are drawn from an associated UIResourceManager.
@@ -34,7 +33,7 @@ import org.eclipse.swt.graphics.Color;
public class Colors {
// --- static members ---
-
+
/** UI Resource manager colors are drawn from */
protected static UIResourceManager s_resources = null;
@@ -67,50 +66,51 @@ public class Colors {
public static Color VERY_DARK_GRAY = null;
public static Color WIDGET_UNEDITABLE_BACKGROUND = null;
public static Color WIDGET_NORMAL_BACKGROUND = null;
-
+
public static void initialize(UIResourceManager resources) {
-
+
// set resource manager for future use
s_resources = resources;
-
+
// Color objects for all the standard "int" colors in the SWT class:
- WHITE = getColor(SWT.COLOR_WHITE);
- BLACK = getColor(SWT.COLOR_BLACK);
- RED = getColor(SWT.COLOR_RED);
- DARK_RED = getColor(SWT.COLOR_DARK_RED);
- GREEN = getColor(SWT.COLOR_GREEN);
- DARK_GREEN = getColor(SWT.COLOR_DARK_GREEN);
- YELLOW = getColor(SWT.COLOR_YELLOW);
- DARK_YELLOW = getColor(SWT.COLOR_DARK_YELLOW);
- BLUE = getColor(SWT.COLOR_BLUE);
- DARK_BLUE = getColor(SWT.COLOR_DARK_BLUE);
- MAGENTA = getColor(SWT.COLOR_MAGENTA);
- DARK_MAGENTA = getColor(SWT.COLOR_DARK_MAGENTA);
- CYAN = getColor(SWT.COLOR_CYAN);
- DARK_CYAN = getColor(SWT.COLOR_DARK_CYAN);
- GRAY = getColor(SWT.COLOR_GRAY);
- DARK_GRAY = getColor(SWT.COLOR_DARK_GRAY);
+ WHITE = getColor(SWT.COLOR_WHITE);
+ BLACK = getColor(SWT.COLOR_BLACK);
+ RED = getColor(SWT.COLOR_RED);
+ DARK_RED = getColor(SWT.COLOR_DARK_RED);
+ GREEN = getColor(SWT.COLOR_GREEN);
+ DARK_GREEN = getColor(SWT.COLOR_DARK_GREEN);
+ YELLOW = getColor(SWT.COLOR_YELLOW);
+ DARK_YELLOW = getColor(SWT.COLOR_DARK_YELLOW);
+ BLUE = getColor(SWT.COLOR_BLUE);
+ DARK_BLUE = getColor(SWT.COLOR_DARK_BLUE);
+ MAGENTA = getColor(SWT.COLOR_MAGENTA);
+ DARK_MAGENTA = getColor(SWT.COLOR_DARK_MAGENTA);
+ CYAN = getColor(SWT.COLOR_CYAN);
+ DARK_CYAN = getColor(SWT.COLOR_DARK_CYAN);
+ GRAY = getColor(SWT.COLOR_GRAY);
+ DARK_GRAY = getColor(SWT.COLOR_DARK_GRAY);
// Other "custom" Color objects:
- ORANGE = getColor(255, 150, 90);
- MEDIUM_GREEN = getColor( 0, 192, 0);
- DARK_ORANGE = getColor(215, 128, 81);
- SEMI_DARK_YELLOW = getColor(192, 192, 0);
- DARK_MUTED_YELLOW = getColor( 90, 90, 50);
- DARK_MUTED_GREEN = getColor( 18, 92, 18);
- DARKER_RED = getColor(174, 25, 13);
- VERY_DARK_GRAY = getColor( 60, 60, 60);
-
+ ORANGE = getColor(255, 150, 90);
+ MEDIUM_GREEN = getColor(0, 192, 0);
+ DARK_ORANGE = getColor(215, 128, 81);
+ SEMI_DARK_YELLOW = getColor(192, 192, 0);
+ DARK_MUTED_YELLOW = getColor(90, 90, 50);
+ DARK_MUTED_GREEN = getColor(18, 92, 18);
+ DARKER_RED = getColor(174, 25, 13);
+ VERY_DARK_GRAY = getColor(60, 60, 60);
+
WIDGET_NORMAL_BACKGROUND = getColor(SWT.COLOR_WHITE);
- WIDGET_UNEDITABLE_BACKGROUND = getColor(220,220,220);
+ WIDGET_UNEDITABLE_BACKGROUND = getColor(220, 220, 220);
}
-
+
// --- constructors/destructors ---
/** Constructor
* Private, since this is basically a bunch of constants.
*/
- private Colors() {}
+ private Colors() {
+ }
/**
* Gets color for a given SWT color constant.
@@ -119,7 +119,7 @@ public class Colors {
public static final Color getColor(int colorID) {
return (s_resources == null) ? null : s_resources.getColor(colorID);
}
-
+
/**
* Gets color for given RGB values (0-255).
*/
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Event.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Event.java
index 41bdd52d8c..6a89719e46 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Event.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Event.java
@@ -14,7 +14,6 @@
package org.eclipse.cdt.visualizer.ui.util;
-
// ---------------------------------------------------------------------------
// Event
// ---------------------------------------------------------------------------
@@ -22,45 +21,41 @@ package org.eclipse.cdt.visualizer.ui.util;
/**
* Base class for events
*/
-public class Event
-{
-
+public class Event {
+
// --- event types ---
-
+
/** Event type constant */
public static final int UNDEFINED = 0;
-
// --- members ---
-
+
/** Source of the event */
protected Object m_source = null;
-
+
/** Type of event */
protected int m_type = UNDEFINED;
-
// --- constructors/destructors ---
-
+
/** Constructor */
public Event(Object source) {
this(source, UNDEFINED);
}
-
+
/** Constructor */
public Event(Object source, int type) {
m_source = source;
m_type = type;
}
-
+
/** Dispose method */
public void dispose() {
m_source = null;
}
-
// --- Object methods ---
-
+
/** Returns string representation of event */
public String toString() {
StringBuilder result = new StringBuilder();
@@ -72,35 +67,35 @@ public class Event
result.append("]");
return result.toString();
}
-
+
/** Converts event type to string */
public String typeToString(int type) {
String result = "";
switch (type) {
- case UNDEFINED:
- result = "UNDEFINED"; break;
- default:
- result = "OTHER(" + type +")";
- break;
+ case UNDEFINED:
+ result = "UNDEFINED";
+ break;
+ default:
+ result = "OTHER(" + type + ")";
+ break;
}
return result;
}
-
// --- accessors ---
-
+
/** Gets source of the event */
public Object getSource() {
return m_source;
}
-
+
/**
* Gets type of event
*/
public int getType() {
return m_type;
}
-
+
/**
* Returns true if event has specified type.
*/
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/GUIUtils.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/GUIUtils.java
index 05143bdd94..9fdc311ec4 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/GUIUtils.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/GUIUtils.java
@@ -21,7 +21,6 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
-
//---------------------------------------------------------------------------
// GUIUtils
//---------------------------------------------------------------------------
@@ -30,132 +29,121 @@ import org.eclipse.swt.widgets.Display;
* Assorted high-level UI utilities.
*/
public class GUIUtils {
-
+
// --- display methods ---
-
+
/** Gets current SWT display. */
- static public Display getDisplay() {
- Display display= Display.getCurrent();
- if (display == null) {
- display= Display.getDefault();
- }
- return display;
- }
-
-
+ static public Display getDisplay() {
+ Display display = Display.getCurrent();
+ if (display == null) {
+ display = Display.getDefault();
+ }
+ return display;
+ }
+
// --- delayed execution methods ---
-
- /** Posts the specified runnable for execution by the UI thread.
- * Nonblocking, returns immediately.
- */
- static public void exec(Runnable runnable) {
- Display display = getDisplay();
- exec(display, runnable, false);
- }
-
- /** Posts the specified runnable for execution by the UI thread.
- * Nonblocking, returns immediately.
- */
- static public void exec(Runnable runnable, boolean blocking) {
- Display display = getDisplay();
- exec(display, runnable, blocking);
- }
-
- /** Posts the specified runnable for execution by the UI thread.
- * If blocking is true, waits for completion, otherwise returns immediately.
- */
- static public void execAndWait(Runnable runnable) {
- Display display = getDisplay();
- exec(display, runnable, true);
- }
-
- /** Posts the specified runnable for execution by the UI thread.
- * If blocking is true, waits for completion, otherwise returns immediately.
- */
- static protected void exec(Display display, Runnable runnable, boolean blocking) {
- if (display != null && runnable != null) {
- if (blocking) {
- display.syncExec(runnable);
- }
- else {
- display.asyncExec(runnable);
- }
- }
- }
-
-
+
+ /** Posts the specified runnable for execution by the UI thread.
+ * Nonblocking, returns immediately.
+ */
+ static public void exec(Runnable runnable) {
+ Display display = getDisplay();
+ exec(display, runnable, false);
+ }
+
+ /** Posts the specified runnable for execution by the UI thread.
+ * Nonblocking, returns immediately.
+ */
+ static public void exec(Runnable runnable, boolean blocking) {
+ Display display = getDisplay();
+ exec(display, runnable, blocking);
+ }
+
+ /** Posts the specified runnable for execution by the UI thread.
+ * If blocking is true, waits for completion, otherwise returns immediately.
+ */
+ static public void execAndWait(Runnable runnable) {
+ Display display = getDisplay();
+ exec(display, runnable, true);
+ }
+
+ /** Posts the specified runnable for execution by the UI thread.
+ * If blocking is true, waits for completion, otherwise returns immediately.
+ */
+ static protected void exec(Display display, Runnable runnable, boolean blocking) {
+ if (display != null && runnable != null) {
+ if (blocking) {
+ display.syncExec(runnable);
+ } else {
+ display.asyncExec(runnable);
+ }
+ }
+ }
+
// --- drawing methods ---
- /** Draws transparent text, with the default alignment (top/left). */
- static public void drawText(GC gc, String text, int x, int y)
- {
+ /** Draws transparent text, with the default alignment (top/left). */
+ static public void drawText(GC gc, String text, int x, int y) {
gc.drawText(text, x, y, SWT.DRAW_TRANSPARENT);
}
- /** Draws transparent text, with the default alignment (top/left).
- * @since 1.1*/
- static public void drawText(GC gc, String text, Rectangle clip, int x, int y)
- {
+ /** Draws transparent text, with the default alignment (top/left).
+ * @since 1.1*/
+ static public void drawText(GC gc, String text, Rectangle clip, int x, int y) {
Rectangle oldClip = gc.getClipping();
gc.setClipping(clip);
drawText(gc, text, x, y);
gc.setClipping(oldClip);
}
- /** Draws transparent text, with the specified alignments. */
- static public void drawTextAligned(GC gc, String text, int x, int y, boolean left, boolean top)
- {
+ /** Draws transparent text, with the specified alignments. */
+ static public void drawTextAligned(GC gc, String text, int x, int y, boolean left, boolean top) {
if (left && top) {
gc.drawText(text, x, y, SWT.DRAW_TRANSPARENT);
- }
- else {
+ } else {
Point te = gc.textExtent(text);
int dx = left ? 0 : te.x;
- int dy = top ? 0 : te.y;
+ int dy = top ? 0 : te.y;
gc.drawText(text, x - dx, y - dy, SWT.DRAW_TRANSPARENT);
}
}
- /** Draws transparent text, with the specified alignments.
- * @since 1.1*/
- static public void drawTextAligned(GC gc, String text, Rectangle clip, int x, int y, boolean left, boolean top)
- {
+ /** Draws transparent text, with the specified alignments.
+ * @since 1.1*/
+ static public void drawTextAligned(GC gc, String text, Rectangle clip, int x, int y, boolean left, boolean top) {
Rectangle oldClip = gc.getClipping();
gc.setClipping(clip);
drawTextAligned(gc, text, x, y, left, top);
gc.setClipping(oldClip);
}
- /** Draws transparent text, centered on the specified point. */
- static public void drawTextCentered(GC gc, String text, int x, int y)
- {
+ /** Draws transparent text, centered on the specified point. */
+ static public void drawTextCentered(GC gc, String text, int x, int y) {
Point te = gc.textExtent(text);
// Rounding produces less "jumpy" display when graphics are resized.
- gc.drawText(text, x - (int) Math.round(te.x / 2.0),
- y - (int) Math.round(te.y / 2.0), SWT.DRAW_TRANSPARENT);
+ gc.drawText(text, x - (int) Math.round(te.x / 2.0), y - (int) Math.round(te.y / 2.0), SWT.DRAW_TRANSPARENT);
}
- /** Draws transparent text, centered on the specified point.
- * @since 1.1*/
- static public void drawTextCentered(GC gc, String text, Rectangle clip, int x, int y)
- {
+ /** Draws transparent text, centered on the specified point.
+ * @since 1.1*/
+ static public void drawTextCentered(GC gc, String text, Rectangle clip, int x, int y) {
Rectangle oldClip = gc.getClipping();
gc.setClipping(clip);
drawTextCentered(gc, text, x, y);
gc.setClipping(oldClip);
}
-
// --- graphic methods ---
-
+
/** Shrinks rectangle by specified margin on all edges. */
- public static void inset(Rectangle rect, int margin)
- {
+ public static void inset(Rectangle rect, int margin) {
rect.x += margin;
rect.y += margin;
rect.width -= margin * 2;
- if (rect.width < 0) rect.width = 0;
- rect.height -= margin * 2;
- if (rect.height < 0) rect.height = 0;
+ if (rect.width < 0)
+ rect.width = 0;
+ rect.height -= margin * 2;
+ if (rect.height < 0)
+ rect.height = 0;
}
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ListenerList.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ListenerList.java
index 0d405ce510..7126718f46 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ListenerList.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ListenerList.java
@@ -16,44 +16,41 @@ package org.eclipse.cdt.visualizer.ui.util;
import java.util.ArrayList;
-
// ---------------------------------------------------------------------------
// ListenerList
// ---------------------------------------------------------------------------
/**
- * Utility class for managing a list of event listeners.
+ * Utility class for managing a list of event listeners.
* Maintains a list of listener instances, and dispatches events to them.
*
* To use this class, create a derived type that implements the raise(listener, event)
* method to appropriately delegate an event to a listener.
- *
+ *
* Note: it is the responsibility of the user of this class to check types
* of listeners and events (for example, by having strongly-typed add/remove methods
* that delegate to the add/remove methods on this class).
*/
-abstract public class ListenerList
-{
+abstract public class ListenerList {
// --- members ---
-
+
/** Object that owns this listener list */
protected Object m_owner = null;
-
+
/** listener list display label */
protected String m_label = null;
-
+
/** listener list */
protected ArrayList<Object> m_listeners = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public ListenerList(Object owner, String label) {
m_owner = owner;
m_label = label;
}
-
+
/** Dispose method. */
public void dispose() {
m_owner = null;
@@ -63,45 +60,43 @@ abstract public class ListenerList
m_listeners = null;
}
}
-
-
+
// --- methods ---
-
+
/** Clears list of listeners */
public synchronized void clear() {
if (m_listeners != null) {
m_listeners.clear();
}
}
-
+
/** Returns count of current listeners. */
public synchronized int size() {
return (m_listeners == null) ? 0 : m_listeners.size();
}
-
+
/** Adds a listener */
public synchronized void addListener(Object listener) {
if (m_listeners == null) {
m_listeners = new ArrayList<Object>();
}
- if (! m_listeners.contains(listener)) {
+ if (!m_listeners.contains(listener)) {
m_listeners.add(listener);
}
}
-
+
/** Removes a listener */
public synchronized void removeListener(Object listener) {
if (m_listeners != null) {
m_listeners.remove(listener);
}
}
-
+
/**
* Dispatches event to all attached listeners
* Invokes raise(listener, event) for each attached listener.
*/
- public void raise (final Object event)
- {
+ public void raise(final Object event) {
// we can't use an iterator here, because
// the listener list might change while we're walking it,
// which would make the iterator throw a ConcurrentModificationException,
@@ -114,24 +109,23 @@ abstract public class ListenerList
}
}
int count = (listeners == null) ? 0 : listeners.size();
- for (int i=0; i<count; i++) {
+ for (int i = 0; i < count; i++) {
Object listener = (Object) listeners.get(i);
try {
raise(listener, event);
- }
- catch (Throwable t) {
+ } catch (Throwable t) {
// TODO: decide how to log this
}
}
}
-
+
/**
* Dispatches typed event to specified listener
* Intended to be overloaded by derived class to cast listener and event
* to appropriate type and invoke appropriate listener method(s).
- *
+ *
* For example:
- *
+ *
* ListenerList m_listeners =
* new ListenerList(this, "VisualizerViewer event listeners")
* {
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/MouseMonitor.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/MouseMonitor.java
index 7e03b2f02e..81b85d1918 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/MouseMonitor.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/MouseMonitor.java
@@ -24,133 +24,126 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
-
/**
* Monitors mouse down/move/up events on a specified control (e.g. a canvas)
* and converts them to semantic events (click, double-click, select, drag, etc.)
*/
-public class MouseMonitor
-{
+public class MouseMonitor {
// --- constants ---
-
+
/** MouseEvent button ID for Left mouse button */
public static final int LEFT_BUTTON = 1;
-
+
/** MouseEvent button ID for Middle mouse button */
public static final int MIDDLE_BUTTON = 2;
-
+
/** MouseEvent button ID for Right mouse button */
public static final int RIGHT_BUTTON = 3;
-
-
+
/** Mouse drag state value */
public static final int MOUSE_DRAG_BEGIN = 0;
-
+
/** Mouse drag state value */
public static final int MOUSE_DRAG = 1;
/** Mouse drag state value */
public static final int MOUSE_DRAG_END = 2;
-
+
/** Distance mouse must move for a mouse-down to be treated as a drag */
public static final int MOUSE_DRAG_HYSTERESIS = 4;
-
// --- members ---
-
+
/** Control being monitored */
protected Control m_control = null;
-
+
/** Mouse button listener */
protected MouseListener m_mouseButtonListener = null;
-
+
/** Mouse move listener */
protected MouseMoveListener m_mouseMoveListener = null;
-
+
/** Mouse enter/exit event listener */
protected MouseTrackListener m_mouseTrackListener = null;
-
+
/** Whether mouse button is down. */
protected boolean m_mouseDown = false;
-
+
/** Whether mouse is being dragged. */
protected boolean m_mouseDrag = false;
-
+
/** Mouse-down point. */
- protected Point m_mouseDownPoint = new Point(0,0);
-
+ protected Point m_mouseDownPoint = new Point(0, 0);
+
/** Last button down. */
protected int m_mouseDownButton = 0;
-
+
/** Current mouse drag point. */
- protected Point m_dragPoint = new Point(0,0);
-
+ protected Point m_dragPoint = new Point(0, 0);
+
/** Drag region. */
- protected Rectangle m_dragRegion = new Rectangle(0,0,0,0);
-
-
+ protected Rectangle m_dragRegion = new Rectangle(0, 0, 0, 0);
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public MouseMonitor() {
}
-
+
/** Constructor. */
public MouseMonitor(Control control) {
this();
m_control = control;
attach(m_control);
}
-
+
/** Dispose method. */
public void dispose() {
detach(m_control);
}
-
// --- init methods ---
-
+
/** Attach event listeners to specified control. */
protected void attach(Control control) {
detach(m_control);
- control.addMouseListener(
- m_mouseButtonListener = new MouseListener() {
- public void mouseDown(MouseEvent e) {
- mouseDownHandler(e.button, e.x, e.y, e.stateMask);
- }
- public void mouseUp(MouseEvent e) {
- mouseUpHandler(e.button, e.x, e.y, e.stateMask);
- }
- public void mouseDoubleClick(MouseEvent e) {
- mouseDoubleClickHandler(e.button, e.x, e.y, e.stateMask);
- }
+ control.addMouseListener(m_mouseButtonListener = new MouseListener() {
+ public void mouseDown(MouseEvent e) {
+ mouseDownHandler(e.button, e.x, e.y, e.stateMask);
}
- );
- control.addMouseMoveListener(
- m_mouseMoveListener = new MouseMoveListener() {
- public void mouseMove(MouseEvent e) {
- mouseMoveHandler(e.x, e.y, e.stateMask);
- }
+
+ public void mouseUp(MouseEvent e) {
+ mouseUpHandler(e.button, e.x, e.y, e.stateMask);
}
- );
- control.addMouseTrackListener(
- m_mouseTrackListener = new MouseTrackListener() {
- public void mouseEnter(MouseEvent e) {
- mouseEnterHandler(e.x, e.y);
- }
- public void mouseExit(MouseEvent e) {
- mouseExitHandler(e.x, e.y);
- }
- public void mouseHover(MouseEvent e) {
- mouseHoverHandler(e.x, e.y);
- }
+
+ public void mouseDoubleClick(MouseEvent e) {
+ mouseDoubleClickHandler(e.button, e.x, e.y, e.stateMask);
}
- );
+ });
+ control.addMouseMoveListener(m_mouseMoveListener = new MouseMoveListener() {
+ public void mouseMove(MouseEvent e) {
+ mouseMoveHandler(e.x, e.y, e.stateMask);
+ }
+ });
+ control.addMouseTrackListener(m_mouseTrackListener = new MouseTrackListener() {
+ public void mouseEnter(MouseEvent e) {
+ mouseEnterHandler(e.x, e.y);
+ }
+
+ public void mouseExit(MouseEvent e) {
+ mouseExitHandler(e.x, e.y);
+ }
+
+ public void mouseHover(MouseEvent e) {
+ mouseHoverHandler(e.x, e.y);
+ }
+ });
}
-
+
/** Detach event listeners from specified control. */
protected void detach(Control control) {
- if (control == null) return;
+ if (control == null)
+ return;
if (m_control != null) {
if (m_mouseButtonListener != null) {
m_control.removeMouseListener(m_mouseButtonListener);
@@ -166,115 +159,110 @@ public class MouseMonitor
}
}
}
-
-
+
// --- accessors ---
-
+
/** Gets associated control */
public Control getControl() {
return m_control;
}
-
+
/** Sets associated control */
public void setControl(Control control) {
detach(m_control);
m_control = control;
attach(m_control);
}
-
+
/** Gets mouse down point of current drag, if any */
public Point getMouseDownPoint() {
return m_mouseDownPoint;
}
-
+
/** Gets current drag x,y point. */
public Point getDragPoint() {
return m_dragPoint;
}
-
+
/** Gets bounds of most recent drag region. */
public Rectangle getDragRegion() {
return m_dragRegion;
}
-
-
+
// --- utilities ---
-
+
/** Returns true if either Shift key is down in mouse event modifier key mask. */
public static boolean isShiftDown(int keys) {
return ((keys & SWT.SHIFT) != 0);
}
-
+
/** Returns true if either Control key is down in mouse event modifier key mask. */
public static boolean isControlDown(int keys) {
return ((keys & SWT.CONTROL) != 0);
}
-
+
/** Returns true if either Alt key is down in mouse event modifier key mask. */
public static boolean isAltDown(int keys) {
return ((keys & SWT.ALT) != 0);
}
-
-
+
// --- methods ---
-
+
/** Internal -- sets drag point */
protected void setDragPoint(int x, int y) {
- m_dragPoint.x=x;
- m_dragPoint.y=y;
+ m_dragPoint.x = x;
+ m_dragPoint.y = y;
}
-
+
/** Internal -- sets drag region explicitly */
protected void setDragRegion(int x, int y, int width, int height) {
- m_dragRegion.x=x;
- m_dragRegion.y=y;
- m_dragRegion.width=width;
- m_dragRegion.height=height;
+ m_dragRegion.x = x;
+ m_dragRegion.y = y;
+ m_dragRegion.width = width;
+ m_dragRegion.height = height;
}
-
+
/** Internal -- sets drag region from specified drag start/end points */
protected void setDragRegionFromPoints(int x1, int y1, int x2, int y2) {
if (x1 < x2) {
m_dragRegion.x = x1;
m_dragRegion.width = x2 - x1;
- }
- else {
+ } else {
m_dragRegion.x = x2;
m_dragRegion.width = x1 - x2;
}
if (y1 < y2) {
m_dragRegion.y = y1;
m_dragRegion.height = y2 - y1;
- }
- else {
+ } else {
m_dragRegion.y = y2;
m_dragRegion.height = y1 - y2;
}
}
-
+
/** Invoked when mouse button is pressed */
protected void mouseDownHandler(int button, int x, int y, int keys) {
// Drag not applicable to right-click
- if (! m_mouseDown && button != RIGHT_BUTTON) {
+ if (!m_mouseDown && button != RIGHT_BUTTON) {
m_mouseDown = true;
m_mouseDownPoint.x = x;
m_mouseDownPoint.y = y;
m_mouseDownButton = button;
- setDragPoint(x,y);
- setDragRegion(x,y,0,0);
+ setDragPoint(x, y);
+ setDragRegion(x, y, 0, 0);
}
mouseDown(button, x, y, keys);
}
-
+
/** Invoked when mouse is moved */
protected void mouseMoveHandler(int x, int y, int keys) {
if (m_mouseDown) {
- if (! m_mouseDrag) {
+ if (!m_mouseDrag) {
// allow a small hysteresis before we start dragging, so clicks with a little movement don't cause drags
int distance = Math.abs(x - m_mouseDownPoint.x) + Math.abs(y - m_mouseDownPoint.y);
if (distance > MOUSE_DRAG_HYSTERESIS) {
m_mouseDrag = true;
-
+
// initialize mouse drag
drag(m_mouseDownButton, m_mouseDownPoint.x, m_mouseDownPoint.y, keys, MOUSE_DRAG_BEGIN);
}
@@ -283,14 +271,14 @@ public class MouseMonitor
// update mouse drag
int dx = x - m_mouseDownPoint.x;
int dy = y - m_mouseDownPoint.y;
- setDragPoint(x,y);
+ setDragPoint(x, y);
setDragRegionFromPoints(m_mouseDownPoint.x, m_mouseDownPoint.y, x, y);
drag(m_mouseDownButton, dx, dy, keys, MOUSE_DRAG);
}
}
mouseMove(x, y, keys);
}
-
+
/** Invoked when mouse button is released */
protected void mouseUpHandler(int button, int x, int y, int keys) {
if (m_mouseDown) {
@@ -298,16 +286,14 @@ public class MouseMonitor
// finish mouse drag
int dx = x - m_mouseDownPoint.x;
int dy = y - m_mouseDownPoint.y;
- setDragPoint(x,y);
+ setDragPoint(x, y);
setDragRegionFromPoints(m_mouseDownPoint.x, m_mouseDownPoint.y, x, y);
drag(m_mouseDownButton, dx, dy, keys, MOUSE_DRAG_END);
m_mouseDrag = false;
- }
- else {
+ } else {
if (button == RIGHT_BUTTON) {
contextMenu(x, y, keys);
- }
- else {
+ } else {
select(x, y, keys);
}
}
@@ -323,50 +309,55 @@ public class MouseMonitor
/** Invoked when mouse pointer enters control region */
protected void mouseEnterHandler(int x, int y) {
- if (! m_mouseDown) {
+ if (!m_mouseDown) {
mouseEnter(x, y);
}
}
/** Invoked when mouse pointer exits control region */
protected void mouseExitHandler(int x, int y) {
- if (! m_mouseDown) {
+ if (!m_mouseDown) {
mouseExit(x, y);
}
}
-
+
/** Invoked when mouse pointer hovers over control */
protected void mouseHoverHandler(int x, int y) {
- if (! m_mouseDown) {
+ if (!m_mouseDown) {
mouseHover(x, y);
}
}
-
-
+
// --- event handlers ---
-
+
// These are intended to be overridden by derived types.
// A user of this class need only override methods for events
// that need to be tracked.
-
+
/** Invoked when mouse button is pressed */
- public void mouseDown(int button, int x, int y, int keys) {}
-
+ public void mouseDown(int button, int x, int y, int keys) {
+ }
+
/** Invoked when mouse is moved */
- public void mouseMove(int x, int y, int keys) {}
-
+ public void mouseMove(int x, int y, int keys) {
+ }
+
/** Invoked when mouse button is released */
- public void mouseUp(int button, int x, int y, int keys) {}
-
+ public void mouseUp(int button, int x, int y, int keys) {
+ }
+
/** Invoked for a selection click at the specified point. */
- public void select(int x, int y, int keys) {}
-
+ public void select(int x, int y, int keys) {
+ }
+
/** Invoked for a context menu click at the specified point. */
- public void contextMenu(int x, int y, int keys) {}
-
+ public void contextMenu(int x, int y, int keys) {
+ }
+
/** Invoked when mouse button is double-clicked */
- public void mouseDoubleClick(int button, int x, int y, int keys) {}
-
+ public void mouseDoubleClick(int button, int x, int y, int keys) {
+ }
+
/** Invoked when mouse is dragged (moved with mouse button down).
* Drag state indicates stage of drag:
* - MOUSE_DRAG_BEGIN -- dx, dy offset from initial mouse down point (initial mouse down)
@@ -374,15 +365,19 @@ public class MouseMonitor
* - MOUSE_DRAG_END -- dx, dy of final drag offset (mouse up)
* The pattern of calls is always: BEGIN, DRAG(+), END.
*/
- public void drag(int button, int x, int y, int keys, int dragState) {}
-
+ public void drag(int button, int x, int y, int keys, int dragState) {
+ }
+
/** Invoked when mouse pointer enters control region */
- public void mouseEnter(int x, int y) {}
+ public void mouseEnter(int x, int y) {
+ }
/** Invoked when mouse pointer exits control region */
- public void mouseExit(int x, int y) {}
-
+ public void mouseExit(int x, int y) {
+ }
+
/** Invoked when mouse pointer hovers over control */
- public void mouseHover(int x, int y) {}
+ public void mouseHover(int x, int y) {
+ }
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/RunnableWithResult.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/RunnableWithResult.java
index 8aa3bf6a95..ffe5165c52 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/RunnableWithResult.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/RunnableWithResult.java
@@ -16,72 +16,66 @@ package org.eclipse.cdt.visualizer.ui.util;
import java.util.concurrent.Callable;
-
/**
* Runnable object that returns a result object.
- *
+ *
* This is like Future<V> from the concurrent package,
* but with a few less bells and whistles.
- *
+ *
* Intended to be used, for example, as follows:
- *
+ *
* RunnableWithResult<X> runnable = new RunnableWithResult<X>() {
* public X call() {
* ... do work, return an X object ...
* }
* }
- *
+ *
* Thread thread = new Thread(runnable);
* thread.start();
* X result = runnable.getResult(0);
- *
+ *
* or, to run it on the UI thread...
- *
+ *
* GUIUtils.execAndWait(runnable);
* X result = runnable.getResult(0);
- *
+ *
* Note: if you're invoking this from the UI thread,
* it's important to use execAndWait(), so that the runnable
* gets a turn on the event loop, otherwise you'll hang the UI!
- *
+ *
*/
-public class RunnableWithResult<V>
- implements Runnable, Callable<V>
-{
+public class RunnableWithResult<V> implements Runnable, Callable<V> {
// --- members ---
/** Result to return */
protected V m_result = null;
-
+
/** Whether run() has completed */
protected boolean m_done = false;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public RunnableWithResult() {
}
-
+
/** Dispose method. */
public void dispose() {
m_result = null;
}
-
// --- accessors ---
/** Sets result value */
public void setResult(V result) {
m_result = result;
}
-
+
/** Gets result value. */
public V getResult() {
return m_result;
}
-
// --- Runnable implementation ---
/** Run method.
@@ -95,10 +89,9 @@ public class RunnableWithResult<V>
notifyAll();
}
}
-
-
+
// --- Callable implementation ---
-
+
/** Method that returns the value.
* Default implementation returns null.
*/
@@ -106,19 +99,18 @@ public class RunnableWithResult<V>
return null;
}
-
// --- methods ---
-
+
/** Waits for result and returns it. */
public V waitForResult() {
return waitForResult(0, null);
}
-
+
/** Waits for result and returns it. */
public V waitForResult(long timeout) {
return waitForResult(timeout, null);
}
-
+
/** Waits for result and returns it.
* Returns null if specified timeout is exceeded.
*/
@@ -128,35 +120,33 @@ public class RunnableWithResult<V>
if (timeout == 0) {
// wait forever
// (guard against spurious thread wakeup -- see wait() Javadoc)
- while (! m_done) {
+ while (!m_done) {
synchronized (this) {
this.wait(0);
}
}
- }
- else {
+ } else {
// wait until specified timeout
// (guard against spurious thread wakeup -- see wait() Javadoc)
long then = now();
long waitstep = timeout / 10;
- if (waitstep == 0) waitstep = 1;
+ if (waitstep == 0)
+ waitstep = 1;
do {
synchronized (this) {
this.wait(waitstep);
}
- }
- while (! m_done && ((now() - then) < timeout));
+ } while (!m_done && ((now() - then) < timeout));
}
+ } catch (InterruptedException e) {
}
- catch (InterruptedException e) {
- }
- if (m_done) result = getResult();
+ if (m_done)
+ result = getResult();
return result;
}
-
+
/** Returns current time in milliseconds. */
protected static long now() {
return System.currentTimeMillis();
}
}
-
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ScrollPanel.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ScrollPanel.java
index c95f644c4b..6424fd5f7f 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ScrollPanel.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/ScrollPanel.java
@@ -19,7 +19,6 @@ import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-
// ---------------------------------------------------------------------------
// ScrollPanel
// ---------------------------------------------------------------------------
@@ -27,30 +26,25 @@ import org.eclipse.swt.widgets.Control;
/**
* Container panel that adds scrollbar(s) to a content control.
*/
-public class ScrollPanel extends ScrolledComposite
-{
+public class ScrollPanel extends ScrolledComposite {
// --- constructors/destructors ---
-
+
/** Constructor. */
- public ScrollPanel(Composite parent)
- {
+ public ScrollPanel(Composite parent) {
this(parent, null, true, true);
}
-
+
/** Constructor. */
- public ScrollPanel(Composite parent, boolean hscrollbar, boolean vscrollbar)
- {
+ public ScrollPanel(Composite parent, boolean hscrollbar, boolean vscrollbar) {
this(parent, null, hscrollbar, vscrollbar);
}
-
+
/** Constructor. */
- public ScrollPanel(Composite parent, Control contentControl, boolean hscrollbar, boolean vscrollbar)
- {
- super(parent, ((hscrollbar) ? SWT.H_SCROLL : SWT.NONE) |
- ((vscrollbar) ? SWT.V_SCROLL : SWT.NONE));
+ public ScrollPanel(Composite parent, Control contentControl, boolean hscrollbar, boolean vscrollbar) {
+ super(parent, ((hscrollbar) ? SWT.H_SCROLL : SWT.NONE) | ((vscrollbar) ? SWT.V_SCROLL : SWT.NONE));
initScrollPanel(contentControl, hscrollbar, vscrollbar);
}
-
+
/** Dispose method. */
public void dispose() {
cleanupScrollPanel();
@@ -61,27 +55,26 @@ public class ScrollPanel extends ScrolledComposite
protected void checkSubclass() {
// do nothing -- superclass implementation throws a "Subclassing not allowed" exception
}
-
-
+
// --- init methods ---
-
+
/** Initializes control */
protected void initScrollPanel(Control contentControl, boolean hscrollbar, boolean vscrollbar) {
- setMinSize(0,0);
- setShowFocusedControl(true);
- // If user doesn't want either scrollbar, we'll auto-size in that direction by default.
- setAutoResizeWidth(! hscrollbar);
- setAutoResizeHeight(! vscrollbar);
- if (contentControl != null) setContent(contentControl);
+ setMinSize(0, 0);
+ setShowFocusedControl(true);
+ // If user doesn't want either scrollbar, we'll auto-size in that direction by default.
+ setAutoResizeWidth(!hscrollbar);
+ setAutoResizeHeight(!vscrollbar);
+ if (contentControl != null)
+ setContent(contentControl);
}
-
+
/** Cleans up control */
protected void cleanupScrollPanel() {
}
-
-
+
// --- methods ---
-
+
/** Sets whether ScrollPanel auto-resizes the width of its contained control
* to match the size of the scrollpanel's content area, save when the control
* is smaller than the minimum width. (This also implicitly disables/hides
@@ -90,7 +83,7 @@ public class ScrollPanel extends ScrolledComposite
public void setAutoResizeWidth(boolean resizeWidth) {
setExpandHorizontal(resizeWidth);
}
-
+
/** Sets whether ScrollPanel auto-resizes the height of its contained control
* to match the size of the scrollpanel's content area, save when the control
* is smaller than the minimum width. (This also implicitly disables/hides
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionManager.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionManager.java
index d45a78253e..55b406d64e 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionManager.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionManager.java
@@ -19,7 +19,6 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
-
// ---------------------------------------------------------------------------
// SelectionManager
// ---------------------------------------------------------------------------
@@ -27,140 +26,129 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
/**
* Selection management utility class
*/
-public class SelectionManager
- implements ISelectionProvider
-{
+public class SelectionManager implements ISelectionProvider {
// --- members ---
-
+
/** Actual source to report for selection change events. */
protected ISelectionProvider m_source = null;
-
+
/** Manager label, also used on listener list. */
protected String m_label = null;
/** Current selection, if any. */
protected ISelection m_selection = SelectionUtils.EMPTY_SELECTION;
-
- /** Selection changed listeners */
- protected ListenerList m_selectionListeners = null;
-
- /** Whether selection events are enabled */
- protected boolean m_selectionEventsEnabled = true;
-
- // --- constructors/destructors ---
-
- /** Constructor. */
- public SelectionManager(ISelectionProvider source, String label)
- {
- m_source = (source == null) ? this : source;
- m_label = label;
+
+ /** Selection changed listeners */
+ protected ListenerList m_selectionListeners = null;
+
+ /** Whether selection events are enabled */
+ protected boolean m_selectionEventsEnabled = true;
+
+ // --- constructors/destructors ---
+
+ /** Constructor. */
+ public SelectionManager(ISelectionProvider source, String label) {
+ m_source = (source == null) ? this : source;
+ m_label = label;
m_selectionListeners = new ListenerList(this, label + ", listener list") {
public void raise(Object listener, Object event) {
- if (listener instanceof ISelectionChangedListener &&
- event instanceof SelectionChangedEvent)
- {
- ISelectionChangedListener typedListener = (ISelectionChangedListener) listener;
- SelectionChangedEvent typedEvent = (SelectionChangedEvent) event;
- typedListener.selectionChanged(typedEvent);
- }
+ if (listener instanceof ISelectionChangedListener && event instanceof SelectionChangedEvent) {
+ ISelectionChangedListener typedListener = (ISelectionChangedListener) listener;
+ SelectionChangedEvent typedEvent = (SelectionChangedEvent) event;
+ typedListener.selectionChanged(typedEvent);
+ }
}
};
- }
-
- /** Dispose method. */
- public void dispose()
- {
- m_selectionEventsEnabled = false;
- m_selection = SelectionUtils.EMPTY_SELECTION;
- if (m_selectionListeners != null) {
- m_selectionListeners.clear();
- m_selectionListeners = null;
- }
- // m_label = null; // leave label, to aid in debugging cleanup
- m_source = null;
- }
-
- // --- ISelectionProvider implementation ---
-
- /** Adds selection changed listener. */
- public void addSelectionChangedListener(ISelectionChangedListener listener)
- {
- if (listener == null) return;
+ }
+
+ /** Dispose method. */
+ public void dispose() {
+ m_selectionEventsEnabled = false;
+ m_selection = SelectionUtils.EMPTY_SELECTION;
+ if (m_selectionListeners != null) {
+ m_selectionListeners.clear();
+ m_selectionListeners = null;
+ }
+ // m_label = null; // leave label, to aid in debugging cleanup
+ m_source = null;
+ }
+
+ // --- ISelectionProvider implementation ---
+
+ /** Adds selection changed listener. */
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ if (listener == null)
+ return;
m_selectionListeners.addListener(listener);
// fake a selection changed event so new listener can update itself properly
listener.selectionChanged(new SelectionChangedEvent(m_source, getSelection()));
}
- /** Removes selection changed listener. */
- public void removeSelectionChangedListener(ISelectionChangedListener listener)
- {
- if (listener == null) return;
+ /** Removes selection changed listener. */
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ if (listener == null)
+ return;
m_selectionListeners.removeListener(listener);
}
/** Returns current selection. */
- public ISelection getSelection()
- {
+ public ISelection getSelection() {
return m_selection;
}
/** Sets selection, and raises change event. */
- public void setSelection(ISelection selection)
- {
+ public void setSelection(ISelection selection) {
setSelection(selection, true);
}
-
+
/** Sets selection, and raises change event with specified provider as the source. */
- public void setSelection(ISelectionProvider provider, ISelection selection)
- {
+ public void setSelection(ISelectionProvider provider, ISelection selection) {
setSelection(provider, selection, true);
}
-
+
/** Sets selection, and raises change event
* if raiseEvent is true. */
- public void setSelection(ISelection selection, boolean raiseEvent)
- {
+ public void setSelection(ISelection selection, boolean raiseEvent) {
if (selection == null)
selection = SelectionUtils.EMPTY_SELECTION;
m_selection = selection;
- if (raiseEvent) raiseSelectionChangedEvent();
+ if (raiseEvent)
+ raiseSelectionChangedEvent();
}
/** Sets selection, and raises change event with specified provider as the source
* if raiseEvent is true. */
- public void setSelection(ISelectionProvider provider, ISelection selection, boolean raiseEvent)
- {
+ public void setSelection(ISelectionProvider provider, ISelection selection, boolean raiseEvent) {
if (selection == null)
selection = SelectionUtils.EMPTY_SELECTION;
m_selection = selection;
- if (raiseEvent) raiseSelectionChangedEvent(provider);
+ if (raiseEvent)
+ raiseSelectionChangedEvent(provider);
}
-
+
/** Returns true if we currently have a non-emptr selection. */
- public boolean hasSelection()
- {
+ public boolean hasSelection() {
return (SelectionUtils.getSelectionSize(m_selection) > 0);
}
-
-
+
// --- methods ---
-
- /** Gets whether selection events are enabled. */
- public boolean getSelectionEventsEnabled() {
- return m_selectionEventsEnabled;
- }
- /** Sets whether selection events are enabled. */
- public void setSelectionEventsEnabled(boolean enabled) {
- m_selectionEventsEnabled = enabled;
- }
+ /** Gets whether selection events are enabled. */
+ public boolean getSelectionEventsEnabled() {
+ return m_selectionEventsEnabled;
+ }
+
+ /** Sets whether selection events are enabled. */
+ public void setSelectionEventsEnabled(boolean enabled) {
+ m_selectionEventsEnabled = enabled;
+ }
/** Raises selection changed event. */
public void raiseSelectionChangedEvent() {
if (m_selectionEventsEnabled)
m_selectionListeners.raise(new SelectionChangedEvent(m_source, getSelection()));
}
-
+
/** Raises selection changed event with specified provider as source. */
public void raiseSelectionChangedEvent(ISelectionProvider provider) {
if (m_selectionEventsEnabled)
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionProviderAdapter.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionProviderAdapter.java
index e80470f008..020999fbc0 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionProviderAdapter.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionProviderAdapter.java
@@ -18,7 +18,6 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
-
// ---------------------------------------------------------------------------
// SelectionProviderAdapter
// ---------------------------------------------------------------------------
@@ -27,59 +26,52 @@ import org.eclipse.jface.viewers.ISelectionProvider;
* Wrapper for selection "providers" that don't happen to implement
* ISelectionProvider interface.
*/
-public class SelectionProviderAdapter
- implements ISelectionProvider
-{
+public class SelectionProviderAdapter implements ISelectionProvider {
// --- members ---
-
+
/** Real source object. */
protected Object m_source = null;
-
+
/** Selection manager. */
protected SelectionManager m_selectionManager = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public SelectionProviderAdapter(Object source) {
m_source = source;
m_selectionManager = new SelectionManager(this, "SelectionProviderAdapter for source " + m_source.toString());
}
-
+
/** Dispose method. */
public void dispose() {
m_source = null;
- if (m_selectionManager != null) {
- m_selectionManager.dispose();
- m_selectionManager = null;
- }
+ if (m_selectionManager != null) {
+ m_selectionManager.dispose();
+ m_selectionManager = null;
+ }
}
-
-
+
// --- accessors ---
-
+
/** Gets wrapped selection source. */
public Object getActualSource() {
return m_source;
}
-
// --- ISelectionProvider implementation ---
/** Adds selection change listener.
* Default implementation does nothing.
*/
- public void addSelectionChangedListener(ISelectionChangedListener listener)
- {
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
m_selectionManager.addSelectionChangedListener(listener);
}
/** Removes selection change listener.
* Default implementation does nothing.
*/
- public void removeSelectionChangedListener(ISelectionChangedListener listener)
- {
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
m_selectionManager.removeSelectionChangedListener(listener);
}
@@ -93,8 +85,7 @@ public class SelectionProviderAdapter
/** Sets selection.
* Default implementation does nothing.
*/
- public void setSelection(ISelection selection)
- {
+ public void setSelection(ISelection selection) {
m_selectionManager.setSelection(selection);
}
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionUtils.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionUtils.java
index d2c9f0ea42..4c4d48e11c 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionUtils.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/SelectionUtils.java
@@ -27,37 +27,33 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
-
//----------------------------------------------------------------------------
// SelectionUtils
//----------------------------------------------------------------------------
/** Eclipse ISelection munging utilities. */
-public class SelectionUtils
-{
+public class SelectionUtils {
// --- constants ---
-
+
/** Special value for an "empty" selection,
* since selection cannot be null.
*/
public static final ISelection EMPTY_SELECTION = new EmptySelection();
/** "Empty" or undefined selection. */
- public static class EmptySelection
- implements ISelection, IStructuredSelection
- {
+ public static class EmptySelection implements ISelection, IStructuredSelection {
public boolean isEmpty() {
return true;
}
-
+
public Iterator<Object> iterator() {
return new ArrayList<Object>().iterator();
}
-
+
public List<Object> toList() {
return new ArrayList<Object>();
}
-
+
public int size() {
return 0;
}
@@ -70,37 +66,36 @@ public class SelectionUtils
return new Object[0];
}
}
-
-
+
// --- selection utilities ---
-
- /**
- * Returns workbench selection, if any.
- */
- public static ISelection getWorkbenchSelection() {
- ISelection result = null;
+
+ /**
+ * Returns workbench selection, if any.
+ */
+ public static ISelection getWorkbenchSelection() {
+ ISelection result = null;
IWorkbenchPage page = getWorkbenchPage();
if (page != null) {
result = page.getSelection();
}
return result;
- }
+ }
/** Creates an ISelection from a collection of objects */
public static ISelection toSelection(Collection<?> objects) {
return (objects == null) ? null : new StructuredSelection(toList(objects));
}
-
+
/** Creates an ISelection from a list of objects */
public static ISelection toSelection(List<?> objects) {
return (objects == null) ? null : new StructuredSelection(objects);
}
-
+
/** Creates an ISelection from the specified object(s) */
public static <T> ISelection toSelection(T... objects) {
return (objects == null) ? null : new StructuredSelection(objects);
}
-
+
/**
* Gets number of top-level object(s) from an Eclipse ISelection.
*/
@@ -108,25 +103,22 @@ public class SelectionUtils
int result = 0;
if (selection == EMPTY_SELECTION) {
// nothing to do
- }
- else if (selection instanceof IStructuredSelection) {
+ } else if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
result = structuredSelection.size();
- }
- else if (selection instanceof ISelection) {
+ } else if (selection instanceof ISelection) {
result = ((ISelection) selection).isEmpty() ? 0 : 1;
}
// collections are not ISelections, this just makes the method a little more generic
else if (selection instanceof Collection) {
Collection<?> collection = (Collection<?>) selection;
result = collection.size();
- }
- else if (selection != null) {
+ } else if (selection != null) {
result = 1;
}
return result;
}
-
+
/**
* Gets selected object(s) from an Eclipse ISelection as a List.
* If selection is a multiple selection (an IStructuredSelection or Collection),
@@ -138,19 +130,17 @@ public class SelectionUtils
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
result = new ArrayList<Object>((List<?>) structuredSelection.toList());
- }
- else if (selection instanceof Collection) {
+ } else if (selection instanceof Collection) {
Collection<?> collection = (Collection<?>) selection;
result = new ArrayList<Object>(collection);
- }
- else {
+ } else {
List<Object> list = new ArrayList<Object>();
list.add(selection);
result = list;
}
return result;
}
-
+
/**
* Gets single selected object from an Eclipse ISelection.
* If selection is a single selection, returns it.
@@ -161,18 +151,17 @@ public class SelectionUtils
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
result = structuredSelection.getFirstElement();
- }
- else if (selection instanceof Collection) {
+ } else if (selection instanceof Collection) {
Collection<?> collection = (Collection<?>) selection;
Iterator<?> i = collection.iterator();
- if (i.hasNext()) result = i.next();
- }
- else {
+ if (i.hasNext())
+ result = i.next();
+ } else {
result = selection;
}
return result;
}
-
+
/**
* Creates Eclipse ISelection from a list.
*/
@@ -186,7 +175,7 @@ public class SelectionUtils
public static <T> ISelection toISelection(T... items) {
return new StructuredSelection(items);
}
-
+
/**
* Gets iterator for an ISelection.
* Note: returns null if ISelection is not an IStructuredSelection,
@@ -200,35 +189,32 @@ public class SelectionUtils
return result;
}
-
- // --- debugging tools ---
-
+ // --- debugging tools ---
+
/** Converts selection to string, for debug display. */
public static String toString(ISelection selection) {
String result = null;
// convert selection to text string
if (selection == null) {
result = "No selection";
- }
- else if (selection instanceof IStructuredSelection) {
+ } else if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
List<?> elements = structuredSelection.toList();
int size = elements.size();
if (size == 0) {
result = "Empty selection";
- }
- else {
+ } else {
result = "Selection: ";
- for (int i=0; i<size; i++) {
- if (i>0) result += "\n";
+ for (int i = 0; i < size; i++) {
+ if (i > 0)
+ result += "\n";
Object o = elements.get(i);
String type = o.getClass().getName();
String value = o.toString();
result += "[" + i + "]: type= + " + type + ", value='" + value + "'";
}
}
- }
- else {
+ } else {
String type = selection.getClass().getName();
String value = selection.toString();
result = "Selection: (type = " + type + ") " + value;
@@ -237,47 +223,47 @@ public class SelectionUtils
}
// --- utilities ---
-
- /** Creates list from array/set of elements */
- public static List<Object> toList(Collection<?> collection) {
- int size = (collection == null) ? 0 : collection.size();
- List<Object> result = new ArrayList<Object>(size);
- if (collection != null) result.addAll(collection);
- return result;
- }
-
- /** Gets current Eclipse workbench */
+
+ /** Creates list from array/set of elements */
+ public static List<Object> toList(Collection<?> collection) {
+ int size = (collection == null) ? 0 : collection.size();
+ List<Object> result = new ArrayList<Object>(size);
+ if (collection != null)
+ result.addAll(collection);
+ return result;
+ }
+
+ /** Gets current Eclipse workbench */
public static IWorkbench getWorkbench() {
- IWorkbench result = null;
- try {
- result = PlatformUI.getWorkbench();
- }
- catch (IllegalStateException e) {
- // Workbench is not defined for some reason. Oh well.
- }
- return result;
- }
-
- /** Gets current Eclipse workbench window.
- * Returns null if workbench does not exist.
- */
- public static IWorkbenchWindow getWorkbenchWindow() {
+ IWorkbench result = null;
+ try {
+ result = PlatformUI.getWorkbench();
+ } catch (IllegalStateException e) {
+ // Workbench is not defined for some reason. Oh well.
+ }
+ return result;
+ }
+
+ /** Gets current Eclipse workbench window.
+ * Returns null if workbench does not exist.
+ */
+ public static IWorkbenchWindow getWorkbenchWindow() {
IWorkbenchWindow result = null;
- IWorkbench workbench = getWorkbench();
- if (workbench != null) {
- result = workbench.getActiveWorkbenchWindow();
- if (result == null) {
+ IWorkbench workbench = getWorkbench();
+ if (workbench != null) {
+ result = workbench.getActiveWorkbenchWindow();
+ if (result == null) {
if (workbench.getWorkbenchWindowCount() > 0) {
result = (IWorkbenchWindow) workbench.getWorkbenchWindows()[0];
}
- }
- }
- return result;
- }
-
- /** Gets current Eclipse workbench page */
- public static IWorkbenchPage getWorkbenchPage() {
- IWorkbenchWindow window = getWorkbenchWindow();
- return (window == null) ? null : window.getActivePage();
- }
+ }
+ }
+ return result;
+ }
+
+ /** Gets current Eclipse workbench page */
+ public static IWorkbenchPage getWorkbenchPage() {
+ IWorkbenchWindow window = getWorkbenchWindow();
+ return (window == null) ? null : window.getActivePage();
+ }
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Timer.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Timer.java
index 7a73e96645..76c1d529e8 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Timer.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Timer.java
@@ -17,7 +17,6 @@ package org.eclipse.cdt.visualizer.ui.util;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-
// ---------------------------------------------------------------------------
// Timer
// ---------------------------------------------------------------------------
@@ -25,20 +24,17 @@ import java.awt.event.ActionListener;
/**
* Periodic event timer class.
*/
-public class Timer
- implements ActionListener, Runnable
-{
+public class Timer implements ActionListener, Runnable {
// --- members ---
-
+
/** Actual timer */
// NOTE: we delegate rather than subclassing, because
// Timer class implements ISerializable, so every derived type
// must either declare a serialization ID, or suppress the warning.
protected javax.swing.Timer m_timer = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public Timer(int intervalMilliseconds) {
m_timer = new javax.swing.Timer(intervalMilliseconds, null);
@@ -47,7 +43,7 @@ public class Timer
m_timer.setCoalesce(true);
m_timer.start();
}
-
+
/** Dispose method. */
public void dispose() {
if (m_timer != null) {
@@ -58,44 +54,44 @@ public class Timer
}
}
-
- // --- methods ---
-
- /** Gets whether timer repeatedly fires events. */
- public boolean isRepeating() {
- return m_timer.isRepeats();
- }
-
- /** Sets whether timer repeatedly fires events. */
- public void setRepeating(boolean repeats) {
- m_timer.setRepeats(repeats);
- }
-
- /** Starts/restarts timer.
- * Has no effect if timer is already running
- */
- public void start() {
- if (! m_timer.isRunning()) m_timer.start();
- }
-
- /** Stops timer.
- * Has no effect if timer is already stopped.
- */
- public void stop() {
- if (m_timer.isRunning()) m_timer.stop();
- }
-
-
+ // --- methods ---
+
+ /** Gets whether timer repeatedly fires events. */
+ public boolean isRepeating() {
+ return m_timer.isRepeats();
+ }
+
+ /** Sets whether timer repeatedly fires events. */
+ public void setRepeating(boolean repeats) {
+ m_timer.setRepeats(repeats);
+ }
+
+ /** Starts/restarts timer.
+ * Has no effect if timer is already running
+ */
+ public void start() {
+ if (!m_timer.isRunning())
+ m_timer.start();
+ }
+
+ /** Stops timer.
+ * Has no effect if timer is already stopped.
+ */
+ public void stop() {
+ if (m_timer.isRunning())
+ m_timer.stop();
+ }
+
// --- ActionListener implementation ---
- /**
- * Invoked each time the timer fires.
- * Default implementation invokes the run() method on the UI thread.
- */
- public void actionPerformed(ActionEvent e) {
+ /**
+ * Invoked each time the timer fires.
+ * Default implementation invokes the run() method on the UI thread.
+ */
+ public void actionPerformed(ActionEvent e) {
GUIUtils.exec(this);
- }
-
+ }
+
/** Invoked each time the timer fires. */
public void run() {
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Todo.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Todo.java
index 464be5bbf3..ad65928e70 100644
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Todo.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/Todo.java
@@ -16,42 +16,40 @@ package org.eclipse.cdt.visualizer.ui.util;
/** Counter for objects that need to track asynchronous progress. */
public class Todo {
-
+
// --- members ---
-
+
/** Count of things left to do. */
int m_count = 0;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor. */
public Todo() {
}
-
+
/** Constructor. */
public Todo(int count) {
m_count = count;
}
-
+
/** Dispose method. */
public void dispose() {
m_count = 0;
}
-
-
+
// --- accessors ---
-
+
/** Gets count. */
public int get() {
return m_count;
}
-
+
/** Sets count. */
public void set(int count) {
m_count = count;
}
-
+
/** Returns true if count has reached zero. */
public boolean isDone() {
return m_count <= 0;
@@ -76,10 +74,9 @@ public class Todo {
public int decrement() {
return (m_count -= 1);
}
-
-
+
// --- methods ---
-
+
/** Adds completion steps to count. */
public void add(int n) {
increment(n);
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/UIResourceManager.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/UIResourceManager.java
index b605d34c05..f271c888d4 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/UIResourceManager.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/UIResourceManager.java
@@ -30,7 +30,6 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.plugin.AbstractUIPlugin;
-
// ---------------------------------------------------------------------------
// UIResourceManager
// ---------------------------------------------------------------------------
@@ -42,28 +41,26 @@ import org.eclipse.ui.plugin.AbstractUIPlugin;
* This class should be instanced in the UI plugin's "start()" method,
* and disposed in the "stop()" method.
*/
-public class UIResourceManager extends ResourceManager
-{
+public class UIResourceManager extends ResourceManager {
// --- members ---
-
+
/** UI Plugin */
protected AbstractUIPlugin m_UIplugin = null;
-
+
/** Parent resource manager, if any */
protected UIResourceManager m_parentUIManager = null;
-
+
/** Image resource manager */
protected ImageRegistry m_images = null;
-
+
/** Font resource manager */
protected FontRegistry m_fonts = null;
-
+
/** Color resource manager */
protected ColorRegistry m_colors = null;
-
-
+
// --- constructors/destructors ---
-
+
/** Constructor
* Note: the plugin ID is assumed to also be the parent package name
* of the plugin, for example "com.tilera.ide.core"; it's assumed that string
@@ -73,27 +70,25 @@ public class UIResourceManager extends ResourceManager
super(plugin);
m_UIplugin = plugin;
getImageRegistry(); // creates registry object
- getFontRegistry(); // creates registry object
+ getFontRegistry(); // creates registry object
getColorRegistry(); // creates registry object
}
-
+
/** Dispose method */
public void dispose() {
disposeImageRegistry();
disposeFontRegistry();
disposeColorRegistry();
- }
+ }
-
// --- parent manager management ---
-
+
/** Sets parent resource manager, if any */
public void setParentManager(ResourceManager parentManager) {
super.setParentManager(parentManager);
if (parentManager instanceof UIResourceManager) {
m_parentUIManager = (UIResourceManager) parentManager;
- }
- else {
+ } else {
m_parentUIManager = null;
}
}
@@ -103,9 +98,8 @@ public class UIResourceManager extends ResourceManager
return m_parentUIManager;
}
-
// --- image resource management ---
-
+
/** Creates/returns image registry */
protected ImageRegistry getImageRegistry() {
if (m_images == null) {
@@ -114,7 +108,7 @@ public class UIResourceManager extends ResourceManager
}
return m_images;
}
-
+
/** Disposes image registry */
protected void disposeImageRegistry() {
if (m_images != null) {
@@ -124,85 +118,84 @@ public class UIResourceManager extends ResourceManager
}
}
- /**
- * Returns an image descriptor for the image file at the given
- * plug-in relative path.
- */
- public ImageDescriptor getImageDescriptor(String path) {
- ImageDescriptor result = null;
- if (path == null) return result;
-
- // get image registry, look up path
- ImageRegistry images = getImageRegistry();
- result = images.getDescriptor(path);
-
- // if we don't find it, see if it exists as a file in this plugin
- if (result == null) {
- URL url = m_UIplugin.getBundle().getEntry(path);
- if (url != null) {
- // if so, we'll add an entry for it to this resource manager
- ImageDescriptor desc = ImageDescriptor.createFromURL(url);
- images.put(path, desc);
- result = images.getDescriptor(path);
- }
- else {
- // if not, see if we can find it in the parent manager
- // NOTE: this may be in a different plugin, so the path will be
- // resolved relative to that plugin's base directory
- UIResourceManager parent = getParentManager();
- if (parent != null) {
- result = parent.getImageDescriptor(path);
- }
- }
- }
- return result;
- }
-
- /**
- * Gets specified image from plugin directory.
- * Caches images so subsequent requests will be faster.
- */
- public Image getImage(String path) {
- Image result = null;
- if (path == null) return result;
-
- // get image registry, look up path
- ImageRegistry images = getImageRegistry();
- result = images.get(path);
-
- // if we don't find it, see if it exists as a file in this plugin
- if (result == null) {
- URL url = m_UIplugin.getBundle().getEntry(path);
- if (url != null) {
- // if so, we'll add an entry for it to this resource manager
- ImageDescriptor desc = ImageDescriptor.createFromURL(url);
- images.put(path, desc);
- result = images.get(path);
- }
- else {
- // if not, see if we can find it in the parent manager
- // NOTE: this may be in a different plugin, so the path will be
- // resolved relative to that plugin's base directory
- UIResourceManager parent = getParentManager();
- if (parent != null) {
- result = parent.getImage(path);
- }
- }
- }
- return result;
- }
-
-
- // --- font registry ---
-
- /** Creates/returns font registry */
- protected FontRegistry getFontRegistry() {
- if (m_fonts == null) {
- Display display = getDisplay();
- m_fonts = new FontRegistry(display);
- }
- return m_fonts;
- }
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path.
+ */
+ public ImageDescriptor getImageDescriptor(String path) {
+ ImageDescriptor result = null;
+ if (path == null)
+ return result;
+
+ // get image registry, look up path
+ ImageRegistry images = getImageRegistry();
+ result = images.getDescriptor(path);
+
+ // if we don't find it, see if it exists as a file in this plugin
+ if (result == null) {
+ URL url = m_UIplugin.getBundle().getEntry(path);
+ if (url != null) {
+ // if so, we'll add an entry for it to this resource manager
+ ImageDescriptor desc = ImageDescriptor.createFromURL(url);
+ images.put(path, desc);
+ result = images.getDescriptor(path);
+ } else {
+ // if not, see if we can find it in the parent manager
+ // NOTE: this may be in a different plugin, so the path will be
+ // resolved relative to that plugin's base directory
+ UIResourceManager parent = getParentManager();
+ if (parent != null) {
+ result = parent.getImageDescriptor(path);
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Gets specified image from plugin directory.
+ * Caches images so subsequent requests will be faster.
+ */
+ public Image getImage(String path) {
+ Image result = null;
+ if (path == null)
+ return result;
+
+ // get image registry, look up path
+ ImageRegistry images = getImageRegistry();
+ result = images.get(path);
+
+ // if we don't find it, see if it exists as a file in this plugin
+ if (result == null) {
+ URL url = m_UIplugin.getBundle().getEntry(path);
+ if (url != null) {
+ // if so, we'll add an entry for it to this resource manager
+ ImageDescriptor desc = ImageDescriptor.createFromURL(url);
+ images.put(path, desc);
+ result = images.get(path);
+ } else {
+ // if not, see if we can find it in the parent manager
+ // NOTE: this may be in a different plugin, so the path will be
+ // resolved relative to that plugin's base directory
+ UIResourceManager parent = getParentManager();
+ if (parent != null) {
+ result = parent.getImage(path);
+ }
+ }
+ }
+ return result;
+ }
+
+ // --- font registry ---
+
+ /** Creates/returns font registry */
+ protected FontRegistry getFontRegistry() {
+ if (m_fonts == null) {
+ Display display = getDisplay();
+ m_fonts = new FontRegistry(display);
+ }
+ return m_fonts;
+ }
/** Disposes font registry */
protected void disposeFontRegistry() {
@@ -213,80 +206,78 @@ public class UIResourceManager extends ResourceManager
}
}
- /** Sets cached font for specified ID */
- public void setFont(String fontID, String fontName, int height, int style) {
- setCachedFont(fontID, fontName, height, style);
- }
-
- /** Gets cached font for specified ID */
- public Font getFont(String fontID) {
- return getCachedFont(fontID);
- }
-
- /** Gets/creates font with specified properties */
- public Font getFont(String fontName, int height) {
- return getCachedFont(fontName, height, SWT.NORMAL);
- }
-
- /** Gets/creates font with specified properties */
- public Font getFont(String fontName, int height, int style) {
- return getCachedFont(fontName, height, style);
- }
-
- /** Sets cached font for specified ID */
- protected void setCachedFont(String fontID, String fontName, int height, int style) {
- FontData[] fontData = new FontData[1];
- fontData[0] = new FontData(fontName, height, style);
- FontRegistry fonts = getFontRegistry();
- fonts.put(fontID, fontData);
- }
-
- /** Gets cached font, if any, for specified ID */
- protected Font getCachedFont(String fontID) {
- Font result = null;
-
- // get font registry, look up font ID
- FontRegistry fonts = getFontRegistry();
- if (fonts.hasValueFor(fontID)) {
- result = fonts.get(fontID);
- }
- else {
- // if we don't find it, see if parent manager has it
- UIResourceManager parent = getParentManager();
- if (parent != null) {
- result = parent.getCachedFont(fontID);
- }
- }
- return result;
- }
-
- /** Gets/creates font with specified properties */
- protected Font getCachedFont(String fontName, int height, int style) {
- Font result = null;
- String fontID = fontName + "," + height + "," + style;
-
- // look for the cached font (this checks the parent manager too)
- result = getCachedFont(fontID);
-
- // if we didn't find it, add an entry to this resource manager
- if (result == null) {
- setCachedFont(fontID, fontName, height, style);
- result = getCachedFont(fontID);
- }
- return result;
- }
-
-
- // --- color registry ---
-
- /** Creates/returns color registry */
- protected ColorRegistry getColorRegistry() {
- if (m_colors == null) {
- Display display = getDisplay();
- m_colors = new ColorRegistry(display);
- }
- return m_colors;
- }
+ /** Sets cached font for specified ID */
+ public void setFont(String fontID, String fontName, int height, int style) {
+ setCachedFont(fontID, fontName, height, style);
+ }
+
+ /** Gets cached font for specified ID */
+ public Font getFont(String fontID) {
+ return getCachedFont(fontID);
+ }
+
+ /** Gets/creates font with specified properties */
+ public Font getFont(String fontName, int height) {
+ return getCachedFont(fontName, height, SWT.NORMAL);
+ }
+
+ /** Gets/creates font with specified properties */
+ public Font getFont(String fontName, int height, int style) {
+ return getCachedFont(fontName, height, style);
+ }
+
+ /** Sets cached font for specified ID */
+ protected void setCachedFont(String fontID, String fontName, int height, int style) {
+ FontData[] fontData = new FontData[1];
+ fontData[0] = new FontData(fontName, height, style);
+ FontRegistry fonts = getFontRegistry();
+ fonts.put(fontID, fontData);
+ }
+
+ /** Gets cached font, if any, for specified ID */
+ protected Font getCachedFont(String fontID) {
+ Font result = null;
+
+ // get font registry, look up font ID
+ FontRegistry fonts = getFontRegistry();
+ if (fonts.hasValueFor(fontID)) {
+ result = fonts.get(fontID);
+ } else {
+ // if we don't find it, see if parent manager has it
+ UIResourceManager parent = getParentManager();
+ if (parent != null) {
+ result = parent.getCachedFont(fontID);
+ }
+ }
+ return result;
+ }
+
+ /** Gets/creates font with specified properties */
+ protected Font getCachedFont(String fontName, int height, int style) {
+ Font result = null;
+ String fontID = fontName + "," + height + "," + style;
+
+ // look for the cached font (this checks the parent manager too)
+ result = getCachedFont(fontID);
+
+ // if we didn't find it, add an entry to this resource manager
+ if (result == null) {
+ setCachedFont(fontID, fontName, height, style);
+ result = getCachedFont(fontID);
+ }
+ return result;
+ }
+
+ // --- color registry ---
+
+ /** Creates/returns color registry */
+ protected ColorRegistry getColorRegistry() {
+ if (m_colors == null) {
+ Display display = getDisplay();
+ m_colors = new ColorRegistry(display);
+ }
+ return m_colors;
+ }
/** Disposes color registry */
protected void disposeColorRegistry() {
@@ -297,81 +288,79 @@ public class UIResourceManager extends ResourceManager
}
}
- /** Gets cached color with specified SWT color ID */
- public Color getColor(int colorID) {
- // NOTE: we don't cache these colors, we just look them up every time
- return getDisplay().getSystemColor(colorID);
- }
-
- /** Gets cached color with specified ID */
- public Color getColor(String colorID) {
- return getCachedColor(colorID);
- }
-
- /** Gets/creates color with specified properties */
- public Color getColor(int red, int green, int blue) {
- return getCachedColor(red, green, blue);
- }
-
- /** Sets cached color for specified ID */
- protected void setCachedColor(String colorID, int red, int green, int blue) {
- RGB rgb = new RGB(red, green, blue);
- ColorRegistry colors = getColorRegistry();
- colors.put(colorID, rgb);
- }
-
- /** Gets cached color with specified ID */
- protected Color getCachedColor(String colorID) {
- Color result = null;
- ColorRegistry colors = getColorRegistry();
- if (colors.hasValueFor(colorID)) {
- result = colors.get(colorID);
- }
- else {
- // if we don't find it, see if parent manager has it
- UIResourceManager parent = getParentManager();
- if (parent != null) {
- result = parent.getCachedColor(colorID);
- }
- }
- return result;
- }
-
- /** Gets/creates color with specified properties */
- protected Color getCachedColor(int red, int green, int blue) {
- Color result = null;
- String colorID = "Color[R=" + red + ",G=" + green + ",B=" + blue + "]";
-
- // look for the cached color (this checks the parent manager too)
- result = getCachedColor(colorID);
-
- // if we don't find it, create an entry in this resource manager
- if (result == null) {
- setCachedColor(colorID, red, green, blue);
- result = getCachedColor(colorID);
- }
- return result;
- }
-
-
- // --- utilities ---
-
+ /** Gets cached color with specified SWT color ID */
+ public Color getColor(int colorID) {
+ // NOTE: we don't cache these colors, we just look them up every time
+ return getDisplay().getSystemColor(colorID);
+ }
+
+ /** Gets cached color with specified ID */
+ public Color getColor(String colorID) {
+ return getCachedColor(colorID);
+ }
+
+ /** Gets/creates color with specified properties */
+ public Color getColor(int red, int green, int blue) {
+ return getCachedColor(red, green, blue);
+ }
+
+ /** Sets cached color for specified ID */
+ protected void setCachedColor(String colorID, int red, int green, int blue) {
+ RGB rgb = new RGB(red, green, blue);
+ ColorRegistry colors = getColorRegistry();
+ colors.put(colorID, rgb);
+ }
+
+ /** Gets cached color with specified ID */
+ protected Color getCachedColor(String colorID) {
+ Color result = null;
+ ColorRegistry colors = getColorRegistry();
+ if (colors.hasValueFor(colorID)) {
+ result = colors.get(colorID);
+ } else {
+ // if we don't find it, see if parent manager has it
+ UIResourceManager parent = getParentManager();
+ if (parent != null) {
+ result = parent.getCachedColor(colorID);
+ }
+ }
+ return result;
+ }
+
+ /** Gets/creates color with specified properties */
+ protected Color getCachedColor(int red, int green, int blue) {
+ Color result = null;
+ String colorID = "Color[R=" + red + ",G=" + green + ",B=" + blue + "]";
+
+ // look for the cached color (this checks the parent manager too)
+ result = getCachedColor(colorID);
+
+ // if we don't find it, create an entry in this resource manager
+ if (result == null) {
+ setCachedColor(colorID, red, green, blue);
+ result = getCachedColor(colorID);
+ }
+ return result;
+ }
+
+ // --- utilities ---
+
/**
* Returns the current SWT display.
- *
+ *
* The method first checks whether the caller already has
* an associated display. If so, this display is returned.
* Otherwise the method returns the default display.
- *
+ *
* This allows GUIUtils to work in contexts like tests
* where the SWT display has not already been defined.
- *
+ *
* (Credit: Borrowed from DebugUIPlugin.)
*/
public static Display getDisplay() {
- Display display= Display.getCurrent();
+ Display display = Display.getCurrent();
if (display == null) {
- display= Display.getDefault();
+ display = Display.getDefault();
}
return display;
}
diff --git a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/WorkbenchSelectionAdapter.java b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/WorkbenchSelectionAdapter.java
index fa73d2d2d7..4e3f72181d 100755
--- a/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/WorkbenchSelectionAdapter.java
+++ b/visualizer/org.eclipse.cdt.visualizer.ui/src/org/eclipse/cdt/visualizer/ui/util/WorkbenchSelectionAdapter.java
@@ -26,7 +26,6 @@ import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPart;
-
// ---------------------------------------------------------------------------
// WorkbenchSelectionAdapter
// ---------------------------------------------------------------------------
@@ -34,55 +33,50 @@ import org.eclipse.ui.IWorkbenchPart;
/**
* Selection change event manager
*/
-public class WorkbenchSelectionAdapter
- implements ISelectionListener, ISelectionProvider
-{
+public class WorkbenchSelectionAdapter implements ISelectionListener, ISelectionProvider {
// --- members ---
-
+
/** Workbench part (view) this adapter is associated with. */
protected IViewPart m_view = null;
-
+
/** Current selection */
protected ISelection m_selection = null;
-
+
/** Listeners for selection changed events. */
protected ListenerList m_selectionListeners = null;
/** Whether selection events are reported */
protected boolean m_trackSelection = true;
-
// --- constructors/destructors ---
-
+
/** Constructor. */
public WorkbenchSelectionAdapter(IViewPart view) {
m_view = view;
m_selection = null;
- m_selectionListeners = new ListenerList(view, "WorkbenchSelectionAdapter for view " + view.getClass().getSimpleName())
- {
+ m_selectionListeners = new ListenerList(view,
+ "WorkbenchSelectionAdapter for view " + view.getClass().getSimpleName()) {
/** Dispatches event to listeners */
public void raise(Object listener, Object event) {
- if (listener instanceof ISelectionChangedListener &&
- event instanceof SelectionChangedEvent)
- {
+ if (listener instanceof ISelectionChangedListener && event instanceof SelectionChangedEvent) {
ISelectionChangedListener typedListener = (ISelectionChangedListener) listener;
SelectionChangedEvent typedEvent = (SelectionChangedEvent) event;
typedListener.selectionChanged(typedEvent);
}
}
};
-
+
// listen for external selection changed events
m_view.getSite().getPage().addSelectionListener(this);
-
+
// set selection provider for this view
m_view.getSite().setSelectionProvider(this);
-
+
// initialize selection
setSelection(m_view.getSite().getPage().getSelection());
}
-
+
/** Dispose method. */
public void dispose() {
if (m_view != null) {
@@ -96,54 +90,52 @@ public class WorkbenchSelectionAdapter
m_selectionListeners = null;
}
}
-
// --- accessors ---
-
+
/** Gets whether selection change events are reported. */
public boolean getTrackSelection() {
return m_trackSelection;
}
-
+
/** Sets whether selection change events are reported. */
public void setTrackSelection(boolean trackSelection) {
m_trackSelection = trackSelection;
}
-
-
+
// --- ISelectionListener implementation ---
/** Invoked when selection changes externally. */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// ignore selection change events that came from us
- if (part == m_view) return;
+ if (part == m_view)
+ return;
if (m_trackSelection) {
workbenchSelectionChanged(part, selection);
}
}
-
+
/** Invoked when selection changes.
* Intended to be overloaded by derived implementations.
*/
public void workbenchSelectionChanged(ISelection selection) {
setSelection(selection);
}
-
+
/** Invoked when selection changes.
* Intended to be overloaded by derived implementations.
*/
public void workbenchSelectionChanged(ISelectionProvider provider, ISelection selection) {
setSelection(provider, selection);
}
-
+
/** Invoked when selection changes.
* Intended to be overloaded by derived implementations.
*/
public void workbenchSelectionChanged(Object provider, ISelection selection) {
setSelection(provider, selection);
}
-
-
+
// --- ISelectionProvider implementation ---
/** Gets current selection. */
@@ -154,7 +146,8 @@ public class WorkbenchSelectionAdapter
/** Sets current selection, and raises selection changed event. */
public void setSelection(ISelection selection) {
// for some reason, SelectionChangedEvent can't stand a null selection
- if (selection == null) selection = StructuredSelection.EMPTY;
+ if (selection == null)
+ selection = StructuredSelection.EMPTY;
m_selection = selection;
m_selectionListeners.raise(new SelectionChangedEvent(this, m_selection));
}
@@ -162,15 +155,17 @@ public class WorkbenchSelectionAdapter
/** Sets current selection, and raises selection changed event. */
public void setSelection(ISelectionProvider source, ISelection selection) {
// for some reason, SelectionChangedEvent can't stand a null selection
- if (selection == null) selection = StructuredSelection.EMPTY;
+ if (selection == null)
+ selection = StructuredSelection.EMPTY;
m_selection = selection;
m_selectionListeners.raise(new SelectionChangedEvent(source, m_selection));
}
-
+
/** Sets current selection, and raises selection changed event. */
public void setSelection(Object source, ISelection selection) {
// for some reason, SelectionChangedEvent can't stand a null selection
- if (selection == null) selection = StructuredSelection.EMPTY;
+ if (selection == null)
+ selection = StructuredSelection.EMPTY;
m_selection = selection;
m_selectionListeners.raise(new SelectionChangedEvent(new SelectionProviderAdapter(source), m_selection));
}
@@ -185,35 +180,32 @@ public class WorkbenchSelectionAdapter
m_selectionListeners.removeListener(listener);
}
-
// --- utilities ---
-
+
/** Converts selection to string, for debug display. */
protected String selectionToString(ISelection selection) {
String result = null;
// convert selection to text string
if (m_selection == null) {
result = "No Selection";
- }
- else if (m_selection instanceof IStructuredSelection) {
+ } else if (m_selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) m_selection;
List<?> elements = structuredSelection.toList();
int size = elements.size();
if (size == 0) {
result = "Empty Selection";
- }
- else {
+ } else {
result = "";
- for (int i=0; i<size; i++) {
- if (i>0) result += "\n";
+ for (int i = 0; i < size; i++) {
+ if (i > 0)
+ result += "\n";
Object o = elements.get(i);
String type = o.getClass().getName();
String value = o.toString();
result += "[" + i + "]: type= + " + type + ", value='" + value + "'";
}
}
- }
- else {
+ } else {
String type = m_selection.getClass().getName();
String value = m_selection.toString();
result = "type=" + type + ", value='" + value + "'";

Back to the top