Search in sources :

Example 26 with VNumberArray

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

the class ValueUtil method getLongArray.

/**
 * Try to get a 'long' type array from a value.
 *  @param value Value of a PV
 *  @return Current value as long[].
 *          Will return single-element array for scalar value.
 */
public static long[] getLongArray(final VType value) {
    if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final Object wrapped = CollectionNumbers.wrappedArray(list);
        if (wrapped instanceof long[])
            return (long[]) wrapped;
        final long[] result = new long[list.size()];
        for (int i = 0; i < result.length; i++) result[i] = list.getLong(i);
        return result;
    }
    return new long[] { getLong(value) };
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber)

Example 27 with VNumberArray

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

the class SymbolRepresentation method updateChanges.

@Override
public void updateChanges() {
    super.updateChanges();
    Object value;
    if (dirtyGeometry.checkAndClear()) {
        value = model_widget.propVisible().getValue();
        if (!Objects.equals(value, jfx_node.isVisible())) {
            jfx_node.setVisible((boolean) value);
        }
        value = model_widget.propAutoSize().getValue();
        if (!Objects.equals(value, autoSize)) {
            autoSize = (boolean) value;
        }
        if (autoSize) {
            model_widget.propWidth().setValue((int) Math.round(maxSize.getWidth()));
            model_widget.propHeight().setValue((int) Math.round(maxSize.getHeight()));
        }
        double w = model_widget.propWidth().getValue();
        double h = model_widget.propHeight().getValue();
        jfx_node.setLayoutX(model_widget.propX().getValue());
        jfx_node.setLayoutY(model_widget.propY().getValue());
        jfx_node.setPrefWidth(w);
        jfx_node.setPrefHeight(h);
        double minSize = Math.min(w, h);
        indexLabelBackground.setRadius(Math.min(minSize / 2, 16.0));
    }
    if (dirtyIndex.checkAndClear()) {
        setImageIndex(Math.min(Math.max(model_widget.propInitialIndex().getValue(), 0), imagesList.size() - 1));
    }
    if (dirtyContent.checkAndClear()) {
        value = model_widget.propArrayIndex().getValue();
        if (!Objects.equals(value, arrayIndex)) {
            arrayIndex = Math.max(0, (int) value);
        }
        setImageIndex(Math.min(Math.max(getImageIndex(), 0), imagesList.size() - 1));
    }
    if (dirtyStyle.checkAndClear()) {
        value = model_widget.propPreserveRatio().getValue();
        if (!Objects.equals(value, imageView.isPreserveRatio())) {
            imageView.setPreserveRatio((boolean) value);
        }
        value = model_widget.propEnabled().getValue();
        if (!Objects.equals(value, enabled)) {
            enabled = (boolean) value;
            Styles.update(jfx_node, Styles.NOT_ENABLED, !enabled);
        }
        value = model_widget.propShowIndex().getValue();
        if (!Objects.equals(value, indexLabel.isVisible())) {
            indexLabel.setVisible((boolean) value);
            indexLabelBackground.setVisible((boolean) value);
        }
        if (model_widget.propTransparent().getValue()) {
            jfx_node.setBackground(null);
        } else {
            jfx_node.setBackground(new Background(new BackgroundFill(JFXUtil.convert(model_widget.propBackgroundColor().getValue()), CornerRadii.EMPTY, Insets.EMPTY)));
        }
        value = model_widget.propRotation().getValue();
        if (!Objects.equals(value, imagePane.getRotate())) {
            imagePane.setRotate((double) value);
        }
    }
    if (dirtyValue.checkAndClear() && updatingValue.compareAndSet(false, true)) {
        int idx = -1;
        try {
            value = model_widget.runtimePropValue().getValue();
            if (value != null) {
                if (value instanceof VBoolean) {
                    idx = ((VBoolean) value).getValue() ? 1 : 0;
                } else if (value instanceof VString) {
                    try {
                        idx = Integer.parseInt(((VString) value).getValue());
                    } catch (NumberFormatException nfex) {
                        logger.log(Level.FINE, "Failure parsing the string value: {0} [{1}].", new Object[] { ((VString) value).getValue(), nfex.getMessage() });
                    }
                } else if (value instanceof VNumber) {
                    idx = ((VNumber) value).getValue().intValue();
                } else if (value instanceof VEnum) {
                    idx = ((VEnum) value).getIndex();
                } else if (value instanceof VNumberArray) {
                    ListNumber array = ((VNumberArray) value).getData();
                    if (array.size() > 0) {
                        idx = array.getInt(Math.min(arrayIndex, array.size() - 1));
                    }
                } else if (value instanceof VEnumArray) {
                    ListInt array = ((VEnumArray) value).getIndexes();
                    if (array.size() > 0) {
                        idx = array.getInt(Math.min(arrayIndex, array.size() - 1));
                    }
                }
            }
        } finally {
            updatingValue.set(false);
        }
        setImageIndex(Math.min(Math.max(idx, 0), imagesList.size() - 1));
    }
}
Also used : VEnumArray(org.diirt.vtype.VEnumArray) ListInt(org.diirt.util.array.ListInt) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) VNumber(org.diirt.vtype.VNumber) VBoolean(org.diirt.vtype.VBoolean) VEnum(org.diirt.vtype.VEnum) VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) VString(org.diirt.vtype.VString)

Example 28 with VNumberArray

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

the class TextSymbolRepresentation method updateChanges.

@Override
public void updateChanges() {
    super.updateChanges();
    Object value;
    if (dirtyGeometry.checkAndClear()) {
        value = model_widget.propVisible().getValue();
        if (!Objects.equals(value, jfx_node.isVisible())) {
            jfx_node.setVisible((boolean) value);
        }
        jfx_node.setLayoutX(model_widget.propX().getValue());
        jfx_node.setLayoutY(model_widget.propY().getValue());
        jfx_node.setPrefWidth(model_widget.propWidth().getValue());
        jfx_node.setPrefHeight(model_widget.propHeight().getValue());
    }
    if (dirtyContent.checkAndClear()) {
        value = model_widget.propArrayIndex().getValue();
        if (!Objects.equals(value, arrayIndex)) {
            arrayIndex = Math.max(0, (int) value);
        }
        symbolIndex = Math.min(Math.max(symbolIndex, 0), model_widget.propSymbols().size() - 1);
        jfx_node.setText((symbolIndex >= 0) ? model_widget.propSymbols().getElement(symbolIndex).getValue() : "\u263A");
    }
    if (dirtyStyle.checkAndClear()) {
        final int width = model_widget.propWidth().getValue();
        final int height = model_widget.propHeight().getValue();
        final RotationStep rotation = model_widget.propRotationStep().getValue();
        switch(rotation) {
            case NONE:
                jfx_node.setPrefSize(width, height);
                if (was_ever_transformed) {
                    jfx_node.getTransforms().clear();
                }
                break;
            case NINETY:
                jfx_node.setPrefSize(height, width);
                jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()), new Translate(-height, 0));
                was_ever_transformed = true;
                break;
            case ONEEIGHTY:
                jfx_node.setPrefSize(width, height);
                jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()), new Translate(-width, -height));
                was_ever_transformed = true;
                break;
            case MINUS_NINETY:
                jfx_node.setPrefSize(height, width);
                jfx_node.getTransforms().setAll(new Rotate(-rotation.getAngle()), new Translate(0, -width));
                was_ever_transformed = true;
                break;
        }
        value = model_widget.propEnabled().getValue();
        if (!Objects.equals(value, enabled)) {
            enabled = (boolean) value;
            Styles.update(jfx_node, Styles.NOT_ENABLED, !enabled);
        }
        jfx_node.setAlignment(JFXUtil.computePos(model_widget.propHorizontalAlignment().getValue(), model_widget.propVerticalAlignment().getValue()));
        jfx_node.setBackground(model_widget.propTransparent().getValue() ? null : new Background(new BackgroundFill(JFXUtil.convert(model_widget.propBackgroundColor().getValue()), CornerRadii.EMPTY, Insets.EMPTY)));
        jfx_node.setFont(JFXUtil.convert(model_widget.propFont().getValue()));
        jfx_node.setTextFill(JFXUtil.convert(model_widget.propForegroundColor().getValue()));
        jfx_node.setWrapText(model_widget.propWrapWords().getValue());
    }
    if (dirtyValue.checkAndClear() && updatingValue.compareAndSet(false, true)) {
        try {
            value = model_widget.runtimePropValue().getValue();
            if (value != null) {
                if (value instanceof VBoolean) {
                    symbolIndex = ((VBoolean) value).getValue() ? 1 : 0;
                } else if (value instanceof VString) {
                    try {
                        symbolIndex = Integer.parseInt(((VString) value).getValue());
                    } catch (NumberFormatException nfex) {
                        logger.log(Level.FINE, "Failure parsing the string value: {0} [{1}].", new Object[] { ((VString) value).getValue(), nfex.getMessage() });
                    }
                } else if (value instanceof VNumber) {
                    symbolIndex = ((VNumber) value).getValue().intValue();
                } else if (value instanceof VEnum) {
                    symbolIndex = ((VEnum) value).getIndex();
                } else if (value instanceof VNumberArray) {
                    ListNumber array = ((VNumberArray) value).getData();
                    if (array.size() > 0) {
                        symbolIndex = array.getInt(Math.min(arrayIndex, array.size() - 1));
                    }
                } else if (value instanceof VEnumArray) {
                    ListInt array = ((VEnumArray) value).getIndexes();
                    if (array.size() > 0) {
                        symbolIndex = array.getInt(Math.min(arrayIndex, array.size() - 1));
                    }
                }
            }
        } finally {
            updatingValue.set(false);
        }
        symbolIndex = Math.min(Math.max(symbolIndex, 0), model_widget.propSymbols().size() - 1);
        jfx_node.setText((symbolIndex >= 0) ? model_widget.propSymbols().getElement(symbolIndex).getValue() : "\u263A");
    }
}
Also used : VEnumArray(org.diirt.vtype.VEnumArray) ListInt(org.diirt.util.array.ListInt) Rotate(javafx.scene.transform.Rotate) Background(javafx.scene.layout.Background) BackgroundFill(javafx.scene.layout.BackgroundFill) VNumber(org.diirt.vtype.VNumber) VBoolean(org.diirt.vtype.VBoolean) VEnum(org.diirt.vtype.VEnum) VNumberArray(org.diirt.vtype.VNumberArray) RotationStep(org.csstudio.display.builder.model.properties.RotationStep) ListNumber(org.diirt.util.array.ListNumber) VString(org.diirt.vtype.VString) Translate(javafx.scene.transform.Translate)

Example 29 with VNumberArray

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

the class WaveformValueDataProvider method setValue.

/**
 * Update the waveform value.
 *  @param value New value
 *  Fires event to listeners (plot)
 */
public void setValue(final VType value) {
    final ListNumber new_numbers;
    if (value instanceof VNumberArray)
        new_numbers = ((VNumberArray) value).getData();
    else
        new_numbers = new ArrayDouble(VTypeHelper.toDouble(value));
    lock.writeLock().lock();
    try {
        numbers = new_numbers;
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) ArrayDouble(org.diirt.util.array.ArrayDouble)

Example 30 with VNumberArray

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

the class FormatOptionHandler method format.

/**
 * Format value as string
 *
 *  @param value Value to format
 *  @param option How to format the value
 *  @param precision Precision to use. -1 will try to fetch precision from VType
 *  @param show_units Include units?
 *  @return Formatted value
 */
public static String format(final VType value, final FormatOption option, int precision, final boolean show_units) {
    precision = actualPrecision(value, precision);
    if (value == null)
        return "<null>";
    if (value instanceof VNumber) {
        final VNumber number = (VNumber) value;
        final String text = formatNumber(number.getValue(), number, option, precision);
        if (show_units && !number.getUnits().isEmpty())
            return text + " " + number.getUnits();
        return text;
    } else if (value instanceof VString)
        return ((VString) value).getValue();
    else if (value instanceof VEnum)
        return formatEnum((VEnum) value, option);
    else if (value instanceof VNumberArray) {
        final VNumberArray array = (VNumberArray) value;
        if (option == FormatOption.STRING)
            return getLongString(array);
        final ListNumber data = array.getData();
        if (data.size() <= 0)
            return "[]";
        final StringBuilder buf = new StringBuilder("[");
        buf.append(formatNumber(data.getDouble(0), array, option, precision));
        for (int i = 1; i < data.size(); ++i) {
            buf.append(", ");
            buf.append(formatNumber(data.getDouble(i), array, option, precision));
        }
        buf.append("]");
        if (show_units && !array.getUnits().isEmpty())
            buf.append(" ").append(array.getUnits());
        return buf.toString();
    } else if (value instanceof VEnumArray) {
        final List<String> labels = ((VEnumArray) value).getLabels();
        final StringBuilder buf = new StringBuilder("[");
        for (int i = 0; i < labels.size(); ++i) {
            if (i > 0)
                buf.append(", ");
            buf.append(labels.get(i));
        }
        buf.append("]");
        return buf.toString();
    } else if (value instanceof VStringArray)
        return StringList.join(((VStringArray) value).getData());
    else if (value instanceof VImage) {
        final VImage image = (VImage) value;
        return "VImage(" + image.getWidth() + " x " + image.getHeight() + ")";
    } else if (value instanceof VTable)
        return formatTable((VTable) value);
    return "<" + value.getClass().getName() + ">";
}
Also used : VEnumArray(org.diirt.vtype.VEnumArray) VNumber(org.diirt.vtype.VNumber) VString(org.diirt.vtype.VString) VEnum(org.diirt.vtype.VEnum) VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable) VStringArray(org.diirt.vtype.VStringArray) VImage(org.diirt.vtype.VImage)

Aggregations

VNumberArray (org.diirt.vtype.VNumberArray)30 ListNumber (org.diirt.util.array.ListNumber)13 VNumber (org.diirt.vtype.VNumber)10 VString (org.diirt.vtype.VString)6 ValueFactory.newVNumberArray (org.diirt.vtype.ValueFactory.newVNumberArray)6 VEnumArray (org.diirt.vtype.VEnumArray)5 VType (org.diirt.vtype.VType)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ArrayDouble (org.diirt.util.array.ArrayDouble)4 ListInt (org.diirt.util.array.ListInt)4 VStringArray (org.diirt.vtype.VStringArray)4 VEnum (org.diirt.vtype.VEnum)3 VTable (org.diirt.vtype.VTable)3 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ListDouble (org.diirt.util.array.ListDouble)2 ArrayDimensionDisplay (org.diirt.vtype.ArrayDimensionDisplay)2 VBoolean (org.diirt.vtype.VBoolean)2 VDoubleArray (org.diirt.vtype.VDoubleArray)2