Search in sources :

Example 76 with Dimension

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

the class AbstractPolyModel 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 PointList rotatePoints(final PointList points, final double angle) {
    Rectangle pointBounds = points.getBounds();
    Point rotationPoint = pointBounds.getCenter();
    PointList newPoints = new PointList();
    for (int i = 0; i < points.size(); i++) {
        newPoints.addPoint(PointsUtil.rotate(points.getPoint(i), 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) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point)

Example 77 with Dimension

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

the class ColorMapRamp method getPreferredSize.

@Override
public Dimension getPreferredSize(int hint, int hint2) {
    Dimension result = super.getPreferredSize(hint, hint2);
    result.width = RAMP_WIDTH + scale.getPreferredSize(hint, hint2).width;
    return result;
}
Also used : Dimension(org.eclipse.draw2d.geometry.Dimension)

Example 78 with Dimension

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

the class RoundScaleTickLabels method updateTickLabelAreas.

/**
 * Updates the the draw area of each label.
 */
private void updateTickLabelAreas() {
    int lableRadius;
    tickLabelAreas.clear();
    for (int i = 0; i < tickLabelPositions.size(); i++) {
        Dimension ls = FigureUtilities.getTextExtents(tickLabels.get(i), scale.getFont());
        if (scale.getTickLablesSide() == LabelSide.Primary)
            lableRadius = (int) (scale.getRadius() + RoundScaleTickMarks.MAJOR_TICK_LENGTH + RoundScale.SPACE_BTW_MARK_LABEL + ls.width / 2.0 * Math.abs(Math.cos(tickLabelPositions.get(i))) + ls.height / 2.0 * Math.abs(Math.sin(tickLabelPositions.get(i))));
        else
            lableRadius = (int) (scale.getRadius() - RoundScaleTickMarks.MAJOR_TICK_LENGTH - RoundScale.SPACE_BTW_MARK_LABEL - ls.width / 2.0 * Math.abs(Math.cos(tickLabelPositions.get(i))) - ls.height / 2.0 * Math.abs(Math.sin(tickLabelPositions.get(i))));
        Point lp = new PolarPoint(lableRadius, tickLabelPositions.get(i)).toRelativePoint(scale.getBounds());
        tickLabelAreas.add(new Rectangle(lp.x - ls.width / 2, lp.y - ls.height / 2, ls.width, ls.height));
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 79 with Dimension

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

the class AbstractBoolFigure method calculateLabelLocation.

protected void calculateLabelLocation(Point defaultLocation) {
    if (boolLabelPosition == BoolLabelPosition.DEFAULT) {
        labelLocation = defaultLocation;
        return;
    }
    Rectangle textArea = getClientArea();
    Dimension textSize = Draw2dSingletonUtil.getTextUtilities().getTextExtents(boolLabel.getText(), getFont());
    int x = 0;
    if (textArea.width > textSize.width) {
        switch(boolLabelPosition) {
            case CENTER:
            case TOP:
            case BOTTOM:
                x = (textArea.width - textSize.width) / 2;
                break;
            case RIGHT:
            case TOP_RIGHT:
            case BOTTOM_RIGHT:
                x = textArea.width - textSize.width;
                break;
            default:
                break;
        }
    }
    int y = 0;
    if (textArea.height > textSize.height) {
        switch(boolLabelPosition) {
            case CENTER:
            case LEFT:
            case RIGHT:
                y = (textArea.height - textSize.height) / 2;
                break;
            case BOTTOM:
            case BOTTOM_LEFT:
            case BOTTOM_RIGHT:
                y = textArea.height - textSize.height;
                break;
            default:
                break;
        }
    }
    if (useLocalCoordinates())
        labelLocation = new Point(x, y);
    else
        labelLocation = new Point(x + textArea.x, y + textArea.y);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Example 80 with Dimension

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

the class ActionButtonFigure method calculateTextPosition.

public void calculateTextPosition(int width, int height) {
    if (image != null) {
        Dimension textDimension = Draw2dSingletonUtil.getTextUtilities().getTextExtents(getText(), getFont());
        // Calculate available space in height and width
        double hratio = ((double) height - image.getBounds().height) / textDimension.height;
        double wratio = ((double) width - image.getBounds().width) / textDimension.width;
        // Put the label where we have the most space (highest ratio)
        if (wratio > hratio) {
            // Space for text on the right of the icon
            label.setTextPlacement(PositionConstants.EAST);
            label.setTextAlignment(PositionConstants.LEFT);
        } else {
            // Text goes under the icon
            label.setTextPlacement(PositionConstants.SOUTH);
            label.setTextAlignment(PositionConstants.CENTER);
        }
    } else {
        // Center text
        label.setTextAlignment(PositionConstants.CENTER);
    }
}
Also used : 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