Skip to content

Commit

Permalink
Merge pull request #2362 from baham4s/#2275
Browse files Browse the repository at this point in the history
#2275 : add horizontal property to widget Tank
  • Loading branch information
kasemir authored Aug 19, 2022
2 parents 844fcf6 + 4e9882f commit 2b9ea45
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,6 +131,8 @@ public WidgetConfigurator getConfigurator(final Version persisted_version)
private volatile WidgetProperty<Double> minimum;
private volatile WidgetProperty<Double> maximum;
private volatile WidgetProperty<Boolean> log_scale;
private volatile WidgetProperty<Boolean> horizontal;


/** Constructor */
public TankWidget()
Expand All @@ -151,6 +154,7 @@ protected void defineProperties(final List<WidgetProperty<?>> 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
Expand Down Expand Up @@ -221,4 +225,10 @@ public WidgetProperty<Boolean> propLogScale()
{
return log_scale;
}

/** @return 'horizontal' property */
public WidgetProperty<Boolean> propHorizontal()
{
return horizontal;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -30,6 +33,7 @@ public class TankRepresentation extends RegionBaseRepresentation<Pane, TankWidge
private final DirtyFlag dirty_look = new DirtyFlag();
private final UntypedWidgetPropertyListener lookListener = this::lookChanged;
private final UntypedWidgetPropertyListener valueListener = this::valueChanged;
private final WidgetPropertyListener<Boolean> orientationChangedListener = this::orientationChanged;

private volatile RTTank tank;

Expand Down Expand Up @@ -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);
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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<Boolean> 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()
{
Expand All @@ -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()));
Expand Down

0 comments on commit 2b9ea45

Please sign in to comment.