Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-11-06 13:08:40 +0000
committerEike Stepper2012-11-06 13:08:40 +0000
commit0aa08334f3433908823bcb398807ff390af2bbf5 (patch)
treeafcd7f42b2a69b21302c2e47e71893bec13c0ced /plugins/org.eclipse.emf.cdo.examples.client.offline
parent9600fac225df0217ffd815626678e8f063256c32 (diff)
downloadcdo-0aa08334f3433908823bcb398807ff390af2bbf5.tar.gz
cdo-0aa08334f3433908823bcb398807ff390af2bbf5.tar.xz
cdo-0aa08334f3433908823bcb398807ff390af2bbf5.zip
Offline Example
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.examples.client.offline')
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/.externalToolBuilders/org.eclipse.emf.cdo.examples.client.offline.launch10
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/.project6
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/Application.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverMonitorView.java410
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverRepositoryView.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeManagerDialog.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/wb/swt/SWTResourceManager.java913
9 files changed, 847 insertions, 506 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/.externalToolBuilders/org.eclipse.emf.cdo.examples.client.offline.launch b/plugins/org.eclipse.emf.cdo.examples.client.offline/.externalToolBuilders/org.eclipse.emf.cdo.examples.client.offline.launch
index 3af3dcccbc..144e35bb1a 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/.externalToolBuilders/org.eclipse.emf.cdo.examples.client.offline.launch
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/.externalToolBuilders/org.eclipse.emf.cdo.examples.client.offline.launch
@@ -4,18 +4,16 @@
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/>
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.client.offline&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.installer/examples&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
-<booleanAttribute key="org.eclipse.debug.core.capture_output" value="false"/>
-<booleanAttribute key="org.eclipse.debug.ui.ATTR_CONSOLE_OUTPUT_ON" value="false"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ant.internal.launching.remote.InternalAntRunner"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value=""/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.emf.cdo.examples.client.offline"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_BUILDER_ENABLED" value="true"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/.classpath&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/.externalToolBuilders&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/.gitignore&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/.project&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/.settings&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/about.html&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/build.properties&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/config&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/copyright.txt&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/ExampleMasterServer.launch&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/META-INF&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/plugin.properties&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.master/README.html&quot; type=&quot;1&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc:/org.eclipse.emf.cdo.examples.master}/.externalToolBuilders/copyExample.ant"/>
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value=""/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;resources&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.client.offline&quot; type=&quot;4&quot;/&gt;&#13;&#10;&lt;item path=&quot;/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.client.offline&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/resources&gt;}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${project_loc:/org.eclipse.emf.cdo.examples.client.offline}/.externalToolBuilders/copyExample.ant"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="incremental,auto,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-Dbuild.project=${project_loc:/org.eclipse.emf.cdo.examples.client.offline}"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/.project b/plugins/org.eclipse.emf.cdo.examples.client.offline/.project
index cd3302d1d2..47cabb0053 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/.project
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/.project
@@ -26,12 +26,16 @@
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
- <triggers>full,incremental,</triggers>
+ <triggers>auto,full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/org.eclipse.emf.cdo.examples.client.offline.launch</value>
</dictionary>
+ <dictionary>
+ <key>incclean</key>
+ <value>true</value>
+ </dictionary>
</arguments>
</buildCommand>
</buildSpec>
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.examples.client.offline/META-INF/MANIFEST.MF
index 0fcf9585ed..946a6439ae 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/META-INF/MANIFEST.MF
@@ -16,8 +16,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.cdo.net4j;bundle-version="[4.0.0,5.0.0)",
org.eclipse.net4j.tcp;bundle-version="[4.0.0,5.0.0)",
org.eclipse.net4j.db.h2;bundle-version="[4.0.0,5.0.0)",
- org.eclipse.net4j.util.ui;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.nebula.widgets.oscilloscope;bundle-version="[1.0.0,2.0.0)"
+ org.eclipse.net4j.util.ui;bundle-version="[3.0.0,4.0.0)"
Import-Package: org.h2.jdbcx;version="[1.0.0,2.0.0)"
Bundle-ClassPath: .
Export-Package: org.eclipse.emf.cdo.examples.client.offline;version="4.2.0";x-internal:=true,
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/Application.java b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/Application.java
index 5d9e3e9809..f04b27ecf8 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/Application.java
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/Application.java
@@ -29,8 +29,6 @@ import java.io.File;
*/
public class Application implements IApplication
{
- public static final String TITLE = "CDO Offline Example";
-
public static final String PLUGIN_ID = "org.eclipse.emf.cdo.examples.client.offline";
private static final String ROOT_PROPERTY = "node.manager.root";
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverMonitorView.java b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverMonitorView.java
index dbd3c7a274..d458ca8037 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverMonitorView.java
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverMonitorView.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.emf.cdo.examples.client.offline;
+import org.eclipse.emf.cdo.examples.client.offline.FailoverMonitorView.OScope.Channel;
import org.eclipse.emf.cdo.server.net4j.FailoverMonitor;
import org.eclipse.emf.cdo.server.net4j.FailoverMonitor.AgentProtocol;
@@ -20,16 +21,22 @@ import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.ui.views.ItemProvider;
-import org.eclipse.nebula.widgets.oscilloscope.multichannel.Oscilloscope;
-import org.eclipse.nebula.widgets.oscilloscope.multichannel.OscilloscopeDispatcher;
-import org.eclipse.nebula.widgets.oscilloscope.multichannel.OscilloscopeStackAdapter;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.ByteArrayInputStream;
import java.util.Random;
+import java.util.SortedMap;
+import java.util.TreeMap;
/**
* @author Eike Stepper
@@ -38,14 +45,6 @@ public class FailoverMonitorView extends AbstractView<FailoverMonitor>
{
public static final String ID = "org.eclipse.emf.cdo.examples.client.offline.FailoverMonitorView"; //$NON-NLS-1$
- private static final int AMPLITUDE = 100;
-
- private static final int LENGTH = 5;
-
- private static final int[] ZERO = new int[LENGTH];
-
- private static final int[] PEAK = createPeakValues();
-
public FailoverMonitorView()
{
super(FailoverMonitor.class);
@@ -54,116 +53,367 @@ public class FailoverMonitorView extends AbstractView<FailoverMonitor>
@Override
protected void createPane(Composite parent, FailoverMonitor monitor, ItemProvider<FailoverMonitor> itemProvider)
{
- final Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new FillLayout(SWT.VERTICAL));
-
+ final OScope scope = new OScope(parent, SWT.NONE);
monitor.addListener(new ContainerEventAdapter<AgentProtocol>()
{
- private Map<String, AgentOscilloscope> oscilloscopes = new HashMap<String, AgentOscilloscope>();
-
@Override
protected void onAdded(IContainer<AgentProtocol> monitor, final AgentProtocol agent)
{
- final AgentOscilloscope oscilloscope = getOscilloscope(composite, agent);
+ final Channel channel = scope.getChannel(agent.getConnectorDescription());
agent.addListener(new IListener()
{
public void notifyEvent(IEvent event)
{
if (event instanceof SignalScheduledEvent)
{
- oscilloscope.scheduleValues(PEAK);
+ if (!scope.isDisposed())
+ {
+ scope.getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ if (!scope.isDisposed())
+ {
+ channel.peak();
+ }
+ }
+ });
+ }
}
}
});
}
+ });
+ }
- @Override
- protected void onRemoved(IContainer<AgentProtocol> container, AgentProtocol agent)
- {
- AgentOscilloscope oscilloscope = getOscilloscope(composite, agent);
- oscilloscope.scheduleValues(ZERO);
- }
+ @Override
+ public void setFocus()
+ {
+ }
- protected AgentOscilloscope getOscilloscope(final Composite parent, AgentProtocol agent)
- {
- String key = agent.toString();
+ /**
+ * @author Eike Stepper
+ */
+ public static class OScope extends Canvas implements Runnable, PaintListener, ControlListener
+ {
+ public static final int[] PEAK = { 25, 50, 100, 80, 100, 50, 25, 10, 5 };
+
+ private static final String INITIAL = "#INITIAL#";
+
+ private static final Random RANDOM = new Random();
+
+ private static final int[] BACKGROUND = { 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 72, 0, 72, 0,
+ 0, 255, 254, 0, 19, 67, 114, 101, 97, 116, 101, 100, 32, 119, 105, 116, 104, 32, 71, 73, 77, 80, 255, 219, 0,
+ 67, 0, 5, 3, 4, 4, 4, 3, 5, 4, 4, 4, 5, 5, 5, 6, 7, 12, 8, 7, 7, 7, 7, 15, 11, 11, 9, 12, 17, 15, 18, 18, 17,
+ 15, 17, 17, 19, 22, 28, 23, 19, 20, 26, 21, 17, 17, 24, 33, 24, 26, 29, 29, 31, 31, 31, 19, 23, 34, 36, 34, 30,
+ 36, 28, 30, 31, 30, 255, 219, 0, 67, 1, 5, 5, 5, 7, 6, 7, 14, 8, 8, 14, 30, 20, 17, 20, 30, 30, 30, 30, 30, 30,
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
+ 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 255, 192, 0, 17, 8, 0, 20, 0, 20, 3, 1, 34, 0,
+ 2, 17, 1, 3, 17, 1, 255, 196, 0, 23, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 7, 255, 196,
+ 0, 34, 16, 0, 2, 2, 0, 5, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 4, 2, 20, 33, 52, 84, 17, 115, 145, 178,
+ 209, 97, 255, 196, 0, 23, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 1, 3, 255, 196, 0, 27, 17,
+ 0, 2, 2, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 17, 33, 49, 81, 18, 255, 218, 0, 12, 3, 1, 0, 2, 17,
+ 3, 17, 0, 63, 0, 225, 37, 87, 118, 245, 59, 79, 217, 140, 212, 60, 24, 60, 226, 250, 83, 110, 196, 74, 10, 205,
+ 211, 133, 245, 141, 180, 155, 122, 106, 255, 0, 78, 77, 187, 88, 4, 164, 237, 96, 204, 5, 89, 168, 120, 48,
+ 121, 197, 244, 10, 223, 5, 233, 240, 148, 170, 238, 222, 167, 105, 251, 48, 9, 237, 20, 182, 137, 64, 6, 140,
+ 255, 217 };
+
+ private SortedMap<String, Channel> channels = new TreeMap<String, Channel>();
+
+ private Channel[] channelArray;
+
+ private int width;
+
+ private int height;
+
+ private int channelHeight;
+
+ private int x;
+
+ private boolean resizing;
+
+ private Color black;
+
+ private Color white;
+
+ public OScope(Composite parent, int style)
+ {
+ super(parent, style | SWT.DOUBLE_BUFFERED);
+ black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
+ white = getDisplay().getSystemColor(SWT.COLOR_WHITE);
+
+ setBackgroundImage(createBackgroundImage());
+ addPaintListener(this);
+ addControlListener(this);
+
+ Channel channel = new Channel(INITIAL);
+ channels.put(INITIAL, channel);
+ channelArray = new Channel[] { channel };
+
+ run();
+ }
- final AgentOscilloscope[] oscilloscope = { oscilloscopes.get(key) };
- if (oscilloscope[0] == null)
+ public int getTimerExecMillis()
+ {
+ return 25;
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+ }
+
+ public Channel getChannel(String name)
+ {
+ synchronized (channels)
+ {
+ Channel channel = channels.get(name);
+ if (channel == null)
{
- if (!parent.isDisposed())
+ boolean resize = false;
+
+ channel = channels.remove(INITIAL);
+ if (channel == null)
+ {
+ channel = new Channel(name);
+ resize = true;
+ }
+ else
+ {
+ channel.setName(name);
+ }
+
+ channels.put(name, channel);
+ channelArray = channels.values().toArray(new Channel[channels.size()]);
+
+ if (resize)
{
- parent.getDisplay().syncExec(new Runnable()
+ getDisplay().syncExec(new Runnable()
{
public void run()
{
- oscilloscope[0] = new AgentOscilloscope(parent);
- parent.layout();
+ controlResized(null);
}
});
-
- oscilloscopes.put(key, oscilloscope[0]);
}
}
- return oscilloscope[0];
+ return channel;
}
- });
- }
+ }
- @Override
- public void setFocus()
- {
- }
+ public void controlMoved(ControlEvent e)
+ {
+ // Do nothing
+ }
- private static int[] createPeakValues()
- {
- Random random = new Random(3);
+ public void controlResized(ControlEvent e)
+ {
+ try
+ {
+ resizing = true;
+ Point size = getSize();
+ width = size.x;
+ height = size.y;
+
+ int count = channelArray.length;
+ if (count == 0)
+ {
+ return;
+ }
+
+ x = Math.min(x, width);
+
+ int oldChannelHeight = channelHeight;
+ if (oldChannelHeight == 0)
+ {
+ oldChannelHeight = 1;
+ }
+
+ channelHeight = height / (2 * count);
+
+ int y = channelHeight;
+ for (Channel channel : channelArray)
+ {
+ channel.resize(y, oldChannelHeight);
+ y += channelHeight + channelHeight;
+ }
+ }
+ finally
+ {
+ resizing = false;
+ }
+ }
- int length = 2 * LENGTH;
- int[] values = new int[length];
- for (int i = 0; i < length; i++)
+ public void paintControl(PaintEvent e)
{
- values[i] = random.nextInt(2 * AMPLITUDE) - AMPLITUDE;
- values[++i] = -values[i - 1];
+ if (!resizing)
+ {
+ GC gc = e.gc;
+ gc.setAdvanced(true);
+ gc.setAntialias(SWT.ON);
+
+ for (Channel channel : channelArray)
+ {
+ channel.paint(e.gc);
+ }
+ }
}
- return values;
- }
+ public void run()
+ {
+ if (isDisposed())
+ {
+ return;
+ }
- /**
- * @author Eike Stepper
- */
- private static class AgentOscilloscope extends Oscilloscope
- {
- private int[] values = ZERO;
+ redraw();
+
+ if (++x >= width)
+ {
+ x = 0;
+ }
+
+ getDisplay().timerExec(getTimerExecMillis(), this);
+ }
+
+ protected Image createBackgroundImage()
+ {
+ byte[] bytes = new byte[BACKGROUND.length];
+ for (int i = 0; i < BACKGROUND.length; i++)
+ {
+ bytes[i] = (byte)BACKGROUND[i];
+ }
- public AgentOscilloscope(Composite parent)
+ return new Image(getDisplay(), new ByteArrayInputStream(bytes));
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public class Channel
{
- super(parent, SWT.NONE);
- setConnect(0, true);
- setSteady(0, true, -1);
- setFade(0, false);
- setTailSize(0, Oscilloscope.TAILSIZE_MAX);
- setTailFade(0, 0);
+ private String name;
+
+ private int[] values;
+
+ private int[] head;
+
+ private int headIndex;
+
+ private boolean headNegate;
+
+ private int y;
+
+ public Channel(String name)
+ {
+ this.name = name;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setHead(int[] head)
+ {
+ headIndex = 0;
+ headNegate = false;
+ this.head = head;
+ }
+
+ public void peak()
+ {
+ setHead(PEAK);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Channel[" + name + "]";
+ }
- addStackListener(0, new OscilloscopeStackAdapter()
+ public void resize(int y, int oldChannelHeight)
{
- @Override
- public void stackEmpty(Oscilloscope scope, int channel)
+ int max = 0;
+ int[] newValues = new int[2 * width];
+ if (values != null)
{
- setValues(0, values);
- values = ZERO;
+ System.arraycopy(values, 0, newValues, 0, Math.min(values.length, newValues.length));
+ max = Math.min(values.length / 2, width);
}
- });
- OscilloscopeDispatcher dispatcher = new OscilloscopeDispatcher(0, this);
- dispatcher.dispatch();
- }
+ int x = 0;
+ for (; x < max; x++)
+ {
+ int i = 2 * x;
+ newValues[i] = x;
+ newValues[i + 1] = (newValues[i + 1] - this.y) * channelHeight / oldChannelHeight + y;
+ }
- public void scheduleValues(int[] values)
- {
- this.values = values;
+ for (; x < width; x++)
+ {
+ int i = 2 * x;
+ newValues[i] = x;
+ newValues[i + 1] = y;
+ }
+
+ values = newValues;
+ this.y = y;
+ }
+
+ public void paint(GC gc)
+ {
+ int i = 2 * x + 1;
+ if (values == null || i >= values.length)
+ {
+ return;
+ }
+
+ int value = getNextValue() + RANDOM.nextInt(4) - 2;
+ int fx = y + value * channelHeight / 100;
+ values[i] = fx;
+
+ gc.setForeground(white);
+ gc.setLineWidth(1);
+ gc.drawPolyline(values);
+
+ gc.setForeground(black);
+ gc.setLineWidth(2);
+ gc.drawRectangle(x, fx, 2, 2);
+ }
+
+ void setName(String name)
+ {
+ this.name = name;
+ }
+
+ private int getNextValue()
+ {
+ if (head == null)
+ {
+ return 0;
+ }
+
+ int value;
+ if (headNegate)
+ {
+ value = -head[headIndex];
+ if (++headIndex >= head.length)
+ {
+ setHead(null);
+ headNegate = !headNegate;
+ }
+ }
+ else
+ {
+ value = head[headIndex];
+ }
+
+ headNegate = !headNegate;
+ return value;
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverRepositoryView.java b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverRepositoryView.java
index 35c0d6b07e..653047b32d 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverRepositoryView.java
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/FailoverRepositoryView.java
@@ -10,7 +10,6 @@
*/
package org.eclipse.emf.cdo.examples.client.offline;
-
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeManagerDialog.java b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeManagerDialog.java
index 2168cea1af..cb025c7102 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeManagerDialog.java
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeManagerDialog.java
@@ -59,6 +59,8 @@ public class NodeManagerDialog extends TitleAreaDialog
private boolean updatingDetails;
+ public static final String TITLE = "CDO Offline Example";
+
public NodeManagerDialog(Shell parentShell, NodeManager nodeManager)
{
super(parentShell);
@@ -86,7 +88,7 @@ public class NodeManagerDialog extends TitleAreaDialog
protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
- newShell.setText(Application.TITLE);
+ newShell.setText(TITLE);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java
index 81c45d08bd..5c04b5acc3 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/emf/cdo/examples/client/offline/nodes/NodeType.java
@@ -148,7 +148,7 @@ public abstract class NodeType extends SetContainer<Node> implements IElement
public void configureWindow(IWorkbenchWindowConfigurer configurer)
{
configurer.setInitialSize(new Point(1000, 700));
- configurer.setTitle(Application.TITLE);
+ configurer.setTitle(Application.NODE.getName());
configurer.setShowCoolBar(false);
configurer.setShowMenuBar(false);
configurer.setShowStatusLine(false);
@@ -285,7 +285,7 @@ public abstract class NodeType extends SetContainer<Node> implements IElement
protected IRepository createRepository(Node node)
{
JdbcDataSource dataSource = new JdbcDataSource();
- dataSource.setURL("jdbc:h2:" + node.getFolder() + "/repository");
+ dataSource.setURL("jdbc:h2:" + node.getFolder() + "/db/repository");
IMappingStrategy mappingStrategy = CDODBUtil.createHorizontalMappingStrategy(true, true);
IDBAdapter dbAdapter = new H2Adapter();
diff --git a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/wb/swt/SWTResourceManager.java b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/wb/swt/SWTResourceManager.java
index d8a285807a..3bcc1029a6 100644
--- a/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/wb/swt/SWTResourceManager.java
+++ b/plugins/org.eclipse.emf.cdo.examples.client.offline/src/org/eclipse/wb/swt/SWTResourceManager.java
@@ -10,12 +10,6 @@
*******************************************************************************/
package org.eclipse.wb.swt;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
@@ -28,6 +22,12 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc.
* <p>
@@ -40,408 +40,499 @@ import org.eclipse.swt.widgets.Display;
* @author scheglov_ke
* @author Dan Rubel
*/
-public class SWTResourceManager {
- ////////////////////////////////////////////////////////////////////////////
- //
- // Color
- //
- ////////////////////////////////////////////////////////////////////////////
- private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
- /**
- * Returns the system {@link Color} matching the specific ID.
- *
- * @param systemColorID
- * the ID value for the color
- * @return the system {@link Color} matching the specific ID
- */
- public static Color getColor(int systemColorID) {
- Display display = Display.getCurrent();
- return display.getSystemColor(systemColorID);
- }
- /**
- * Returns a {@link Color} given its red, green and blue component values.
- *
- * @param r
- * the red component of the color
- * @param g
- * the green component of the color
- * @param b
- * the blue component of the color
- * @return the {@link Color} matching the given red, green and blue component values
- */
- public static Color getColor(int r, int g, int b) {
- return getColor(new RGB(r, g, b));
- }
- /**
- * Returns a {@link Color} given its RGB value.
- *
- * @param rgb
- * the {@link RGB} value of the color
- * @return the {@link Color} matching the RGB value
- */
- public static Color getColor(RGB rgb) {
- Color color = m_colorMap.get(rgb);
- if (color == null) {
- Display display = Display.getCurrent();
- color = new Color(display, rgb);
- m_colorMap.put(rgb, color);
- }
- return color;
- }
- /**
- * Dispose of all the cached {@link Color}'s.
- */
- public static void disposeColors() {
- for (Color color : m_colorMap.values()) {
- color.dispose();
- }
- m_colorMap.clear();
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Image
- //
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Maps image paths to images.
- */
- private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
- /**
- * Returns an {@link Image} encoded by the specified {@link InputStream}.
- *
- * @param stream
- * the {@link InputStream} encoding the image data
- * @return the {@link Image} encoded by the specified input stream
- */
- protected static Image getImage(InputStream stream) throws IOException {
- try {
- Display display = Display.getCurrent();
- ImageData data = new ImageData(stream);
- if (data.transparentPixel > 0) {
- return new Image(display, data, data.getTransparencyMask());
- }
- return new Image(display, data);
- } finally {
- stream.close();
- }
- }
- /**
- * Returns an {@link Image} stored in the file at the specified path.
- *
- * @param path
- * the path to the image file
- * @return the {@link Image} stored in the file at the specified path
- */
- public static Image getImage(String path) {
- Image image = m_imageMap.get(path);
- if (image == null) {
- try {
- image = getImage(new FileInputStream(path));
- m_imageMap.put(path, image);
- } catch (Exception e) {
- image = getMissingImage();
- m_imageMap.put(path, image);
- }
- }
- return image;
- }
- /**
- * Returns an {@link Image} stored in the file at the specified path relative to the specified class.
- *
- * @param clazz
- * the {@link Class} relative to which to find the image
- * @param path
- * the path to the image file, if starts with <code>'/'</code>
- * @return the {@link Image} stored in the file at the specified path
- */
- public static Image getImage(Class<?> clazz, String path) {
- String key = clazz.getName() + '|' + path;
- Image image = m_imageMap.get(key);
- if (image == null) {
- try {
- image = getImage(clazz.getResourceAsStream(path));
- m_imageMap.put(key, image);
- } catch (Exception e) {
- image = getMissingImage();
- m_imageMap.put(key, image);
- }
- }
- return image;
- }
- private static final int MISSING_IMAGE_SIZE = 10;
- /**
- * @return the small {@link Image} that can be used as placeholder for missing image.
- */
- private static Image getMissingImage() {
- Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
- //
- GC gc = new GC(image);
- gc.setBackground(getColor(SWT.COLOR_RED));
- gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
- gc.dispose();
- //
- return image;
- }
- /**
- * Style constant for placing decorator image in top left corner of base image.
- */
- public static final int TOP_LEFT = 1;
- /**
- * Style constant for placing decorator image in top right corner of base image.
- */
- public static final int TOP_RIGHT = 2;
- /**
- * Style constant for placing decorator image in bottom left corner of base image.
- */
- public static final int BOTTOM_LEFT = 3;
- /**
- * Style constant for placing decorator image in bottom right corner of base image.
- */
- public static final int BOTTOM_RIGHT = 4;
- /**
- * Internal value.
- */
- protected static final int LAST_CORNER_KEY = 5;
- /**
- * Maps images to decorated images.
- */
- @SuppressWarnings("unchecked")
- private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
- /**
- * Returns an {@link Image} composed of a base image decorated by another image.
- *
- * @param baseImage
- * the base {@link Image} that should be decorated
- * @param decorator
- * the {@link Image} to decorate the base image
- * @return {@link Image} The resulting decorated image
- */
- public static Image decorateImage(Image baseImage, Image decorator) {
- return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
- }
- /**
- * Returns an {@link Image} composed of a base image decorated by another image.
- *
- * @param baseImage
- * the base {@link Image} that should be decorated
- * @param decorator
- * the {@link Image} to decorate the base image
- * @param corner
- * the corner to place decorator image
- * @return the resulting decorated {@link Image}
- */
- public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
- if (corner <= 0 || corner >= LAST_CORNER_KEY) {
- throw new IllegalArgumentException("Wrong decorate corner");
- }
- Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
- if (cornerDecoratedImageMap == null) {
- cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
- m_decoratedImageMap[corner] = cornerDecoratedImageMap;
- }
- Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
- if (decoratedMap == null) {
- decoratedMap = new HashMap<Image, Image>();
- cornerDecoratedImageMap.put(baseImage, decoratedMap);
- }
- //
- Image result = decoratedMap.get(decorator);
- if (result == null) {
- Rectangle bib = baseImage.getBounds();
- Rectangle dib = decorator.getBounds();
- //
- result = new Image(Display.getCurrent(), bib.width, bib.height);
- //
- GC gc = new GC(result);
- gc.drawImage(baseImage, 0, 0);
- if (corner == TOP_LEFT) {
- gc.drawImage(decorator, 0, 0);
- } else if (corner == TOP_RIGHT) {
- gc.drawImage(decorator, bib.width - dib.width, 0);
- } else if (corner == BOTTOM_LEFT) {
- gc.drawImage(decorator, 0, bib.height - dib.height);
- } else if (corner == BOTTOM_RIGHT) {
- gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
- }
- gc.dispose();
- //
- decoratedMap.put(decorator, result);
- }
- return result;
- }
- /**
- * Dispose all of the cached {@link Image}'s.
- */
- public static void disposeImages() {
- // dispose loaded images
- {
- for (Image image : m_imageMap.values()) {
- image.dispose();
- }
- m_imageMap.clear();
- }
- // dispose decorated images
- for (int i = 0; i < m_decoratedImageMap.length; i++) {
- Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
- if (cornerDecoratedImageMap != null) {
- for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
- for (Image image : decoratedMap.values()) {
- image.dispose();
- }
- decoratedMap.clear();
- }
- cornerDecoratedImageMap.clear();
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Font
- //
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Maps font names to fonts.
- */
- private static Map<String, Font> m_fontMap = new HashMap<String, Font>();
- /**
- * Maps fonts to their bold versions.
- */
- private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
- /**
- * Returns a {@link Font} based on its name, height and style.
- *
- * @param name
- * the name of the font
- * @param height
- * the height of the font
- * @param style
- * the style of the font
- * @return {@link Font} The font matching the name, height and style
- */
- public static Font getFont(String name, int height, int style) {
- return getFont(name, height, style, false, false);
- }
- /**
- * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
- * flags are also supported.
- *
- * @param name
- * the name of the font
- * @param size
- * the size of the font
- * @param style
- * the style of the font
- * @param strikeout
- * the strikeout flag (warning: Windows only)
- * @param underline
- * the underline flag (warning: Windows only)
- * @return {@link Font} The font matching the name, height, style, strikeout and underline
- */
- public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
- String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
- Font font = m_fontMap.get(fontName);
- if (font == null) {
- FontData fontData = new FontData(name, size, style);
- if (strikeout || underline) {
- try {
- Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
- Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
- if (logFont != null && logFontClass != null) {
- if (strikeout) {
- logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
- }
- if (underline) {
- logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
- }
- }
- } catch (Throwable e) {
- System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- font = new Font(Display.getCurrent(), fontData);
- m_fontMap.put(fontName, font);
- }
- return font;
- }
- /**
- * Returns a bold version of the given {@link Font}.
- *
- * @param baseFont
- * the {@link Font} for which a bold version is desired
- * @return the bold version of the given {@link Font}
- */
- public static Font getBoldFont(Font baseFont) {
- Font font = m_fontToBoldFontMap.get(baseFont);
- if (font == null) {
- FontData fontDatas[] = baseFont.getFontData();
- FontData data = fontDatas[0];
- font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
- m_fontToBoldFontMap.put(baseFont, font);
- }
- return font;
- }
- /**
- * Dispose all of the cached {@link Font}'s.
- */
- public static void disposeFonts() {
- // clear fonts
- for (Font font : m_fontMap.values()) {
- font.dispose();
- }
- m_fontMap.clear();
- // clear bold fonts
- for (Font font : m_fontToBoldFontMap.values()) {
- font.dispose();
- }
- m_fontToBoldFontMap.clear();
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // Cursor
- //
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Maps IDs to cursors.
- */
- private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
- /**
- * Returns the system cursor matching the specific ID.
- *
- * @param id
- * int The ID value for the cursor
- * @return Cursor The system cursor matching the specific ID
- */
- public static Cursor getCursor(int id) {
- Integer key = Integer.valueOf(id);
- Cursor cursor = m_idToCursorMap.get(key);
- if (cursor == null) {
- cursor = new Cursor(Display.getDefault(), id);
- m_idToCursorMap.put(key, cursor);
- }
- return cursor;
- }
- /**
- * Dispose all of the cached cursors.
- */
- public static void disposeCursors() {
- for (Cursor cursor : m_idToCursorMap.values()) {
- cursor.dispose();
- }
- m_idToCursorMap.clear();
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // General
- //
- ////////////////////////////////////////////////////////////////////////////
- /**
- * Dispose of cached objects and their underlying OS resources. This should only be called when the cached
- * objects are no longer needed (e.g. on application shutdown).
- */
- public static void dispose() {
- disposeColors();
- disposeImages();
- disposeFonts();
- disposeCursors();
- }
-} \ No newline at end of file
+public class SWTResourceManager
+{
+ // //////////////////////////////////////////////////////////////////////////
+ //
+ // Color
+ //
+ // //////////////////////////////////////////////////////////////////////////
+ private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
+
+ /**
+ * Returns the system {@link Color} matching the specific ID.
+ *
+ * @param systemColorID
+ * the ID value for the color
+ * @return the system {@link Color} matching the specific ID
+ */
+ public static Color getColor(int systemColorID)
+ {
+ Display display = Display.getCurrent();
+ return display.getSystemColor(systemColorID);
+ }
+
+ /**
+ * Returns a {@link Color} given its red, green and blue component values.
+ *
+ * @param r
+ * the red component of the color
+ * @param g
+ * the green component of the color
+ * @param b
+ * the blue component of the color
+ * @return the {@link Color} matching the given red, green and blue component values
+ */
+ public static Color getColor(int r, int g, int b)
+ {
+ return getColor(new RGB(r, g, b));
+ }
+
+ /**
+ * Returns a {@link Color} given its RGB value.
+ *
+ * @param rgb
+ * the {@link RGB} value of the color
+ * @return the {@link Color} matching the RGB value
+ */
+ public static Color getColor(RGB rgb)
+ {
+ Color color = m_colorMap.get(rgb);
+ if (color == null)
+ {
+ Display display = Display.getCurrent();
+ color = new Color(display, rgb);
+ m_colorMap.put(rgb, color);
+ }
+ return color;
+ }
+
+ /**
+ * Dispose of all the cached {@link Color}'s.
+ */
+ public static void disposeColors()
+ {
+ for (Color color : m_colorMap.values())
+ {
+ color.dispose();
+ }
+ m_colorMap.clear();
+ }
+
+ // //////////////////////////////////////////////////////////////////////////
+ //
+ // Image
+ //
+ // //////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps image paths to images.
+ */
+ private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
+
+ /**
+ * Returns an {@link Image} encoded by the specified {@link InputStream}.
+ *
+ * @param stream
+ * the {@link InputStream} encoding the image data
+ * @return the {@link Image} encoded by the specified input stream
+ */
+ protected static Image getImage(InputStream stream) throws IOException
+ {
+ try
+ {
+ Display display = Display.getCurrent();
+ ImageData data = new ImageData(stream);
+ if (data.transparentPixel > 0)
+ {
+ return new Image(display, data, data.getTransparencyMask());
+ }
+ return new Image(display, data);
+ }
+ finally
+ {
+ stream.close();
+ }
+ }
+
+ /**
+ * Returns an {@link Image} stored in the file at the specified path.
+ *
+ * @param path
+ * the path to the image file
+ * @return the {@link Image} stored in the file at the specified path
+ */
+ public static Image getImage(String path)
+ {
+ Image image = m_imageMap.get(path);
+ if (image == null)
+ {
+ try
+ {
+ image = getImage(new FileInputStream(path));
+ m_imageMap.put(path, image);
+ }
+ catch (Exception e)
+ {
+ image = getMissingImage();
+ m_imageMap.put(path, image);
+ }
+ }
+ return image;
+ }
+
+ /**
+ * Returns an {@link Image} stored in the file at the specified path relative to the specified class.
+ *
+ * @param clazz
+ * the {@link Class} relative to which to find the image
+ * @param path
+ * the path to the image file, if starts with <code>'/'</code>
+ * @return the {@link Image} stored in the file at the specified path
+ */
+ public static Image getImage(Class<?> clazz, String path)
+ {
+ String key = clazz.getName() + '|' + path;
+ Image image = m_imageMap.get(key);
+ if (image == null)
+ {
+ try
+ {
+ image = getImage(clazz.getResourceAsStream(path));
+ m_imageMap.put(key, image);
+ }
+ catch (Exception e)
+ {
+ image = getMissingImage();
+ m_imageMap.put(key, image);
+ }
+ }
+ return image;
+ }
+
+ private static final int MISSING_IMAGE_SIZE = 10;
+
+ /**
+ * @return the small {@link Image} that can be used as placeholder for missing image.
+ */
+ private static Image getMissingImage()
+ {
+ Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
+ //
+ GC gc = new GC(image);
+ gc.setBackground(getColor(SWT.COLOR_RED));
+ gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
+ gc.dispose();
+ //
+ return image;
+ }
+
+ /**
+ * Style constant for placing decorator image in top left corner of base image.
+ */
+ public static final int TOP_LEFT = 1;
+
+ /**
+ * Style constant for placing decorator image in top right corner of base image.
+ */
+ public static final int TOP_RIGHT = 2;
+
+ /**
+ * Style constant for placing decorator image in bottom left corner of base image.
+ */
+ public static final int BOTTOM_LEFT = 3;
+
+ /**
+ * Style constant for placing decorator image in bottom right corner of base image.
+ */
+ public static final int BOTTOM_RIGHT = 4;
+
+ /**
+ * Internal value.
+ */
+ protected static final int LAST_CORNER_KEY = 5;
+
+ /**
+ * Maps images to decorated images.
+ */
+ @SuppressWarnings("unchecked")
+ private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
+
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @return {@link Image} The resulting decorated image
+ */
+ public static Image decorateImage(Image baseImage, Image decorator)
+ {
+ return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
+ }
+
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @param corner
+ * the corner to place decorator image
+ * @return the resulting decorated {@link Image}
+ */
+ public static Image decorateImage(final Image baseImage, final Image decorator, final int corner)
+ {
+ if (corner <= 0 || corner >= LAST_CORNER_KEY)
+ {
+ throw new IllegalArgumentException("Wrong decorate corner");
+ }
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
+ if (cornerDecoratedImageMap == null)
+ {
+ cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
+ m_decoratedImageMap[corner] = cornerDecoratedImageMap;
+ }
+ Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
+ if (decoratedMap == null)
+ {
+ decoratedMap = new HashMap<Image, Image>();
+ cornerDecoratedImageMap.put(baseImage, decoratedMap);
+ }
+ //
+ Image result = decoratedMap.get(decorator);
+ if (result == null)
+ {
+ Rectangle bib = baseImage.getBounds();
+ Rectangle dib = decorator.getBounds();
+ //
+ result = new Image(Display.getCurrent(), bib.width, bib.height);
+ //
+ GC gc = new GC(result);
+ gc.drawImage(baseImage, 0, 0);
+ if (corner == TOP_LEFT)
+ {
+ gc.drawImage(decorator, 0, 0);
+ }
+ else if (corner == TOP_RIGHT)
+ {
+ gc.drawImage(decorator, bib.width - dib.width, 0);
+ }
+ else if (corner == BOTTOM_LEFT)
+ {
+ gc.drawImage(decorator, 0, bib.height - dib.height);
+ }
+ else if (corner == BOTTOM_RIGHT)
+ {
+ gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
+ }
+ gc.dispose();
+ //
+ decoratedMap.put(decorator, result);
+ }
+ return result;
+ }
+
+ /**
+ * Dispose all of the cached {@link Image}'s.
+ */
+ public static void disposeImages()
+ {
+ // dispose loaded images
+ {
+ for (Image image : m_imageMap.values())
+ {
+ image.dispose();
+ }
+ m_imageMap.clear();
+ }
+ // dispose decorated images
+ for (int i = 0; i < m_decoratedImageMap.length; i++)
+ {
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
+ if (cornerDecoratedImageMap != null)
+ {
+ for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values())
+ {
+ for (Image image : decoratedMap.values())
+ {
+ image.dispose();
+ }
+ decoratedMap.clear();
+ }
+ cornerDecoratedImageMap.clear();
+ }
+ }
+ }
+
+ // //////////////////////////////////////////////////////////////////////////
+ //
+ // Font
+ //
+ // //////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps font names to fonts.
+ */
+ private static Map<String, Font> m_fontMap = new HashMap<String, Font>();
+
+ /**
+ * Maps fonts to their bold versions.
+ */
+ private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
+
+ /**
+ * Returns a {@link Font} based on its name, height and style.
+ *
+ * @param name
+ * the name of the font
+ * @param height
+ * the height of the font
+ * @param style
+ * the style of the font
+ * @return {@link Font} The font matching the name, height and style
+ */
+ public static Font getFont(String name, int height, int style)
+ {
+ return getFont(name, height, style, false, false);
+ }
+
+ /**
+ * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
+ * flags are also supported.
+ *
+ * @param name
+ * the name of the font
+ * @param size
+ * the size of the font
+ * @param style
+ * the style of the font
+ * @param strikeout
+ * the strikeout flag (warning: Windows only)
+ * @param underline
+ * the underline flag (warning: Windows only)
+ * @return {@link Font} The font matching the name, height, style, strikeout and underline
+ */
+ public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline)
+ {
+ String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
+ Font font = m_fontMap.get(fontName);
+ if (font == null)
+ {
+ FontData fontData = new FontData(name, size, style);
+ if (strikeout || underline)
+ {
+ try
+ {
+ Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
+ Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
+ if (logFont != null && logFontClass != null)
+ {
+ if (strikeout)
+ {
+ logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte)1)); //$NON-NLS-1$
+ }
+ if (underline)
+ {
+ logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte)1)); //$NON-NLS-1$
+ }
+ }
+ }
+ catch (Throwable e)
+ {
+ System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ font = new Font(Display.getCurrent(), fontData);
+ m_fontMap.put(fontName, font);
+ }
+ return font;
+ }
+
+ /**
+ * Returns a bold version of the given {@link Font}.
+ *
+ * @param baseFont
+ * the {@link Font} for which a bold version is desired
+ * @return the bold version of the given {@link Font}
+ */
+ public static Font getBoldFont(Font baseFont)
+ {
+ Font font = m_fontToBoldFontMap.get(baseFont);
+ if (font == null)
+ {
+ FontData fontDatas[] = baseFont.getFontData();
+ FontData data = fontDatas[0];
+ font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
+ m_fontToBoldFontMap.put(baseFont, font);
+ }
+ return font;
+ }
+
+ /**
+ * Dispose all of the cached {@link Font}'s.
+ */
+ public static void disposeFonts()
+ {
+ // clear fonts
+ for (Font font : m_fontMap.values())
+ {
+ font.dispose();
+ }
+ m_fontMap.clear();
+ // clear bold fonts
+ for (Font font : m_fontToBoldFontMap.values())
+ {
+ font.dispose();
+ }
+ m_fontToBoldFontMap.clear();
+ }
+
+ // //////////////////////////////////////////////////////////////////////////
+ //
+ // Cursor
+ //
+ // //////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps IDs to cursors.
+ */
+ private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
+
+ /**
+ * Returns the system cursor matching the specific ID.
+ *
+ * @param id
+ * int The ID value for the cursor
+ * @return Cursor The system cursor matching the specific ID
+ */
+ public static Cursor getCursor(int id)
+ {
+ Integer key = Integer.valueOf(id);
+ Cursor cursor = m_idToCursorMap.get(key);
+ if (cursor == null)
+ {
+ cursor = new Cursor(Display.getDefault(), id);
+ m_idToCursorMap.put(key, cursor);
+ }
+ return cursor;
+ }
+
+ /**
+ * Dispose all of the cached cursors.
+ */
+ public static void disposeCursors()
+ {
+ for (Cursor cursor : m_idToCursorMap.values())
+ {
+ cursor.dispose();
+ }
+ m_idToCursorMap.clear();
+ }
+
+ // //////////////////////////////////////////////////////////////////////////
+ //
+ // General
+ //
+ // //////////////////////////////////////////////////////////////////////////
+ /**
+ * Dispose of cached objects and their underlying OS resources. This should only be called when the cached
+ * objects are no longer needed (e.g. on application shutdown).
+ */
+ public static void dispose()
+ {
+ disposeColors();
+ disposeImages();
+ disposeFonts();
+ disposeCursors();
+ }
+}

Back to the top