Search in sources :

Example 1 with WidgetFontStyle

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

StringTokenizer (java.util.StringTokenizer)1 NamedWidgetFont (org.csstudio.display.builder.model.properties.NamedWidgetFont)1 WidgetFontStyle (org.csstudio.display.builder.model.properties.WidgetFontStyle)1