Search in sources :

Example 11 with LabelWidget

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

the class ClassSupportUnitTest method testUsingWidgetClass.

@Test
public void testUsingWidgetClass() {
    // Default behavior
    final Widget widget = new LabelWidget();
    assertThat(widget.getProperty("text").isUsingWidgetClass(), equalTo(false));
    assertThat(widget.getProperty("font").isUsingWidgetClass(), equalTo(false));
    // Can be changed
    widget.getProperty("text").useWidgetClass(true);
    assertThat(widget.getProperty("text").isUsingWidgetClass(), equalTo(true));
}
Also used : LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Test(org.junit.Test)

Example 12 with LabelWidget

use of org.csstudio.display.builder.model.widgets.LabelWidget 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 13 with LabelWidget

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

Aggregations

LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)13 Test (org.junit.Test)8 DisplayModel (org.csstudio.display.builder.model.DisplayModel)6 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 ChoiceDialog (javafx.scene.control.ChoiceDialog)2 Dragboard (javafx.scene.input.Dragboard)2 Widget (org.csstudio.display.builder.model.Widget)2 ScriptPV (org.csstudio.display.builder.model.properties.ScriptPV)2 RuleInfo (org.csstudio.display.builder.model.rules.RuleInfo)2 EmbeddedDisplayWidget (org.csstudio.display.builder.model.widgets.EmbeddedDisplayWidget)2 PictureWidget (org.csstudio.display.builder.model.widgets.PictureWidget)2 WebBrowserWidget (org.csstudio.display.builder.model.widgets.WebBrowserWidget)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 RenderingHints (java.awt.RenderingHints)1