Search in sources :

Example 1 with SpinnerFigure

use of org.csstudio.swt.widgets.figures.SpinnerFigure in project yamcs-studio by yamcs.

the class SpinnerEditpart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    // text
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            String text = (String) newValue;
            try {
                // $NON-NLS-1$ //$NON-NLS-2$
                text = text.replace("e", "E");
                double value = new DecimalFormat().parse(text).doubleValue();
                // coerce value in range
                value = Math.max(((SpinnerFigure) figure).getMin(), Math.min(((SpinnerFigure) figure).getMax(), value));
                ((SpinnerFigure) figure).setValue(value);
                if (getExecutionMode() == ExecutionMode.RUN_MODE)
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, value);
                getWidgetModel().setText(((SpinnerFigure) figure).getLabelFigure().getText(), false);
                return false;
            } catch (Exception e) {
                return false;
            }
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_TEXT, handler);
    IWidgetPropertyChangeHandler pvNameHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            registerLoadLimitsListener();
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVNAME, pvNameHandler);
    // pv value
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (newValue == null)
                return false;
            double value = VTypeHelper.getDouble((VType) newValue);
            ((SpinnerFigure) figure).setDisplayValue(value);
            getWidgetModel().setText(((SpinnerFigure) figure).getLabelFigure().getText(), false);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_PVVALUE, handler);
    // min
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setMin((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_MIN, handler);
    // max
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setMax((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_MAX, handler);
    // step increment
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setStepIncrement((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_STEP_INCREMENT, handler);
    // page increment
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setPageIncrement((Double) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_PAGE_INCREMENT, handler);
    // font
    IWidgetPropertyChangeHandler fontHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setFont(CustomMediaFactory.getInstance().getFont(((OPIFont) newValue).getFontData()));
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_FONT, fontHandler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setHorizontalAlignment(H_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_H, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setVerticalAlignment(V_ALIGN.values()[(Integer) newValue]);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_ALIGN_V, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).getLabelFigure().setOpaque(!(Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(LabelModel.PROP_TRANSPARENT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setFormatType(NumericFormatType.values()[(Integer) newValue]);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_FORMAT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setPrecision((Integer) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_PRECISION, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setArrowButtonsOnLeft((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_BUTTONS_ON_LEFT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).setArrowButtonsHorizontal((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_HORIZONTAL_BUTTONS_LAYOUT, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((SpinnerFigure) figure).showText((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(SpinnerModel.PROP_SHOW_TEXT, handler);
}
Also used : OPIFont(org.csstudio.opibuilder.util.OPIFont) SpinnerFigure(org.csstudio.swt.widgets.figures.SpinnerFigure) DecimalFormat(java.text.DecimalFormat) VType(org.diirt.vtype.VType) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with SpinnerFigure

use of org.csstudio.swt.widgets.figures.SpinnerFigure in project yamcs-studio by yamcs.

the class SpinnerEditpart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    SpinnerFigure spinner = new SpinnerFigure();
    TextFigure labelFigure = spinner.getLabelFigure();
    labelFigure.setFont(getWidgetModel().getFont().getSWTFont());
    labelFigure.setFontPixels(getWidgetModel().getFont().isSizeInPixels());
    labelFigure.setOpaque(!getWidgetModel().isTransparent());
    labelFigure.setHorizontalAlignment(getWidgetModel().getHorizontalAlignment());
    labelFigure.setVerticalAlignment(getWidgetModel().getVerticalAlignment());
    spinner.setMax(getWidgetModel().getMaximum());
    spinner.setMin(getWidgetModel().getMinimum());
    spinner.setStepIncrement(getWidgetModel().getStepIncrement());
    spinner.setPageIncrement(getWidgetModel().getPageIncrement());
    spinner.setFormatType(getWidgetModel().getFormat());
    spinner.setPrecision((Integer) getPropertyValue(SpinnerModel.PROP_PRECISION));
    spinner.setArrowButtonsOnLeft(getWidgetModel().isButtonsOnLeft());
    spinner.setArrowButtonsHorizontal(getWidgetModel().isHorizontalButtonsLayout());
    spinner.showText(getWidgetModel().showText());
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        spinner.addManualValueChangeListener(new IManualValueChangeListener() {

            @Override
            public void manualValueChanged(double newValue) {
                setPVValue(SpinnerModel.PROP_PVNAME, newValue);
                getWidgetModel().setText(((SpinnerFigure) getFigure()).getLabelFigure().getText(), false);
            }
        });
    }
    return spinner;
}
Also used : IManualValueChangeListener(org.csstudio.swt.widgets.datadefinition.IManualValueChangeListener) SpinnerFigure(org.csstudio.swt.widgets.figures.SpinnerFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) TextFigure(org.csstudio.swt.widgets.figures.TextFigure)

Aggregations

SpinnerFigure (org.csstudio.swt.widgets.figures.SpinnerFigure)2 DecimalFormat (java.text.DecimalFormat)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 OPIFont (org.csstudio.opibuilder.util.OPIFont)1 IManualValueChangeListener (org.csstudio.swt.widgets.datadefinition.IManualValueChangeListener)1 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)1 TextFigure (org.csstudio.swt.widgets.figures.TextFigure)1 VType (org.diirt.vtype.VType)1 IFigure (org.eclipse.draw2d.IFigure)1