Search in sources :

Example 6 with VEnum

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

the class MenuButtonEditPart method registerLoadActionsListener.

private void registerLoadActionsListener() {
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        if (getWidgetModel().isActionsFromPV()) {
            IPV pv = getPV(AbstractPVWidgetModel.PROP_PVNAME);
            if (pv != null) {
                if (loadActionsFromPVListener == null)
                    loadActionsFromPVListener = new IPVListener.Stub() {

                        @Override
                        public void valueChanged(IPV pv) {
                            VType value = pv.getValue();
                            if (value != null && value instanceof VEnum) {
                                List<String> new_meta = ((VEnum) value).getLabels();
                                if (meta == null || !meta.equals(new_meta)) {
                                    meta = new_meta;
                                    ActionsInput actionsInput = new ActionsInput();
                                    for (String writeValue : meta) {
                                        WritePVAction action = new WritePVAction();
                                        action.setPropertyValue(WritePVAction.PROP_PVNAME, getWidgetModel().getPVName());
                                        action.setPropertyValue(WritePVAction.PROP_VALUE, writeValue);
                                        action.setPropertyValue(WritePVAction.PROP_DESCRIPTION, writeValue);
                                        actionsInput.getActionsList().add(action);
                                    }
                                    getWidgetModel().setPropertyValue(AbstractWidgetModel.PROP_ACTIONS, actionsInput);
                                }
                            }
                        }
                    };
                pv.addListener(loadActionsFromPVListener);
            }
        }
    }
}
Also used : VType(org.diirt.vtype.VType) ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) WritePVAction(org.csstudio.opibuilder.widgetActions.WritePVAction) VEnum(org.diirt.vtype.VEnum) IPV(org.csstudio.simplepv.IPV)

Example 7 with VEnum

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

the class FormatOptionHandlerTest method testEnum.

@Test
public void testEnum() throws Exception {
    final VEnum value = ValueFactory.newVEnum(1, Arrays.asList("One", "Two"), ValueFactory.alarmNone(), ValueFactory.timeNow());
    String text = FormatOptionHandler.format(value, FormatOption.DECIMAL, 4, true);
    System.out.println(text);
    assertThat(text, equalTo("1"));
    text = FormatOptionHandler.format(value, FormatOption.DEFAULT, -4, true);
    System.out.println(text);
    assertThat(text, equalTo("Two"));
}
Also used : VEnum(org.diirt.vtype.VEnum) Test(org.junit.Test)

Example 8 with VEnum

use of org.diirt.vtype.VEnum 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 9 with VEnum

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

the class RadioRepresentation method contentChanged.

/**
 * The value or how we treat the value changed
 */
private void contentChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final VType value = model_widget.runtimePropValue().getValue();
    final boolean fromPV = model_widget.propItemsFromPV().getValue() && value instanceof VEnum;
    items = computeItems(value, fromPV);
    index = determineIndex(items, value);
    dirty_content.mark();
    // Adjust colors
    dirty_style.mark();
    toolkit.scheduleUpdate(this);
}
Also used : VType(org.diirt.vtype.VType) VEnum(org.diirt.vtype.VEnum)

Example 10 with VEnum

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

Aggregations

VEnum (org.diirt.vtype.VEnum)12 VType (org.diirt.vtype.VType)7 VString (org.diirt.vtype.VString)4 IPV (org.csstudio.simplepv.IPV)3 ListNumber (org.diirt.util.array.ListNumber)3 VEnumArray (org.diirt.vtype.VEnumArray)3 VNumber (org.diirt.vtype.VNumber)3 VNumberArray (org.diirt.vtype.VNumberArray)3 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ListInt (org.diirt.util.array.ListInt)2 VBoolean (org.diirt.vtype.VBoolean)2 VTable (org.diirt.vtype.VTable)2 Rotate (javafx.scene.transform.Rotate)1 Translate (javafx.scene.transform.Translate)1 RotationStep (org.csstudio.display.builder.model.properties.RotationStep)1 ActionsInput (org.csstudio.opibuilder.widgetActions.ActionsInput)1 WritePVAction (org.csstudio.opibuilder.widgetActions.WritePVAction)1 VImage (org.diirt.vtype.VImage)1 VStringArray (org.diirt.vtype.VStringArray)1