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