Search in sources :

Example 11 with LightweightSystem

use of org.eclipse.draw2d.LightweightSystem in project nebula by eclipse.

the class ProgressBarExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setSize(300, 120);
    shell.open();
    // use LightweightSystem to create the bridge between SWT and draw2D
    final LightweightSystem lws = new LightweightSystem(shell);
    // Create Gauge
    final ProgressBarFigure progressBarFigure = new ProgressBarFigure();
    // Init gauge
    progressBarFigure.setFillColor(XYGraphMediaFactory.getInstance().getColor(0, 255, 0));
    progressBarFigure.setRange(-100, 100);
    progressBarFigure.setLoLevel(-50);
    progressBarFigure.setLoloLevel(-80);
    progressBarFigure.setHiLevel(60);
    progressBarFigure.setHihiLevel(80);
    progressBarFigure.setMajorTickMarkStepHint(50);
    progressBarFigure.setHorizontal(true);
    progressBarFigure.setOriginIgnored(true);
    lws.setContents(progressBarFigure);
    // 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() {
                    progressBarFigure.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 : ProgressBarFigure(org.eclipse.nebula.visualization.widgets.figures.ProgressBarFigure) Shell(org.eclipse.swt.widgets.Shell) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LightweightSystem(org.eclipse.draw2d.LightweightSystem) Display(org.eclipse.swt.widgets.Display)

Example 12 with LightweightSystem

use of org.eclipse.draw2d.LightweightSystem in project nebula by eclipse.

the class AbstractWidgetTest method testAll.

@Test
public void testAll() throws Exception {
    shell = new Shell();
    shell.open();
    shell.setLayout(new GridLayout(1, false));
    final Canvas canvas = new Canvas(shell, SWT.None);
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    text = new Text(shell, SWT.READ_ONLY);
    text.setFont(XYGraphMediaFactory.getInstance().getFont("default", 18, SWT.BOLD));
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    final LightweightSystem lws = new LightweightSystem(canvas);
    lws.setContents(getTestBench());
    shell.setSize(800, 500);
    testGetBeanInfo();
    testWidget();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) Canvas(org.eclipse.swt.widgets.Canvas) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text) LightweightSystem(org.eclipse.draw2d.LightweightSystem) Test(org.junit.Test)

Example 13 with LightweightSystem

use of org.eclipse.draw2d.LightweightSystem in project nebula by eclipse.

the class XYGraphTest2 method main.

public static void main(final String[] args) {
    // if testName is Default, the original Axis implementation will be
    // used. If Diamond, the new DAxis implementation will be used to
    // generate the tick marks.
    String testName = "Default";
    String[] testNames = new String[] { "Default", "Diamond" };
    final Shell shell = new Shell();
    shell.setSize(800, 500);
    shell.open();
    final LightweightSystem lws = new LightweightSystem(shell);
    XYGraphTest2 testFigure = null;
    if (testName.equals(testNames[0])) {
        testFigure = new XYGraphTest2(new XYGraph(new DefaultAxesFactory()), new Axis("X-2", false), new Axis("Log Scale", true));
    } else {
        testFigure = new XYGraphTest2(new XYGraph(new DAxesFactory()), new DAxis("X-2", false), new DAxis("Log Scale", true));
    }
    lws.setContents(testFigure);
    shell.setText("XY Graph Test");
    final Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
// System.out.println(Calendar.getInstance().getTime());
}
Also used : Shell(org.eclipse.swt.widgets.Shell) DefaultAxesFactory(org.eclipse.nebula.visualization.xygraph.figures.DefaultAxesFactory) DAxesFactory(org.eclipse.nebula.visualization.xygraph.figures.DAxesFactory) DAxis(org.eclipse.nebula.visualization.xygraph.figures.DAxis) LightweightSystem(org.eclipse.draw2d.LightweightSystem) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) DAxis(org.eclipse.nebula.visualization.xygraph.figures.DAxis) Axis(org.eclipse.nebula.visualization.xygraph.figures.Axis) Display(org.eclipse.swt.widgets.Display)

Example 14 with LightweightSystem

use of org.eclipse.draw2d.LightweightSystem in project nebula by eclipse.

the class SimpleToolbarArmedXYGraphExample method main.

public static void main(String[] args) {
    final Shell shell = new Shell();
    shell.setSize(600, 400);
    shell.open();
    // use LightweightSystem to create the bridge between SWT and draw2D
    final LightweightSystem lws = new LightweightSystem(shell);
    // create a new XY Graph.
    IXYGraph xyGraph = new XYGraph();
    ToolbarArmedXYGraph toolbarArmedXYGraph = new ToolbarArmedXYGraph(xyGraph);
    xyGraph.setTitle("Simple Toolbar Armed XYGraph Example");
    // set it as the content of LightwightSystem
    lws.setContents(toolbarArmedXYGraph);
    xyGraph.getPrimaryXAxis().setShowMajorGrid(true);
    xyGraph.getPrimaryYAxis().setShowMajorGrid(true);
    // create a trace data provider, which will provide the data to the
    // trace.
    CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(false);
    traceDataProvider.setBufferSize(100);
    traceDataProvider.setCurrentXDataArray(new double[] { 10, 23, 34, 45, 56, 78, 88, 99 });
    traceDataProvider.setCurrentYDataArray(new double[] { 11, 44, 55, 45, 88, 98, 52, 23 });
    // create the trace
    Trace trace = new Trace("Trace1-XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(), traceDataProvider);
    // set trace property
    trace.setPointStyle(PointStyle.XCROSS);
    // add the trace to xyGraph
    xyGraph.addTrace(trace);
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) Shell(org.eclipse.swt.widgets.Shell) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) LightweightSystem(org.eclipse.draw2d.LightweightSystem) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) Display(org.eclipse.swt.widgets.Display)

Example 15 with LightweightSystem

use of org.eclipse.draw2d.LightweightSystem in project nebula by eclipse.

the class StaircaseExample method main.

public static void main(final String[] args) {
    // Main window (shell)
    final Shell shell = new Shell();
    shell.setSize(800, 500);
    shell.open();
    // XYGraph
    final LightweightSystem lws = new LightweightSystem(shell);
    final ToolbarArmedXYGraph plot = new ToolbarArmedXYGraph(new XYGraph(), XYGraphFlags.SEPARATE_ZOOM | XYGraphFlags.STAGGER);
    final XYGraph xygraph = (XYGraph) plot.getXYGraph();
    xygraph.setTransparent(false);
    xygraph.setTitle("You should see a line. Zoom out to see more data");
    lws.setContents(plot);
    // Add data & trace
    final CircularBufferDataProvider data = new CircularBufferDataProvider(true);
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 2, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 3, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    data.addSample(new Sample(next_x++, 1, 1, 1, 0, 0));
    // Add Double.NaN gap, single point
    data.addSample(new Sample(next_x++, Double.NaN, 0, 0, 0, 0, "Disconnected"));
    data.addSample(new Sample(next_x++, 1, 0, 0, 0, 0));
    // Another gap, single point
    data.addSample(new Sample(next_x++, Double.NaN, 0, 0, 0, 0, "Disconnected"));
    data.addSample(new Sample(next_x++, 2, 0, 0, 0, 0));
    // Last value is valid 'forever'
    data.addSample(new Sample(Double.MAX_VALUE, 2, 0, 0, 0, 0));
    // Always looked OK with this range
    xygraph.getPrimaryXAxis().setRange(data.getXDataMinMax());
    xygraph.getPrimaryYAxis().setRange(data.getYDataMinMax());
    // With STEP_HORIZONTALLY this should have shown just a horizontal
    // line, but a bug resulted in nothing when both the 'start' and 'end'
    // point of the horizontal line were outside the plot range.
    // Similarly, using STEP_VERTICALLY failed to draw anything when
    // both end-points of the horizontal or vertical section of the step
    // were outside the plot. (fixed)
    // 
    // There's still a question about handling 'YErrorInArea':
    // For now, the axis intersection removes x/y errors,
    // so when moving a sample with y error left or right outside
    // of the plot range, the error area suddenly shrinks when
    // the axis intersection is assumed to have +-0 y error.
    xygraph.getPrimaryXAxis().setRange(4.1, 4.9);
    // Gap, start of X range, sample @ x==8, gap @ 9, end of range.
    // Bug failed to show line from that sample up to gap @ 9.
    xygraph.getPrimaryXAxis().setRange(7.5, 9.5);
    final Trace trace = new Trace("Demo", xygraph.getPrimaryXAxis(), xygraph.getPrimaryYAxis(), data);
    trace.setTraceType(TraceType.STEP_HORIZONTALLY);
    // trace.setTraceType(TraceType.STEP_VERTICALLY);
    // // SOLID_LINE does not show individual points
    // trace.setTraceType(TraceType.SOLID_LINE);
    // trace.setPointStyle(PointStyle.CIRCLE);
    trace.setErrorBarEnabled(true);
    trace.setDrawYErrorInArea(true);
    xygraph.addTrace(trace);
    Font LEGEND_FONT = XYGraphMediaFactory.getInstance().getFont(new FontData("Lucida Sans", 11, SWT.BOLD));
    Legend legend = xygraph.getLegend(trace);
    legend.setDrawBorder(true);
    legend.setPreferredHeight(100);
    legend.setTextFont(LEGEND_FONT);
    // SWT main loop
    final Display display = Display.getDefault();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Trace(org.eclipse.nebula.visualization.xygraph.figures.Trace) Shell(org.eclipse.swt.widgets.Shell) Legend(org.eclipse.nebula.visualization.xygraph.figures.Legend) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) Sample(org.eclipse.nebula.visualization.xygraph.dataprovider.Sample) FontData(org.eclipse.swt.graphics.FontData) LightweightSystem(org.eclipse.draw2d.LightweightSystem) XYGraph(org.eclipse.nebula.visualization.xygraph.figures.XYGraph) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) CircularBufferDataProvider(org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider) Font(org.eclipse.swt.graphics.Font) Display(org.eclipse.swt.widgets.Display)

Aggregations

LightweightSystem (org.eclipse.draw2d.LightweightSystem)55 Shell (org.eclipse.swt.widgets.Shell)33 Display (org.eclipse.swt.widgets.Display)32 Canvas (org.eclipse.swt.widgets.Canvas)23 XYGraph (org.eclipse.nebula.visualization.xygraph.figures.XYGraph)16 CircularBufferDataProvider (org.eclipse.nebula.visualization.xygraph.dataprovider.CircularBufferDataProvider)15 Trace (org.eclipse.nebula.visualization.xygraph.figures.Trace)15 ScrollableThumbnail (org.eclipse.draw2d.parts.ScrollableThumbnail)14 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 Viewport (org.eclipse.draw2d.Viewport)12 MarginBorder (org.eclipse.draw2d.MarginBorder)11 IXYGraph (org.eclipse.nebula.visualization.xygraph.figures.IXYGraph)11 ToolbarArmedXYGraph (org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph)11 IManualValueChangeListener (org.eclipse.nebula.visualization.widgets.datadefinition.IManualValueChangeListener)7 SchemeBorder (org.eclipse.draw2d.SchemeBorder)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 GaugeFigure (org.eclipse.nebula.visualization.widgets.figures.GaugeFigure)5 KnobFigure (org.eclipse.nebula.visualization.widgets.figures.KnobFigure)5 TankFigure (org.eclipse.nebula.visualization.widgets.figures.TankFigure)5