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();
}
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();
}
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());
}
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();
}
}
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();
}
}
Aggregations