Search in sources :

Example 36 with Rectangle2D

use of javafx.geometry.Rectangle2D 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)

Example 37 with Rectangle2D

use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.

the class SelectedWidgetUITracker method updateTrackerFromWidgets.

private void updateTrackerFromWidgets() {
    if (updating)
        return;
    final Rectangle2D rect = GeometryTools.getDisplayBounds(widgets);
    updating = true;
    // Update overall tracker rectangle
    setPosition(rect);
    // Add a highlight to each selected widget
    // (tracker area may cover widgets that are not actually selected)
    // Only do that for 2 or more widgets.
    // For a single widget, the tracker rectangle is sufficient.
    widget_highlights.getChildren().clear();
    if (widgets.size() > 1)
        for (Widget widget : widgets) {
            final Rectangle2D bounds = GeometryTools.getDisplayBounds(widget);
            final Rectangle highlight = new Rectangle(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
            highlight.getStyleClass().add("tracker_highlight");
            // highlight is 'behind' rest of tracker, but still pass mouse clicks through to widgets
            highlight.setMouseTransparent(true);
            widget_highlights.getChildren().add(highlight);
        }
    updating = false;
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget) Rectangle(javafx.scene.shape.Rectangle)

Example 38 with Rectangle2D

use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.

the class DisplayEditor method pasteFromClipboard.

/**
 * Paste widgets from clipboard
 *  @param x Desired coordinate of upper-left widget ..
 *  @param y .. when pasted
 */
public void pasteFromClipboard(int x, int y) {
    if (selection_tracker.isInlineEditorActive())
        return;
    final String xml = Clipboard.getSystemClipboard().getString();
    // Anything on clipboard?
    if (xml == null)
        return;
    // Does it look like widget XML?
    if (!(xml.startsWith("<?xml") && xml.contains("<display")))
        return;
    // Correct the y coordinate, measured inside this editor,
    // by height of toolbar
    y -= toolbar.getHeight();
    // Correct coordinates by zoom factor
    final double zoom = toolkit.getZoom();
    x = (int) Math.round(x / zoom);
    y = (int) Math.round(y / zoom);
    try {
        final DisplayModel model = ModelReader.parseXML(xml);
        final List<Widget> widgets = model.getChildren();
        logger.log(Level.FINE, "Pasted {0} widgets", widgets.size());
        GeometryTools.moveWidgets(x, y, widgets);
        final Rectangle2D bounds = GeometryTools.getBounds(widgets);
        // Potentially activate group at drop point
        group_handler.locateParent(x, y, bounds.getWidth(), bounds.getHeight());
        addWidgets(widgets);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to paste content of clipboard", ex);
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) Widget(org.csstudio.display.builder.model.Widget) Rectangle2D(javafx.geometry.Rectangle2D)

Example 39 with Rectangle2D

use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.

the class ParentHandler method locateParent.

/**
 * Locate parent for region of display.
 *
 *  <p>If there is a group or tab that contains the region, it is highlighted.
 *
 *  <p>The widgets in the current selection themselves are ignored
 *  in the search to prevent having a group that's moved locate itself.
 *
 *  @param x
 *  @param y
 *  @param width
 *  @param height
 *  @see #getActiveParentChildren()
 */
public void locateParent(final double x, final double y, final double width, final double height) {
    final Rectangle2D bounds = new Rectangle2D(x, y, width, height);
    final List<Widget> selected_widgets = selection.getSelection();
    final ParentSearchResult res = new ParentWidgetSearch(bounds, model, selected_widgets).compute();
    final ChildrenProperty parent = res.children;
    if (parent == null)
        parent_highlight.setVisible(false);
    else {
        final Rectangle2D group_bounds = GeometryTools.getDisplayBounds(parent.getWidget());
        parent_highlight.setX(group_bounds.getMinX());
        parent_highlight.setY(group_bounds.getMinY());
        parent_highlight.setWidth(group_bounds.getWidth());
        parent_highlight.setHeight(group_bounds.getHeight());
        parent_highlight.setVisible(true);
    }
    active_parent_children = parent;
}
Also used : ChildrenProperty(org.csstudio.display.builder.model.ChildrenProperty) Rectangle2D(javafx.geometry.Rectangle2D) ArrayWidget(org.csstudio.display.builder.model.widgets.ArrayWidget) TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget)

Example 40 with Rectangle2D

use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.

the class ImageRepresentation method createROI.

private void createROI(final ROIWidgetProperty model_roi) {
    final RegionOfInterest plot_roi = image_plot.addROI(model_roi.name().getValue(), JFXUtil.convert(model_roi.color().getValue()), model_roi.visible().getValue(), model_roi.interactive().getValue());
    // Show/hide ROI as roi.visible() changes
    model_roi.visible().addPropertyListener((prop, old, visible) -> {
        plot_roi.setVisible(visible);
        Platform.runLater(() -> image_plot.removeROITracker());
        image_plot.requestUpdate();
    });
    // For now _not_ listening to runtime changes of roi.interactive() or roi.file() ...
    // Listen to roi.x_value(), .. and update plot_roi
    final WidgetPropertyListener<Double> model_roi_listener = (o, old, value) -> {
        if (changing_roi)
            return;
        Rectangle2D region = plot_roi.getRegion();
        region = new Rectangle2D(existingOrProperty(region.getMinX(), model_roi.x_value()), existingOrProperty(region.getMinY(), model_roi.y_value()), existingOrProperty(region.getWidth(), model_roi.width_value()), existingOrProperty(region.getHeight(), model_roi.height_value()));
        changing_roi = true;
        plot_roi.setRegion(region);
        changing_roi = false;
        image_plot.requestUpdate();
    };
    model_roi.x_value().addPropertyListener(model_roi_listener);
    model_roi.y_value().addPropertyListener(model_roi_listener);
    model_roi.width_value().addPropertyListener(model_roi_listener);
    model_roi.height_value().addPropertyListener(model_roi_listener);
    // Load image file (if there is one) on background thread
    ModelThreadPool.getExecutor().execute(() -> loadROI_Image(plot_roi, model_roi));
}
Also used : Arrays(java.util.Arrays) DisplayModel(org.csstudio.display.builder.model.DisplayModel) PredefinedColorMaps(org.csstudio.display.builder.model.properties.PredefinedColorMaps) Interpolation(org.csstudio.javafx.rtplot.Interpolation) VImageType(org.diirt.vtype.VImageType) Level(java.util.logging.Level) RTImagePlotListener(org.csstudio.javafx.rtplot.RTImagePlotListener) ValueFactory(org.diirt.vtype.ValueFactory) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) RTImagePlot(org.csstudio.javafx.rtplot.RTImagePlot) ArrayInt(org.diirt.util.array.ArrayInt) DirtyFlag(org.csstudio.display.builder.model.DirtyFlag) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) AxisWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.AxisWidgetProperty) VNumberArray(org.diirt.vtype.VNumberArray) Pane(javafx.scene.layout.Pane) NamedColorMappings(org.csstudio.javafx.rtplot.NamedColorMappings) ModelResourceUtil(org.csstudio.display.builder.model.util.ModelResourceUtil) Rectangle2D(javafx.geometry.Rectangle2D) ROIWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty) RegionBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.RegionBaseRepresentation) RepresentationUpdateThrottle(org.csstudio.display.builder.representation.RepresentationUpdateThrottle) RegionOfInterest(org.csstudio.javafx.rtplot.RegionOfInterest) VType(org.diirt.vtype.VType) ColorMap(org.csstudio.display.builder.model.properties.ColorMap) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) Platform(javafx.application.Platform) List(java.util.List) MacroHandler(org.csstudio.display.builder.model.macros.MacroHandler) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) ArrayDouble(org.diirt.util.array.ArrayDouble) ColorMappingFunction(org.csstudio.javafx.rtplot.ColorMappingFunction) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) Axis(org.csstudio.javafx.rtplot.Axis) VImage(org.diirt.vtype.VImage) Image(javafx.scene.image.Image) RegionOfInterest(org.csstudio.javafx.rtplot.RegionOfInterest) Rectangle2D(javafx.geometry.Rectangle2D) ArrayDouble(org.diirt.util.array.ArrayDouble)

Aggregations

Rectangle2D (javafx.geometry.Rectangle2D)76 Image (javafx.scene.image.Image)14 Scene (javafx.scene.Scene)10 Screen (javafx.stage.Screen)10 Stage (javafx.stage.Stage)7 Point2D (javafx.geometry.Point2D)6 IOException (java.io.IOException)5 ImageView (javafx.scene.image.ImageView)5 BufferedImage (java.awt.image.BufferedImage)4 File (java.io.File)4 List (java.util.List)4 Color (javafx.scene.paint.Color)4 Optional (java.util.Optional)3 Level (java.util.logging.Level)3 Application (javafx.application.Application)3 Platform (javafx.application.Platform)3 Menu (javafx.scene.control.Menu)3 MenuBar (javafx.scene.control.MenuBar)3 MenuItem (javafx.scene.control.MenuItem)3 Pane (javafx.scene.layout.Pane)3