Search in sources :

Example 1 with ThumbWheelFigure

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

the class ThumbWheelEditPart method doCreateFigure.

/**
 * {@inheritDoc}
 */
@Override
protected IFigure doCreateFigure() {
    model = (ThumbWheelModel) getWidgetModel();
    logic = new ThumbWheelLogic(0, model.getWholePartDigits(), model.getDecimalPartDigits());
    logic.setMax(model.getMaximum());
    logic.setMin(model.getMinimum());
    figure = new ThumbWheelFigure(logic.getIntegerWheels(), logic.getDecimalWheels(), this.getExecutionMode() == ExecutionMode.RUN_MODE);
    model.setWholePartDigits(logic.getIntegerWheels());
    model.setDecimalPartDigits(logic.getDecimalWheels());
    FontData fontData = model.getFont().getFontData();
    figure.setWheelFont(CustomMediaFactory.getInstance().getFont(fontData.getName(), fontData.getHeight(), fontData.getStyle()));
    figure.setInternalBorderColor(model.getInternalBorderColor());
    figure.setInternalFocusedBorderColor(model.getInternalFocusedBorderColor());
    figure.setInternalBorderThickness(model.getInternalBorderWidth());
    figure.setButtonVisibility(model.isButtonVisible());
    markAsControlPV(AbstractPVWidgetModel.PROP_PVNAME, AbstractPVWidgetModel.PROP_PVVALUE);
    figure.addWheelListener(new WheelListener() {

        @Override
        public void decrementDecimalPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.decrementDecimalDigitAt(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }

        @Override
        public void incrementDecimalPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.incrementDecimalDigitAt(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }

        @Override
        public void decrementIntegerPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.decrementIntigerDigitAt(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }

        @Override
        public void incrementIntegerPart(int index) {
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                logic.incrementIntigerWheel(index);
                updateWheelValues();
                // write value to pv if pv name is not empty
                if (getWidgetModel().getPVName().trim().length() > 0) {
                    double doubleValue = logic.getValue();
                    setPVValue(AbstractPVWidgetModel.PROP_PVNAME, doubleValue);
                }
            }
        }
    });
    updateWheelValues();
    return figure;
}
Also used : ThumbWheelFigure(org.csstudio.swt.widgets.figures.ThumbWheelFigure) WheelListener(org.csstudio.swt.widgets.figures.ThumbWheelFigure.WheelListener) FontData(org.eclipse.swt.graphics.FontData)

Example 2 with ThumbWheelFigure

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

the class ThumbWheelEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    // PV value
    IWidgetPropertyChangeHandler pvhandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            if (newValue != null) {
                double doubleValue = VTypeHelper.getDouble((VType) newValue);
                logic.setValue(doubleValue);
                updateWheelValues();
            }
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_PVVALUE, pvhandler);
    IWidgetPropertyChangeHandler pvNameHandler = new IWidgetPropertyChangeHandler() {

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

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            logic.setDecimalWheels((Integer) newValue);
            figure.setDecimalDigits(logic.getDecimalWheels());
            model.setDecimalPartDigits(logic.getDecimalWheels());
            updateWheelValues();
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_DECIMAL_DIGITS_PART, handler);
    // integer wheels
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            logic.setIntegerWheels((Integer) newValue);
            figure.setIntegerDigits(logic.getIntegerWheels());
            model.setWholePartDigits(logic.getIntegerWheels());
            updateWheelValues();
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_INTEGER_DIGITS_PART, handler);
    // min
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            logic.setMin((Double) newValue);
            updateWheelValues();
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_MIN, handler);
    // max
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            logic.setMax((Double) newValue);
            updateWheelValues();
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_MAX, handler);
    // value
    // handler = new IWidgetPropertyChangeHandler() {
    // public boolean handleChange(final Object oldValue,
    // final Object newValue, final IFigure refreshableFigure) {
    // logic.setValue((Double) newValue);
    // updateWheelValues();
    // return true;
    // }
    // };
    // setPropertyChangeHandler(ThumbWheelModel.PROP_VALUE, handler);
    // font
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            FontData fontData = ((OPIFont) newValue).getFontData();
            figure.setWheelFont(CustomMediaFactory.getInstance().getFont(fontData.getName(), fontData.getHeight(), fontData.getStyle()));
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_FONT, handler);
    // border color
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            figure.setInternalBorderColor(((OPIColor) newValue).getSWTColor());
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_INTERNAL_FRAME_COLOR, handler);
    // focused border color
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            figure.setInternalFocusedBorderColor(((OPIColor) newValue).getSWTColor());
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_INTERNAL_FOCUSED_FRAME_COLOR, handler);
    // border width
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            figure.setInternalBorderThickness((Integer) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_INTERNAL_FRAME_THICKNESS, handler);
    // show button
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThumbWheelFigure figure = (ThumbWheelFigure) refreshableFigure;
            figure.setButtonVisibility((Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(ThumbWheelModel.PROP_SHOW_BUTTONS, handler);
}
Also used : ThumbWheelFigure(org.csstudio.swt.widgets.figures.ThumbWheelFigure) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) FontData(org.eclipse.swt.graphics.FontData) OPIColor(org.csstudio.opibuilder.util.OPIColor) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

ThumbWheelFigure (org.csstudio.swt.widgets.figures.ThumbWheelFigure)2 FontData (org.eclipse.swt.graphics.FontData)2 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 WheelListener (org.csstudio.swt.widgets.figures.ThumbWheelFigure.WheelListener)1 IFigure (org.eclipse.draw2d.IFigure)1