From 4e9882f4b2db7abeb7d3277c626fe2ac673a0751 Mon Sep 17 00:00:00 2001 From: Baptiste DUBIN Date: Fri, 19 Aug 2022 13:05:30 +0200 Subject: [PATCH] #2275 : add horizontal property to widget Tank --- .../builder/model/widgets/TankWidget.java | 10 +++++ .../javafx/widgets/TankRepresentation.java | 37 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/TankWidget.java b/app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/TankWidget.java index a6c57dac99..74bdd8e20f 100644 --- a/app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/TankWidget.java +++ b/app/display/model/src/main/java/org/csstudio/display/builder/model/widgets/TankWidget.java @@ -17,6 +17,7 @@ import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMaximum; import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propMinimum; import static org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.propLogscale; +import static org.csstudio.display.builder.model.properties.CommonWidgetProperties.propHorizontal; import java.util.Arrays; import java.util.List; @@ -130,6 +131,8 @@ public WidgetConfigurator getConfigurator(final Version persisted_version) private volatile WidgetProperty minimum; private volatile WidgetProperty maximum; private volatile WidgetProperty log_scale; + private volatile WidgetProperty horizontal; + /** Constructor */ public TankWidget() @@ -151,6 +154,7 @@ protected void defineProperties(final List> properties) properties.add(minimum = propMinimum.createProperty(this, 0.0)); properties.add(maximum = propMaximum.createProperty(this, 100.0)); properties.add(log_scale = propLogscale.createProperty(this, false)); + properties.add(horizontal = propHorizontal.createProperty(this, false)); } @Override @@ -221,4 +225,10 @@ public WidgetProperty propLogScale() { return log_scale; } + + /** @return 'horizontal' property */ + public WidgetProperty propHorizontal() + { + return horizontal; + } } diff --git a/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/TankRepresentation.java b/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/TankRepresentation.java index 8fec3a55d0..783a3b7246 100644 --- a/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/TankRepresentation.java +++ b/app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/TankRepresentation.java @@ -12,6 +12,7 @@ import org.csstudio.display.builder.model.DirtyFlag; import org.csstudio.display.builder.model.UntypedWidgetPropertyListener; import org.csstudio.display.builder.model.WidgetProperty; +import org.csstudio.display.builder.model.WidgetPropertyListener; import org.csstudio.display.builder.model.util.VTypeUtil; import org.csstudio.display.builder.model.widgets.TankWidget; import org.csstudio.display.builder.representation.Preferences; @@ -21,6 +22,8 @@ import org.epics.vtype.VType; import javafx.scene.layout.Pane; +import javafx.scene.transform.Rotate; +import javafx.scene.transform.Translate; /** Creates JavaFX item for model widget * @author Kay Kasemir @@ -30,6 +33,7 @@ public class TankRepresentation extends RegionBaseRepresentation orientationChangedListener = this::orientationChanged; private volatile RTTank tank; @@ -59,6 +63,7 @@ protected void registerListeners() model_widget.propMaximum().addUntypedPropertyListener(valueListener); model_widget.propLogScale().addUntypedPropertyListener(valueListener); model_widget.runtimePropValue().addUntypedPropertyListener(valueListener); + model_widget.propHorizontal().addPropertyListener(orientationChangedListener); valueChanged(null, null, null); } @@ -79,6 +84,7 @@ protected void unregisterListeners() model_widget.propMaximum().removePropertyListener(valueListener); model_widget.propLogScale().removePropertyListener(valueListener); model_widget.runtimePropValue().removePropertyListener(valueListener); + model_widget.propHorizontal().removePropertyListener(orientationChangedListener); super.unregisterListeners(); } @@ -117,6 +123,17 @@ private void valueChanged(final WidgetProperty property, final Object old_val tank.setLogScale(model_widget.propLogScale().getValue()); } + private void orientationChanged(final WidgetProperty prop, final Boolean old, final Boolean horizontal) + { + if (toolkit.isEditMode()) { + final int w = model_widget.propWidth().getValue(); + final int h = model_widget.propHeight().getValue(); + model_widget.propWidth().setValue(h); + model_widget.propHeight().setValue(w); + } + lookChanged(prop, old, horizontal); + } + @Override public void updateChanges() { @@ -125,9 +142,23 @@ public void updateChanges() { double width = model_widget.propWidth().getValue(); double height = model_widget.propHeight().getValue(); - jfx_node.setPrefSize(width, height); - tank.setWidth(width); - tank.setHeight(height); + boolean horizontal = model_widget.propHorizontal().getValue(); + if (horizontal) + { + jfx_node.getTransforms().setAll( + new Translate(width, 0), + new Rotate(90, 0, 0)); + jfx_node.setPrefSize(height, width); + tank.setWidth(height); + tank.setHeight(width); + } + else + { + jfx_node.getTransforms().clear(); + jfx_node.setPrefSize(width, height); + tank.setWidth(width); + tank.setHeight(height); + } tank.setFont(JFXUtil.convert(model_widget.propFont().getValue())); tank.setBackground(JFXUtil.convert(model_widget.propBackground().getValue())); tank.setForeground(JFXUtil.convert(model_widget.propForeground().getValue()));