Search in sources :

Example 16 with VString

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

the class TableUnionFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VString columnName = (VString) args.get(0);
    VStringArray columnValues = (VStringArray) args.get(1);
    List<VTable> tables = new ArrayList<>();
    for (int i = 2; i < args.size(); i++) {
        Object object = args.get(i);
        tables.add((VTable) object);
    }
    return VTableFactory.union(columnName, columnValues, tables.toArray(new VTable[tables.size()]));
}
Also used : VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable) ArrayList(java.util.ArrayList) VStringArray(org.diirt.vtype.VStringArray)

Example 17 with VString

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

the class ValueFormatter method format.

/**
 * @return Value formatted into columns
 */
public String format(final VType value) {
    final VTypeFormat format_for_this_value;
    if (value instanceof VString || value instanceof VStringArray)
        format_for_this_value = new StringVTypeFormat();
    else {
        if (Double.isNaN(VTypeHelper.toDouble(value))) {
            if (min_max_column)
                return Messages.Export_NoValueMarker + Messages.Export_Delimiter + Messages.Export_NoValueMarker + Messages.Export_Delimiter + Messages.Export_NoValueMarker;
            else
                return Messages.Export_NoValueMarker;
        }
        format_for_this_value = format;
    }
    final VStatistics stats = (value instanceof VStatistics) ? (VStatistics) value : null;
    final StringBuilder buf = new StringBuilder();
    if (stats != null)
        // Show only the average, since min/max handled separately
        format_for_this_value.format(stats.getAverage(), stats, buf);
    else
        format_for_this_value.format(value, buf);
    // Optional min, max
    if (min_max_column) {
        buf.append(Messages.Export_Delimiter);
        if (stats != null) {
            // Turn min..max into negative & positive error
            buf.append(stats.getAverage() - stats.getMin());
            buf.append(Messages.Export_Delimiter);
            buf.append(stats.getMax() - stats.getAverage());
        } else {
            buf.append(0);
            buf.append(Messages.Export_Delimiter);
            buf.append(0);
        }
    }
    return buf.toString();
}
Also used : StringVTypeFormat(org.csstudio.archive.vtype.StringVTypeFormat) VTypeFormat(org.csstudio.archive.vtype.VTypeFormat) StringVTypeFormat(org.csstudio.archive.vtype.StringVTypeFormat) VString(org.diirt.vtype.VString) VStringArray(org.diirt.vtype.VStringArray) VStatistics(org.diirt.vtype.VStatistics)

Example 18 with VString

use of org.diirt.vtype.VString 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 19 with VString

use of org.diirt.vtype.VString 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 20 with VString

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

VString (org.diirt.vtype.VString)20 VTable (org.diirt.vtype.VTable)9 VNumberArray (org.diirt.vtype.VNumberArray)5 ListInt (org.diirt.util.array.ListInt)4 ListNumber (org.diirt.util.array.ListNumber)4 VNumber (org.diirt.vtype.VNumber)4 VStringArray (org.diirt.vtype.VStringArray)4 VType (org.diirt.vtype.VType)4 VEnum (org.diirt.vtype.VEnum)3 VEnumArray (org.diirt.vtype.VEnumArray)3 ArrayList (java.util.ArrayList)2 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ArrayInt (org.diirt.util.array.ArrayInt)2 VBoolean (org.diirt.vtype.VBoolean)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Rotate (javafx.scene.transform.Rotate)1 Translate (javafx.scene.transform.Translate)1