Search in sources :

Example 16 with OPIColor

use of org.csstudio.opibuilder.util.OPIColor in project yamcs-studio by yamcs.

the class AbstractBaseEditPart method registerBasePropertyChangeHandlers.

protected void registerBasePropertyChangeHandlers() {
    IWidgetPropertyChangeHandler refreshVisualHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            refreshVisuals();
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_XPOS, refreshVisualHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_YPOS, refreshVisualHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_WIDTH, refreshVisualHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_HEIGHT, refreshVisualHandler);
    // add connection should not be ignored by widget listener.
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_SRC_CONNECTIONS).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            refreshSourceConnections();
        }
    });
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_TGT_CONNECTIONS).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            refreshTargetConnections();
        }
    });
    IWidgetPropertyChangeHandler backColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setBackgroundColor(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_BACKGROUND, backColorHandler);
    IWidgetPropertyChangeHandler foreColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setForegroundColor(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_FOREGROUND, foreColorHandler);
    IWidgetPropertyChangeHandler fontHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setFont(((OPIFont) newValue).getSWTFont());
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_FONT, fontHandler);
    IWidgetPropertyChangeHandler borderHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            setFigureBorder(calculateBorder());
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_STYLE, borderHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_COLOR, borderHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_WIDTH, borderHandler);
    IWidgetPropertyChangeHandler labelBorderHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (figure.getBorder() instanceof LabeledBorder)
                figure.setBorder(BorderFactory.createBorder(getWidgetModel().getBorderStyle(), getWidgetModel().getBorderWidth(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_NAME, labelBorderHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_FONT, labelBorderHandler);
    IWidgetPropertyChangeHandler enableHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setEnabled((Boolean) newValue);
            figure.repaint();
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, enableHandler);
    IWidgetPropertyChangeHandler tooltipHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (// $NON-NLS-1$
            newValue.toString().equals(""))
                figure.setToolTip(null);
            else {
                if (tooltipLabel == null)
                    tooltipLabel = new TooltipLabel(AbstractBaseEditPart.this);
                figure.setToolTip(tooltipLabel);
            }
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_TOOLTIP, tooltipHandler);
    IWidgetPropertyChangeHandler visibilityHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            boolean visible = (Boolean) newValue;
            final IFigure figure = getFigure();
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                figure.setVisible(visible);
            } else {
                if (!visible) {
                    figure.setVisible(false);
                    UIJob job = new UIJob("reset") {

                        @Override
                        public IStatus runInUIThread(final IProgressMonitor monitor) {
                            figure.setVisible(true);
                            return Status.OK_STATUS;
                        }
                    };
                    job.schedule(2000);
                }
            }
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_VISIBLE, visibilityHandler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) WidgetPropertyChangeListener(org.csstudio.opibuilder.properties.WidgetPropertyChangeListener) TooltipLabel(org.csstudio.opibuilder.visualparts.TooltipLabel) LabeledBorder(org.eclipse.draw2d.LabeledBorder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) UIJob(org.eclipse.ui.progress.UIJob) OPIColor(org.csstudio.opibuilder.util.OPIColor) IFigure(org.eclipse.draw2d.IFigure)

Example 17 with OPIColor

use of org.csstudio.opibuilder.util.OPIColor in project yamcs-studio by yamcs.

the class DisplayEditpart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    IWidgetPropertyChangeHandler backColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setBackgroundColor(((OPIColor) newValue).getSWTColor());
            getViewer().getControl().setBackground(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_BACKGROUND, backColorHandler);
    // grid
    if (getExecutionMode() == ExecutionMode.EDIT_MODE) {
        IWidgetPropertyChangeHandler gridColorHandler = new IWidgetPropertyChangeHandler() {

            @Override
            public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
                ((ScalableFreeformRootEditPart) getViewer().getRootEditPart()).getLayer(LayerConstants.GRID_LAYER).setForegroundColor(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
                return false;
            }
        };
        setPropertyChangeHandler(DisplayModel.PROP_COLOR_FOREGROUND, gridColorHandler);
        IWidgetPropertyChangeHandler gridSpaceHandler = new IWidgetPropertyChangeHandler() {

            @Override
            public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
                getViewer().setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension((Integer) newValue, (Integer) newValue));
                return false;
            }
        };
        setPropertyChangeHandler(DisplayModel.PROP_GRID_SPACE, gridSpaceHandler);
        IWidgetPropertyChangeHandler showGridHandler = new IWidgetPropertyChangeHandler() {

            @Override
            public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
                getViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, (Boolean) newValue);
                getViewer().setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, (Boolean) newValue);
                return false;
            }
        };
        setPropertyChangeHandler(DisplayModel.PROP_SHOW_GRID, showGridHandler);
        IWidgetPropertyChangeHandler showRulerHandler = new IWidgetPropertyChangeHandler() {

            @Override
            public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
                getViewer().setProperty(RulerProvider.PROPERTY_RULER_VISIBILITY, (Boolean) newValue);
                return false;
            }
        };
        setPropertyChangeHandler(DisplayModel.PROP_SHOW_RULER, showRulerHandler);
        IWidgetPropertyChangeHandler snapGeoHandler = new IWidgetPropertyChangeHandler() {

            @Override
            public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
                getViewer().setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, (Boolean) newValue);
                return false;
            }
        };
        setPropertyChangeHandler(DisplayModel.PROP_SNAP_GEOMETRY, snapGeoHandler);
        IWidgetPropertyChangeHandler showEditRangeHandler = new IWidgetPropertyChangeHandler() {

            @Override
            public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
                figure.repaint();
                return true;
            }
        };
        setPropertyChangeHandler(DisplayModel.PROP_SHOW_EDIT_RANGE, showEditRangeHandler);
    }
}
Also used : IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) Dimension(org.eclipse.draw2d.geometry.Dimension) OPIColor(org.csstudio.opibuilder.util.OPIColor) IFigure(org.eclipse.draw2d.IFigure)

Example 18 with OPIColor

use of org.csstudio.opibuilder.util.OPIColor in project yamcs-studio by yamcs.

the class ColorProperty method readValueFromXML.

@Override
public Object readValueFromXML(Element propElement) {
    Element colorElement = propElement.getChild(XML_ELEMENT_COLOR);
    String name = colorElement.getAttributeValue(XML_ATTRIBUTE_NAME);
    if (name == null) {
        RGB result = new RGB(Integer.parseInt(colorElement.getAttributeValue(XML_ATTRIBUTE_RED)), Integer.parseInt(colorElement.getAttributeValue(XML_ATTRIBUTE_GREEN)), Integer.parseInt(colorElement.getAttributeValue(XML_ATTRIBUTE_BLUE)));
        return new OPIColor(result);
    } else {
        String red = colorElement.getAttributeValue(XML_ATTRIBUTE_RED);
        String green = colorElement.getAttributeValue(XML_ATTRIBUTE_GREEN);
        String blue = colorElement.getAttributeValue(XML_ATTRIBUTE_BLUE);
        RGB rgb;
        if (red != null && green != null && blue != null) {
            rgb = new RGB(Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue));
            return MediaService.getInstance().getOPIColor(name, rgb);
        }
        return MediaService.getInstance().getOPIColor(name);
    }
}
Also used : Element(org.jdom.Element) RGB(org.eclipse.swt.graphics.RGB) OPIColor(org.csstudio.opibuilder.util.OPIColor)

Aggregations

OPIColor (org.csstudio.opibuilder.util.OPIColor)18 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)10 IFigure (org.eclipse.draw2d.IFigure)10 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 VType (org.diirt.vtype.VType)3 RGB (org.eclipse.swt.graphics.RGB)3 BooleanProperty (org.csstudio.opibuilder.properties.BooleanProperty)2 ColorProperty (org.csstudio.opibuilder.properties.ColorProperty)2 DoubleProperty (org.csstudio.opibuilder.properties.DoubleProperty)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 Element (org.jdom.Element)2 WidgetIgnorableUITask (org.csstudio.opibuilder.datadefinition.WidgetIgnorableUITask)1 WidgetPropertyChangeListener (org.csstudio.opibuilder.properties.WidgetPropertyChangeListener)1 TooltipLabel (org.csstudio.opibuilder.visualparts.TooltipLabel)1 ByteMonitorModel (org.csstudio.opibuilder.widgets.model.ByteMonitorModel)1 ColorMap (org.csstudio.swt.widgets.datadefinition.ColorMap)1 PredefinedColorMap (org.csstudio.swt.widgets.datadefinition.ColorMap.PredefinedColorMap)1 AbstractBoolFigure (org.csstudio.swt.widgets.figures.AbstractBoolFigure)1 ByteMonitorFigure (org.csstudio.swt.widgets.figures.ByteMonitorFigure)1