diff --git a/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java b/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java
index f62055fd2..387a99d41 100644
--- a/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java
+++ b/src/org.eclipse.ice.viz.service.paraview/src/org/eclipse/ice/viz/service/paraview/ParaViewPlot.java
@@ -16,15 +16,11 @@
import java.util.Map;
import java.util.Random;
-import org.eclipse.ice.client.widgets.viz.service.IPlot;
import org.eclipse.ice.viz.service.MultiPlot;
-import org.eclipse.ice.viz.service.PlotComposite;
-import org.eclipse.ice.viz.service.connections.ConnectionPlot;
+import org.eclipse.ice.viz.service.PlotRender;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
-import com.kitware.vtk.web.VtkWebClient;
-
/**
* This class is responsible for embedding ParaView-supported graphics inside
* client {@link Composite}s.
@@ -59,43 +55,61 @@ public ParaViewPlot(ParaViewVizService vizService, URI file) {
*/
@Override
public Map getPlotTypes() throws Exception {
- Map plotTypes = new HashMap();
- plotTypes.put("", new String[] { "" });
- return plotTypes;
+ return new HashMap();
}
/*
* (non-Javadoc)
*
- * @see org.eclipse.ice.client.widgets.viz.service.IPlot#getNumberOfAxes()
+ * @see
+ * org.eclipse.ice.viz.service.MultiPlot#createPlotRender(org.eclipse.swt
+ * .widgets.Composite)
*/
@Override
- public int getNumberOfAxes() {
- // TODO Auto-generated method stub
- return 0;
+ protected PlotRender createPlotRender(Composite parent) {
+ // TODO We need a custom PlotRender.
+ return new PlotRender(parent, this) {
+ @Override
+ protected Composite createPlotComposite(Composite parent, int style) {
+ return new Composite(parent, style);
+ }
+
+ @Override
+ protected void updatePlotComposite(Composite plotComposite)
+ throws Exception {
+ int seed = (getPlotCategory() + getPlotType()).hashCode();
+ Random r = new Random(seed);
+ plotComposite.setBackground(new Color(plotComposite
+ .getDisplay(), r.nextInt(255), r.nextInt(255), r
+ .nextInt(255)));
+ }
+ };
}
/*
* (non-Javadoc)
*
- * @see org.eclipse.ice.client.widgets.viz.service.IPlot#getSourceHost()
+ * @see
+ * org.eclipse.ice.viz.service.MultiPlot#updatePlotRender(org.eclipse.ice
+ * .viz.service.PlotRender)
*/
@Override
- public String getSourceHost() {
- // TODO Auto-generated method stub
- return null;
+ protected void updatePlotRender(PlotRender plotRender) {
+ // TODO We will need to update it in a custom way.
+ super.updatePlotRender(plotRender);
}
-// /*
-// * (non-Javadoc)
-// *
-// * @see
-// * org.eclipse.ice.viz.service.connections.ConnectionPlot#getPreferenceNodeID
-// * ()
-// */
-// @Override
-// protected String getPreferenceNodeID() {
-// return "org.eclipse.ice.viz.service.paraview.preferences";
-// }
+ // /*
+ // * (non-Javadoc)
+ // *
+ // * @see
+ // *
+ // org.eclipse.ice.viz.service.connections.ConnectionPlot#getPreferenceNodeID
+ // * ()
+ // */
+ // @Override
+ // protected String getPreferenceNodeID() {
+ // return "org.eclipse.ice.viz.service.paraview.preferences";
+ // }
}
diff --git a/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/MultiPlot.java b/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/MultiPlot.java
index dc93f2786..916af5aad 100644
--- a/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/MultiPlot.java
+++ b/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/MultiPlot.java
@@ -11,10 +11,39 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+/**
+ * This class provides a basic plot capable of drawing in multiple parent
+ * {@code Composite}s simply via the methods provided by the {@link IPlot}
+ * interface.
+ *
+ * For client code that will be drawing these plots, do the following:
+ *
+ * - Call {@link #draw(String, String, Composite)} with a {@code Composite}
+ * and any category and type. This renders (if possible) a plot inside the
+ * specified {@code Composite} based on the specified plot category and type.
+ * - Call {@link #draw(String, String, Composite)} with the same
+ * {@code Composite} but different category and type. The plot rendered by
+ * the previous call will have its plot category and type changed.
+ * - Call {@link #draw(String, String, Composite)} with a {@code Composite}
+ * and any category and type. This renders (if possible) a plot inside the
+ * {@code Composite} based on the specified plot category and type. You now
+ * have two separate renderings based on the same {@code IPlot}.
+ *
+ *
+ *
+ * Sub-classes should override the following methods so that the correct
+ * {@link PlotRender} is created and updated properly:
+ *
+ * - {@link #createPlotRender(Composite)}
+ * - {@link #updatePlotRender(PlotRender)}
+ *
+ *
+ *
+ * @author Jordan
+ *
+ */
public abstract class MultiPlot implements IPlot {
- // TODO Implement support for multiple plot Composites.
-
/**
* The visualization service responsible for this plot.
*/
@@ -26,9 +55,10 @@ public abstract class MultiPlot implements IPlot {
private URI source;
/**
- * The composite responsible for rendering the plot data.
+ * The map of current {@link PlotRender}s, keyed on their parent
+ * {@code Composite}s.
*/
- private PlotComposite plotComposite;
+ private final Map plotRenders;
/**
* The default constructor.
@@ -47,6 +77,9 @@ public MultiPlot(IVizService vizService, URI file) {
this.vizService = vizService;
+ // Initialize the map of PlotRenders.
+ plotRenders = new HashMap();
+
// Set the data source now. This should build any required meta data.
setDataSource(file);
@@ -64,9 +97,6 @@ public MultiPlot(IVizService vizService, URI file) {
@Override
public void draw(String category, String plotType, Composite parent)
throws Exception {
- // Get the current parent control.
- Composite currentParent = (plotComposite != null ? plotComposite.parent
- : null);
// Check the parameters.
if (category == null || plotType == null || parent == null) {
@@ -75,18 +105,19 @@ public void draw(String category, String plotType, Composite parent)
} else if (parent.isDisposed()) {
throw new SWTException(SWT.ERROR_WIDGET_DISPOSED, "IPlot error: "
+ "Cannot draw plot inside disposed Composite.");
- } else if (currentParent != null && parent != currentParent) {
- throw new IllegalArgumentException("IPlot error: "
- + "Cannot draw same plot in multiple Composites.");
}
- // If necessary, create the plotComposite.
- if (plotComposite == null) {
- plotComposite = createPlotComposite(parent);
+ final PlotRender plotRender;
+
+ // If necessary, create the PlotRender.
+ if (!plotRenders.containsKey(parent)) {
+ // Create it and save it in the map.
+ plotRender = createPlotRender(parent);
+ plotRenders.put(parent, plotRender);
- // Send the new plot category and type to the plotComposite.
- plotComposite.setPlotCategory(category);
- plotComposite.setPlotType(plotType);
+ // Send the new plot category and type to the PlotRender.
+ plotRender.setPlotCategory(category);
+ plotRender.setPlotType(plotType);
// If we are not on the UI thread, create its content asynchronously
// on the UI thread.
@@ -94,26 +125,38 @@ public void draw(String category, String plotType, Composite parent)
parent.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
- plotComposite.createPlotContent(SWT.NONE);
+ plotRender.createPlotContent(SWT.NONE);
}
});
}
// If we are on the UI thread, create the content synchronously.
else {
- plotComposite.createPlotContent(SWT.NONE);
+ plotRender.createPlotContent(SWT.NONE);
}
} else {
- // Send the new plot category and type to the plotComposite.
- plotComposite.setPlotCategory(category);
- plotComposite.setPlotType(plotType);
+ // Get the existing PlotCopmosite.
+ plotRender = plotRenders.get(parent);
+
+ // Send the new plot category and type to the PlotRender.
+ plotRender.setPlotCategory(category);
+ plotRender.setPlotType(plotType);
}
- // Trigger the appropriate update to the plotComposite's content.
- updatePlotComposite(plotComposite);
+ // Trigger the appropriate update to the PlotRender's content.
+ updatePlotRender(plotRender);
return;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ice.client.widgets.viz.service.IPlot#getNumberOfAxes()
+ */
+ public int getNumberOfAxes() {
+ return 0;
+ }
+
/*
* (non-Javadoc)
*
@@ -146,6 +189,15 @@ public URI getDataSource() {
return source;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ice.client.widgets.viz.service.IPlot#getSourceHost()
+ */
+ public String getSourceHost() {
+ return source.getHost();
+ }
+
/*
* (non-Javadoc)
*
@@ -182,12 +234,27 @@ protected IVizService getVizService() {
}
// ---- UI Widgets ---- //
- protected PlotComposite createPlotComposite(Composite parent) {
- return new PlotComposite(parent, this);
- };
+ /**
+ * Creates a {@link PlotRender} inside the specified parent
+ * {@code Composite}. The {@code PlotRender}'s content should not be created
+ * yet.
+ *
+ * @param parent
+ * The parent {@code Composite} that will contain the new
+ * {@code PlotRender}.
+ * @return The new {@code PlotRender}.
+ */
+ protected abstract PlotRender createPlotRender(Composite parent);
- protected void updatePlotComposite(PlotComposite composite) {
- plotComposite.refresh();
+ /**
+ * Updates the specified {@link PlotRender}. The default behavior of this
+ * method is to call {@link PlotRender#refresh()}.
+ *
+ * @param plotRender
+ * The {@code PlotRender} to update.
+ */
+ protected void updatePlotRender(PlotRender plotRender) {
+ plotRender.refresh();
}
// -------------------- //
diff --git a/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/PlotComposite.java b/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/PlotRender.java
similarity index 95%
rename from src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/PlotComposite.java
rename to src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/PlotRender.java
index 45684c95e..08c344581 100644
--- a/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/PlotComposite.java
+++ b/src/org.eclipse.ice.viz.service/src/org/eclipse/ice/viz/service/PlotRender.java
@@ -12,7 +12,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
-public class PlotComposite {
+public abstract class PlotRender {
public final Composite parent;
public final MultiPlot plot;
@@ -47,7 +47,7 @@ public class PlotComposite {
// -------------------- //
- public PlotComposite(Composite parent, MultiPlot plot) {
+ public PlotRender(Composite parent, MultiPlot plot) {
this.parent = parent;
this.plot = plot;