Search in sources :

Example 6 with WidgetPropertyListener

use of org.csstudio.display.builder.model.WidgetPropertyListener 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)

Example 7 with WidgetPropertyListener

use of org.csstudio.display.builder.model.WidgetPropertyListener in project org.csstudio.display.builder by kasemir.

the class PropertyChangeHandler method firePropertyChange.

/**
 * Notify listeners of property change.
 *
 *  <p>New value usually matches <code>property.getValue()</code>,
 *  but in multi-threaded context value might already have changed
 *  _again_ by the time this executes.
 *
 *  <p>Suppresses notifications where old_value equals new_value,
 *  unless both values are null, treating that as a "notify anyway"
 *  case.
 *
 *  @param property Property that changed, or <code>null</code> for "many"
 *  @param old_value Original value
 *  @param new_value New value
 */
@SuppressWarnings("unchecked")
protected void firePropertyChange(final WidgetProperty<T> property, final T old_value, final T new_value) {
    // Does anybody care?
    final List<BaseWidgetPropertyListener> safe_copy = listeners;
    if (safe_copy == null)
        return;
    // Any change at all?
    if (new_value != null && old_value != null && new_value.equals(old_value))
        return;
    // If a property listener changes the property,
    // that triggers a recursive listener invocation.
    // Not necessarily a problem, but likely better avoided.
    final int recursion_level = recursions.incrementAndGet();
    if (recursion_level > 1)
        logger.log(Level.WARNING, "Recursive update of property " + property.getName() + ", " + recursion_level + " deep");
    // Notify listeners
    for (BaseWidgetPropertyListener listener : safe_copy) {
        try {
            if (listener instanceof WidgetPropertyListener)
                ((WidgetPropertyListener<T>) listener).propertyChanged(property, old_value, new_value);
            else
                ((UntypedWidgetPropertyListener) listener).propertyChanged(property, old_value, new_value);
        } catch (Throwable ex) {
            // Log error, then continue with next listener
            logger.log(Level.WARNING, "Property update error for " + property, ex);
        }
    }
    recursions.decrementAndGet();
}
Also used : UntypedWidgetPropertyListener(org.csstudio.display.builder.model.UntypedWidgetPropertyListener) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) BaseWidgetPropertyListener(org.csstudio.display.builder.model.BaseWidgetPropertyListener) BaseWidgetPropertyListener(org.csstudio.display.builder.model.BaseWidgetPropertyListener)

Aggregations

WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)7 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)6 List (java.util.List)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Level (java.util.logging.Level)4 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)4 ROIWidgetProperty (org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty)3 VType (org.diirt.vtype.VType)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 TimeUnit (java.util.concurrent.TimeUnit)2 Pane (javafx.scene.layout.Pane)2 DirtyFlag (org.csstudio.display.builder.model.DirtyFlag)2 UntypedWidgetPropertyListener (org.csstudio.display.builder.model.UntypedWidgetPropertyListener)2 VTypeUtil (org.csstudio.display.builder.model.util.VTypeUtil)2 ImageWidget (org.csstudio.display.builder.model.widgets.plots.ImageWidget)2 TraceWidgetProperty (org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty)2