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;
}
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;
}
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));
}
}
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);
}
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);
}
}
Aggregations