Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Renamed the PlotComposite class to PlotRender since it isn't a Composite
Browse files Browse the repository at this point in the history
but wraps one (multiple, actually).

Updated the MultiPlot class to support rendering in multiple parent
Composites. Added documentation to this class explaining the behavior.

Signed-off-by: Jordan <jordan.deyton@gmail.com>
  • Loading branch information
jdeyton committed Mar 5, 2015
1 parent 0bdee42 commit 966574d
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 57 deletions.
Expand Up @@ -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.
Expand Down Expand Up @@ -59,43 +55,61 @@ public ParaViewPlot(ParaViewVizService vizService, URI file) {
*/
@Override
public Map<String, String[]> getPlotTypes() throws Exception {
Map<String, String[]> plotTypes = new HashMap<String, String[]>();
plotTypes.put("", new String[] { "" });
return plotTypes;
return new HashMap<String, String[]>();
}

/*
* (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";
// }

}
Expand Up @@ -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.
* <p>
* For client code that will be drawing these plots, do the following:
* <ol>
* <li>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.</li>
* <li>Call {@link #draw(String, String, Composite)} with the same
* {@code Composite} but different category and type. <i>The plot rendered by
* the previous call will have its plot category and type changed.</i></li>
* <li>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. <i>You now
* have two separate renderings based on the same {@code IPlot}.</i></li>
* </ol>
* </p>
* <p>
* Sub-classes should override the following methods so that the correct
* {@link PlotRender} is created and updated properly:
* <ol>
* <li>{@link #createPlotRender(Composite)}</li>
* <li>{@link #updatePlotRender(PlotRender)}</li>
* </ol>
* </p>
*
* @author Jordan
*
*/
public abstract class MultiPlot implements IPlot {

// TODO Implement support for multiple plot Composites.

/**
* The visualization service responsible for this plot.
*/
Expand All @@ -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<Composite, PlotRender> plotRenders;

/**
* The default constructor.
Expand All @@ -47,6 +77,9 @@ public MultiPlot(IVizService vizService, URI file) {

this.vizService = vizService;

// Initialize the map of PlotRenders.
plotRenders = new HashMap<Composite, PlotRender>();

// Set the data source now. This should build any required meta data.
setDataSource(file);

Expand All @@ -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) {
Expand All @@ -75,45 +105,58 @@ 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.
if (Display.getCurrent() == null) {
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)
*
Expand Down Expand Up @@ -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)
*
Expand Down Expand Up @@ -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();
}
// -------------------- //

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 966574d

Please sign in to comment.