Search in sources :

Example 6 with LabelWidget

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));
}
Also used : LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) WidgetFont(org.csstudio.display.builder.model.properties.WidgetFont) NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont) NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont) Test(org.junit.Test)

Example 7 with LabelWidget

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));
}
Also used : LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Test(org.junit.Test)

Example 8 with LabelWidget

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"));
}
Also used : LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) WidgetColor(org.csstudio.display.builder.model.properties.WidgetColor) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) Test(org.junit.Test)

Example 9 with LabelWidget

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"));
}
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 10 with LabelWidget

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());
}
Also used : UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) Widget(org.csstudio.display.builder.model.Widget) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo)

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