Search in sources :

Example 21 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class ProgressBarRepresentation method valueChanged.

private void valueChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final VType vtype = model_widget.runtimePropValue().getValue();
    final boolean limits_from_pv = model_widget.propLimitsFromPV().getValue();
    double min_val = model_widget.propMinimum().getValue();
    double max_val = model_widget.propMaximum().getValue();
    if (limits_from_pv) {
        // Try display range from PV
        final Display display_info = ValueUtil.displayOf(vtype);
        if (display_info != null) {
            min_val = display_info.getLowerDisplayLimit();
            max_val = display_info.getUpperDisplayLimit();
        }
    }
    // Fall back to 0..100 range
    if (min_val >= max_val) {
        min_val = 0.0;
        max_val = 100.0;
    }
    // Determine percentage of value within the min..max range
    final double value = VTypeUtil.getValueNumber(vtype).doubleValue();
    final double percentage = (value - min_val) / (max_val - min_val);
    // Limit to 0.0 .. 1.0
    if (percentage < 0.0)
        this.percentage = 0.0;
    else if (percentage > 1.0)
        this.percentage = 1.0;
    else
        this.percentage = percentage;
    dirty_value.mark();
    toolkit.scheduleUpdate(this);
}
Also used : VType(org.diirt.vtype.VType) Display(org.diirt.vtype.Display)

Example 22 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class ScaledSliderRepresentation method updateChanges.

@Override
public void updateChanges() {
    super.updateChanges();
    if (dirty_enablement.checkAndClear()) {
        jfx_node.setDisable(!enabled);
        Styles.update(jfx_node, Styles.NOT_ENABLED, !enabled);
    }
    if (dirty_layout.checkAndClear()) {
        final boolean horizontal = model_widget.propHorizontal().getValue();
        slider.setOrientation(horizontal ? Orientation.HORIZONTAL : Orientation.VERTICAL);
        final boolean any_markers = !(Double.isNaN(lolo) && Double.isNaN(low) && Double.isNaN(high) && Double.isNaN(hihi));
        if (any_markers) {
            if (!jfx_node.getChildren().contains(markers))
                jfx_node.add(markers, 0, 0);
            if (horizontal) {
                GridPane.setConstraints(slider, 0, 1);
                GridPane.setHgrow(slider, Priority.ALWAYS);
                GridPane.setVgrow(slider, Priority.NEVER);
                GridPane.setVgrow(markers, Priority.NEVER);
            } else {
                GridPane.setConstraints(slider, 1, 0);
                GridPane.setHgrow(slider, Priority.NEVER);
                GridPane.setHgrow(markers, Priority.NEVER);
                GridPane.setVgrow(slider, Priority.ALWAYS);
            }
        } else {
            if (jfx_node.getChildren().contains(markers))
                jfx_node.getChildren().remove(markers);
            GridPane.setConstraints(slider, 0, 0);
            if (horizontal) {
                GridPane.setHgrow(slider, Priority.ALWAYS);
                GridPane.setVgrow(slider, Priority.NEVER);
            } else {
                GridPane.setHgrow(slider, Priority.NEVER);
                GridPane.setVgrow(slider, Priority.ALWAYS);
            }
        }
        final double width = model_widget.propWidth().getValue();
        final double height = model_widget.propHeight().getValue();
        jfx_node.setMaxSize(width, height);
        jfx_node.setMinSize(width, height);
        if (model_widget.propHorizontal().getValue())
            slider.setMaxSize(width, Double.MAX_VALUE);
        else
            slider.setMaxSize(Double.MAX_VALUE, height);
        final Color background_color;
        if (model_widget.propTransparent().getValue())
            background_color = Color.TRANSPARENT;
        else
            background_color = JFXUtil.convert(model_widget.propBackgroundColor().getValue());
        final Background background = new Background(new BackgroundFill(background_color, CornerRadii.EMPTY, Insets.EMPTY));
        jfx_node.setBackground(background);
        markers.setBackground(background);
        final Font font = JFXUtil.convert(model_widget.propFont().getValue());
        markers.setFont(font);
        final // Text color (and border around the 'track')
        String style = "-fx-text-background-color: " + JFXUtil.webRGB(model_widget.propForegroundColor().getValue()) + // Axis tick marks
        "; -fx-background: " + JFXUtil.webRGB(model_widget.propForegroundColor().getValue()) + // Font (XXX: size isn't used, would have to set it on the SliderSkin's axis?)
        "; " + JFXUtil.cssFont("-fx-tick-label-font", font);
        jfx_node.setStyle(style);
        if (model_widget.propShowScale().getValue()) {
            String format = model_widget.propScaleFormat().getValue();
            if (format.isEmpty())
                format = "#.#";
            slider.setLabelFormatter(new FormatStringConverter<Double>(new DecimalFormat(format)));
            slider.setShowTickLabels(true);
            slider.setShowTickMarks(model_widget.propShowMinorTicks().getValue());
        } else {
            slider.setShowTickLabels(false);
            slider.setShowTickMarks(false);
        }
        slider.setMin(min);
        slider.setMax(max);
        slider.setMajorTickUnit(tick_unit);
        slider.setBlockIncrement(increment);
        // Create minor ticks that mimic the increments,
        // but limit to 9 minor ticks between major ticks
        slider.setMinorTickCount(Math.min((int) Math.round(tick_unit / increment) - 1, 9));
        if (any_markers)
            markers.setAlarmMarkers(lolo, low, high, hihi);
    }
    if (dirty_value.checkAndClear()) {
        active = true;
        try {
            final VType vtype = model_widget.runtimePropValue().getValue();
            double newval = VTypeUtil.getValueNumber(vtype).doubleValue();
            if (newval < min)
                newval = min;
            else if (newval > max)
                newval = max;
            if (!slider.isValueChanging()) {
                if (Double.isNaN(newval)) {
                    logger.log(Level.FINE, model_widget + " PV has invalid value " + vtype);
                    // Setting slider to NaN will hide the 'knob', so user can never
                    // set it back to a normal value.
                    // In addition, the UI can lock up (see SliderGlitchDemo).
                    // --> Set to min
                    slider.setValue(min);
                } else
                    slider.setValue(newval);
            }
            value = newval;
        } finally {
            active = false;
        }
    }
}
Also used : VType(org.diirt.vtype.VType) Background(javafx.scene.layout.Background) Color(javafx.scene.paint.Color) BackgroundFill(javafx.scene.layout.BackgroundFill) DecimalFormat(java.text.DecimalFormat) Font(javafx.scene.text.Font)

Example 23 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testEngineering.

@Test
public void testEngineering() throws Exception {
    VType number = ValueFactory.newVDouble(0.0316, display);
    // 1 'significant digits': 31.6
    String text = FormatOptionHandler.format(number, FormatOption.ENGINEERING, 1, true);
    System.out.println(text);
    assertThat(text, equalTo("31.6E-3 V"));
    // 3 digits
    text = FormatOptionHandler.format(number, FormatOption.ENGINEERING, 3, false);
    System.out.println(text);
    assertThat(text, equalTo("31.600E-3"));
    // 4 'significant digits': 31.6000
    text = FormatOptionHandler.format(number, FormatOption.ENGINEERING, 4, true);
    System.out.println(text);
    assertThat(text, equalTo("31.6000E-3 V"));
    number = ValueFactory.newVDouble(12345678.0, display);
    text = FormatOptionHandler.format(number, FormatOption.ENGINEERING, 2, true);
    System.out.println(text);
    assertThat(text, equalTo("12.35E6 V"));
    text = FormatOptionHandler.format(number, FormatOption.ENGINEERING, 3, true);
    System.out.println(text);
    assertThat(text, equalTo("12.346E6 V"));
    // Can't use that to compute more digits for pi
    number = ValueFactory.newVDouble(3.14, display);
    text = FormatOptionHandler.format(number, FormatOption.ENGINEERING, 10, true);
    System.out.println(text);
    assertThat(text, equalTo("3.1400000000E0 V"));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Example 24 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testNumberParsing.

@Test
public void testNumberParsing() throws Exception {
    VType value = ValueFactory.newVDouble(3.16, display);
    Object parsed = FormatOptionHandler.parse(value, "42.5 Socks", FormatOption.DEFAULT);
    assertThat(parsed, instanceOf(Number.class));
    assertThat(((Number) parsed).doubleValue(), equalTo(42.5));
}
Also used : VType(org.diirt.vtype.VType) ListNumber(org.diirt.util.array.ListNumber) Test(org.junit.Test)

Example 25 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testNaNInf.

@Test
public void testNaNInf() throws Exception {
    VType number = ValueFactory.newVDouble(Double.NaN, display);
    String text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("NaN V"));
    number = ValueFactory.newVDouble(Double.POSITIVE_INFINITY, display);
    text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("Infinity V"));
    number = ValueFactory.newVDouble(Double.NEGATIVE_INFINITY, display);
    text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("-Infinity V"));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Aggregations

VType (org.diirt.vtype.VType)76 Test (org.junit.Test)17 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)10 IFigure (org.eclipse.draw2d.IFigure)10 IPV (org.csstudio.simplepv.IPV)9 VEnum (org.diirt.vtype.VEnum)8 ArrayList (java.util.ArrayList)7 Display (org.diirt.vtype.Display)7 ListNumber (org.diirt.util.array.ListNumber)6 VNumberArray (org.diirt.vtype.VNumberArray)6 VString (org.diirt.vtype.VString)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 Instant (java.time.Instant)5 List (java.util.List)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)5 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ValueIterator (org.csstudio.archive.reader.ValueIterator)3