Search in sources :

Example 6 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentation method backgroundChanged.

private void backgroundChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final DisplayModel content_model = active_content_model.get();
    if (model_widget.propTransparent().getValue()) {
        inner_background = TRANSPARENT_BACKGROUND;
        // Reinstall the frame in edit mode. Scroll is unusable, so make it with inner
        if (toolkit.isEditMode())
            inner_border = EDIT_BORDER;
    } else {
        if (content_model == null)
            inner_background = Background.EMPTY;
        else
            inner_background = new Background(new BackgroundFill(JFXUtil.convert(content_model.propBackgroundColor().getValue()), CornerRadii.EMPTY, Insets.EMPTY));
        // TODO Haven't found perfect way to set the 'background' color
        // of the embedded content.
        // Setting the 'inner' background will sometimes leave a gray section in the right and or bottom edge
        // of the embedded content if the container is (much) larger than the content
        // The scroll pane background can only be set via style,
        // and then shines through on the outside of the scrollbars
        // scroll.setStyle("-fx-control-inner-background: " + JFXUtil.webRGB(content_model.propBackgroundColor().getValue()) +
        // "; -fx-background: " + JFXUtil.webRGB(content_model.propBackgroundColor().getValue()));
        inner_border = Border.EMPTY;
    }
    dirty_background.mark();
    toolkit.scheduleUpdate(this);
}
Also used : Background(javafx.scene.layout.Background) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel) BackgroundFill(javafx.scene.layout.BackgroundFill)

Example 7 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class ExampleModels method createModel.

/**
 * @return {@link DisplayModel}
 */
public static DisplayModel createModel() {
    final DisplayModel model = new DisplayModel();
    model.setPropertyValue(CommonWidgetProperties.propWidth, 1400);
    model.setPropertyValue(CommonWidgetProperties.propHeight, 20 * 50);
    for (int i = 0; i < 200; ++i) {
        final int x = 0 + (i / 20) * 132;
        final int y = 0 + (i % 20) * 50;
        final GroupWidget group = new GroupWidget();
        group.setPropertyValue(CommonWidgetProperties.propName, "Group " + i);
        group.setPropertyValue(CommonWidgetProperties.propX, x);
        group.setPropertyValue(CommonWidgetProperties.propY, y);
        group.setPropertyValue(CommonWidgetProperties.propWidth, 125);
        group.setPropertyValue(CommonWidgetProperties.propHeight, 53);
        final LabelWidget label = new LabelWidget();
        label.setPropertyValue(CommonWidgetProperties.propName, "Label " + i);
        label.setPropertyValue(CommonWidgetProperties.propX, 0);
        label.setPropertyValue(CommonWidgetProperties.propY, 4);
        label.setPropertyValue(CommonWidgetProperties.propWidth, 15);
        label.setPropertyValue(CommonWidgetProperties.propHeight, 15);
        label.setPropertyValue(CommonWidgetProperties.propText, Integer.toString(i));
        group.runtimeChildren().addChild(label);
        // For SWT implementation, rect. is not 'transparent',
        // so needs to be behind text
        final RectangleWidget rect = new RectangleWidget();
        rect.setPropertyValue(CommonWidgetProperties.propName, "Rect " + i);
        rect.setPropertyValue(CommonWidgetProperties.propX, 10);
        rect.setPropertyValue(CommonWidgetProperties.propY, 0);
        rect.setPropertyValue(CommonWidgetProperties.propWidth, 80);
        rect.setPropertyValue(CommonWidgetProperties.propHeight, 19);
        rect.setPropertyValue(CommonWidgetProperties.propScripts, Arrays.asList(new ScriptInfo("../org.csstudio.display.builder.runtime.test/examples/fudge_width.py", true, new ScriptPV("noise"))));
        group.runtimeChildren().addChild(rect);
        final TextUpdateWidget text = new TextUpdateWidget();
        text.setPropertyValue(CommonWidgetProperties.propName, "Text " + i);
        text.setPropertyValue(CommonWidgetProperties.propX, 30);
        text.setPropertyValue(CommonWidgetProperties.propY, 4);
        text.setPropertyValue(CommonWidgetProperties.propWidth, 45);
        text.setPropertyValue(CommonWidgetProperties.propHeight, 15);
        text.setPropertyValue(CommonWidgetProperties.propPVName, "ramp");
        group.runtimeChildren().addChild(text);
        model.runtimeChildren().addChild(group);
    }
    return model;
}
Also used : RectangleWidget(org.csstudio.display.builder.model.widgets.RectangleWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget)

Example 8 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class ExampleModels method main.

public static void main(String[] args) throws Exception {
    final DisplayModel model = createModel();
    final ModelWriter writer = new ModelWriter(new FileOutputStream("example.opi"));
    try {
        writer.writeModel(model);
    } finally {
        writer.close();
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) FileOutputStream(java.io.FileOutputStream) ModelWriter(org.csstudio.display.builder.model.persist.ModelWriter)

Example 9 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentationUtil method createErrorModel.

/**
 * @param message Error message
 *  @return DisplayModel that shows the message
 */
private static DisplayModel createErrorModel(final Widget model_widget, final String message) {
    final LabelWidget info = new LabelWidget();
    info.propText().setValue(message);
    info.propForegroundColor().setValue(WidgetColorService.getColor(NamedWidgetColors.ALARM_DISCONNECTED));
    // Size a little smaller than the widget to fill but not require scrollbars
    final int wid = model_widget.propWidth().getValue() - 2;
    final int hei = model_widget.propHeight().getValue() - 2;
    info.propWidth().setValue(wid);
    info.propHeight().setValue(hei);
    final DisplayModel error_model = new DisplayModel();
    error_model.propWidth().setValue(wid);
    error_model.propHeight().setValue(hei);
    error_model.runtimeChildren().addChild(info);
    error_model.setUserData(DisplayModel.USER_DATA_EMBEDDING_WIDGET, model_widget);
    return error_model;
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget)

Example 10 with DisplayModel

use of org.csstudio.display.builder.model.DisplayModel in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentationUtil method reduceDisplayModelToGroup.

/**
 * Reduce display model to content of one named group
 *  @param display_file Name of the display file
 *  @param model Model loaded from that file
 *  @param group_name Name of group to use
 */
private static void reduceDisplayModelToGroup(final Widget model_widget, final DisplayModel model, final DisplayAndGroup display_and_group) {
    final String group_name = display_and_group.getGroupName();
    final List<Widget> children = model.runtimeChildren().getValue();
    // Find all groups with desired name.
    // Could just loop to get the first matching group,
    // but finding all and logging them helps to debug displays.
    final List<Widget> groups = children.parallelStream().filter(child -> child instanceof GroupWidget && child.getName().equals(group_name)).collect(Collectors.toList());
    // Expect exactly one
    if (groups.size() != 1)
        logger.log(Level.WARNING, "Expected one group named '" + group_name + "' in '" + display_and_group.getDisplayFile() + "', found " + groups);
    // If no group found, use the complete display
    if (groups.size() <= 0)
        return;
    // Replace display with just the content of that group
    final GroupWidget group = (GroupWidget) groups.get(0);
    model.runtimeChildren().setValue(group.runtimeChildren().getValue());
    // Group model correction - use group background color, not the display background color
    model.propBackgroundColor().setValue(group.propBackgroundColor().getValue());
    // If the group is transparent, see if the embedding widget can also be
    if (group.propTransparent().getValue())
        model_widget.checkProperty(CommonWidgetProperties.propTransparent).ifPresent(trans -> trans.setValue(true));
    // Not removing children from 'group', since group will be GC'ed anyway.
    shrinkModelToWidgets(model);
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) TimeoutException(java.util.concurrent.TimeoutException) VisibleWidget(org.csstudio.display.builder.model.widgets.VisibleWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) Version(org.osgi.framework.Version) Collectors(java.util.stream.Collectors) ModelLoader(org.csstudio.display.builder.model.persist.ModelLoader) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Level(java.util.logging.Level) ToolkitRepresentation.logger(org.csstudio.display.builder.representation.ToolkitRepresentation.logger) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Future(java.util.concurrent.Future) WidgetColorService(org.csstudio.display.builder.model.persist.WidgetColorService) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) NavigationTabsWidget(org.csstudio.display.builder.model.widgets.NavigationTabsWidget) NamedWidgetColors(org.csstudio.display.builder.model.persist.NamedWidgetColors) VisibleWidget(org.csstudio.display.builder.model.widgets.VisibleWidget) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) NavigationTabsWidget(org.csstudio.display.builder.model.widgets.NavigationTabsWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget)

Aggregations

DisplayModel (org.csstudio.display.builder.model.DisplayModel)73 Widget (org.csstudio.display.builder.model.Widget)15 Test (org.junit.Test)10 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)9 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)7 EmbeddedDisplayRepresentationUtil.loadDisplayModel (org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)5 Image (javafx.scene.image.Image)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Parent (javafx.scene.Parent)3 Macros (org.csstudio.display.builder.model.macros.Macros)3 PictureWidget (org.csstudio.display.builder.model.widgets.PictureWidget)3 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 Rectangle2D (javafx.geometry.Rectangle2D)2 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)2 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)2 ModelWriter (org.csstudio.display.builder.model.persist.ModelWriter)2