Search in sources :

Example 86 with IFigure

use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.

the class ThermometerEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    registerCommonPropertyChangeHandlers();
    // fillColor
    IWidgetPropertyChangeHandler fillColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
            thermometer.setFillColor(((OPIColor) newValue).getSWTColor());
            return false;
        }
    };
    setPropertyChangeHandler(ThermometerModel.PROP_FILL_COLOR, fillColorHandler);
    // fillBackgroundColor
    IWidgetPropertyChangeHandler fillBackColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
            thermometer.setFillBackgroundColor(((OPIColor) newValue).getSWTColor());
            return false;
        }
    };
    setPropertyChangeHandler(ThermometerModel.PROP_FILLBACKGROUND_COLOR, fillBackColorHandler);
    // show bulb
    IWidgetPropertyChangeHandler showBulbHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
            thermometer.setShowBulb((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(ThermometerModel.PROP_SHOW_BULB, showBulbHandler);
    // unit
    IWidgetPropertyChangeHandler fahrenheitHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThermometerFigure thermometer = (ThermometerFigure) refreshableFigure;
            thermometer.setTemperatureUnit(TemperatureUnit.values()[(Integer) newValue]);
            return false;
        }
    };
    setPropertyChangeHandler(ThermometerModel.PROP_UNIT, fahrenheitHandler);
    // effect 3D
    IWidgetPropertyChangeHandler effect3DHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ThermometerFigure thermo = (ThermometerFigure) refreshableFigure;
            thermo.setEffect3D((Boolean) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(ThermometerModel.PROP_EFFECT3D, effect3DHandler);
    // Change fill color when "FillColor Alarm Sensitive" property changes.
    IWidgetPropertyChangeHandler fillColorAlarmSensitiveHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure refreshableFigure) {
            ThermometerFigure figure = (ThermometerFigure) refreshableFigure;
            boolean sensitive = (Boolean) newValue;
            figure.setFillColor(delegate.calculateAlarmColor(sensitive, getWidgetModel().getFillColor()));
            return true;
        }
    };
    setPropertyChangeHandler(ThermometerModel.PROP_FILLCOLOR_ALARM_SENSITIVE, fillColorAlarmSensitiveHandler);
    // Change fill color when alarm severity changes.
    delegate.addAlarmSeverityListener(new AlarmSeverityListener() {

        @Override
        public boolean severityChanged(AlarmSeverity severity, IFigure figure) {
            if (!getWidgetModel().isFillColorAlarmSensitive())
                return false;
            ThermometerFigure thermo = (ThermometerFigure) figure;
            thermo.setFillColor(delegate.calculateAlarmColor(getWidgetModel().isFillColorAlarmSensitive(), getWidgetModel().getFillColor()));
            return true;
        }
    });
}
Also used : ThermometerFigure(org.csstudio.swt.widgets.figures.ThermometerFigure) AlarmSeverity(org.diirt.vtype.AlarmSeverity) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AlarmSeverityListener(org.csstudio.opibuilder.editparts.AlarmSeverityListener) IFigure(org.eclipse.draw2d.IFigure)

Example 87 with IFigure

use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.

the class XYGraphEditPart method registerAxesAmountChangeHandler.

private void registerAxesAmountChangeHandler() {
    final IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure refreshableFigure) {
            XYGraphModel model = (XYGraphModel) getModel();
            IXYGraph xyGraph = ((ToolbarArmedXYGraph) refreshableFigure).getXYGraph();
            int currentAxisAmount = xyGraph.getAxisList().size();
            // add axis
            if ((Integer) newValue > currentAxisAmount) {
                for (int i = 0; i < (Integer) newValue - currentAxisAmount; i++) {
                    for (AxisProperty axisProperty : AxisProperty.values()) {
                        String propID = XYGraphModel.makeAxisPropID(axisProperty.propIDPre, i + currentAxisAmount);
                        model.setPropertyVisible(propID, true);
                    }
                    xyGraph.addAxis(axisList.get(i + currentAxisAmount));
                }
            } else if ((Integer) newValue < currentAxisAmount) {
                // remove axis
                for (int i = 0; i < currentAxisAmount - (Integer) newValue; i++) {
                    for (AxisProperty axisProperty : AxisProperty.values()) {
                        String propID = XYGraphModel.makeAxisPropID(axisProperty.propIDPre, i + (Integer) newValue);
                        model.setPropertyVisible(propID, false);
                    }
                    xyGraph.removeAxis(axisList.get(i + (Integer) newValue));
                }
            }
            return true;
        }
    };
    getWidgetModel().getProperty(XYGraphModel.PROP_AXIS_COUNT).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            handler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
        }
    });
// setPropertyChangeHandler(XYGraphModel.PROP_AXES_AMOUNT, handler);
}
Also used : AxisProperty(org.csstudio.opibuilder.widgets.model.XYGraphModel.AxisProperty) PropertyChangeEvent(java.beans.PropertyChangeEvent) XYGraphModel(org.csstudio.opibuilder.widgets.model.XYGraphModel) ToolbarArmedXYGraph(org.eclipse.nebula.visualization.xygraph.figures.ToolbarArmedXYGraph) PropertyChangeListener(java.beans.PropertyChangeListener) IXYGraph(org.eclipse.nebula.visualization.xygraph.figures.IXYGraph) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 88 with IFigure

use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.

the class PerformAutoSizeAction method run.

@Override
public void run(IAction action) {
    if (getContainerEditpart().getChildren().size() <= 0) {
        return;
    }
    CompoundCommand compoundCommand = new CompoundCommand("Perform AutoSize");
    AbstractContainerEditpart containerEditpart = getContainerEditpart();
    AbstractContainerModel containerModel = containerEditpart.getWidgetModel();
    // temporary unlock children so children will not be resized.
    if (containerEditpart instanceof GroupingContainerEditPart) {
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, false));
    }
    IFigure figure = getContainerFigure();
    Rectangle childrenRange = GeometryUtil.getChildrenRange(containerEditpart);
    Point tranlateSize = new Point(childrenRange.x, childrenRange.y);
    compoundCommand.add(new SetBoundsCommand(containerModel, new Rectangle(containerModel.getLocation().translate(tranlateSize), new Dimension(childrenRange.width + figure.getInsets().left + figure.getInsets().right, childrenRange.height + figure.getInsets().top + figure.getInsets().bottom))));
    for (Object editpart : containerEditpart.getChildren()) {
        AbstractWidgetModel widget = ((AbstractBaseEditPart) editpart).getWidgetModel();
        compoundCommand.add(new SetBoundsCommand(widget, new Rectangle(widget.getLocation().translate(tranlateSize.getNegated()), widget.getSize())));
    }
    // recover lock
    if (containerEditpart instanceof GroupingContainerEditPart) {
        Object oldvalue = containerEditpart.getWidgetModel().getPropertyValue(GroupingContainerModel.PROP_LOCK_CHILDREN);
        compoundCommand.add(new SetWidgetPropertyCommand(containerModel, GroupingContainerModel.PROP_LOCK_CHILDREN, oldvalue));
    }
    execute(compoundCommand);
}
Also used : AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) SetBoundsCommand(org.csstudio.opibuilder.commands.SetBoundsCommand) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GroupingContainerEditPart(org.csstudio.opibuilder.widgets.editparts.GroupingContainerEditPart) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) AbstractContainerModel(org.csstudio.opibuilder.model.AbstractContainerModel) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) AbstractContainerEditpart(org.csstudio.opibuilder.editparts.AbstractContainerEditpart) IFigure(org.eclipse.draw2d.IFigure)

Example 89 with IFigure

use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.

the class AbstractBoolControlEditPart method registerCommonPropertyChangeHandlers.

/**
 * Registers property change handlers for the properties defined in
 * {@link AbstractBoolWidgetModel}. This method is provided for the convenience
 * of subclasses, which can call this method in their implementation of
 * {@link #registerPropertyChangeHandlers()}.
 */
@Override
protected void registerCommonPropertyChangeHandlers() {
    configureButtonListener((AbstractBoolControlFigure) getFigure());
    super.registerCommonPropertyChangeHandlers();
    // toggle button
    final IWidgetPropertyChangeHandler toggleHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
            figure.setToggle((Boolean) newValue);
            return true;
        }
    };
    getWidgetModel().getProperty(AbstractBoolControlModel.PROP_TOGGLE_BUTTON).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            toggleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
        }
    });
    // setPropertyChangeHandler(AbstractBoolControlModel.PROP_TOGGLE_BUTTON, handler);
    // show confirm dialog
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
            figure.setShowConfirmDialog(getWidgetModel().getShowConfirmDialog());
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolControlModel.PROP_CONFIRM_DIALOG, handler);
    // confirm tip
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
            figure.setConfirmTip((String) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolControlModel.PROP_CONFIRM_TIP, handler);
    // password
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
            figure.setPassword((String) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolControlModel.PROP_PASSWORD, handler);
    // enabled. WidgetBaseEditPart will force the widget as disabled in edit model,
    // which is not the case for the bool control widget
    IWidgetPropertyChangeHandler enableHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolControlFigure figure = (AbstractBoolControlFigure) refreshableFigure;
            figure.setEnabled((Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolControlModel.PROP_ENABLED, enableHandler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AbstractBoolControlFigure(org.csstudio.swt.widgets.figures.AbstractBoolControlFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 90 with IFigure

use of org.eclipse.draw2d.IFigure in project yamcs-studio by yamcs.

the class AbstractPolyEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    super.registerPropertyChangeHandlers();
    // points
    IWidgetPropertyChangeHandler pointsHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            Polyline polyline = (Polyline) refreshableFigure;
            PointList points = (PointList) newValue;
            if (points.size() != polyline.getPoints().size()) {
                anchorMap = null;
                // delete connections on deleted points
                if (points.size() < polyline.getPoints().size()) {
                    for (ConnectionModel conn : getWidgetModel().getSourceConnections()) {
                        if (Integer.parseInt(conn.getSourceTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                    for (ConnectionModel conn : getWidgetModel().getTargetConnections()) {
                        if (Integer.parseInt(conn.getTargetTerminal()) >= points.size()) {
                            conn.disconnect();
                        }
                    }
                }
            }
            // deselect the widget (this refreshes the polypoint drag
            // handles)
            int selectionState = getSelected();
            setSelected(EditPart.SELECTED_NONE);
            polyline.setPoints(points);
            doRefreshVisuals(polyline);
            // restore the selection state
            setSelected(selectionState);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_POINTS, pointsHandler);
    IWidgetPropertyChangeHandler rotationHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            getWidgetModel().setPoints(PointsUtil.rotatePoints(getWidgetModel().getOriginalPoints().getCopy(), (Double) newValue), false);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractPolyModel.PROP_ROTATION, rotationHandler);
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) Polyline(org.eclipse.draw2d.Polyline) ConnectionModel(org.csstudio.opibuilder.model.ConnectionModel) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

IFigure (org.eclipse.draw2d.IFigure)225 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)61 Rectangle (org.eclipse.draw2d.geometry.Rectangle)42 Point (org.eclipse.draw2d.geometry.Point)36 Dimension (org.eclipse.draw2d.geometry.Dimension)30 PropertyChangeEvent (java.beans.PropertyChangeEvent)25 PropertyChangeListener (java.beans.PropertyChangeListener)25 List (java.util.List)20 Figure (org.eclipse.draw2d.Figure)17 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)13 DefaultSizeNodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure)12 NodeFigure (org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure)12 StackLayout (org.eclipse.draw2d.StackLayout)11 Iterator (java.util.Iterator)10 VType (org.diirt.vtype.VType)10 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)9 OPIColor (org.csstudio.opibuilder.util.OPIColor)9 EditPart (org.eclipse.gef.EditPart)9 ArrayList (java.util.ArrayList)7 Label (org.eclipse.draw2d.Label)7