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

Commit

Permalink
Added Anna's widgets to the PlotGridComposite's ToolBar, but converted
Browse files Browse the repository at this point in the history
them to use JFace and added a FormToolkit to decorate them.



Signed-off-by: Jordan Deyton <deytonjh@ornl.gov>
  • Loading branch information
Jordan Deyton committed Apr 10, 2015
1 parent 3d7f8d5 commit 88c03be
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 5 deletions.
Expand Up @@ -195,7 +195,8 @@ public void widgetDisposed(DisposeEvent event) {
pageComposite.layout();

// Create the grid of plots.
plotGridComposite = new PlotGridComposite(pageComposite, SWT.NONE);
plotGridComposite = new PlotGridComposite(pageComposite, SWT.NONE,
toolkit);
toolkit.adapt(plotGridComposite);

// Set the workbench page reference
Expand Down
Expand Up @@ -9,6 +9,7 @@
import org.eclipse.ice.client.widgets.viz.service.IPlot;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
Expand All @@ -24,7 +25,9 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.forms.widgets.FormToolkit;

/**
* A {@code PlotGridComposite} is designed to display a grid of drawn
Expand Down Expand Up @@ -65,7 +68,7 @@ public class PlotGridComposite extends Composite {
*/
private int rows = 2;
/**
* The number of columsn to display in the grid.
* The number of columns to display in the grid.
*/
private int columns = 2;

Expand All @@ -86,6 +89,11 @@ public class PlotGridComposite extends Composite {
*/
private final List<DrawnPlot> drawnPlots;

/**
* The toolkit used to decorate SWT components. May be null.
*/
private final FormToolkit toolkit;

/**
* The default constructor. Creates a {@code Composite} designed to display
* a grid of {@link IPlot} renderings.
Expand All @@ -97,8 +105,28 @@ public class PlotGridComposite extends Composite {
* The style of widget to construct.
*/
public PlotGridComposite(Composite parent, int style) {
this(parent, style, null);
}

/**
* The full constructor. Children of this {@code Composite} will be
* decorated with the specified {@code FormToolkit}.
*
* @param parent
* A widget that will be the parent of the new instance (cannot
* be null).
* @param style
* The style of widget to construct.
* @param toolkit
* The toolkit used to decorate SWT components.
*/
public PlotGridComposite(Composite parent, int style, FormToolkit toolkit) {
super(parent, style);

// Set the form toolkit for decorating widgets in this Composite.
this.toolkit = toolkit;
adapt(this);

// Initialize the list of drawn plots.
drawnPlots = new ArrayList<DrawnPlot>();

Expand All @@ -107,6 +135,7 @@ public PlotGridComposite(Composite parent, int style) {

// Set up the Composite containing the grid of plots.
gridComposite = new Composite(this, SWT.NONE);
adapt(gridComposite);
gridLayout = new GridLayout();
gridComposite.setLayout(gridLayout);

Expand Down Expand Up @@ -141,6 +170,16 @@ public void mouseExit(MouseEvent e) {
return;
}

/**
* A convenience method to use the {@link #toolkit}, if available, to
* decorate a given {@code Composite}.
*/
private void adapt(Composite composite) {
if (toolkit != null) {
toolkit.adapt(composite);
}
}

/**
* Creates a {@code ToolBar} for this {@code Composite}. It includes the
* following controls:
Expand All @@ -156,9 +195,58 @@ public void mouseExit(MouseEvent e) {
*/
private ToolBar createToolBar(Composite parent) {

ToolBarManager toolBarManager = new ToolBarManager();
// Create and adapt the ToolBar first so that the default styles will be
// passed down to the widgets created by the ToolBarManager.
ToolBar toolBar = new ToolBar(parent, SWT.WRAP | SWT.FLAT
| SWT.HORIZONTAL);
adapt(toolBar);
ToolBarManager toolBarManager = new ToolBarManager(toolBar);

// Add a "Rows" label next to the row Spinner.
LabelContribution rowLabel = new LabelContribution("rows.label");
rowLabel.setText("Rows:");
toolBarManager.add(rowLabel);

// Add a Spinner for setting the grid rows to the ToolBarManager (this
// requires a JFace ControlContribution).
SpinnerContribution rowSpinner = new SpinnerContribution("rows.spinner");
rowSpinner.setMinimum(1);
rowSpinner.setMaximum(4);
rowSpinner.setSelection(rows);
rowSpinner.setIncrement(1);
rowSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
rows = ((Spinner) e.widget).getSelection();
refreshLayout();
}
});
toolBarManager.add(rowSpinner);

// Add a "Columns" label next to the row Spinner.
LabelContribution columnLabel = new LabelContribution("columns.label");
columnLabel.setText("Columns:");
toolBarManager.add(columnLabel);

// Add a Spinner for setting the grid columns to the ToolBarManager
// (this requires a JFace ControlContribution).
SpinnerContribution columnSpinner = new SpinnerContribution(
"columns.spinner");
columnSpinner.setMinimum(1);
columnSpinner.setMaximum(4);
columnSpinner.setSelection(columns);
columnSpinner.setIncrement(1);
columnSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
columns = ((Spinner) e.widget).getSelection();
refreshLayout();
}
});
toolBarManager.add(columnSpinner);

// TODO Add the grid controls.
// Add a separator between the spinners and the clear button.
toolBarManager.add(new Separator());

// Add a ToolBar button to clear the plots.
toolBarManager.add(new Action("Clear") {
Expand All @@ -168,7 +256,10 @@ public void run() {
}
});

return toolBarManager.createControl(parent);
// Apply the ToolBarManager changes to the ToolBar.
toolBarManager.update(true);

return toolBar;
}

/**
Expand Down Expand Up @@ -213,6 +304,7 @@ public int addPlot(IPlot plot) throws Exception {
if (category != null && type != null) {
// Create the Composite to contain the plot rendering.
Composite composite = new Composite(gridComposite, SWT.NONE);
adapt(composite);

// Try to create the plot rendering.
DrawnPlot drawnPlot;
Expand Down

0 comments on commit 88c03be

Please sign in to comment.