1 19 20 package org.objectweb.jac.ide.diagrams; 21 22 import CH.ifa.draw.standard.AbstractLocator; 23 import CH.ifa.draw.standard.ChopBoxConnector; 24 import CH.ifa.draw.framework.Figure; 25 import java.awt.Point ; 26 import java.awt.Rectangle ; 27 import org.objectweb.jac.util.Log; 28 29 public class AttachedTextLocator extends AbstractLocator { 30 31 public Point locate(Figure owner,Figure locatedObject) { 32 Log.trace("locator","locate text "+locatedObject+" owned by "+owner); 34 35 LinkFigure f = (LinkFigure)owner; 36 Point center = owner.center(); 37 38 if (f.endFigure()==null 39 || f.startFigure()==null 40 || locatedObject==null) 41 return center; 42 43 AttachedTextFigure text = (AttachedTextFigure)locatedObject; 44 45 if (text.getType()==AttachedTextFigure.START_ROLE) { 46 47 Log.trace("diagram",2,"locating end role"); 48 ChopBoxConnector chopper = new ChopBoxConnector(f.endFigure()); 49 return locate(chopper.findEnd(f),f.endFigure(),false); 50 51 } else if (text.getType()==AttachedTextFigure.END_ROLE) { 52 53 Log.trace("diagram",2,"locating start role"); 54 ChopBoxConnector chopper = new ChopBoxConnector(f.startFigure()); 55 return locate(chopper.findStart(f),f.startFigure(),true); 56 57 } else if (text.getType()==AttachedTextFigure.START_CARDINALITY) { 58 59 Log.trace("locator","locating end cardinality "+f.endFigure().center()); 60 ChopBoxConnector chopper = new ChopBoxConnector(f.endFigure()); 61 return locate(chopper.findEnd(f),f.endFigure(),true); 62 63 } else if (text.getType()==AttachedTextFigure.END_CARDINALITY) { 64 65 Log.trace("locator","locating start cardinality "+f.startFigure().center()); 66 ChopBoxConnector chopper = new ChopBoxConnector(f.startFigure()); 67 return locate(chopper.findStart(f),f.startFigure(),false); 68 69 } else if (text.getType()==AttachedTextFigure.NAME) { 70 71 Rectangle r = owner.displayBox(); 72 Rectangle r2 = locatedObject.displayBox(); 73 Point p = owner.center(); 74 if (r.getWidth()>r.getHeight()) { 75 return new Point (p.x, p.y+10); } else { 77 return new Point ((int)(p.x-(r2.getWidth()/2)-5), p.y-10); } 79 } 80 return center; 81 } 82 83 89 Point locate(Point ep, Figure f, boolean flip) { 90 Point result = null; 91 Point center = f.center(); 92 double dY = (double)(ep.y - center.y); 93 double dX = (double)(ep.x - center.x); 94 double c = 20/Math.sqrt(dY*dY+dX*dX); 95 double dx = dX*c; 96 double dy = dY*c; 97 if (!flip) { 98 result = new Point ((int)(ep.x+dx-dy),(int)(ep.y+dy+dx)); 99 } else { 100 result = new Point ((int)(ep.x+dx+dy),(int)(ep.y+dy-dx)); 101 } 102 Log.trace("locator","ep="+ep+" center="+center+ 103 " dx,dy="+(int)dx+","+(int)dy+" -> "+result); 104 return result; 105 } 106 } 107 108 109 | Popular Tags |