Search in sources :

Example 1 with LEDFigure

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

the class LEDEditPart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    final LEDModel model = getWidgetModel();
    LEDFigure led = new LEDFigure();
    initializeCommonFigureProperties(led, model);
    led.setEffect3D(model.isEffect3D());
    led.setSquareLED(model.isSquareLED());
    return led;
}
Also used : LEDFigure(org.csstudio.swt.widgets.figures.LEDFigure) LEDModel(org.csstudio.opibuilder.widgets.model.LEDModel)

Example 2 with LEDFigure

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

the class LEDEditPart method initializeCommonFigureProperties.

@Override
protected void initializeCommonFigureProperties(final AbstractBoolFigure abstractFigure, final AbstractBoolWidgetModel abstractModel) {
    super.initializeCommonFigureProperties(abstractFigure, abstractModel);
    LEDModel model = (LEDModel) abstractModel;
    LEDFigure figure = (LEDFigure) abstractFigure;
    initializeStateBulbBorderColor(model.getBulbBorderColor(), figure, model);
    initializeStateBulbBorderWidth(model.getBulbBorderWidth(), figure, model);
    initializeNStatesProperties(LEDFigure.MAX_NSTATES, model.getNStates(), figure, model);
    initializeStateFallbackLabel(null, model.getStateFallbackLabel(), figure, model);
    initializeStateFallbackColor(null, model.getStateFallbackColor(), figure, model);
    for (int state = 0; state < LEDFigure.MAX_NSTATES; state++) {
        initializeStateColor(state, null, model.getStateColor(state), figure, model);
        initializeStateLabel(state, null, model.getStateLabel(state), figure, model);
        initializeStateValue(state, 0.0, model.getStateValue(state), figure, model);
    }
}
Also used : LEDFigure(org.csstudio.swt.widgets.figures.LEDFigure) LEDModel(org.csstudio.opibuilder.widgets.model.LEDModel)

Example 3 with LEDFigure

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

the class LEDEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    registerCommonPropertyChangeHandlers();
    setPropertyChangeHandler(PROP_EFFECT3D, (oldValue, newValue, refreshableFigure) -> {
        var led = (LEDFigure) refreshableFigure;
        led.setEffect3D((Boolean) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_SQUARE_LED, (oldValue, newValue, refreshableFigure) -> {
        var led = (LEDFigure) refreshableFigure;
        led.setSquareLED((Boolean) newValue);
        if (!(Boolean) newValue) {
            var width = Math.min(getWidgetModel().getWidth(), getWidgetModel().getHeight());
            getWidgetModel().setSize(width, width);
        }
        return true;
    });
    // force square size
    IWidgetPropertyChangeHandler sizeHandler = (oldValue, newValue, figure) -> {
        if (getWidgetModel().isSquareLED()) {
            return false;
        }
        if (((Integer) newValue) < LEDModel.MINIMUM_SIZE) {
            newValue = LEDModel.MINIMUM_SIZE;
        }
        getWidgetModel().setSize((Integer) newValue, (Integer) newValue);
        return false;
    };
    PropertyChangeListener sizeListener = evt -> sizeHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
    getWidgetModel().getProperty(PROP_WIDTH).addPropertyChangeListener(sizeListener);
    getWidgetModel().getProperty(PROP_HEIGHT).addPropertyChangeListener(sizeListener);
    getWidgetModel().getProperty(PROP_NSTATES).addPropertyChangeListener(evt -> initializeNStatesProperties((Integer) evt.getOldValue(), (Integer) evt.getNewValue(), (LEDFigure) getFigure(), getWidgetModel()));
    getWidgetModel().getProperty(PROP_STATE_FALLBACK_LABEL).addPropertyChangeListener(evt -> initializeStateFallbackLabel((String) evt.getOldValue(), (String) evt.getNewValue(), (LEDFigure) getFigure(), getWidgetModel()));
    getWidgetModel().getProperty(PROP_STATE_FALLBACK_COLOR).addPropertyChangeListener(evt -> initializeStateFallbackColor(((OPIColor) evt.getOldValue()).getSWTColor(), ((OPIColor) evt.getNewValue()).getSWTColor(), (LEDFigure) getFigure(), getWidgetModel()));
    getWidgetModel().getProperty(PROP_BULB_BORDER).addPropertyChangeListener(evt -> initializeStateBulbBorderWidth((Integer) evt.getNewValue(), (LEDFigure) getFigure(), getWidgetModel()));
    getWidgetModel().getProperty(PROP_BULB_BORDER_COLOR).addPropertyChangeListener(evt -> initializeStateBulbBorderColor(((OPIColor) evt.getNewValue()).getSWTColor(), (LEDFigure) getFigure(), getWidgetModel()));
    for (var idx = 0; idx < LEDFigure.MAX_NSTATES; idx++) {
        var state = idx;
        getWidgetModel().getProperty(String.format(PROP_STATE_LABEL, state)).addPropertyChangeListener(evt -> initializeStateLabel(state, (String) evt.getOldValue(), (String) evt.getNewValue(), (LEDFigure) getFigure(), getWidgetModel()));
        getWidgetModel().getProperty(String.format(PROP_STATE_COLOR, state)).addPropertyChangeListener(evt -> initializeStateColor(state, ((OPIColor) evt.getOldValue()).getSWTColor(), ((OPIColor) evt.getNewValue()).getSWTColor(), (LEDFigure) getFigure(), getWidgetModel()));
        getWidgetModel().getProperty(String.format(PROP_STATE_VALUE, state)).addPropertyChangeListener(evt -> initializeStateValue(state, (Double) evt.getOldValue(), (Double) evt.getNewValue(), (LEDFigure) getFigure(), getWidgetModel()));
    }
}
Also used : PROP_STATE_LABEL(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_LABEL) AbstractBoolFigure(org.csstudio.swt.widgets.figures.AbstractBoolFigure) LEDFigure(org.csstudio.swt.widgets.figures.LEDFigure) PROP_BULB_BORDER_COLOR(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_BULB_BORDER_COLOR) PROP_HEIGHT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT) PROP_OFF_LABEL(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_LABEL) IFigure(org.eclipse.draw2d.IFigure) AbstractBoolWidgetModel(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel) PROP_OFF_COLOR(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_COLOR) OPIColor(org.csstudio.opibuilder.util.OPIColor) PROP_BULB_BORDER(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_BULB_BORDER) PROP_SQUARE_LED(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_SQUARE_LED) LEDModel(org.csstudio.opibuilder.widgets.model.LEDModel) PROP_ON_COLOR(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_COLOR) PROP_EFFECT3D(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_EFFECT3D) PROP_STATE_COLOR(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_COLOR) PROP_STATE_FALLBACK_COLOR(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_FALLBACK_COLOR) PROP_NSTATES(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_NSTATES) PropertyChangeListener(java.beans.PropertyChangeListener) Color(org.eclipse.swt.graphics.Color) PROP_STATE_FALLBACK_LABEL(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_FALLBACK_LABEL) PROP_ON_LABEL(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_LABEL) PROP_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH) PROP_STATE_VALUE(org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_VALUE) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) LEDFigure(org.csstudio.swt.widgets.figures.LEDFigure) OPIColor(org.csstudio.opibuilder.util.OPIColor)

Aggregations

LEDModel (org.csstudio.opibuilder.widgets.model.LEDModel)3 LEDFigure (org.csstudio.swt.widgets.figures.LEDFigure)3 PropertyChangeListener (java.beans.PropertyChangeListener)1 PROP_HEIGHT (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT)1 PROP_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 AbstractBoolWidgetModel (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel)1 PROP_OFF_COLOR (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_COLOR)1 PROP_OFF_LABEL (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_LABEL)1 PROP_ON_COLOR (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_COLOR)1 PROP_ON_LABEL (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_LABEL)1 PROP_BULB_BORDER (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_BULB_BORDER)1 PROP_BULB_BORDER_COLOR (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_BULB_BORDER_COLOR)1 PROP_EFFECT3D (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_EFFECT3D)1 PROP_NSTATES (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_NSTATES)1 PROP_SQUARE_LED (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_SQUARE_LED)1 PROP_STATE_COLOR (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_COLOR)1 PROP_STATE_FALLBACK_COLOR (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_FALLBACK_COLOR)1 PROP_STATE_FALLBACK_LABEL (org.csstudio.opibuilder.widgets.model.LEDModel.PROP_STATE_FALLBACK_LABEL)1