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