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));
}
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
}
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));
}
Aggregations