Skip to content

Commit 40dd5e4

Browse files
authored
Merge pull request #3868 from rjwills28/rotated_label_in_group_bug
Rotated Label causes Group widget to extend further than it should
2 parents 10bab6f + 12fcf4d commit 40dd5e4

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

  • app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/widgets/LabelRepresentation.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*******************************************************************************/
88
package org.csstudio.display.builder.representation.javafx.widgets;
99

10+
import javafx.scene.layout.Pane;
1011
import org.csstudio.display.builder.model.DirtyFlag;
1112
import org.csstudio.display.builder.model.UntypedWidgetPropertyListener;
1213
import org.csstudio.display.builder.model.WidgetProperty;
@@ -32,13 +33,14 @@
3233
* @author Kay Kasemir
3334
*/
3435
@SuppressWarnings("nls")
35-
public class LabelRepresentation extends RegionBaseRepresentation<Label, LabelWidget>
36+
public class LabelRepresentation extends RegionBaseRepresentation<Pane, LabelWidget>
3637
{
3738
private final DirtyFlag dirty_style = new DirtyFlag();
3839
private final DirtyFlag dirty_content = new DirtyFlag();
3940
private final UntypedWidgetPropertyListener contentChangedListener = this::contentChanged;
4041
private final UntypedWidgetPropertyListener styleChangedListener = this::styleChanged;
4142
private volatile Pos pos;
43+
private Label label;
4244

4345
/** Was there ever any transformation applied to the jfx_node?
4446
*
@@ -49,11 +51,11 @@ public class LabelRepresentation extends RegionBaseRepresentation<Label, LabelWi
4951
private boolean was_ever_transformed = false;
5052

5153
@Override
52-
public Label createJFXNode() throws Exception
54+
public Pane createJFXNode() throws Exception
5355
{
54-
final Label label = new Label();
56+
label = new Label();
5557
label.getStyleClass().add("text_update");
56-
return label;
58+
return new Pane(label);
5759
}
5860

5961
@Override
@@ -119,7 +121,7 @@ public void updateChanges()
119121
if (dirty_content.checkAndClear())
120122
{
121123
final String text = model_widget.propText().getValue();
122-
jfx_node.setText(text);
124+
label.setText(text);
123125
if (model_widget.propAutoSize().getValue())
124126
{
125127
final Dimension2D size = TextUtils.computeTextSize(JFXUtil.convert(model_widget.propFont().getValue()), text);
@@ -140,48 +142,52 @@ public void updateChanges()
140142
jfx_node.setPrefSize(width, height);
141143
jfx_node.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
142144
jfx_node.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
145+
label.setPrefSize(width, height);
143146
if (was_ever_transformed)
144-
jfx_node.getTransforms().clear();
147+
label.getTransforms().clear();
145148
break;
146149
case NINETY:
147-
jfx_node.setPrefSize(height, width);
150+
jfx_node.setPrefSize(width, height);
148151
jfx_node.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
149152
jfx_node.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
150-
jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()),
153+
label.setPrefSize(height, width);
154+
label.getTransforms().setAll(new Rotate(-rotation.getAngle()),
151155
new Translate(-height, 0));
152156
was_ever_transformed = true;
153157
break;
154158
case ONEEIGHTY:
155159
jfx_node.setPrefSize(width, height);
156160
jfx_node.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
157161
jfx_node.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
158-
jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()),
162+
label.setPrefSize(width, height);
163+
label.getTransforms().setAll(new Rotate(-rotation.getAngle()),
159164
new Translate(-width, -height));
160165
was_ever_transformed = true;
161166
break;
162167
case MINUS_NINETY:
163-
jfx_node.setPrefSize(height, width);
168+
jfx_node.setPrefSize(width, height);
164169
jfx_node.setMinSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
165170
jfx_node.setMaxSize(Control.USE_PREF_SIZE, Control.USE_PREF_SIZE);
166-
jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()),
171+
label.setPrefSize(height, width);
172+
label.getTransforms().setAll(new Rotate(-rotation.getAngle()),
167173
new Translate(0, -width));
168174
was_ever_transformed = true;
169175
break;
170176
}
171-
jfx_node.setAlignment(pos);
172-
jfx_node.setTextAlignment(TextAlignment.values()[model_widget.propHorizontalAlignment().getValue().ordinal()]);
173-
jfx_node.setWrapText(model_widget.propWrapWords().getValue());
177+
label.setAlignment(pos);
178+
label.setTextAlignment(TextAlignment.values()[model_widget.propHorizontalAlignment().getValue().ordinal()]);
179+
label.setWrapText(model_widget.propWrapWords().getValue());
174180

175181
Color color = JFXUtil.convert(model_widget.propForegroundColor().getValue());
176-
jfx_node.setTextFill(color);
182+
label.setTextFill(color);
177183
if (model_widget.propTransparent().getValue())
178-
jfx_node.setBackground(null); // No fill
184+
label.setBackground(null); // No fill
179185
else
180186
{ // Fill background
181187
color = JFXUtil.convert(model_widget.propBackgroundColor().getValue());
182-
jfx_node.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
188+
label.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
183189
}
184-
jfx_node.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
190+
label.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
185191
}
186192
}
187193
}

0 commit comments

Comments
 (0)