Search in sources :

Example 1 with NamedWidgetFont

use of org.csstudio.display.builder.model.properties.NamedWidgetFont 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 2 with NamedWidgetFont

use of org.csstudio.display.builder.model.properties.NamedWidgetFont in project org.csstudio.display.builder by kasemir.

the class NamedWidgetFonts method defineDefaultFonts.

private void defineDefaultFonts() {
    define(BASE);
    define(new NamedWidgetFont("Default Bold", BASE.getFamily(), WidgetFontStyle.BOLD, BASE.getSize()));
    define(new NamedWidgetFont("Header 1", BASE.getFamily(), WidgetFontStyle.BOLD, BASE.getSize() + 8));
    define(new NamedWidgetFont("Header 2", BASE.getFamily(), WidgetFontStyle.BOLD, BASE.getSize() + 4));
    define(new NamedWidgetFont("Header 3", BASE.getFamily(), WidgetFontStyle.BOLD, BASE.getSize() + 2));
    define(new NamedWidgetFont("Comment", BASE.getFamily(), WidgetFontStyle.ITALIC, BASE.getSize()));
    define(new NamedWidgetFont("Fine Print", BASE.getFamily(), WidgetFontStyle.REGULAR, BASE.getSize() - 2));
}
Also used : NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont)

Example 3 with NamedWidgetFont

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

Example 4 with NamedWidgetFont

use of org.csstudio.display.builder.model.properties.NamedWidgetFont in project org.csstudio.display.builder by kasemir.

the class NamedWidgetFonts method parse.

@Override
protected void parse(String name, final String value) throws Exception {
    final String os = getOSName();
    String selector = "";
    // Check if name is qualified by OS selector
    final int sep = name.indexOf('(');
    if (sep > 0) {
        final int end = name.indexOf(')', sep + 1);
        if (end < 0)
            throw new Exception("Cannot locate end of OS selector in '" + name + "'");
        selector = name.substring(sep + 1, end);
        name = name.substring(0, sep);
        // Ignore entries that do not match this OS
        if (!selector.startsWith(os))
            return;
    }
    String tvalue = value.trim();
    if (tvalue.startsWith("@")) {
        final Optional<NamedWidgetFont> optionalFont = getFont(tvalue.substring(1).trim());
        if (optionalFont.isPresent()) {
            NamedWidgetFont namedFont = optionalFont.get();
            define(new NamedWidgetFont(name, namedFont.getFamily(), namedFont.getStyle(), namedFont.getSize()));
        } else
            throw new Exception(MessageFormat.format("Cannot parse font ''{0}'': font not previously defined.", tvalue));
    } else {
        final StringTokenizer tokenizer = new StringTokenizer(value, "-");
        try {
            String family = tokenizer.nextToken().trim();
            final WidgetFontStyle style = parseStyle(tokenizer.nextToken().trim());
            final double size = Double.parseDouble(tokenizer.nextToken().trim());
            if (family.equalsIgnoreCase("SystemDefault"))
                family = BASE.getFamily();
            define(new NamedWidgetFont(name, family, style, size));
        } catch (Throwable ex) {
            throw new Exception(MessageFormat.format("Cannot parse font ''{0}'' from ''{1}''", name, value), ex);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) NamedWidgetFont(org.csstudio.display.builder.model.properties.NamedWidgetFont) WidgetFontStyle(org.csstudio.display.builder.model.properties.WidgetFontStyle)

Aggregations

NamedWidgetFont (org.csstudio.display.builder.model.properties.NamedWidgetFont)4 LabelWidget (org.csstudio.display.builder.model.widgets.LabelWidget)2 Test (org.junit.Test)2 StringTokenizer (java.util.StringTokenizer)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 WidgetFactoryUnitTest (org.csstudio.display.builder.model.WidgetFactoryUnitTest)1 WidgetFont (org.csstudio.display.builder.model.properties.WidgetFont)1 WidgetFontStyle (org.csstudio.display.builder.model.properties.WidgetFontStyle)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1