Search in sources :

Example 1 with VEnumArray

use of org.diirt.vtype.VEnumArray in project yamcs-studio by yamcs.

the class PVUtil method getStringArray.

/**
 * Get string array from pv.
 *
 * @param pv
 *            The PV.
 * @return String array. For string array, it's the actual strings. For numeric arrays, the numbers are formatted as
 *         strings. For enum array, the labels are returned. For scalar PVs, an array with a single string is
 *         returned.
 */
public static final String[] getStringArray(IPV pv) {
    final VType value = checkPVValue(pv);
    if (value instanceof VStringArray) {
        final List<String> list = ((VStringArray) value).getData();
        return list.toArray(new String[list.size()]);
    } else if (value instanceof VDoubleArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Double.toString(list.getDouble(i));
        return text;
    } else if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Long.toString(list.getLong(i));
        return text;
    } else if (value instanceof VEnumArray) {
        final List<String> labels = ((VEnumArray) value).getLabels();
        final ListInt list = ((VEnumArray) value).getIndexes();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) {
            final int index = list.getInt(i);
            if (index >= 0 && index <= labels.size())
                text[i] = labels.get(index);
            else
                text[i] = "<" + index + ">";
        }
        return text;
    }
    return new String[] { getString(pv) };
}
Also used : VDoubleArray(org.diirt.vtype.VDoubleArray) VNumberArray(org.diirt.vtype.VNumberArray) VEnumArray(org.diirt.vtype.VEnumArray) ListNumber(org.diirt.util.array.ListNumber) ListInt(org.diirt.util.array.ListInt) VType(org.diirt.vtype.VType) List(java.util.List) VStringArray(org.diirt.vtype.VStringArray)

Example 2 with VEnumArray

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

the class ValueUtil method getStringArray.

/**
 * Get string array from pv.
 *  @param value Value of a PV
 *  @return String array.
 *          For string array, it's the actual strings.
 *          For numeric arrays, the numbers are formatted as strings.
 *          For enum array, the labels are returned.
 *          For scalar PVs, an array with a single string is returned.
 */
public static final String[] getStringArray(final VType value) {
    if (value instanceof VStringArray) {
        final List<String> list = ((VStringArray) value).getData();
        return list.toArray(new String[list.size()]);
    } else if (value instanceof VDoubleArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Double.toString(list.getDouble(i));
        return text;
    } else if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Long.toString(list.getLong(i));
        return text;
    } else if (value instanceof VEnumArray) {
        final List<String> labels = ((VEnumArray) value).getLabels();
        final ListInt list = ((VEnumArray) value).getIndexes();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) {
            final int index = list.getInt(i);
            if (index >= 0 && index <= labels.size())
                text[i] = labels.get(index);
            else
                text[i] = "<" + index + ">";
        }
        return text;
    }
    return new String[] { getString(value) };
}
Also used : VDoubleArray(org.diirt.vtype.VDoubleArray) VNumberArray(org.diirt.vtype.VNumberArray) VEnumArray(org.diirt.vtype.VEnumArray) ListNumber(org.diirt.util.array.ListNumber) ListInt(org.diirt.util.array.ListInt) ArrayList(java.util.ArrayList) List(java.util.List) VStringArray(org.diirt.vtype.VStringArray)

Example 3 with VEnumArray

use of org.diirt.vtype.VEnumArray 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 4 with VEnumArray

use of org.diirt.vtype.VEnumArray 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 5 with VEnumArray

use of org.diirt.vtype.VEnumArray 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

ListNumber (org.diirt.util.array.ListNumber)5 VEnumArray (org.diirt.vtype.VEnumArray)5 VNumberArray (org.diirt.vtype.VNumberArray)5 ListInt (org.diirt.util.array.ListInt)4 VEnum (org.diirt.vtype.VEnum)3 VNumber (org.diirt.vtype.VNumber)3 VString (org.diirt.vtype.VString)3 VStringArray (org.diirt.vtype.VStringArray)3 List (java.util.List)2 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 VBoolean (org.diirt.vtype.VBoolean)2 VDoubleArray (org.diirt.vtype.VDoubleArray)2 ArrayList (java.util.ArrayList)1 Rotate (javafx.scene.transform.Rotate)1 Translate (javafx.scene.transform.Translate)1 RotationStep (org.csstudio.display.builder.model.properties.RotationStep)1 VImage (org.diirt.vtype.VImage)1 VTable (org.diirt.vtype.VTable)1 VType (org.diirt.vtype.VType)1