KickJava   Java API By Example, From Geeks To Geeks.

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


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: 18.04.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

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