1 8 package com.nightlabs.editor2d.handle; 9 10 import java.util.List ; 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 editParts; 24 protected IFigure figure; 25 public AbstractMultipleLocator(List 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(), 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
|