Java Code Examples for org.eclipse.draw2d.LightweightSystem#setContents()

The following examples show how to use org.eclipse.draw2d.LightweightSystem#setContents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComprehensiveExample.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
	final Shell shell = new Shell();
	shell.setSize(800, 500);
    shell.open();

	final LightweightSystem lws = new LightweightSystem(shell);
	final XYGraphTest testFigure = new XYGraphTest();
	lws.setContents(testFigure);

    shell.setText("Comprehensive Example");
    final Display display = Display.getDefault();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
           display.sleep();
       }
    }
}
 
Example 2
Source File: TimelineComposite.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public TimelineComposite(Composite parent, int style) {
	super(parent, style);

	fResourceManager = new LocalResourceManager(JFaceResources.getResources(), this);

	final FillLayout layout = new FillLayout();
	layout.marginHeight = 10;
	layout.marginWidth = 10;
	setLayout(layout);

	setBackground(ColorConstants.black);

	final Canvas canvas = new Canvas(this, SWT.DOUBLE_BUFFERED);
	canvas.setBackground(ColorConstants.black);
	final LightweightSystem lightWeightSystem = new LightweightSystem(canvas);

	fRootFigure = new RootFigure(fResourceManager);
	fRootFigure.setFont(parent.getFont());
	lightWeightSystem.setContents(fRootFigure);

	// draw2d does not directly support mouseWheelEvents, so register on canvas
	canvas.addMouseWheelListener(new TimelineScaler(this));
}
 
Example 3
Source File: ProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * initialize the overview
 */
protected void initializeOverview() {
	LightweightSystem lws = new LightweightSystem(overview);
	RootEditPart rep = getGraphicalViewer().getRootEditPart();
	DiagramRootEditPart root = (DiagramRootEditPart) rep;
	thumbnail = new ScrollableThumbnailEx((Viewport) root.getFigure());
	// thumbnail.setSource(root.getLayer(org.eclipse.gef.LayerConstants.PRINTABLE_LAYERS));
	thumbnail.setSource(root.getLayer(LayerConstants.SCALABLE_LAYERS));

	lws.setContents(thumbnail);
	disposeListener = new DisposeListener() {

		public void widgetDisposed(DisposeEvent e) {
			if (thumbnail != null) {
				thumbnail.deactivate();
				thumbnail = null;
			}
		}
	};
	getEditor().addDisposeListener(disposeListener);
	this.overviewInitialized = true;
}
 
Example 4
Source File: GraphDemo.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public static void main(final String[] args) {
	final Shell shell = new Shell();
	shell.setSize(800, 500);
    shell.open();

	final LightweightSystem lws = new LightweightSystem(shell);
	final XYGraphTest2 testFigure = new XYGraphTest2();
	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());
}
 
Example 5
Source File: ImageTest.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
private static void main() throws FileNotFoundException {
    try {
        shell.setSize(100, 100);

        final LightweightSystem lws = new LightweightSystem(shell);

        final IFigure panel = new Figure();
        panel.setLayoutManager(new ToolbarLayout());

        initialize(panel);

        lws.setContents(panel);

        shell.open();

        final Display display = Display.getDefault();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }

    } finally {
        if (image != null) {
            image.dispose();
        }
    }
}
 
Example 6
Source File: SankeyMiniViewAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Control createContents(Composite parent) {
	Composite composite = createForm(parent);
	createScale(composite);
	Canvas canvas = new Canvas(composite, SWT.BORDER);
	canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	LightweightSystem lws = new LightweightSystem(canvas);
	ScrollableThumbnail thumbnail = createThumbnail();
	lws.setContents(thumbnail);
	viewer.getControl().addDisposeListener((e) -> {
		if (!closed)
			close();
	});
	return super.createContents(parent);
}
 
Example 7
Source File: ImageTest.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private static void main() throws FileNotFoundException {
	// �f�t�H���gDisplay���g�p���ăV�F�����쐬
	try {
		shell.setSize(100, 100); // �V�F���̃T�C�Y���w��

		// �쐬�����V�F�����g�p����LightweightSystem�̍쐬
		LightweightSystem lws = new LightweightSystem(shell);

		// ���[�g�E�t�B�M���A�̍쐬
		IFigure panel = new Figure();
		panel.setLayoutManager(new ToolbarLayout());

		initialize(panel);

		// ���[�g�E�t�B�M���A�̓o�^
		lws.setContents(panel);

		// �ȉ��́A���̑���SWT�A�v���P�[�V�����Ɠ��l
		shell.open();

		Display display = Display.getDefault();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}

	} finally {
		if (image != null) {
			image.dispose();
		}
	}
}
 
Example 8
Source File: KnobExample.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 250);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create Knob
	final KnobFigure knobFigure = new KnobFigure();
	
	//Init Knob
	knobFigure.setRange(-100, 100);
	knobFigure.setLoLevel(-50);
	knobFigure.setLoloLevel(-80);
	knobFigure.setHiLevel(60);
	knobFigure.setHihiLevel(80);
	knobFigure.setMajorTickMarkStepHint(50);
	knobFigure.setThumbColor(ColorConstants.gray);
	knobFigure.addManualValueChangeListener(new IManualValueChangeListener() {			
		public void manualValueChanged(double newValue) {
			System.out.println("You set value to: " + newValue);
		}
	});
	
	lws.setContents(knobFigure);		
	
	
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }

   
}
 
Example 9
Source File: ScaledSliderExample.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 250);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create Scaled Slider
	final ScaledSliderFigure slider = new ScaledSliderFigure();
	
	//Init Scaled Slider
	slider.setRange(-100, 100);
	slider.setLoLevel(-50);
	slider.setLoloLevel(-80);
	slider.setHiLevel(60);
	slider.setHihiLevel(80);
	slider.setMajorTickMarkStepHint(50);
	slider.setThumbColor(ColorConstants.gray);
	slider.addManualValueChangeListener(new IManualValueChangeListener() {			
		@Override
		public void manualValueChanged(double newValue) {
			System.out.println("You set value to: " + newValue);
		}
	});
	
	lws.setContents(slider);		
	
	
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }

   
}
 
Example 10
Source File: XYGraphStyledDoubleExampleView.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
  public void createPartControl(Composite parent) {

      // use LightweightSystem to create the bridge between SWT and draw2D
      final LightweightSystem lws = new LightweightSystem(new Canvas(parent, SWT.NONE));

// create a new XY Graph.
IXYGraph xyGraph = new XYGraph();

ToolbarArmedXYGraph toolbarArmedXYGraph = new ToolbarArmedXYGraph(xyGraph);

      xyGraph.setTitle("Simple Styled Example");
      // set it as the content of LightwightSystem
      lws.setContents(toolbarArmedXYGraph);

      // 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[] { 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6 });
      traceDataProvider.setCurrentYDataArray(new double[] { 1, 1, 1, 1, 1, 1, 1 });

      // create the trace
      Trace trace = new Trace("Trace-Styled XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(), traceDataProvider);

      // set trace property
      trace.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_GRAY));
      trace.setTraceType(TraceType.POINT);

      // set point properties
      trace.setPointStyle(PointStyle.FILLED_SQUARE);
      trace.setPointSize(40);
      trace.setPointStyleProvider(new Rainbowstyle());

      // add the trace to xyGraph
      xyGraph.addTrace(trace);

      // perform AutoScale
      xyGraph.performAutoScale();

  }
 
Example 11
Source File: GaugeExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
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();
   
}
 
Example 12
Source File: SimpleToolbarArmedXYGraphExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
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();
	}

}
 
Example 13
Source File: XYGraphStyledBoolExampleView.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	// use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(new Canvas(parent, SWT.NONE));

	// create a new XY Graph.
	IXYGraph xyGraph = new XYGraph();

	ToolbarArmedXYGraph toolbarArmedXYGraph = new ToolbarArmedXYGraph(xyGraph);

	xyGraph.setTitle("Simple Styled Example");
	// set it as the content of LightwightSystem
	lws.setContents(toolbarArmedXYGraph);

	// create a trace data provider, which will provide the data to the
	// trace.
	CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(false);

	for (int i = 0; i < 20; i++) {
		Sample sample = new Sample(Math.random(), Math.random());
		sample.setData(Math.random()<0.5);
		traceDataProvider.addSample(sample);
	}

	// create the trace
	Trace trace = new Trace("Trace-Styled XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(),
			traceDataProvider);

	// set trace property
	trace.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_GRAY));
	trace.setTraceType(TraceType.POINT);

	// set point properties
	trace.setPointStyle(PointStyle.FILLED_SQUARE);
	trace.setPointSize(40);
	trace.setPointStyleProvider(new BooleanStyleProvider());

	// add the trace to xyGraph
	xyGraph.addTrace(trace);

	// perform AutoScale
	xyGraph.performAutoScale();

}
 
Example 14
Source File: MeterExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 150);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create Gauge
	final MeterFigure meterFigure = new MeterFigure();
	
	//Init gauge
	meterFigure.setBackgroundColor(
			XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
	
	meterFigure.setBorder(new SchemeBorder(SchemeBorder.SCHEMES.ETCHED));
	
	meterFigure.setRange(-100, 100);
	meterFigure.setLoLevel(-50);
	meterFigure.setLoloLevel(-80);
	meterFigure.setHiLevel(60);
	meterFigure.setHihiLevel(80);
	meterFigure.setMajorTickMarkStepHint(50);
	
	lws.setContents(meterFigure);		
	
	//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() {
					meterFigure.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();
   
}
 
Example 15
Source File: GaugeExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
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();
   
}
 
Example 16
Source File: BarChartExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 250);
	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();
	xyGraph.setTitle("Bar and Area Chart");
	// set it as the content of LightwightSystem
	lws.setContents(xyGraph);

	// Configure XYGraph
	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[] { 0, 20, 30, 40, 50, 60, 70, 80, 100 });
	traceDataProvider.setCurrentYDataArray(new double[] { 11, 44, 55, 45, 88, 98, 52, 23, 78 });

	// create the trace
	Trace trace = new Trace("Trace1-XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(),
			traceDataProvider);

	// set trace property
	trace.setTraceType(TraceType.BAR);
	trace.setLineWidth(15);
	trace.setAreaAlpha(200);
	trace.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_BLUE));
	// add the trace to xyGraph
	xyGraph.addTrace(trace);

	// create a trace data provider, which will provide the data to the
	// trace.
	CircularBufferDataProvider traceDataProvider2 = new CircularBufferDataProvider(false);
	traceDataProvider2.setBufferSize(100);
	traceDataProvider2.setCurrentXDataArray(new double[] { 0, 20, 30, 40, 50, 60, 70, 80, 100 });
	traceDataProvider2.setCurrentYDataArray(new double[] { 15, 60, 40, 60, 70, 80, 65, 70, 23 });

	// create the trace
	Trace trace2 = new Trace("Trace1-XY Plot", xyGraph.getPrimaryXAxis(), xyGraph.getPrimaryYAxis(),
			traceDataProvider2);

	// set trace property
	trace2.setPointSize(6);
	trace2.setAreaAlpha(150);
	trace2.setTraceType(TraceType.AREA);
	trace2.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_RED));

	// trace2.setLineWidth(5);
	// add the trace to xyGraph
	xyGraph.addTrace(trace2);
	
	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);
	
	Display display = Display.getDefault();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

}
 
Example 17
Source File: BarChartExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 250);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);
	
	//create a new XY Graph.
	XYGraph xyGraph = new XYGraph();
	xyGraph.setTitle("Bar and Area Chart");
	//set it as the content of LightwightSystem
	lws.setContents(xyGraph);
	
	//Configure XYGraph
	xyGraph.primaryXAxis.setShowMajorGrid(true);
	xyGraph.primaryYAxis.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[]{0, 20, 30, 40, 50, 60, 70, 80, 100});
	traceDataProvider.setCurrentYDataArray(new double[]{11, 44, 55, 45, 88, 98, 52, 23, 78});	
	
	//create the trace
	Trace trace = new Trace("Trace1-XY Plot", 
			xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider);			
	
	//set trace property
	trace.setTraceType(TraceType.BAR);
	trace.setLineWidth(15);
	trace.setAreaAlpha(200);
	trace.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_BLUE) );
	//add the trace to xyGraph
	xyGraph.addTrace(trace);			
   
	//create a trace data provider, which will provide the data to the trace.
	CircularBufferDataProvider traceDataProvider2 = new CircularBufferDataProvider(false);
	traceDataProvider2.setBufferSize(100);		
	traceDataProvider2.setCurrentXDataArray(new double[]{0, 20, 30, 40, 50, 60, 70, 80, 100});
	traceDataProvider2.setCurrentYDataArray(new double[]{15, 60, 40, 60, 70, 80, 65, 70, 23});	
	
	//create the trace
	Trace trace2 = new Trace("Trace1-XY Plot", 
			xyGraph.primaryXAxis, xyGraph.primaryYAxis, traceDataProvider2);			
	
	//set trace property
	trace2.setPointSize(6);
	trace2.setAreaAlpha(150);
	trace2.setTraceType(TraceType.AREA);
	trace2.setTraceColor(XYGraphMediaFactory.getInstance().getColor(XYGraphMediaFactory.COLOR_RED) );

	//trace2.setLineWidth(5);
	//add the trace to xyGraph
	xyGraph.addTrace(trace2);	
	
    Display display = Display.getDefault();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
   
}
 
Example 18
Source File: ThermometerExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 250);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create widget
	final ThermometerFigure thermo = new ThermometerFigure();
	
	//Init widget
	thermo.setBackgroundColor(
			XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
	
	thermo.setBorder(new SchemeBorder(SchemeBorder.SCHEMES.ETCHED));
	
	thermo.setRange(-100, 100);
	thermo.setLoLevel(-50);
	thermo.setLoloLevel(-80);
	thermo.setHiLevel(60);
	thermo.setHihiLevel(80);
	thermo.setShowHi(false);
	thermo.setMajorTickMarkStepHint(50);
	
	lws.setContents(thermo);		
	
	//Update the widget 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() {
					thermo.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();
   
}
 
Example 19
Source File: StaircaseExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
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();
	}
}
 
Example 20
Source File: TankExample.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	final Shell shell = new Shell();
	shell.setSize(300, 250);
    shell.open();
    
    //use LightweightSystem to create the bridge between SWT and draw2D
	final LightweightSystem lws = new LightweightSystem(shell);		
	
	//Create widget
	final TankFigure tank = new TankFigure();
	
	//Init widget
	tank.setBackgroundColor(
			XYGraphMediaFactory.getInstance().getColor(255, 255, 255));
	
	tank.setBorder(new SchemeBorder(SchemeBorder.SCHEMES.ETCHED));
	
	tank.setRange(-100, 100);
	tank.setLoLevel(-50);
	tank.setLoloLevel(-80);
	tank.setHiLevel(60);
	tank.setHihiLevel(80);
	tank.setMajorTickMarkStepHint(50);
	
	lws.setContents(tank);		
	
	//Update the widget 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() {
					tank.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();
   
}