Search in sources :

Example 41 with DisplayModel

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

the class WidgetTransfer method installEmbeddedDisplayWidgetFromFile.

/**
 * @param display_file Display file for which to create an
 *            {@link EmbeddedDisplayWidget}.
 * @param selection_tracker Used to get the grid steps from its model to be
 *            used
 *            in offsetting multiple widgets.
 * @param widgets The container of the created widgets.
 * @param updates Updates to perform on widgets
 */
private static void installEmbeddedDisplayWidgetFromFile(final String display_file, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates) {
    logger.log(Level.FINE, "Creating EmbeddedDisplayWidget for {0}", display_file);
    final DisplayModel model = selection_tracker.getModel();
    final EmbeddedDisplayWidget widget = (EmbeddedDisplayWidget) EmbeddedDisplayWidget.WIDGET_DESCRIPTOR.createWidget();
    widget.propFile().setValue(display_file);
    // Offset multiple widgets by grid size
    final int index = widgets.size();
    widget.propX().setValue(model.propGridStepX().getValue() * index);
    widget.propY().setValue(model.propGridStepY().getValue() * index);
    widgets.add(widget);
    updates.add(() -> updateEmbeddedDisplayWidget(widget));
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayWidget(org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)

Example 42 with DisplayModel

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

the class WidgetTransfer method updateEmbeddedDisplayWidget.

/**
 * Update an embedded widget's name and size from its input
 *
 * @param widget {@link EmbeddedDisplayWidget}
 */
private static void updateEmbeddedDisplayWidget(final EmbeddedDisplayWidget widget) {
    final String display_file = widget.propFile().getValue();
    final String resolved;
    try {
        resolved = ModelResourceUtil.resolveResource(widget.getTopDisplayModel(), display_file);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Cannot resolve resource " + display_file, ex);
        return;
    }
    try (final InputStream bis = ModelResourceUtil.openResourceStream(resolved)) {
        final ModelReader reader = new ModelReader(bis);
        final DisplayModel embedded_model = reader.readModel();
        final String name = embedded_model.getName();
        if (!name.isEmpty()) {
            widget.propName().setValue(name);
        }
        widget.propWidth().setValue(embedded_model.propWidth().getValue());
        widget.propHeight().setValue(embedded_model.propHeight().getValue());
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error updating embedded widget", ex);
    }
}
Also used : ModelReader(org.csstudio.display.builder.model.persist.ModelReader) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 43 with DisplayModel

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

the class WidgetTransfer method installPictureWidgetFromFile.

/**
 * @param image_file The image file used to create and preset a {@link PictureWidget}.
 * @param selection_tracker Used to get the grid steps from its model to be
 *            used in offsetting multiple widgets.
 * @param widgets The container of the created widgets.
 * @param updates Updates to perform on widgets
 */
private static void installPictureWidgetFromFile(final String image_file, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets, final List<Runnable> updates) {
    logger.log(Level.FINE, "Creating PictureWidget for dropped image {0}", image_file);
    final DisplayModel model = selection_tracker.getModel();
    final PictureWidget widget = (PictureWidget) PictureWidget.WIDGET_DESCRIPTOR.createWidget();
    widget.propFile().setValue(image_file);
    final int index = widgets.size();
    widget.propX().setValue(model.propGridStepX().getValue() * index);
    widget.propY().setValue(model.propGridStepY().getValue() * index);
    widgets.add(widget);
    updates.add(() -> updatePictureWidgetSize(widget));
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) PictureWidget(org.csstudio.display.builder.model.widgets.PictureWidget)

Example 44 with DisplayModel

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

the class MacroHierarchyUnitTest method testMacroHierarchy.

/**
 * Test Macro Hierarchy
 *  @throws Exception on error
 */
@Test
public void testMacroHierarchy() throws Exception {
    // Macros start out empty
    MacroValueProvider macros = new Macros();
    System.out.println(macros);
    assertThat(macros.toString(), equalTo("[]"));
    // Preferences (at least in test setup where there is no preferences service)
    macros = Preferences.getMacros();
    System.out.println(macros);
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Preferences"));
    // Display model uses preferences
    final DisplayModel model = new DisplayModel();
    macros = model.getEffectiveMacros();
    System.out.println(macros);
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Preferences"));
    // .. but display can replace this value
    model.propMacros().getValue().add("EXAMPLE_MACRO", "Value from Display");
    macros = model.getEffectiveMacros();
    System.out.println(macros);
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Display"));
    // Similar, groups can replace macros
    final LabelWidget child = new LabelWidget();
    final GroupWidget group2 = new GroupWidget();
    group2.propMacros().getValue().add("EXAMPLE_MACRO", "In Group 2");
    group2.runtimeChildren().addChild(child);
    final GroupWidget group1 = new GroupWidget();
    group1.propMacros().getValue().add("EXAMPLE_MACRO", "In Group 1");
    group1.runtimeChildren().addChild(group2);
    model.runtimeChildren().addChild(group1);
    macros = group1.getEffectiveMacros();
    System.out.println(macros);
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("In Group 1"));
    macros = group2.getEffectiveMacros();
    System.out.println(macros);
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("In Group 2"));
    macros = child.getEffectiveMacros();
    System.out.println(macros);
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("In Group 2"));
// Finally, the EmbeddedDisplayWidget can replace macros,
// but testing that requires the runtime to load the embedded content
// --> Leaving that to examples/macros
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Test(org.junit.Test)

Example 45 with DisplayModel

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

the class MacroHierarchyUnitTest method testPropertiesAndEnvironment.

/**
 * Test access to widget properties, Java properties and environment
 *  @throws Exception on error
 */
@Test
public void testPropertiesAndEnvironment() throws Exception {
    // Display model uses preferences
    final DisplayModel model = new DisplayModel();
    MacroValueProvider macros = model.getEffectiveMacros();
    assertThat(macros.getValue("EXAMPLE_MACRO"), equalTo("Value from Preferences"));
    // Can also fall back to widget properties
    assertThat(macros.getValue("type"), nullValue());
    macros = model.getMacrosOrProperties();
    String value = macros.getValue("type");
    assertThat(value, equalTo("display"));
    // Check fall back to Java properties
    value = macros.getValue("os.name");
    System.out.println("Java property os.name: " + value);
    assertThat(value, not(nullValue()));
    // Check fall back to environment variables
    value = macros.getValue("HOME");
    System.out.println("Environment variable $HOME: " + value);
    assertThat(value, not(nullValue()));
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) Test(org.junit.Test)

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