Search in sources :

Example 1 with MenuButtonFigure

use of org.csstudio.opibuilder.widgets.figures.MenuButtonFigure in project yamcs-studio by yamcs.

the class MenuButtonEditPart method doCreateFigure.

@Override
protected IFigure doCreateFigure() {
    var model = getWidgetModel();
    updatePropSheet(model.isActionsFromPV());
    var figure = new MenuButtonFigure();
    figure.setOpaque(!model.isTransparent());
    figure.setText(model.getLabel());
    figure.setDownArrowVisible(model.showDownArrow());
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        figure.addMouseListener(new MouseListener() {

            @Override
            public void mouseDoubleClicked(MouseEvent me) {
            }

            @Override
            public void mousePressed(MouseEvent me) {
                if (me.button == 1 && figure.containsPoint(me.getLocation())) {
                    me.consume();
                }
            }

            @Override
            public void mouseReleased(MouseEvent me) {
                // see https://github.com/ControlSystemStudio/cs-studio/issues/1818
                if (me.button == 1 && getExecutionMode().equals(ExecutionMode.RUN_MODE) && figure.containsPoint(me.getLocation())) {
                    var cursorLocation = Display.getCurrent().getCursorLocation();
                    showMenu(me.getLocation(), cursorLocation.x, cursorLocation.y);
                }
            }
        });
    }
    figure.addMouseMotionListener(new MouseMotionListener.Stub() {

        @Override
        public void mouseEntered(MouseEvent me) {
            if (getExecutionMode().equals(ExecutionMode.RUN_MODE)) {
                var backColor = figure.getBackgroundColor();
                var darkColor = GraphicsUtil.mixColors(backColor.getRGB(), new RGB(0, 0, 0), 0.9);
                figure.setBackgroundColor(CustomMediaFactory.getInstance().getColor(darkColor));
            }
        }

        @Override
        public void mouseExited(MouseEvent me) {
            if (getExecutionMode().equals(ExecutionMode.RUN_MODE)) {
                figure.setBackgroundColor(CustomMediaFactory.getInstance().getColor(getWidgetModel().getBackgroundColor()));
            }
        }
    });
    markAsControlPV(PROP_PVNAME, PROP_PVVALUE);
    return figure;
}
Also used : MenuButtonFigure(org.csstudio.opibuilder.widgets.figures.MenuButtonFigure) MouseListener(org.eclipse.draw2d.MouseListener) MouseEvent(org.eclipse.draw2d.MouseEvent) MouseMotionListener(org.eclipse.draw2d.MouseMotionListener) RGB(org.eclipse.swt.graphics.RGB)

Example 2 with MenuButtonFigure

use of org.csstudio.opibuilder.widgets.figures.MenuButtonFigure in project yamcs-studio by yamcs.

the class MenuButtonEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    setPropertyChangeHandler(PROP_PVNAME, (oldValue, newValue, figure) -> {
        registerLoadActionsListener();
        return false;
    });
    setPropertyChangeHandler(PROP_PVVALUE, (oldValue, newValue, refreshableFigure) -> {
        if ((newValue != null) && (newValue instanceof Scalar)) {
            ((MenuButtonFigure) refreshableFigure).setText(VTypeHelper.getString((VType) newValue));
        }
        return true;
    });
    setPropertyChangeHandler(PROP_LABEL, (oldValue, newValue, refreshableFigure) -> {
        ((MenuButtonFigure) refreshableFigure).setText(newValue.toString());
        return true;
    });
    setPropertyChangeHandler(PROP_TRANSPARENT, (oldValue, newValue, refreshableFigure) -> {
        ((MenuButtonFigure) refreshableFigure).setOpaque(!(Boolean) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_SHOW_DOWN_ARROW, (oldValue, newValue, refreshableFigure) -> {
        ((MenuButtonFigure) refreshableFigure).setDownArrowVisible((boolean) newValue);
        return true;
    });
    IWidgetPropertyChangeHandler handler = (oldValue, newValue, refreshableFigure) -> {
        updatePropSheet((Boolean) newValue);
        return false;
    };
    getWidgetModel().getProperty(PROP_ACTIONS_FROM_PV).addPropertyChangeListener(evt -> handler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure()));
}
Also used : PROP_PVVALUE(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE) WidgetActionMenuAction(org.csstudio.opibuilder.actions.WidgetActionMenuAction) PROP_TRANSPARENT(org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_TRANSPARENT) PROP_ACTIONS(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ACTIONS) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) PROP_PVNAME(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME) RequestConstants(org.eclipse.gef.RequestConstants) CustomMediaFactory(org.csstudio.ui.util.CustomMediaFactory) IFigure(org.eclipse.draw2d.IFigure) ITextFigure(org.csstudio.swt.widgets.figures.ITextFigure) PROP_SHOW_DOWN_ARROW(org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_SHOW_DOWN_ARROW) IPV(org.yamcs.studio.data.IPV) Request(org.eclipse.gef.Request) RGB(org.eclipse.swt.graphics.RGB) IPVListener(org.yamcs.studio.data.IPVListener) ActionsInput(org.csstudio.opibuilder.widgetActions.ActionsInput) Scalar(org.yamcs.studio.data.vtype.Scalar) MouseMotionListener(org.eclipse.draw2d.MouseMotionListener) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) VTypeHelper(org.yamcs.studio.data.VTypeHelper) PlatformUI(org.eclipse.ui.PlatformUI) Point(org.eclipse.draw2d.geometry.Point) MenuManager(org.eclipse.jface.action.MenuManager) VEnum(org.yamcs.studio.data.vtype.VEnum) MouseEvent(org.eclipse.draw2d.MouseEvent) PROP_ACTIONS_FROM_PV(org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_ACTIONS_FROM_PV) MouseListener(org.eclipse.draw2d.MouseListener) Display(org.eclipse.swt.widgets.Display) PROP_LABEL(org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_LABEL) MenuButtonFigure(org.csstudio.opibuilder.widgets.figures.MenuButtonFigure) List(java.util.List) WritePVAction(org.csstudio.opibuilder.widgetActions.WritePVAction) VType(org.yamcs.studio.data.vtype.VType) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) MenuButtonModel(org.csstudio.opibuilder.widgets.model.MenuButtonModel) EditPolicy(org.eclipse.gef.EditPolicy) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) GraphicsUtil(org.csstudio.swt.widgets.util.GraphicsUtil) MenuButtonFigure(org.csstudio.opibuilder.widgets.figures.MenuButtonFigure) VType(org.yamcs.studio.data.vtype.VType) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) Scalar(org.yamcs.studio.data.vtype.Scalar)

Aggregations

MenuButtonFigure (org.csstudio.opibuilder.widgets.figures.MenuButtonFigure)2 MouseEvent (org.eclipse.draw2d.MouseEvent)2 MouseListener (org.eclipse.draw2d.MouseListener)2 MouseMotionListener (org.eclipse.draw2d.MouseMotionListener)2 RGB (org.eclipse.swt.graphics.RGB)2 List (java.util.List)1 WidgetActionMenuAction (org.csstudio.opibuilder.actions.WidgetActionMenuAction)1 AbstractPVWidgetEditPart (org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart)1 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 PROP_ACTIONS (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ACTIONS)1 PROP_PVNAME (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME)1 PROP_PVVALUE (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 ActionsInput (org.csstudio.opibuilder.widgetActions.ActionsInput)1 WritePVAction (org.csstudio.opibuilder.widgetActions.WritePVAction)1 MenuButtonModel (org.csstudio.opibuilder.widgets.model.MenuButtonModel)1 PROP_ACTIONS_FROM_PV (org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_ACTIONS_FROM_PV)1 PROP_LABEL (org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_LABEL)1 PROP_SHOW_DOWN_ARROW (org.csstudio.opibuilder.widgets.model.MenuButtonModel.PROP_SHOW_DOWN_ARROW)1