KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > handle > RotateCenterLocator


1 /**
2  * <p> Project: com.nightlabs.editor2d </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 13.04.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.handle;
9
10 import org.eclipse.draw2d.IFigure;
11 import org.eclipse.draw2d.Locator;
12 import org.eclipse.draw2d.geometry.Dimension;
13 import org.eclipse.draw2d.geometry.Point;
14 import org.eclipse.draw2d.geometry.Rectangle;
15
16 import com.nightlabs.editor2d.edit.AbstractDrawComponentEditPart;
17
18
19 public class RotateCenterLocator
20 implements Locator
21 {
22   protected AbstractDrawComponentEditPart owner;
23   public RotateCenterLocator(AbstractDrawComponentEditPart owner)
24   {
25     this.owner = owner;
26   }
27
28   protected Point getLocation()
29   {
30     return new Point(owner.getDrawComponent().getRotationX(),
31         owner.getDrawComponent().getRotationY());
32   }
33   
34   public void relocate(IFigure target)
35   {
36     target.setLocation(calcCenterPoint(target.getBounds(), getReferencePoint(target)));
37   }
38   
39   protected Point calcCenterPoint(Rectangle rect, Point point)
40   {
41     Dimension boundsSize = rect.getSize();
42     return new Point(point.x - boundsSize.width/2, point.y - boundsSize.height/2);
43   }
44   
45   protected Point getReferencePoint(IFigure target)
46   {
47     Point p = getLocation();
48     owner.getFigure().translateToAbsolute(p);
49     target.translateToRelative(p);
50     return p;
51   }
52 }
53
Popular Tags