Search in sources :

Example 66 with Dimension

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

the class PNGSymbolImage method generatePNGData.

private void generatePNGData() {
    if (disposed || originalImageData == null)
        return;
    imageData = (ImageData) originalImageData.clone();
    if (!colorToChange.equals(currentColor))
        imageData = ImageUtils.changeImageColor(currentColor, imageData);
    imageData = ImageUtils.applyMatrix(imageData, permutationMatrix);
    if (stretch && bounds != null) {
        imageData = imageData.scaledTo(bounds.width + leftCrop + rightCrop, bounds.height + topCrop + bottomCrop);
    }
    int imgWidth = imageData.width;
    int imgHeight = imageData.height;
    // Avoid negative number
    topCrop = topCrop > imgHeight ? 0 : topCrop;
    leftCrop = leftCrop > imgWidth ? 0 : leftCrop;
    bottomCrop = (imgHeight - topCrop - bottomCrop) < 0 ? 0 : bottomCrop;
    rightCrop = (imgWidth - leftCrop - rightCrop) < 0 ? 0 : rightCrop;
    // Calculate areas
    int cropedWidth = imageData.width - leftCrop - rightCrop;
    int cropedHeight = imageData.height - bottomCrop - topCrop;
    Dimension newImgDimension = new Dimension(cropedWidth, cropedHeight);
    if (imgDimension == null || newImgDimension.width != imgDimension.width || newImgDimension.height != imgDimension.height)
        fireSizeChanged();
    imgDimension = newImgDimension;
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 67 with Dimension

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

the class PointsUtil method rotatePoints.

/**
 * Rotates all points.
 *
 * @param points The PoinList, which points should be rotated
 * @param angle
 *            The angle to rotate
 * @return The rotated PointList
 */
public static final PointList rotatePoints(final PointList points, final double angle) {
    Rectangle pointBounds = points.getBounds();
    Point rotationPoint = pointBounds.getCenter();
    PointList newPoints = rotatePoints(points, angle, rotationPoint);
    Rectangle newPointBounds = newPoints.getBounds();
    if (!rotationPoint.equals(newPointBounds.getCenter())) {
        Dimension difference = rotationPoint.getCopy().getDifference(newPointBounds.getCenter());
        newPoints.translate(difference.width, difference.height);
    }
    return newPoints;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 68 with Dimension

use of org.eclipse.draw2d.geometry.Dimension 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 69 with Dimension

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

the class ArrayEditPart method registerPropertyChangeHandlers.

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

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            for (AbstractWidgetModel child : getWidgetModel().getAllChildren()) {
                child.setEnabled((Boolean) newValue);
            }
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            VType value = (VType) newValue;
            if (value instanceof VNumberArray) {
                Object wrappedArray = VTypeHelper.getWrappedArray(((VNumberArray) value));
                if (wrappedArray != null)
                    setValue(wrappedArray);
                else
                    setValue(VTypeHelper.getDoubleArray(value));
            } else {
                if (value instanceof VEnum)
                    setValue(new String[] { ((VEnum) value).getValue() });
                else if (value instanceof VString)
                    setValue(new String[] { ((VString) value).getValue() });
                else if (value instanceof VStringArray)
                    setValue(((VStringArray) value).getData().toArray());
                else
                    setValue(VTypeHelper.getDoubleArray(value));
            }
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_PVVALUE, handler);
    getWidgetModel().getProperty(ArrayModel.PROP_PVNAME).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            updatePropSheet();
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            registerLoadPVDataTypeListener();
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_PVNAME, handler);
    getWidgetModel().getProperty(ArrayModel.PROP_DATA_TYPE).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            initValueArray();
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            updateWidgetSize();
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_BORDER_STYLE, handler);
    setPropertyChangeHandler(ArrayModel.PROP_BORDER_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            getArrayFigure().setArrayLength((Integer) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_ARRAY_LENGTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setSpinnerWidth((Integer) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_SPINNER_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setHorizontal((Boolean) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_HORIZONTAL, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setShowScrollbar((Boolean) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_SHOW_SCROLLBAR, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setShowSpinner((Boolean) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_SHOW_SPINNER, handler);
    PropertyChangeListener sizePropertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (getWidgetModel().getChildren().size() == 0 || inSync || keepElementSize)
                return;
            Dimension elementSize = getArrayFigure().getElementSize();
            int delta = (Integer) evt.getNewValue() - (Integer) evt.getOldValue();
            int elementWH = elementSize.height;
            String propID = evt.getPropertyName();
            boolean elementCountDirection = false;
            if (getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_WIDTH)) {
                elementWH = elementSize.width;
                elementCountDirection = true;
            } else if (!getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_HEIGHT)) {
                elementWH = elementSize.height;
                elementCountDirection = true;
            }
            if (elementCountDirection) {
                int deltaElementsCount = Math.round((float) delta / elementWH);
                int idelta = (Math.round((float) delta / elementWH) * elementWH);
                setPropertyValue(propID, (Integer) evt.getOldValue() + idelta, false);
                int visibleElementsCount = getArrayFigure().getVisibleElementsCount() + deltaElementsCount;
                setPropertyValue(ArrayModel.PROP_VISIBLE_ELEMENTS_COUNT, visibleElementsCount);
                setValue(getValue());
            } else {
                int wh;
                if (propID.equals(AbstractWidgetModel.PROP_WIDTH))
                    wh = getArrayFigure().getElementSize().width;
                else
                    wh = getArrayFigure().getElementSize().height;
                syncAllChildrenProperties(propID, wh + delta);
            }
        }
    };
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_WIDTH).addPropertyChangeListener(sizePropertyChangeListener);
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_HEIGHT).addPropertyChangeListener(sizePropertyChangeListener);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) VEnum(org.diirt.vtype.VEnum) VString(org.diirt.vtype.VString) Dimension(org.eclipse.draw2d.geometry.Dimension) VNumberArray(org.diirt.vtype.VNumberArray) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) VType(org.diirt.vtype.VType) ArrayFigure(org.csstudio.swt.widgets.figures.ArrayFigure) VString(org.diirt.vtype.VString) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) VStringArray(org.diirt.vtype.VStringArray) IFigure(org.eclipse.draw2d.IFigure)

Example 70 with Dimension

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

the class ArrayLayoutEditPolicy method addUpdateContainerCommands.

protected void addUpdateContainerCommands(AbstractContainerModel container, Dimension widgetSize, CompoundCommand result) {
    int elementsCount = getHostArrayEditPart().getArrayFigure().calcVisibleElementsCount(widgetSize);
    Dimension proposedContainerSize = getHostArrayEditPart().getArrayFigure().calcWidgetSizeForElements(elementsCount, widgetSize);
    result.add(new WidgetSetConstraintCommand(container, null, new Rectangle(container.getLocation(), proposedContainerSize)));
    result.add(new SetWidgetPropertyCommand(container, ArrayModel.PROP_VISIBLE_ELEMENTS_COUNT, elementsCount));
}
Also used : SetWidgetPropertyCommand(org.csstudio.opibuilder.commands.SetWidgetPropertyCommand) WidgetSetConstraintCommand(org.csstudio.opibuilder.commands.WidgetSetConstraintCommand) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension)

Aggregations

Dimension (org.eclipse.draw2d.geometry.Dimension)180 Rectangle (org.eclipse.draw2d.geometry.Rectangle)80 Point (org.eclipse.draw2d.geometry.Point)70 IFigure (org.eclipse.draw2d.IFigure)31 List (java.util.List)16 Insets (org.eclipse.draw2d.geometry.Insets)10 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)8 PointList (org.eclipse.draw2d.geometry.PointList)6 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)6 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)6 PrecisionRectangle (org.eclipse.draw2d.geometry.PrecisionRectangle)5 ArrayList (java.util.ArrayList)4 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)4 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)4 Font (org.eclipse.swt.graphics.Font)4 Point (org.eclipse.swt.graphics.Point)4 AbstractContainerModel (org.csstudio.opibuilder.model.AbstractContainerModel)3 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)3 Label (org.eclipse.draw2d.Label)3 SimpleHtmlFigure (org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure)3