Search in sources :

Example 1 with TextUpdateWidget

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

the class ExampleModels method createModel.

/**
 * @return {@link DisplayModel}
 */
public static DisplayModel createModel() {
    final DisplayModel model = new DisplayModel();
    model.setPropertyValue(CommonWidgetProperties.propWidth, 1400);
    model.setPropertyValue(CommonWidgetProperties.propHeight, 20 * 50);
    for (int i = 0; i < 200; ++i) {
        final int x = 0 + (i / 20) * 132;
        final int y = 0 + (i % 20) * 50;
        final GroupWidget group = new GroupWidget();
        group.setPropertyValue(CommonWidgetProperties.propName, "Group " + i);
        group.setPropertyValue(CommonWidgetProperties.propX, x);
        group.setPropertyValue(CommonWidgetProperties.propY, y);
        group.setPropertyValue(CommonWidgetProperties.propWidth, 125);
        group.setPropertyValue(CommonWidgetProperties.propHeight, 53);
        final LabelWidget label = new LabelWidget();
        label.setPropertyValue(CommonWidgetProperties.propName, "Label " + i);
        label.setPropertyValue(CommonWidgetProperties.propX, 0);
        label.setPropertyValue(CommonWidgetProperties.propY, 4);
        label.setPropertyValue(CommonWidgetProperties.propWidth, 15);
        label.setPropertyValue(CommonWidgetProperties.propHeight, 15);
        label.setPropertyValue(CommonWidgetProperties.propText, Integer.toString(i));
        group.runtimeChildren().addChild(label);
        // For SWT implementation, rect. is not 'transparent',
        // so needs to be behind text
        final RectangleWidget rect = new RectangleWidget();
        rect.setPropertyValue(CommonWidgetProperties.propName, "Rect " + i);
        rect.setPropertyValue(CommonWidgetProperties.propX, 10);
        rect.setPropertyValue(CommonWidgetProperties.propY, 0);
        rect.setPropertyValue(CommonWidgetProperties.propWidth, 80);
        rect.setPropertyValue(CommonWidgetProperties.propHeight, 19);
        rect.setPropertyValue(CommonWidgetProperties.propScripts, Arrays.asList(new ScriptInfo("../org.csstudio.display.builder.runtime.test/examples/fudge_width.py", true, new ScriptPV("noise"))));
        group.runtimeChildren().addChild(rect);
        final TextUpdateWidget text = new TextUpdateWidget();
        text.setPropertyValue(CommonWidgetProperties.propName, "Text " + i);
        text.setPropertyValue(CommonWidgetProperties.propX, 30);
        text.setPropertyValue(CommonWidgetProperties.propY, 4);
        text.setPropertyValue(CommonWidgetProperties.propWidth, 45);
        text.setPropertyValue(CommonWidgetProperties.propHeight, 15);
        text.setPropertyValue(CommonWidgetProperties.propPVName, "ramp");
        group.runtimeChildren().addChild(text);
        model.runtimeChildren().addChild(group);
    }
    return model;
}
Also used : RectangleWidget(org.csstudio.display.builder.model.widgets.RectangleWidget) DisplayModel(org.csstudio.display.builder.model.DisplayModel) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) LabelWidget(org.csstudio.display.builder.model.widgets.LabelWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget)

Example 2 with TextUpdateWidget

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

the class WidgetPropertyUnitTest method testMacrosAndProperties.

@Test
public void testMacrosAndProperties() throws Exception {
    final DisplayModel display = new DisplayModel();
    final TextUpdateWidget widget = new TextUpdateWidget();
    display.runtimeChildren().addChild(widget);
    // "name" property of widget can be accessed as macro
    widget.propName().setValue("fred");
    assertThat(MacroHandler.replace(widget.getMacrosOrProperties(), "$(name)"), equalTo("fred"));
    // If there is actually a "name" macro, that takes precedence
    display.propMacros().getValue().add("name", "The Name");
    assertThat(MacroHandler.replace(widget.getMacrosOrProperties(), "$(name)"), equalTo("The Name"));
    // Bad recursion: Property was set to macro which in turn requests that same property
    ((MacroizedWidgetProperty<String>) widget.propPVName()).setSpecification("$(pv_name)");
    try {
        MacroHandler.replace(widget.getMacrosOrProperties(), "$(pv_name)");
        fail("Didn't detect recursion");
    } catch (Exception ex) {
        assertThat(ex.getMessage().toLowerCase(), containsString("recursive"));
    }
    // Macro remains unresolved (with many warnings on console)
    assertThat(widget.propPVName().getValue(), equalTo("$(pv_name)"));
}
Also used : TextUpdateWidget(org.csstudio.display.builder.model.widgets.TextUpdateWidget) Test(org.junit.Test)

Aggregations

TextUpdateWidget (org.csstudio.display.builder.model.widgets.TextUpdateWidget)2 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)1 ScriptPV (org.csstudio.display.builder.model.properties.ScriptPV)1 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)1 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)1 RectangleWidget (org.csstudio.display.builder.model.widgets.RectangleWidget)1 Test (org.junit.Test)1