Search in sources :

Example 1 with WidgetPropertyListener

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

the class TabsRepresentation method registerListeners.

@Override
protected void registerListeners() {
    super.registerListeners();
    // Create initial tabs and their children
    addTabs(model_widget.propTabs().getValue());
    final UntypedWidgetPropertyListener listener = this::layoutChanged;
    model_widget.propWidth().addUntypedPropertyListener(listener);
    model_widget.propHeight().addUntypedPropertyListener(listener);
    model_widget.propBackgroundColor().addUntypedPropertyListener(listener);
    model_widget.propFont().addUntypedPropertyListener(listener);
    model_widget.propTabs().addPropertyListener(this::tabsChanged);
    model_widget.propDirection().addUntypedPropertyListener(listener);
    model_widget.propTabHeight().addUntypedPropertyListener(listener);
    // Update UI when model selects a tab
    final WidgetPropertyListener<Integer> track_active_model_tab = (p, old, value) -> {
        if (!changing_active_tab.compareAndSet(false, true))
            return;
        if (value == null)
            value = p.getValue();
        if (value >= jfx_node.getTabs().size())
            value = jfx_node.getTabs().size() - 1;
        jfx_node.getSelectionModel().select(value);
        changing_active_tab.set(false);
    };
    // Select initial tab
    track_active_model_tab.propertyChanged(model_widget.propActiveTab(), null, null);
    model_widget.propActiveTab().addPropertyListener(track_active_model_tab);
    // Update model when UI selects a tab
    jfx_node.getSelectionModel().selectedIndexProperty().addListener((t, o, selected) -> {
        if (!changing_active_tab.compareAndSet(false, true))
            return;
        model_widget.propActiveTab().setValue(selected.intValue());
        changing_active_tab.set(false);
    });
    // Initial update of font, size
    layoutChanged(null, null, null);
}
Also used : TabsWidget(org.csstudio.display.builder.model.widgets.TabsWidget) Label(javafx.scene.control.Label) Font(javafx.scene.text.Font) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Side(javafx.geometry.Side) Background(javafx.scene.layout.Background) Level(java.util.logging.Level) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) Direction(org.csstudio.display.builder.model.properties.Direction) List(java.util.List) TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) BackgroundFill(javafx.scene.layout.BackgroundFill) UntypedWidgetPropertyListener(org.csstudio.display.builder.model.UntypedWidgetPropertyListener) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) Optional(java.util.Optional) Point2D(javafx.geometry.Point2D) DirtyFlag(org.csstudio.display.builder.model.DirtyFlag) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) Widget(org.csstudio.display.builder.model.Widget) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TabItemProperty(org.csstudio.display.builder.model.widgets.TabsWidget.TabItemProperty) Pane(javafx.scene.layout.Pane) UntypedWidgetPropertyListener(org.csstudio.display.builder.model.UntypedWidgetPropertyListener)

Example 2 with WidgetPropertyListener

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

the class XYPlotWidgetRuntime method stop.

@Override
public void stop() {
    // Disconnect Marker PVs and listeners
    for (Map.Entry<WidgetProperty<?>, WidgetPropertyListener<?>> entry : marker_prop_listeners.entrySet()) entry.getKey().removePropertyListener(entry.getValue());
    marker_prop_listeners.clear();
    for (Map.Entry<RuntimePV, RuntimePVListener> entry : marker_pv_listeners.entrySet()) entry.getKey().removeListener(entry.getValue());
    marker_pv_listeners.clear();
    for (RuntimePV pv : marker_pvs) {
        removePV(pv);
        PVFactory.releasePV(pv);
    }
    marker_pvs.clear();
    for (PVNameToValueBinding binding : bindings) binding.dispose();
    super.stop();
}
Also used : TraceWidgetProperty(org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) PVNameToValueBinding(org.csstudio.display.builder.runtime.PVNameToValueBinding) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 3 with WidgetPropertyListener

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

the class ImageWidgetRuntime method bindROI.

/**
 * Bind an ROI PV to an ROI value
 *  @param name_prop Property for the PV name
 *  @param value_prop Property for the value
 */
private void bindROI(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
    final String pv_name = name_prop.getValue();
    if (pv_name.isEmpty())
        return;
    logger.log(Level.FINER, "Connecting {0} to ROI PV {1}", new Object[] { widget, pv_name });
    try {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        roi_pvs.add(pv);
        // Write value changes to the PV
        final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
            try {
                if (value == VTypeUtil.getValueNumber(pv.read()).doubleValue())
                    return;
                // System.out.println("Writing " + value_prop + " to PV " + pv_name);
                pv.write(value);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error writing ROI value to PV " + pv_name, ex);
            }
        };
        value_prop.addPropertyListener(prop_listener);
        roi_prop_listeners.put(value_prop, prop_listener);
        // Write PV updates to the value
        final RuntimePVListener pv_listener = new RuntimePVListener() {

            @Override
            public void valueChanged(final RuntimePV pv, final VType value) {
                final double number = VTypeUtil.getValueNumber(value).doubleValue();
                if (number == value_prop.getValue())
                    return;
                // System.out.println("Writing from PV " + pv_name + " to " + value_prop);
                value_prop.setValue(number);
            }
        };
        pv.addListener(pv_listener);
        roi_pv_listeners.put(pv, pv_listener);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error connecting ROI PV " + pv_name, ex);
    }
}
Also used : VTypeUtil(org.csstudio.display.builder.model.util.VTypeUtil) ROIWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WidgetRuntime(org.csstudio.display.builder.runtime.WidgetRuntime) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) PVFactory(org.csstudio.display.builder.runtime.pv.PVFactory) PVUtil(org.csstudio.display.builder.runtime.script.PVUtil) RuntimePlugin.logger(org.csstudio.display.builder.runtime.RuntimePlugin.logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) List(java.util.List) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) Map(java.util.Map) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 4 with WidgetPropertyListener

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

the class ImageWidgetRuntime method stop.

@Override
public void stop() {
    // Disconnect ROI PVs and listeners
    for (Map.Entry<WidgetProperty<?>, WidgetPropertyListener<?>> entry : roi_prop_listeners.entrySet()) entry.getKey().removePropertyListener(entry.getValue());
    roi_prop_listeners.clear();
    for (Map.Entry<RuntimePV, RuntimePVListener> entry : roi_pv_listeners.entrySet()) entry.getKey().removeListener(entry.getValue());
    roi_pv_listeners.clear();
    for (RuntimePV pv : roi_pvs) {
        removePV(pv);
        PVFactory.releasePV(pv);
    }
    roi_pvs.clear();
    // Disconnect cursor info PV
    if (x_pv != null && y_pv != null) {
        y_pv.removeListener(cursor_pv_listener);
        x_pv.removeListener(cursor_pv_listener);
    }
    if (unbind(cursor_pv))
        widget.runtimePropCursorInfo().removePropertyListener(cursor_info_listener);
    boolean x_or_y = unbind(y_pv);
    x_or_y |= unbind(x_pv);
    if (x_or_y)
        widget.runtimePropCrosshair().removePropertyListener(crosshair_listener);
    y_pv = x_pv = cursor_pv = null;
    super.stop();
}
Also used : ROIWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 5 with WidgetPropertyListener

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

the class XYPlotWidgetRuntime method bindMarker.

private void bindMarker(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
    final String pv_name = name_prop.getValue();
    if (pv_name.isEmpty())
        return;
    logger.log(Level.FINER, "Connecting {0} to Marker PV {1}", new Object[] { widget, pv_name });
    try {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        marker_pvs.add(pv);
        // Write value changes to the PV
        final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
            // Ignore if PV already has same value to break update loops
            double pv_value = VTypeUtil.getValueNumber(pv.read()).doubleValue();
            if (value == pv_value)
                return;
            try {
                // System.out.println("Writing " + value_prop + " to PV " + pv_name);
                pv.write(value);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error writing marker value to PV " + pv_name, ex);
                // Restore property to the unchanged value of the PV
                value_prop.setValue(pv_value);
            }
        };
        value_prop.addPropertyListener(prop_listener);
        marker_prop_listeners.put(value_prop, prop_listener);
        // Write PV updates to the value
        final RuntimePVListener pv_listener = new RuntimePVListener() {

            @Override
            public void valueChanged(final RuntimePV pv, final VType value) {
                final double number = VTypeUtil.getValueNumber(value).doubleValue();
                if (number == value_prop.getValue())
                    return;
                // System.out.println("Writing " + number + " from PV " + pv_name + " to " + value_prop);
                value_prop.setValue(number);
            }
        };
        pv.addListener(pv_listener);
        marker_pv_listeners.put(pv, pv_listener);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error connecting Marker PV " + pv_name, ex);
    }
}
Also used : VTypeUtil(org.csstudio.display.builder.model.util.VTypeUtil) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WidgetRuntime(org.csstudio.display.builder.runtime.WidgetRuntime) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) PVFactory(org.csstudio.display.builder.runtime.pv.PVFactory) RuntimePlugin.logger(org.csstudio.display.builder.runtime.RuntimePlugin.logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) PVNameToValueBinding(org.csstudio.display.builder.runtime.PVNameToValueBinding) List(java.util.List) XYPlotWidget(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget) Map(java.util.Map) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) TraceWidgetProperty(org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) MarkerProperty(org.csstudio.display.builder.model.widgets.plots.XYPlotWidget.MarkerProperty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

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