Search in sources :

Example 1 with Style

use of org.csstudio.display.builder.model.widgets.GroupWidget.Style 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)

Aggregations

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 WidgetFont (org.csstudio.display.builder.model.properties.WidgetFont)1 Style (org.csstudio.display.builder.model.widgets.GroupWidget.Style)1