Search in sources :

Example 1 with Shape

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

the class WidgetConnectionEditPart method activate.

@Override
public void activate() {
    if (!isActive()) {
        super.activate();
        getWidgetModel().getProperty(ConnectionModel.PROP_LINE_COLOR).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setForegroundColor(((OPIColor) evt.getNewValue()).getSWTColor());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_LINE_STYLE).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setLineStyle(getWidgetModel().getLineStyle());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_LINE_WIDTH).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setLineWidth(getWidgetModel().getLineWidth());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_ROUTER).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                updateRouter(getConnectionFigure());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_POINTS).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent evt) {
                if (getViewer() == null || getViewer().getControl() == null) {
                    return;
                }
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        if (((PointList) evt.getOldValue()).size() != ((PointList) evt.getNewValue()).size())
                            updateRouter(getConnectionFigure());
                        else
                            refreshBendpoints(getConnectionFigure());
                    }
                };
                // It should update at the same rate as other widget at run time
                if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                    Display display = getViewer().getControl().getDisplay();
                    WidgetIgnorableUITask task = new WidgetIgnorableUITask(getWidgetModel().getProperty(ConnectionModel.PROP_POINTS), runnable, display);
                    GUIRefreshThread.getInstance(getExecutionMode() == ExecutionMode.RUN_MODE).addIgnorableTask(task);
                } else
                    runnable.run();
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_ARROW_LENGTH).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                updateArrowLength(getConnectionFigure());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_ARROW_TYPE).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                updateDecoration(getConnectionFigure());
                updateArrowLength(getConnectionFigure());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_FILL_ARROW).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                updateDecoration(getConnectionFigure());
                updateArrowLength(getConnectionFigure());
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_ANTIALIAS).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setAntialias(getWidgetModel().isAntiAlias() ? SWT.ON : SWT.OFF);
                for (Object obj : getConnectionFigure().getChildren()) {
                    if (obj instanceof Shape)
                        ((Shape) obj).setAntialias(getWidgetModel().isAntiAlias() ? SWT.ON : SWT.OFF);
                }
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_LINE_JUMP_ADD).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setLineJumpAdd(getWidgetModel().getLineJumpAdd());
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        getConnectionFigure().repaint();
                    }
                };
                WidgetIgnorableUITask task = new WidgetIgnorableUITask(getWidgetModel().getProperty(ConnectionModel.PROP_LINE_JUMP_ADD), runnable, getViewer().getControl().getDisplay());
                GUIRefreshThread.getInstance(getExecutionMode() == ExecutionMode.EDIT_MODE).addIgnorableTask(task);
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_LINE_JUMP_SIZE).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setLineJumpSize(getWidgetModel().getLineJumpSize());
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        getConnectionFigure().repaint();
                    }
                };
                WidgetIgnorableUITask task = new WidgetIgnorableUITask(getWidgetModel().getProperty(ConnectionModel.PROP_LINE_JUMP_SIZE), runnable, getViewer().getControl().getDisplay());
                GUIRefreshThread.getInstance(getExecutionMode() == ExecutionMode.EDIT_MODE).addIgnorableTask(task);
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_LINE_JUMP_STYLE).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                getConnectionFigure().setLineJumpStyle(getWidgetModel().getLineJumpStyle());
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        getConnectionFigure().repaint();
                    }
                };
                WidgetIgnorableUITask task = new WidgetIgnorableUITask(getWidgetModel().getProperty(ConnectionModel.PROP_LINE_JUMP_SIZE), runnable, getViewer().getControl().getDisplay());
                GUIRefreshThread.getInstance(getExecutionMode() == ExecutionMode.EDIT_MODE).addIgnorableTask(task);
            }
        });
        getWidgetModel().getProperty(ConnectionModel.PROP_IS_LOADED_FROM_LINKING_CONTAINER).addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                updateRouter(getConnectionFigure());
            }
        });
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) PropertyChangeEvent(java.beans.PropertyChangeEvent) Shape(org.eclipse.draw2d.Shape) PropertyChangeListener(java.beans.PropertyChangeListener) WidgetIgnorableUITask(org.csstudio.opibuilder.datadefinition.WidgetIgnorableUITask) OPIColor(org.csstudio.opibuilder.util.OPIColor) Display(org.eclipse.swt.widgets.Display)

Example 2 with Shape

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

the class AbstractFixRatioSizeFeedbackFactory method getSizeOnDropFeedback.

/**
 * Lazily creates and returns the Figure to use for size-on-drop feedback.
 *
 * @return the size-on-drop feedback figure
 */
protected Shape getSizeOnDropFeedback() {
    if (sizeOnDropFeedback == null) {
        sizeOnDropFeedback = new RectangleFigure();
        FigureUtilities.makeGhostShape((Shape) sizeOnDropFeedback);
        ((Shape) sizeOnDropFeedback).setLineStyle(Graphics.LINE_DASHDOT);
        sizeOnDropFeedback.setForegroundColor(ColorConstants.white);
    }
    return sizeOnDropFeedback;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) Shape(org.eclipse.draw2d.Shape)

Example 3 with Shape

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

the class AbstractShapeEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    // line width
    IWidgetPropertyChangeHandler lineWidthHandler = new IWidgetPropertyChangeHandler() {

        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            Shape shape = (Shape) refreshableFigure;
            if (((Integer) newValue).equals(0))
                shape.setOutline(false);
            else {
                shape.setOutline(true);
                shape.setLineWidth((Integer) newValue);
            }
            return true;
        }
    };
    setPropertyChangeHandler(AbstractShapeModel.PROP_LINE_WIDTH, lineWidthHandler);
    // line style
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            Shape shape = (Shape) refreshableFigure;
            shape.setLineStyle(LineStyle.values()[(Integer) newValue].getStyle());
            return true;
        }
    };
    setPropertyChangeHandler(AbstractShapeModel.PROP_LINE_STYLE, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (GraphicsUtil.useAdvancedGraphics())
                ((Shape) figure).setAntialias(((Boolean) newValue) ? SWT.ON : null);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractShapeModel.PROP_ANTIALIAS, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (GraphicsUtil.useAdvancedGraphics()) {
                if ((Integer) newValue < 255)
                    ((Shape) figure).setAlpha((Integer) newValue);
                else
                    ((Shape) figure).setAlpha(null);
            }
            return false;
        }
    };
    setPropertyChangeHandler(AbstractShapeModel.PROP_ALPHA, handler);
}
Also used : Shape(org.eclipse.draw2d.Shape) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IFigure(org.eclipse.draw2d.IFigure)

Example 4 with Shape

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

the class AbstractShapeEditPart method createFigure.

@Override
protected IFigure createFigure() {
    Shape shape = (Shape) super.createFigure();
    AbstractShapeModel model = getWidgetModel();
    shape.setOutline(model.getLineWidth() != 0);
    shape.setLineWidth(model.getLineWidth());
    shape.setLineStyle(model.getLineStyle());
    if (GraphicsUtil.useAdvancedGraphics()) {
        if (model.getAlpha() < 255)
            shape.setAlpha(model.getAlpha());
        else
            shape.setAlpha(null);
        shape.setAntialias(model.isAntiAlias() ? SWT.ON : null);
    }
    return shape;
}
Also used : Shape(org.eclipse.draw2d.Shape) AbstractShapeModel(org.csstudio.opibuilder.widgets.model.AbstractShapeModel)

Example 5 with Shape

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

the class WidgetXYLayoutEditPolicy method createSizeOnDropFeedback.

/**
 * Override to provide custom feedback figure for the given create request.
 *
 * @param request
 *            the create request
 * @return custom feedback figure
 */
@Override
protected IFigure createSizeOnDropFeedback(final CreateRequest request) {
    String typeId = determineTypeIdFromRequest(request);
    IGraphicalFeedbackFactory feedbackFactory = WidgetsService.getInstance().getWidgetFeedbackFactory(typeId);
    if (feedbackFactory != null) {
        Shape feedbackFigure = feedbackFactory.createSizeOnDropFeedback(request);
        if (feedbackFigure != null) {
            addFeedback(feedbackFigure);
            return feedbackFigure;
        }
    }
    return super.createSizeOnDropFeedback(request);
}
Also used : Shape(org.eclipse.draw2d.Shape) IGraphicalFeedbackFactory(org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)

Aggregations

Shape (org.eclipse.draw2d.Shape)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 WidgetIgnorableUITask (org.csstudio.opibuilder.datadefinition.WidgetIgnorableUITask)1 IGraphicalFeedbackFactory (org.csstudio.opibuilder.feedback.IGraphicalFeedbackFactory)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 AbstractShapeModel (org.csstudio.opibuilder.widgets.model.AbstractShapeModel)1 IFigure (org.eclipse.draw2d.IFigure)1 RectangleFigure (org.eclipse.draw2d.RectangleFigure)1 PointList (org.eclipse.draw2d.geometry.PointList)1 Display (org.eclipse.swt.widgets.Display)1