Java Code Examples for org.eclipse.draw2d.geometry.Rectangle#getCenter()

The following examples show how to use org.eclipse.draw2d.geometry.Rectangle#getCenter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static PointList CirclePointList(final Rectangle anchRect) {
    final PointList points = new PointList(NB_POINTS_DRAW_CIRCLE);
    final double angle = TWO_PI / NB_POINTS_DRAW_CIRCLE;
    final Point center = anchRect.getCenter();
    final int centerX = center.x;
    final int centerY = center.y;

    final int halfWidth = anchRect.width / 2;
    final int halfHeight = anchRect.height / 2;

    double angleT = 0;
    while (angleT < TWO_PI) {
        points.addPoint((int) (halfWidth * Math.cos(angleT) + centerX), (int) (halfHeight * Math.sin(angleT) + centerY));
        angleT += angle;
    }
    // add last point, the same than the first point
    points.addPoint((int) (halfWidth * Math.cos(0) + centerX), (int) (halfHeight * Math.sin(0) + centerY));
    return points;
}
 
Example 2
Source File: PointsUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: GaugeFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void layout(IFigure container) {
	Rectangle area = container.getClientArea();
	
	area.width = Math.min(area.width, area.height);
	area.height = area.width;
	area.shrink(BORDER_WIDTH, BORDER_WIDTH);
	
	Point center = area.getCenter();			
	
	if(scale != null) {				
		scale.setBounds(area);
	}
	
	if(ramp != null && ramp.isVisible()) {
		Rectangle rampBounds = area.getCopy();
		ramp.setBounds(rampBounds.shrink(area.width/4, area.height/4));
	}
	

	
	if(valueLabel != null) {
		Dimension labelSize = valueLabel.getPreferredSize();
		valueLabel.setBounds(new Rectangle(area.x + area.width/2 - labelSize.width/2,
				(int)(area.y + area.height * 6.3f/8 - labelSize.height/2),
				labelSize.width, labelSize.height));
	}
	
	if(title != null) {
		Dimension titleSize = titleLabel.getPreferredSize();
		titleLabel.setBounds(new Rectangle(area.x + area.width/2 - titleSize.width/2,
				(int)(area.y + area.height * 7.1f/8 - titleSize.height/2),
				titleSize.width, titleSize.height));
	}
	
	if(unit != null) {
		Dimension unitSize = unitLabel.getPreferredSize();
		unitLabel.setBounds(new Rectangle(area.x + area.width/2 - unitSize.width/2,
				(int)(area.y + area.height * 5.5f/8 - unitSize.height/2),
				unitSize.width, unitSize.height));
	}
	
	if(needle != null && scale != null) {
		needlePoints.setPoint (
				new Point(center.x, center.y - NeedleCenter.DIAMETER/2 + 3), 0);
		scale.getScaleTickMarks();
		needlePoints.setPoint(
				new Point(center.x + area.width/2 - RoundScaleTickMarks.MAJOR_TICK_LENGTH
				- GAP_BTW_NEEDLE_SCALE, center.y), 1);
		needlePoints.setPoint(
				new Point(center.x, center.y + NeedleCenter.DIAMETER/2 - 3), 2);
	
		double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);
		if(maximum > minimum){
			if(value > maximum)
				valuePosition += 10;
			else if(value < minimum)
				valuePosition -=10;
		}else{
			if(value > minimum)
				valuePosition -= 10;
			else if(value < maximum)
				valuePosition +=10;
		}
		needlePoints.setPoint(
				PointsUtil.rotate(needlePoints.getPoint(0),	valuePosition, center), 0);
		needlePoints.setPoint(
				PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1);
		needlePoints.setPoint(
				PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center),2);				
		needle.setPoints(needlePoints);			
		
	}
	
	if(needleCenter != null){
		needleCenter.setBounds(new Rectangle(center.x - NeedleCenter.DIAMETER/2,
				center.y - NeedleCenter.DIAMETER/2,
				NeedleCenter.DIAMETER, NeedleCenter.DIAMETER));
	}		
				
}
 
Example 4
Source File: KnobFigure.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void layout(IFigure container) {
	Rectangle area = container.getClientArea();			
	area.width = Math.min(area.width, area.height);
	area.height = area.width;
	area.shrink(BORDER_WIDTH, BORDER_WIDTH);
	
	Point center = area.getCenter();			
	Rectangle bulbBounds = null;
	
	if(scale != null) {				
		scale.setBounds(area);
		bulbBounds = area.getCopy();
		bulbBounds.shrink(area.width/2 - scale.getInnerRadius() + GAP_BTW_BULB_SCALE, 
				area.height/2 - scale.getInnerRadius() + GAP_BTW_BULB_SCALE);
	}
	
	if(scale != null && ramp != null && ramp.isVisible()) {
		Rectangle rampBounds = area.getCopy();
		ramp.setBounds(rampBounds.shrink(area.width/2 - scale.getInnerRadius() - ramp.getRampWidth()+2,
				area.height/2 - scale.getInnerRadius() - ramp.getRampWidth()+2));
	}
	
	if(valueLabel != null && valueLabel.isVisible()) {
		Dimension labelSize = valueLabel.getPreferredSize();				
		valueLabel.setBounds(new Rectangle(bulbBounds.x + bulbBounds.width/2 - labelSize.width/2,
				bulbBounds.y + bulbBounds.height * 3/4 - labelSize.height/2,
				labelSize.width, labelSize.height));
	}
	
	if(bulb != null && scale != null && bulb.isVisible()) {				
		bulb.setBounds(bulbBounds);				
	}
	
	if(scale != null && thumb != null && thumb.isVisible()){
		Point thumbCenter = new Point(bulbBounds.x + bulbBounds.width*7.0/8.0, 
				bulbBounds.y + bulbBounds.height/2);
		double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);				
		thumbCenter = PointsUtil.rotate(thumbCenter,	valuePosition, center);
		int thumbDiameter = bulbBounds.width/6;
		
		thumb.setBounds(new Rectangle(thumbCenter.x - thumbDiameter/2,
				thumbCenter.y - thumbDiameter/2,
				thumbDiameter, thumbDiameter));
	}						
}
 
Example 5
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isWideEast(Rectangle source, Rectangle target) {
	return source.getCenter().x-X_DELTA > target.getCenter().x && source.getCenter().x-X_DELTA > target.getCenter().x+X_SUPER_DELTA ;
}
 
Example 6
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isWideWest(Rectangle source, Rectangle target){
	return source.getCenter().x+X_DELTA <= target.getCenter().x &&  source.getCenter().x+X_DELTA+X_SUPER_DELTA <= target.getCenter().x;
}
 
Example 7
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isEast(Rectangle source, Rectangle target){
	return source.getCenter().x-X_DELTA > target.getCenter().x && source.getCenter().x-X_DELTA <= target.getCenter().x+X_SUPER_DELTA;
}
 
Example 8
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isWest(Rectangle source, Rectangle target){
	return source.getCenter().x+X_DELTA <= target.getCenter().x &&  source.getCenter().x+X_DELTA+X_SUPER_DELTA > target.getCenter().x;
}
 
Example 9
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isTop(Rectangle source, Rectangle target){
	return source.getCenter().y+Y_DELTA <= target.getCenter().y ;
}
 
Example 10
Source File: AnchorUtil.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
public static boolean isBottom(Rectangle source, Rectangle target){
	return source.getCenter().y-Y_DELTA > target.getCenter().y ;
}