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

Commit

Permalink
Added documentation to the PlotRender class and updated some of its code
Browse files Browse the repository at this point in the history
to make it more customizable. Also made a method private, hence the
change to MultiPlot in which I simplified some code.

Created a sub-class of it called ParaViewPlotRender. It does nothing
special yet.

Signed-off-by: Jordan <jordan.deyton@gmail.com>
  • Loading branch information
jdeyton committed Mar 5, 2015
1 parent 966574d commit bb2d8bb
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 94 deletions.
Expand Up @@ -67,23 +67,7 @@ public Map<String, String[]> getPlotTypes() throws Exception {
*/
@Override
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)));
}
};
return new ParaViewPlotRender(parent, this);
}

/*
Expand Down
@@ -0,0 +1,38 @@
package org.eclipse.ice.viz.service.paraview;

import java.util.Random;

import org.eclipse.ice.viz.service.PlotRender;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;

public class ParaViewPlotRender extends PlotRender {

public ParaViewPlotRender(Composite parent, ParaViewPlot plot) {
super(parent, plot);

}

@Override
protected Composite createPlotComposite(Composite parent, int style)
throws Exception {
// TODO Hook this up to the ParaView widgets.
return new Composite(parent, style);
}

@Override
protected void updatePlotComposite(Composite plotComposite)
throws Exception {
// TODO Hook this up to the ParaView widgets.
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)));
}

@Override
protected void disposePlotComposite(Composite plotComposite) {
// Nothing to do yet.
}

}
Expand Up @@ -9,7 +9,6 @@
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;

/**
* This class provides a basic plot capable of drawing in multiple parent
Expand Down Expand Up @@ -107,41 +106,19 @@ public void draw(String category, String plotType, Composite parent)
+ "Cannot draw plot inside disposed Composite.");
}

final PlotRender plotRender;
// Get the PlotRender associated with the parent Composite.
PlotRender plotRender = plotRenders.get(parent);

// If necessary, create the PlotRender.
if (!plotRenders.containsKey(parent)) {
// Create it and save it in the map.
// Create the PlotRender and associate it with the parent as necessary.
if (plotRender == null) {
plotRender = createPlotRender(parent);
plotRenders.put(parent, plotRender);

// 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() {
plotRender.createPlotContent(SWT.NONE);
}
});
}
// If we are on the UI thread, create the content synchronously.
else {
plotRender.createPlotContent(SWT.NONE);
}
} else {
// Get the existing PlotCopmosite.
plotRender = plotRenders.get(parent);

// Send the new plot category and type to the PlotRender.
plotRender.setPlotCategory(category);
plotRender.setPlotType(plotType);
}

// Send the new plot category and type to the PlotRender.
plotRender.setPlotCategory(category);
plotRender.setPlotType(plotType);

// Trigger the appropriate update to the PlotRender's content.
updatePlotRender(plotRender);

Expand Down

0 comments on commit bb2d8bb

Please sign in to comment.