Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
*******************************************************************************/
package org.csstudio.display.builder.representation.javafx.widgets;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.Skin;
import javafx.scene.control.Slider;
import javafx.scene.control.skin.SliderSkin;
import javafx.scene.input.KeyEvent;
Expand All @@ -37,7 +39,6 @@

import java.text.DecimalFormat;
import java.time.Instant;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import static org.csstudio.display.builder.representation.ToolkitRepresentation.logger;
Expand Down Expand Up @@ -75,14 +76,12 @@
private final Slider slider;
private final SliderMarkers markers;

private final AtomicBoolean isHorizontal = new AtomicBoolean(true);

private static final double THUMB_PADDING_DEFAULT = 7.6;
private static final double THUMB_PADDING_MAX = 20.0;
private static final double THUMB_SCALING_FACTOR = 0.3;
private static final double THUMB_SCALING_FACTOR = 0.16;
private static final double TRACK_PADDING_DEFAULT = 3.3;
private static final double TRACK_PADDING_MAX = 13.0;
private static final double TRACK_SCALING_FACTOR = 0.2;
private static final double TRACK_SCALING_FACTOR = 0.1;
private static final double MAJOR_TICK_LENGTH_DEFAULT = 8.0;
private static final double MAJOR_TICK_LENGTH_MAX = 20.0;
private static final double MAJOR_TICK_LENGTH_SCALING_FACTOR = 0.1;
Expand Down Expand Up @@ -137,6 +136,9 @@
// expensive Node.notifyParentOfBoundsChange() recursing up the scene graph
pane.setManaged(false);

// Adjust sizes when a skin is available. Handles initial resizing of slider UI elements.
slider.skinProperty().addListener(new SkinChangeListener());

return pane;
}

Expand Down Expand Up @@ -247,7 +249,6 @@
model_widget.propWidth().setValue(h);
model_widget.propHeight().setValue(w);
}
isHorizontal.set(horizontal);
layoutChanged(prop, old, horizontal);
}

Expand Down Expand Up @@ -534,6 +535,8 @@

if (any_markers)
markers.setAlarmMarkers(lolo, low, high, hihi);

adjustSizes();
}
if (dirty_value.checkAndClear())
{
Expand Down Expand Up @@ -569,7 +572,6 @@
}
}

adjustSizes();
jfx_node.layout();
}

Expand All @@ -595,24 +597,40 @@
* </p>
*/
private void adjustSizes(){
SliderSkin skin = (SliderSkin) slider.getSkin();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this line? You are now calling this method twice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this a bit. In general avoiding explicit cast if not necessary.

if (skin == null) {

Skin<?> skin = slider.getSkin();
if(skin == null){
return;
}
double size = isHorizontal.get() ? jfx_node.getHeight() : jfx_node.getWidth();
for (Node node : skin.getChildren()) {

double size = model_widget.propHorizontal().getValue() ?

Check warning on line 606 in app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/ScaledSliderRepresentation.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a primitive boolean expression here.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ9aeYNs7Ck9GhP6A6e0&open=AZ9aeYNs7Ck9GhP6A6e0&pullRequest=3881
jfx_node.getHeight() :
jfx_node.getWidth();

for (Node node : ((SliderSkin) skin).getChildren()) {
if (node.getStyleClass().contains("thumb")) {
node.setStyle("-fx-padding: " + Math.clamp(size * THUMB_SCALING_FACTOR,
THUMB_PADDING_DEFAULT,
THUMB_PADDING_MAX));
THUMB_PADDING_DEFAULT, THUMB_PADDING_MAX));
} else if (node.getStyleClass().contains("track")) {
node.setStyle("-fx-padding: " + Math.clamp(size * TRACK_SCALING_FACTOR,
TRACK_PADDING_DEFAULT,
TRACK_PADDING_MAX));
TRACK_PADDING_DEFAULT, TRACK_PADDING_MAX));
} else if (node.getStyleClass().contains("axis")) {
node.setStyle("-fx-tick-length: " + Math.clamp(size * MAJOR_TICK_LENGTH_SCALING_FACTOR,
MAJOR_TICK_LENGTH_DEFAULT,
MAJOR_TICK_LENGTH_MAX));
MAJOR_TICK_LENGTH_DEFAULT, MAJOR_TICK_LENGTH_MAX));
}
}
}

/**
* Custom {@link ChangeListener} for the purpose of setting slider sizes once there is a {@link Skin}
* available to manipulate.
*/
private class SkinChangeListener implements ChangeListener<Skin<?>>{
@Override
public void changed(ObservableValue<? extends Skin<?>> observableValue, Skin<?> oldValue, Skin<?> newValue) {
if(oldValue == null && newValue != null){
Comment thread
jacomago marked this conversation as resolved.
adjustSizes();
slider.skinProperty().removeListener(this);
}
}
}
Expand Down
Loading