Search in sources :

Example 11 with PROP_WIDTH

use of org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH in project yamcs-studio by yamcs.

the class ImageBoolButtonEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    registerCommonPropertyChangeHandlers();
    // Save CPU usage
    // removeAllPropertyChangeHandlers(AbstractPVWidgetModel.PROP_PVVALUE);
    // value
    // IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {
    // public boolean handleChange(Object oldValue,
    // final Object newValue,
    // final IFigure refreshableFigure) {
    // if(newValue == null)
    // return false;
    // ImageBoolButtonFigure figure = (ImageBoolButtonFigure) refreshableFigure;
    // //figure.setValue(ValueUtil.getDouble((IValue)newValue));
    // autoSizeWidget(figure);
    // return true;
    // }
    // };
    // setPropertyChangeHandler(AbstractPVWidgetModel.PROP_PVVALUE, handler);
    setPropertyChangeHandler(PROP_ON_IMAGE, (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        var absolutePath = (String) newValue;
        if (!absolutePath.contains("://")) {
            var path = Path.fromPortableString(absolutePath);
            if (!path.isAbsolute()) {
                path = ResourceUtil.buildAbsolutePath(getWidgetModel(), path);
                absolutePath = path.toPortableString();
            }
        }
        imageFigure.setOnImagePath(absolutePath);
        autoSizeWidget(imageFigure);
        return true;
    });
    setPropertyChangeHandler(PROP_OFF_IMAGE, (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        var absolutePath = (String) newValue;
        if (!absolutePath.contains("://")) {
            var path = Path.fromPortableString(absolutePath);
            if (!path.isAbsolute()) {
                path = ResourceUtil.buildAbsolutePath(getWidgetModel(), path);
                absolutePath = path.toPortableString();
            }
        }
        imageFigure.setOffImagePath(absolutePath);
        autoSizeWidget(imageFigure);
        return true;
    });
    setPropertyChangeHandler(PROP_STRETCH, (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        imageFigure.setStretch((Boolean) newValue);
        autoSizeWidget(imageFigure);
        return true;
    });
    FigureTransparencyHelper.addHandler(this, figure);
    setPropertyChangeHandler(PROP_AUTOSIZE, (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        autoSizeWidget(imageFigure);
        return true;
    });
    setPropertyChangeHandler(PROP_NO_ANIMATION, (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        imageFigure.setAnimationDisabled((Boolean) newValue);
        return false;
    });
    setPropertyChangeHandler(PROP_ALIGN_TO_NEAREST_SECOND, (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        imageFigure.setAlignedToNearestSecond((Boolean) newValue);
        return false;
    });
    // changes to the border width property
    IWidgetPropertyChangeHandler handle = (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        autoSizeWidget(imageFigure);
        return true;
    };
    setPropertyChangeHandler(PROP_BORDER_WIDTH, handle);
    setPropertyChangeHandler(PROP_BORDER_STYLE, handle);
    // size change handlers - so we can stretch accordingly
    handle = (oldValue, newValue, figure) -> {
        var imageFigure = (ImageBoolButtonFigure) figure;
        autoSizeWidget(imageFigure);
        return true;
    };
    setPropertyChangeHandler(PROP_HEIGHT, handle);
    setPropertyChangeHandler(PROP_WIDTH, handle);
}
Also used : PROP_OFF_IMAGE(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel.PROP_OFF_IMAGE) PROP_BORDER_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH) PROP_NO_ANIMATION(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel.PROP_NO_ANIMATION) PROP_HEIGHT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT) ImageBoolButtonModel(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel) ResourceUtil(org.csstudio.opibuilder.util.ResourceUtil) Display(org.eclipse.swt.widgets.Display) ImageBoolButtonFigure(org.csstudio.opibuilder.widgets.figures.ImageBoolButtonFigure) IFigure(org.eclipse.draw2d.IFigure) PROP_ON_IMAGE(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel.PROP_ON_IMAGE) PROP_AUTOSIZE(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel.PROP_AUTOSIZE) PROP_STRETCH(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel.PROP_STRETCH) Color(org.eclipse.swt.graphics.Color) PROP_ALIGN_TO_NEAREST_SECOND(org.csstudio.opibuilder.widgets.model.ImageBoolButtonModel.PROP_ALIGN_TO_NEAREST_SECOND) Path(org.eclipse.core.runtime.Path) FigureTransparencyHelper(org.csstudio.opibuilder.widgets.FigureTransparencyHelper) PROP_BORDER_STYLE(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE) SymbolImageProperties(org.csstudio.swt.widgets.symbol.SymbolImageProperties) PROP_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) ImageBoolButtonFigure(org.csstudio.opibuilder.widgets.figures.ImageBoolButtonFigure)

Aggregations

PROP_HEIGHT (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT)11 PROP_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH)11 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)11 IFigure (org.eclipse.draw2d.IFigure)11 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)6 PROP_BORDER_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH)6 PROP_BORDER_STYLE (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE)5 Path (org.eclipse.core.runtime.Path)5 PropertyChangeListener (java.beans.PropertyChangeListener)4 ResourceUtil (org.csstudio.opibuilder.util.ResourceUtil)4 Color (org.eclipse.swt.graphics.Color)4 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)3 AbstractContainerEditpart (org.csstudio.opibuilder.editparts.AbstractContainerEditpart)3 PROP_PVNAME (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME)3 PROP_PVVALUE (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE)3 OPIColor (org.csstudio.opibuilder.util.OPIColor)3 FigureTransparencyHelper (org.csstudio.opibuilder.widgets.FigureTransparencyHelper)3 Arrays (java.util.Arrays)2 List (java.util.List)2 PROP_VISIBLE (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_VISIBLE)2