Search in sources :

Example 1 with WidgetFont

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);
    }
}
Also used : Insets(javafx.geometry.Insets) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) WidgetFont(org.csstudio.display.builder.model.properties.WidgetFont) Style(org.csstudio.display.builder.model.widgets.GroupWidget.Style) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BorderStroke(javafx.scene.layout.BorderStroke) Border(javafx.scene.layout.Border)

Example 2 with WidgetFont

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));
}
Also used : LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) WidgetFont(org.csstudio.display.builder.model.properties.WidgetFont) NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont) NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont) Test(org.junit.Test)

Aggregations

WidgetFont (org.csstudio.display.builder.model.properties.WidgetFont)2 Insets (javafx.geometry.Insets)1 Background (javafx.scene.layout.Background)1 BackgroundFill (javafx.scene.layout.BackgroundFill)1 Border (javafx.scene.layout.Border)1 BorderStroke (javafx.scene.layout.BorderStroke)1 BorderStrokeStyle (javafx.scene.layout.BorderStrokeStyle)1 NamedWidgetFont (org.csstudio.display.builder.model.properties.NamedWidgetFont)1 Style (org.csstudio.display.builder.model.widgets.GroupWidget.Style)1 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)1 Test (org.junit.Test)1