use of org.csstudio.display.builder.model.properties.WidgetFont in project org.csstudio.display.builder by kasemir.
the class GroupRepresentation method updateChanges.
@Override
public void updateChanges() {
super.updateChanges();
if (dirty_border.checkAndClear()) {
if (model_widget.propTransparent().getValue()) {
jfx_node.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null)));
} else {
jfx_node.setBackground(new Background(new BackgroundFill(background_color, null, null)));
}
final WidgetFont font = model_widget.propFont().getValue();
label.setFont(JFXUtil.convert(font));
label.setText(model_widget.propName().getValue());
final Style style = model_widget.propStyle().getValue();
int x = model_widget.propX().getValue();
int y = model_widget.propY().getValue();
int width = model_widget.propWidth().getValue();
int height = model_widget.propHeight().getValue();
// Reset position and size as if style == Style.NONE.
int[] insets = new int[4];
System.arraycopy(model_widget.runtimePropInsets().getValue(), 0, insets, 0, insets.length);
boolean hasChildren = !model_widget.runtimeChildren().getValue().isEmpty();
if (hasChildren) {
inner.relocate(-insets[0], -insets[1]);
x += insets[0];
y += insets[1];
width -= insets[2];
height -= insets[3];
}
switch(style) {
case NONE:
{
inset = 0;
insets[0] = 0;
insets[1] = 0;
insets[2] = 0;
insets[3] = 0;
// handle the totally invisible group
if (toolkit.isEditMode()) {
jfx_node.setBorder(new Border(new BorderStroke(foreground_color, EDTI_NONE_DASHED, CornerRadii.EMPTY, EDTI_NONE_BORDER)));
} else {
jfx_node.setBorder(null);
}
label.setVisible(false);
break;
}
case LINE:
{
inset = 0;
insets[0] = BORDER_WIDTH;
insets[1] = BORDER_WIDTH;
insets[2] = 2 * insets[0];
insets[3] = 2 * insets[1];
jfx_node.setBorder(new Border(new BorderStroke(foreground_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
label.setVisible(false);
break;
}
case TITLE:
{
inset = 2 + (int) (1.2 * font.getSize());
insets[0] = BORDER_WIDTH;
insets[1] = inset + BORDER_WIDTH;
insets[2] = 2 * insets[0];
insets[3] = insets[0] + insets[1];
jfx_node.setBorder(new Border(new BorderStroke(foreground_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
label.setVisible(true);
label.relocate(0, BORDER_WIDTH);
label.setPadding(TITLE_PADDING);
label.setPrefSize(width + ((!firstUpdate && hasChildren) ? insets[2] : 0), inset);
label.setTextFill(background_color);
label.setBackground(new Background(new BackgroundFill(foreground_color, CornerRadii.EMPTY, Insets.EMPTY)));
break;
}
case GROUP:
default:
{
inset = 2 + (int) (1.2 * font.getSize());
insets[0] = inset;
insets[1] = inset;
insets[2] = 2 * insets[0];
insets[3] = 2 * insets[1];
jfx_node.setBorder(new Border(new BorderStroke(foreground_color, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT, new Insets(inset / 2))));
label.setVisible(true);
label.relocate(inset, 0);
label.setPadding(TITLE_PADDING);
label.setPrefSize(Label.USE_COMPUTED_SIZE, Label.USE_COMPUTED_SIZE);
label.setTextFill(foreground_color);
label.setBackground(new Background(new BackgroundFill(background_color, CornerRadii.EMPTY, Insets.EMPTY)));
break;
}
}
inner.relocate(insets[0], insets[1]);
model_widget.runtimePropInsets().setValue(insets);
if (firstUpdate) {
firstUpdate = false;
} else if (hasChildren) {
x -= insets[0];
y -= insets[1];
width += insets[2];
height += insets[3];
model_widget.propX().setValue(x);
model_widget.propY().setValue(y);
model_widget.propWidth().setValue(width);
model_widget.propHeight().setValue(height);
}
jfx_node.relocate(x, y);
jfx_node.setPrefSize(width, height);
}
}
use of org.csstudio.display.builder.model.properties.WidgetFont in project org.csstudio.display.builder by kasemir.
the class ClassSupportUnitTest method testPropertyUpdates.
@Test
public void testPropertyUpdates() throws Exception {
final WidgetClassSupport widget_classes = getExampleClasses();
final LabelWidget widget = new LabelWidget();
assertThat(widget.getWidgetClass(), equalTo(WidgetClassSupport.DEFAULT));
assertThat(widget.propFont().isUsingWidgetClass(), equalTo(false));
// Original, default font of Label
WidgetFont value = widget.propFont().getValue();
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont orig_font = (NamedWidgetFont) value;
System.out.println("Original font: " + orig_font);
// TITLE class -> widget now using a different font
widget.propClass().setValue("TITLE");
widget_classes.apply(widget);
value = widget.propFont().getValue();
System.out.println("TITLE class font: " + value);
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont title_font = (NamedWidgetFont) value;
assertThat(title_font.getName(), not(equalTo(orig_font.getName())));
// COMMENT class -> widget now using a different font
widget.propClass().setValue("COMMENT");
widget_classes.apply(widget);
value = widget.propFont().getValue();
System.out.println("COMMENT class font: " + value);
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont comment_font = (NamedWidgetFont) value;
assertThat(comment_font.getName(), not(equalTo(orig_font.getName())));
assertThat(comment_font.getName(), not(equalTo(title_font.getName())));
assertThat(widget.propFont().isUsingWidgetClass(), equalTo(true));
// DEFAULT class -> stays with the last fone, but no longer 'is using class'
widget.propClass().setValue("DEFAULT");
widget_classes.apply(widget);
value = widget.propFont().getValue();
System.out.println("DEFAULT class font: " + value);
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont default_font = (NamedWidgetFont) value;
assertThat(default_font, equalTo(comment_font));
assertThat(widget.propFont().isUsingWidgetClass(), equalTo(false));
}
Aggregations