Search in sources :

Example 1 with StringWidgetProperty

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

the class TooltipSupport method attach.

/**
 * Attach tool tip
 *  @param node Node that should have the tool tip
 *  @param tooltip_property Tool tip to show
 */
public static void attach(final Node node, final WidgetProperty<String> tooltip_property) {
    // Patch legacy tool tips that defaulted to pv name & value,
    // even for static widgets
    final StringWidgetProperty ttp = (StringWidgetProperty) tooltip_property;
    if (legacy_tooltip.matcher(ttp.getSpecification()).matches() && !tooltip_property.getWidget().checkProperty("pv_name").isPresent())
        ttp.setSpecification("");
    // Avoid listener and code to remove/add tooltip at runtime.
    if (tooltip_property.getValue().isEmpty())
        return;
    final Tooltip tooltip = new Tooltip();
    tooltip.setWrapText(true);
    // Evaluate the macros in tool tip specification each time
    // the tool tip is about to show
    tooltip.setOnShowing(event -> {
        final String spec = ((MacroizedWidgetProperty<?>) tooltip_property).getSpecification();
        final Widget widget = tooltip_property.getWidget();
        final MacroValueProvider macros = widget.getMacrosOrProperties();
        String expanded;
        try {
            expanded = MacroHandler.replace(macros, spec);
            tooltip.setText(expanded);
        } catch (Exception ex) {
            logger.log(Level.WARNING, "Cannot evaluate tooltip of " + widget, ex);
            tooltip.setText(spec);
        }
    });
    Tooltip.install(node, tooltip);
    if (!initialized_behavior) {
        // Unfortunately, no API to control when tooltop shows, and for how long.
        // http://stackoverflow.com/questions/26854301/control-javafx-tooltip-delay
        // has the hack used in here, which only needs to be applied once
        // because it changes a static BEHAVIOR inside the Tooltip.
        // Java 9 will offer API, https://bugs.openjdk.java.net/browse/JDK-8090477
        hack_behavior(tooltip);
        initialized_behavior = true;
    }
}
Also used : MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) MacroValueProvider(org.csstudio.display.builder.model.macros.MacroValueProvider) StringWidgetProperty(org.csstudio.display.builder.model.properties.StringWidgetProperty) Tooltip(javafx.scene.control.Tooltip) Widget(org.csstudio.display.builder.model.Widget)

Example 2 with StringWidgetProperty

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

the class TextUpdateWidget method readLegacyFormat.

/**
 * Read legacy widget's format
 *  @param xml Widget XML
 *  @param format Format property to update
 *  @param precision Precision property to update
 *  @param pv_name PV name property to update
 */
// package-level access for TextEntryWidget
static void readLegacyFormat(final Element xml, final WidgetProperty<FormatOption> format, final WidgetProperty<Integer> precision, final WidgetProperty<String> pv_name) {
    Element element = XMLUtil.getChildElement(xml, "format_type");
    if (element != null) {
        final int legacy_format = Integer.parseInt(XMLUtil.getString(element));
        switch(legacy_format) {
            case // DECIMAL
            1:
                format.setValue(FormatOption.DECIMAL);
                break;
            case // EXP
            2:
                format.setValue(FormatOption.EXPONENTIAL);
                break;
            case // HEX (32)
            3:
                format.setValue(FormatOption.HEX);
                precision.setValue(8);
                break;
            case // STRING
            4:
                format.setValue(FormatOption.STRING);
                break;
            case // HEX64
            5:
                format.setValue(FormatOption.HEX);
                precision.setValue(16);
                break;
            case // COMPACT
            6:
                format.setValue(FormatOption.COMPACT);
                break;
            case // ENG (since Aug. 2016)
            7:
                format.setValue(FormatOption.ENGINEERING);
                break;
            case // SEXA (since Dec. 2016)
            8:
                format.setValue(FormatOption.SEXAGESIMAL);
                break;
            case // SEXA_HMS (since Dec. 2016)
            9:
                format.setValue(FormatOption.SEXAGESIMAL_HMS);
                break;
            case // SEXA_DMS (since Dec. 2016)
            10:
                format.setValue(FormatOption.SEXAGESIMAL_DMS);
                break;
            default:
                format.setValue(FormatOption.DEFAULT);
        }
    }
    // If legacy requested precision-from-PV, mark that in precision
    element = XMLUtil.getChildElement(xml, "precision_from_pv");
    if (element != null && Boolean.parseBoolean(XMLUtil.getString(element)))
        precision.setValue(-1);
    // Remove legacy longString attribute from PV,
    // instead use STRING formatting
    String pv = ((StringWidgetProperty) pv_name).getSpecification();
    if (pv.endsWith(" {\"longString\":true}")) {
        pv = pv.substring(0, pv.length() - 20);
        ((StringWidgetProperty) pv_name).setSpecification(pv);
        format.setValue(FormatOption.STRING);
    }
}
Also used : StringWidgetProperty(org.csstudio.display.builder.model.properties.StringWidgetProperty) Element(org.w3c.dom.Element)

Aggregations

StringWidgetProperty (org.csstudio.display.builder.model.properties.StringWidgetProperty)2 Tooltip (javafx.scene.control.Tooltip)1 MacroizedWidgetProperty (org.csstudio.display.builder.model.MacroizedWidgetProperty)1 Widget (org.csstudio.display.builder.model.Widget)1 MacroValueProvider (org.csstudio.display.builder.model.macros.MacroValueProvider)1 Element (org.w3c.dom.Element)1