Search in sources :

Example 71 with DisplayModel

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

the class PersistenceUnitTest method testWidgetReading.

/**
 * Read widgets from XML
 *  @throws Exception on error
 */
@Test
public void testWidgetReading() throws Exception {
    final String xml = getExampleFile();
    final InputStream stream = new ByteArrayInputStream(xml.getBytes());
    final ModelReader reader = new ModelReader(stream);
    final DisplayModel model = reader.readModel();
    final List<Widget> widgets = model.getChildren();
    for (final Widget widget : widgets) {
        System.out.println(widget);
        System.out.println(widget.getProperties().stream().map(Object::toString).collect(Collectors.joining("\n")));
    }
    assertThat(widgets.size(), equalTo(2));
    final List<String> names = widgets.stream().map(Widget::getName).collect(Collectors.toList());
    assertThat(names, equalTo(Arrays.asList("Demo", "My Group")));
    assertThat(widgets.get(1), instanceOf(GroupWidget.class));
    assertThat(((GroupWidget) widgets.get(1)).runtimeChildren().getValue().get(0).getName(), equalTo("Jänner"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CustomWidget(org.csstudio.display.builder.model.CustomWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) Widget(org.csstudio.display.builder.model.Widget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) WidgetFactoryUnitTest(org.csstudio.display.builder.model.WidgetFactoryUnitTest) Test(org.junit.Test)

Example 72 with DisplayModel

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

the class PersistenceUnitTest method testClassSupportPersistence.

@Test
public void testClassSupportPersistence() throws Exception {
    // By default, Label font does not use class
    final DisplayModel model = new DisplayModel();
    final LabelWidget label = new LabelWidget();
    assertThat(label.propFont().isUsingWidgetClass(), equalTo(false));
    label.propFont().setValue(new NamedWidgetFont("TEST", "Sans", WidgetFontStyle.REGULAR, 10.0));
    model.runtimeChildren().addChild(label);
    String xml = toXML(model);
    System.out.println(xml);
    assertThat(xml, containsString("display version=\"2"));
    assertThat(xml, containsString("font>"));
    DisplayModel readback = ModelReader.parseXML(xml);
    assertThat(readback.getChildren().get(0).getProperty("font").isUsingWidgetClass(), equalTo(false));
    // "use_class" is persisted in XML and read back
    label.propFont().useWidgetClass(true);
    xml = toXML(model);
    System.out.println(xml);
    assertThat(xml, containsString("font use_class=\"true\""));
    readback = ModelReader.parseXML(xml);
    assertThat(readback.getChildren().get(0).getProperty("font").isUsingWidgetClass(), equalTo(true));
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WidgetFactoryUnitTest(org.csstudio.display.builder.model.WidgetFactoryUnitTest) Test(org.junit.Test)

Example 73 with DisplayModel

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

the class ModelLoader method loadModel.

/**
 * Load model, with classes applied (except for *.bcf itself)
 *
 *  @param display_file Model file
 *  @return {@link DisplayModel}
 *  @throws Exception on error
 */
public static DisplayModel loadModel(final InputStream stream, final String display_path) throws Exception {
    final ModelReader reader = new ModelReader(stream);
    final DisplayModel model = reader.readModel();
    model.setUserData(DisplayModel.USER_DATA_INPUT_FILE, display_path);
    // Models from version 2 on support classes
    if (reader.getVersion().getMajor() >= 2 && !display_path.endsWith(WidgetClassSupport.FILE_EXTENSION)) {
        WidgetClassesService.getWidgetClasses().apply(model);
    }
    return model;
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel)

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