Search in sources :

Example 1 with ImagePlot

use of org.csstudio.javafx.rtplot.internal.ImagePlot in project org.csstudio.display.builder by kasemir.

the class ImagePlotDemo method start.

@Override
public void start(final Stage stage) throws Exception {
    final Level level = Level.CONFIG;
    Logger.getLogger("").setLevel(level);
    for (Handler handler : Logger.getLogger("").getHandlers()) handler.setLevel(level);
    final ImagePlot plot = new ImagePlot(true);
    plot.setColorMapping(RAINBOW);
    plot.setAutoscale(true);
    plot.setValueRange(0.0, 2.0);
    plot.getXAxis().setGridVisible(true);
    plot.getYAxis().setGridVisible(true);
    plot.getYAxis().setScaleFont(Font.font("Liberation Sans", FontPosture.ITALIC, 25));
    final RegionOfInterest roi = plot.addROI("R.O.I.", javafx.scene.paint.Color.BLUEVIOLET, true, true);
    roi.setRegion(new Rectangle2D(20, 40, 20, 10));
    plot.setListener(new RTImagePlotListener() {

        @Override
        public void changedCursorInfo(double x, double y, int xi, int yi, double value) {
            System.out.println("Cursor at " + x + ", " + y);
        }

        @Override
        public void changedROI(int index, String name, Rectangle2D region) {
            System.out.println("ROI " + name + " now at " + region);
        }
    });
    timer.scheduleAtFixedRate(() -> plot.setValue(WIDTH, HEIGHT, computeData(), false), 200, 100, TimeUnit.MILLISECONDS);
    timer.scheduleAtFixedRate(() -> {
        show_colorbar = !show_colorbar;
        plot.showColorMap(show_colorbar);
    }, 5000, 5000, TimeUnit.MILLISECONDS);
    final Pane root = new Pane(plot);
    final ChangeListener<? super Number> resize_listener = (p, o, n) -> plot.setSize(root.getWidth(), root.getHeight());
    root.widthProperty().addListener(resize_listener);
    root.heightProperty().addListener(resize_listener);
    final Scene scene = new Scene(root, 800, 600);
    Styles.setSceneStyle(scene);
    stage.setScene(scene);
    stage.setTitle("Image Plot Demo");
    stage.show();
    stage.setOnCloseRequest((event) -> {
        timer.shutdown();
        try {
            timer.awaitTermination(2, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }
        plot.dispose();
    });
}
Also used : Color(java.awt.Color) Scene(javafx.scene.Scene) Rectangle2D(javafx.geometry.Rectangle2D) Font(javafx.scene.text.Font) Logger(java.util.logging.Logger) Executors(java.util.concurrent.Executors) Styles(org.csstudio.javafx.Styles) ImagePlot(org.csstudio.javafx.rtplot.internal.ImagePlot) ListDouble(org.diirt.util.array.ListDouble) Level(java.util.logging.Level) TimeUnit(java.util.concurrent.TimeUnit) Application(javafx.application.Application) Stage(javafx.stage.Stage) FontPosture(javafx.scene.text.FontPosture) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ArrayDouble(org.diirt.util.array.ArrayDouble) Handler(java.util.logging.Handler) ChangeListener(javafx.beans.value.ChangeListener) Pane(javafx.scene.layout.Pane) ImagePlot(org.csstudio.javafx.rtplot.internal.ImagePlot) Rectangle2D(javafx.geometry.Rectangle2D) Handler(java.util.logging.Handler) Scene(javafx.scene.Scene) Pane(javafx.scene.layout.Pane) Level(java.util.logging.Level)

Aggregations

Color (java.awt.Color)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 Handler (java.util.logging.Handler)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Application (javafx.application.Application)1 ChangeListener (javafx.beans.value.ChangeListener)1 Rectangle2D (javafx.geometry.Rectangle2D)1 Scene (javafx.scene.Scene)1 Pane (javafx.scene.layout.Pane)1 Font (javafx.scene.text.Font)1 FontPosture (javafx.scene.text.FontPosture)1 Stage (javafx.stage.Stage)1 Styles (org.csstudio.javafx.Styles)1 ImagePlot (org.csstudio.javafx.rtplot.internal.ImagePlot)1 ArrayDouble (org.diirt.util.array.ArrayDouble)1 ListDouble (org.diirt.util.array.ListDouble)1