package org.eclipse.nebula.snippets.visualization; /******************************************************************************* * Copyright (c) 2010 Oak Ridge National Laboratory. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 ******************************************************************************/ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import org.eclipse.draw2d.LightweightSystem; import org.eclipse.nebula.visualization.widgets.figures.ProgressBarFigure; import org.eclipse.nebula.visualization.xygraph.util.XYGraphMediaFactory; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; /** * A live updated Gauge Example. * @author Xihui Chen * */ public class ProgressBarExample { private static int counter = 0; 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() { public void run() { Display.getDefault().asyncExec(new Runnable() { 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(); } }