Search in sources :

Example 1 with GaugeFigure

use of org.eclipse.nebula.visualization.widgets.figures.GaugeFigure in project nebula by eclipse.

the class MultipleWidgetsExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setText("Multiple Widgets Example");
    shell.setSize(400, 400);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    shell.setLayout(layout);
    // create canvases to hold the widgets.
    Canvas knobCanvas = new Canvas(shell, SWT.NONE);
    knobCanvas.setLayoutData(gd);
    Canvas gaugeCanvas = new Canvas(shell, SWT.NONE);
    gaugeCanvas.setLayoutData(gd);
    Canvas thermoCanvas = new Canvas(shell, SWT.NONE);
    thermoCanvas.setLayoutData(gd);
    Canvas tankCanvas = new Canvas(shell, SWT.NONE);
    tankCanvas.setLayoutData(gd);
    // use LightweightSystem to create the bridge between SWT and draw2D
    LightweightSystem lws = new LightweightSystem(knobCanvas);
    // Create widgets
    final KnobFigure knobFigure = new KnobFigure();
    lws.setContents(knobFigure);
    lws = new LightweightSystem(gaugeCanvas);
    final GaugeFigure gauge = new GaugeFigure();
    gauge.setBackgroundColor(XYGraphMediaFactory.getInstance().getColor(0, 0, 0));
    gauge.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    lws.setContents(gauge);
    lws = new LightweightSystem(thermoCanvas);
    final ThermometerFigure thermo = new ThermometerFigure();
    lws.setContents(thermo);
    lws = new LightweightSystem(tankCanvas);
    final TankFigure tank = new TankFigure();
    lws.setContents(tank);
    // Add listener
    knobFigure.addManualValueChangeListener(new IManualValueChangeListener() {

        public void manualValueChanged(double newValue) {
            gauge.setValue(newValue);
            thermo.setValue(newValue);
            tank.setValue(newValue);
        }
    });
    shell.open();
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : TankFigure(org.eclipse.nebula.visualization.widgets.figures.TankFigure) IManualValueChangeListener(org.eclipse.nebula.visualization.widgets.datadefinition.IManualValueChangeListener) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) ThermometerFigure(org.eclipse.nebula.visualization.widgets.figures.ThermometerFigure) KnobFigure(org.eclipse.nebula.visualization.widgets.figures.KnobFigure) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) LightweightSystem(org.eclipse.draw2d.LightweightSystem) GaugeFigure(org.eclipse.nebula.visualization.widgets.figures.GaugeFigure) Display(org.eclipse.swt.widgets.Display)

Example 2 with GaugeFigure

use of org.eclipse.nebula.visualization.widgets.figures.GaugeFigure in project nebula by eclipse.

the class GaugeExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setSize(300, 250);
    shell.setBackground(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    shell.open();
    // use LightweightSystem to create the bridge between SWT and draw2D
    final LightweightSystem lws = new LightweightSystem(shell);
    // Create Gauge
    final GaugeFigure gaugeFigure = new GaugeFigure();
    // Init gauge
    gaugeFigure.setBackgroundColor(XYGraphMediaFactory.getInstance().getColor(0, 0, 0));
    gaugeFigure.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    gaugeFigure.setRange(-100, 100);
    gaugeFigure.setLoLevel(-50);
    gaugeFigure.setLoloLevel(-80);
    gaugeFigure.setHiLevel(60);
    gaugeFigure.setHihiLevel(80);
    gaugeFigure.setMajorTickMarkStepHint(50);
    lws.setContents(gaugeFigure);
    // Update the gauge in another thread.
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(new Runnable() {

        @Override
        public void run() {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    gaugeFigure.setValue(Math.sin(counter++ / 10.0) * 100);
                }
            });
        }
    }, 100, 100, TimeUnit.MILLISECONDS);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    future.cancel(true);
    scheduler.shutdown();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LightweightSystem(org.eclipse.draw2d.LightweightSystem) GaugeFigure(org.eclipse.nebula.visualization.widgets.figures.GaugeFigure) Display(org.eclipse.swt.widgets.Display)

Example 3 with GaugeFigure

use of org.eclipse.nebula.visualization.widgets.figures.GaugeFigure in project nebula by eclipse.

the class MultipleWidgetsExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setText("Multiple Widgets Example");
    shell.setSize(400, 400);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    shell.setLayout(layout);
    // create canvases to hold the widgets.
    Canvas knobCanvas = new Canvas(shell, SWT.NONE);
    knobCanvas.setLayoutData(gd);
    Canvas gaugeCanvas = new Canvas(shell, SWT.NONE);
    gaugeCanvas.setLayoutData(gd);
    Canvas thermoCanvas = new Canvas(shell, SWT.NONE);
    thermoCanvas.setLayoutData(gd);
    Canvas tankCanvas = new Canvas(shell, SWT.NONE);
    tankCanvas.setLayoutData(gd);
    // use LightweightSystem to create the bridge between SWT and draw2D
    LightweightSystem lws = new LightweightSystem(knobCanvas);
    // Create widgets
    final KnobFigure knobFigure = new KnobFigure();
    lws.setContents(knobFigure);
    lws = new LightweightSystem(gaugeCanvas);
    final GaugeFigure gauge = new GaugeFigure();
    gauge.setBackgroundColor(XYGraphMediaFactory.getInstance().getColor(0, 0, 0));
    gauge.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    lws.setContents(gauge);
    lws = new LightweightSystem(thermoCanvas);
    final ThermometerFigure thermo = new ThermometerFigure();
    lws.setContents(thermo);
    lws = new LightweightSystem(tankCanvas);
    final TankFigure tank = new TankFigure();
    lws.setContents(tank);
    // Add listener
    knobFigure.addManualValueChangeListener(new IManualValueChangeListener() {

        @Override
        public void manualValueChanged(double newValue) {
            gauge.setValue(newValue);
            thermo.setValue(newValue);
            tank.setValue(newValue);
        }
    });
    shell.open();
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : TankFigure(org.eclipse.nebula.visualization.widgets.figures.TankFigure) IManualValueChangeListener(org.eclipse.nebula.visualization.widgets.datadefinition.IManualValueChangeListener) ThermometerFigure(org.eclipse.nebula.visualization.widgets.figures.ThermometerFigure) KnobFigure(org.eclipse.nebula.visualization.widgets.figures.KnobFigure) Canvas(org.eclipse.swt.widgets.Canvas) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) LightweightSystem(org.eclipse.draw2d.LightweightSystem) GaugeFigure(org.eclipse.nebula.visualization.widgets.figures.GaugeFigure) Display(org.eclipse.swt.widgets.Display)

Example 4 with GaugeFigure

use of org.eclipse.nebula.visualization.widgets.figures.GaugeFigure in project nebula by eclipse.

the class WidgetsExampleView method createPartControl.

@Override
public void createPartControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    parent.setLayout(layout);
    // create canvases to hold the widgets.
    Canvas knobCanvas = new Canvas(parent, SWT.BORDER);
    knobCanvas.setLayoutData(gd);
    Canvas gaugeCanvas = new Canvas(parent, SWT.BORDER);
    gaugeCanvas.setLayoutData(gd);
    Canvas thermoCanvas = new Canvas(parent, SWT.BORDER);
    thermoCanvas.setLayoutData(gd);
    Canvas tankCanvas = new Canvas(parent, SWT.BORDER);
    tankCanvas.setLayoutData(gd);
    Canvas xyGraphCanvas = new Canvas(parent, SWT.BORDER);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 3);
    xyGraphCanvas.setLayoutData(gd);
    // use LightweightSystem to create the bridge between SWT and draw2D
    LightweightSystem lws = new LightweightSystem(knobCanvas);
    // Create widgets
    final KnobFigure knobFigure = new KnobFigure();
    lws.setContents(knobFigure);
    lws = new LightweightSystem(gaugeCanvas);
    final GaugeFigure gauge = new GaugeFigure();
    gauge.setBackgroundColor(XYGraphMediaFactory.getInstance().getColor(0, 0, 0));
    gauge.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    lws.setContents(gauge);
    lws = new LightweightSystem(thermoCanvas);
    final ThermometerFigure thermo = new ThermometerFigure();
    lws.setContents(thermo);
    lws = new LightweightSystem(tankCanvas);
    final TankFigure tank = new TankFigure();
    lws.setContents(tank);
    // use LightweightSystem to create the bridge between SWT and draw2D
    lws = new LightweightSystem(xyGraphCanvas);
    // create a new XY Graph.
    IXYGraph xyGraph = new XYGraph();
    xyGraph.getPrimaryXAxis().setAutoScale(true);
    // set it as the content of LightwightSystem
    lws.setContents(xyGraph);
    // create a trace data provider, which will provide the data to the
    // trace.
    // Set chronological to true so it can sort the data chronologically.
    final CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(true);
    traceDataProvider.setBufferSize(100);
    // Update the trace whenever any X or Y data changed. So only set Y data
    // can update the trace.
    traceDataProvider.setUpdateMode(UpdateMode.X_OR_Y);
    // create the trace
    Trace trace = new Trace("Trace1-XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(), traceDataProvider);
    // set trace property
    trace.setPointStyle(PointStyle.POINT);
    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    // Add listener
    knobFigure.addManualValueChangeListener(new IManualValueChangeListener() {

        @Override
        public void manualValueChanged(double newValue) {
            gauge.setValue(newValue);
            thermo.setValue(newValue);
            tank.setValue(newValue);
            traceDataProvider.setCurrentYData(newValue);
        }
    });
}
Also used : TankFigure(org.eclipse.nebula.visualization.widgets.figures.TankFigure) IManualValueChangeListener(org.eclipse.nebula.visualization.widgets.datadefinition.IManualValueChangeListener) ThermometerFigure(org.eclipse.nebula.visualization.widgets.figures.ThermometerFigure) KnobFigure(org.eclipse.nebula.visualization.widgets.figures.KnobFigure) Canvas(org.eclipse.swt.widgets.Canvas) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) GridLayout(org.eclipse.swt.layout.GridLayout) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) GridData(org.eclipse.swt.layout.GridData) LightweightSystem(org.eclipse.draw2d.LightweightSystem) GaugeFigure(org.eclipse.nebula.visualization.widgets.figures.GaugeFigure)

Example 5 with GaugeFigure

use of org.eclipse.nebula.visualization.widgets.figures.GaugeFigure in project nebula by eclipse.

the class GaugeExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setSize(300, 250);
    shell.setBackground(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    shell.open();
    // use LightweightSystem to create the bridge between SWT and draw2D
    final LightweightSystem lws = new LightweightSystem(shell);
    // Create Gauge
    final GaugeFigure gaugeFigure = new GaugeFigure();
    // Init gauge
    gaugeFigure.setBackgroundColor(XYGraphMediaFactory.getInstance().getColor(0, 0, 0));
    gaugeFigure.setForegroundColor(XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
    gaugeFigure.setRange(-90, 90);
    gaugeFigure.setLoLevel(-50);
    gaugeFigure.setLoloLevel(-80);
    gaugeFigure.setHiLevel(60);
    gaugeFigure.setHihiLevel(80);
    gaugeFigure.setMajorTickMarkStepHint(50);
    gaugeFigure.setTitle("Rotation");
    gaugeFigure.setUnit("Degrees");
    lws.setContents(gaugeFigure);
    // Update the gauge in another thread.
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(new Runnable() {

        public void run() {
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    gaugeFigure.setValue(Math.sin(counter++ / 10.0) * 90);
                }
            });
        }
    }, 100, 100, TimeUnit.MILLISECONDS);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    future.cancel(true);
    scheduler.shutdown();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LightweightSystem(org.eclipse.draw2d.LightweightSystem) GaugeFigure(org.eclipse.nebula.visualization.widgets.figures.GaugeFigure) Display(org.eclipse.swt.widgets.Display)

Aggregations

LightweightSystem (org.eclipse.draw2d.LightweightSystem)5 GaugeFigure (org.eclipse.nebula.visualization.widgets.figures.GaugeFigure)5 Display (org.eclipse.swt.widgets.Display)4 Shell (org.eclipse.swt.widgets.Shell)4 IManualValueChangeListener (org.eclipse.nebula.visualization.widgets.datadefinition.IManualValueChangeListener)3 KnobFigure (org.eclipse.nebula.visualization.widgets.figures.KnobFigure)3 TankFigure (org.eclipse.nebula.visualization.widgets.figures.TankFigure)3 ThermometerFigure (org.eclipse.nebula.visualization.widgets.figures.ThermometerFigure)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Canvas (org.eclipse.swt.widgets.Canvas)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 CircularBufferDataProvider (org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider)1 IXYGraph (org.eclipse.nebula.visualization.xygraph.figures.IXYGraph)1 Trace (org.eclipse.nebula.visualization.xygraph.figures.Trace)1 XYGraph (org.eclipse.nebula.visualization.xygraph.figures.XYGraph)1