use of org.csstudio.display.builder.model.widgets.LabelWidget in project org.csstudio.display.builder by kasemir.
the class ClassSupportUnitTest method testPropertyUpdates.
@Test
public void testPropertyUpdates() throws Exception {
final WidgetClassSupport widget_classes = getExampleClasses();
final LabelWidget widget = new LabelWidget();
assertThat(widget.getWidgetClass(), equalTo(WidgetClassSupport.DEFAULT));
assertThat(widget.propFont().isUsingWidgetClass(), equalTo(false));
// Original, default font of Label
WidgetFont value = widget.propFont().getValue();
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont orig_font = (NamedWidgetFont) value;
System.out.println("Original font: " + orig_font);
// TITLE class -> widget now using a different font
widget.propClass().setValue("TITLE");
widget_classes.apply(widget);
value = widget.propFont().getValue();
System.out.println("TITLE class font: " + value);
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont title_font = (NamedWidgetFont) value;
assertThat(title_font.getName(), not(equalTo(orig_font.getName())));
// COMMENT class -> widget now using a different font
widget.propClass().setValue("COMMENT");
widget_classes.apply(widget);
value = widget.propFont().getValue();
System.out.println("COMMENT class font: " + value);
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont comment_font = (NamedWidgetFont) value;
assertThat(comment_font.getName(), not(equalTo(orig_font.getName())));
assertThat(comment_font.getName(), not(equalTo(title_font.getName())));
assertThat(widget.propFont().isUsingWidgetClass(), equalTo(true));
// DEFAULT class -> stays with the last fone, but no longer 'is using class'
widget.propClass().setValue("DEFAULT");
widget_classes.apply(widget);
value = widget.propFont().getValue();
System.out.println("DEFAULT class font: " + value);
assertThat(value, instanceOf(NamedWidgetFont.class));
final NamedWidgetFont default_font = (NamedWidgetFont) value;
assertThat(default_font, equalTo(comment_font));
assertThat(widget.propFont().isUsingWidgetClass(), equalTo(false));
}
use of org.csstudio.display.builder.model.widgets.LabelWidget in project org.csstudio.display.builder by kasemir.
the class WidgetPropertyUnitTest method testMacroDefault.
@Test
public void testMacroDefault() {
// Widget with X position set to $(X), where that macro has the value 0
final DisplayModel display = new DisplayModel();
display.propMacros().getValue().add("X", "0");
final LabelWidget widget = new LabelWidget();
display.runtimeChildren().addChild(widget);
((MacroizedWidgetProperty<Integer>) widget.propX()).setSpecification("$(X)");
// The X position value matches the default
assertThat(widget.propX().getValue(), equalTo(0));
// .. but the property doesn't have the default value,
// i.e. it must be saved by the editor, since $(X) could
// in other invocation evaluate to anything but 0.
assertThat(widget.propX().isDefaultValue(), equalTo(false));
}
use of org.csstudio.display.builder.model.widgets.LabelWidget in project org.csstudio.display.builder by kasemir.
the class RulesTest method testColorRule.
/**
* Rule that uses color
*/
@Test
public void testColorRule() throws Exception {
final LabelWidget widget = new LabelWidget();
final WidgetProperty<WidgetColor> color = widget.propForegroundColor().clone();
color.setValue(new WidgetColor(1, 2, 3));
final RuleInfo rule = new RuleInfo("Color", "foreground_color", false, Arrays.asList(new RuleInfo.ExprInfoValue<WidgetColor>("pv0 > 10", color)), Arrays.asList(new ScriptPV("Whatever")));
System.out.println(rule);
final String script = RuleToScript.generatePy(widget, rule);
System.out.println(script);
// Script must create variables for colors
assertThat(script, containsString("colorVal"));
}
use of org.csstudio.display.builder.model.widgets.LabelWidget in project org.csstudio.display.builder by kasemir.
the class MacroHierarchyUnitTest method testTimeOfExpansion.
/**
* Test when macros get expanded
* @throws Exception on error
*/
@Test
public void testTimeOfExpansion() throws Exception {
// model -> group -> subgroup -> label
final DisplayModel model = new DisplayModel();
final GroupWidget group = new GroupWidget();
model.runtimeChildren().addChild(group);
final GroupWidget subgroup = new GroupWidget();
group.runtimeChildren().addChild(subgroup);
final LabelWidget label = new LabelWidget();
subgroup.runtimeChildren().addChild(label);
// Sanity check: Straight forward macro value replacement.
// Display value replaced by group,
// then replaced by subgroup,
// so label sees "subgroup"
model.propMacros().getValue().add("P", "display");
group.propMacros().getValue().add("P", "group");
subgroup.propMacros().getValue().add("P", "subgroup");
Macros macros = label.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("P"), equalTo("subgroup"));
// When are macros expanded?
// In BOY, they were mostly expanded when set,
// except the following example would fail if all widgets
// were within one display.
model.propMacros().getValue().add("P", "display");
// If macros are expanded early on,
// this sets SAVE=display,
// then redefines P
group.propMacros().getValue().add("SAVE", "$(P)");
group.propMacros().getValue().add("P", "group");
// .. and this would restore P='display', since that's what's im $(SAVE):
subgroup.propMacros().getValue().add("P", "$(SAVE)");
// With lazy macro expansion,
// the label widget would have P=$(SAVE), SAVE=$(P),
// so $(P) results in a "recursive macro" error.
// When macros are expanded as the runtime starts..
DisplayMacroExpander.expandDisplayMacros(model);
// ..you get $(P)="display"
macros = label.getEffectiveMacros();
System.out.println(macros);
assertThat(macros.getValue("P"), equalTo("display"));
assertThat(MacroHandler.replace(macros, "$(P)"), equalTo("display"));
}
use of org.csstudio.display.builder.model.widgets.LabelWidget in project org.csstudio.display.builder by kasemir.
the class RulesDialogDemo method start.
/**
* JavaFX Start
*/
@Override
public void start(final Stage stage) {
final AutocompleteMenu menu = new AutocompleteMenu();
final UndoableActionManager undo = new UndoableActionManager(10);
final Widget widget = new LabelWidget();
final List<RuleInfo> rules = widget.propRules().getValue();
final RulesDialog dialog = new RulesDialog(undo, rules, widget, menu);
System.out.println(dialog.showAndWait());
}
Aggregations