0a1,10 > /* > * @(#)OffsetConnector.java > * > * Project: JHotdraw - a GUI framework for technical drawings > * http://www.jhotdraw.org > * http://jhotdraw.sourceforge.net > * Copyright: © by the original author(s) and all contributors > * License: Lesser GNU Public License (LGPL) > * http://www.opensource.org/licenses/lgpl-license.html > */ 5,5d14 < import java.util.*; 9a42,42 > * 10,11d41 < < 12a20,27 > * An OffsetConnector locates connection points with the help of an > * OffsetLocator. > *

> * It allows the dynamic creation of connection points for new LineConnections. > *

> * It dynamically adjusts connection points when connection handles are > * dragged. > *

13,17d19 < * An OffsetConnector locates connection points with < * the help of an OffsetLocator.

It allows the dynamic < * creation of connection points for new LineConnections. < *

It dynamically adjusts connection points when connection < * handles are dragged. 18,18c28,28 < *

This class is not thread safe --- > * This class is not thread safe 19a47,47 > 20,20d46 < 21a31,32 > * Design Patterns > *

22,22d30 < * Design Patterns

23,23c33,33 < *  o --- > *  o Proxy
--- > * href=../pattlets/sld036.htm>Proxy
26,26c36,36 < * Tracking connectors are Proxy Objects that are provided by the trackConnector --- > * Tracking connectors are Proxy Objects that are provided by the 27,27c37,37 < * method when new connectors need to be created. The tracking connectors permit --- > * trackConnector method when new connectors need to be created. The tracking 27a38,40 > * connectors permit deferral of OffsetConnector creation until the > * finalizeConnector() method is called. New connectors are then created by > * copying the tracking connectors (as in the Prototype pattern). 28,30d37 < * deferral of OffsetConnector creation until the finalizeConnector() method is < * called. New connectors are then created by copying the tracking connectors (as < * in the Prototype pattern). 42a55,55 > // use 42,42c54,54 < // variables used in trackConnector() to control what trackingConnector to use --- > // variables used in trackConnector() to control what trackingConnector to 43,43c56,56 < static private OffsetConnector firstConnector = null; --- > static private OffsetConnector firstConnector; 44,44c57,57 < static private OffsetConnector lastConnector = null; --- > static private OffsetConnector lastConnector; 47,47c60,60 < static private DrawingView view = null; --- > static private DrawingView view; 53a113,113 > } 54,56d112 < < < 58,58c68,68 < * Called when a ConnectionTool starts a new connection. --- > * Called when a ConnectionTool starts a new connection. (ConnectionTool 59,59c69,69 < * (ConnectionTool MouseDown event). --- > * MouseDown event). 60a71,71 > * @param drawingView - 61,61c72,72 < * @param drawingView - the current DrawingView; needed for it's GridConstrainer --- > * the current DrawingView; needed for it's GridConstrainer 72a121,121 > } 73,73d120 < 76a87,87 > *

77a89,89 > * location. The trackingConnector will create a new connector when it's 77,77c88,88 < *

Returns a tracking Connector initialized to the required --- > * Returns a tracking Connector initialized to the required owner and 78,78d88 < * owner and location. The trackingConnector will create a new 79,79c90,90 < * connector when it's method finalizeConnector() is called. --- > * method finalizeConnector() is called. 80a92,92 > *

81,81c93,93 < *

This method depends on trackingConnector1.reset() resetting the --- > * This method depends on trackingConnector1.reset() resetting the 83a165,165 > * 84,84d164 < * 90a178,178 > } 91,91d177 < * 97a108,108 > // have 97,97c107,107 < //being set to null in reset(). Otherwise fOwner and fOwnerBox would have --- > //being set to null in reset(). Otherwise fOwner and fOwnerBox would 98a110,110 > // call. 98,98c109,109 < // to be set unconditionally and would then create a Rectangle on every call. --- > // to be set unconditionally and would then create a Rectangle on every 99,99c111,111 < if (firstConnector != null && owner != trackingConnector1.owner()) --- > if (firstConnector != null && owner != trackingConnector1.owner()) { 106,106c119,119 < if (firstConnector == null) --- > if (firstConnector == null) { 111a232,232 > } 112,112d231 < 114,114c127,127 < * Constructs a connector that has no owner. It is --- > * Constructs a connector that has no owner. It is used internally to 114a128,128 > * resurrect a connector from a StorableOutput and to create the static 115,116d127 < * used internally to resurrect a connector from a < * StorableOutput and to create the static tracking 117,117c129,129 < * connectors. --- > * tracking connectors. 126a239,239 > } 127,127d238 < 129,129c140,140 < * Constructs an OffsetConnector with the given owner and given --- > * Constructs an OffsetConnector with the given owner and given location. 130,130c141,141 < * location. It is called only by the finalizeConnector method; --- > * It is called only by the finalizeConnector method; 141a153,153 > // +","+offsetY+")"); 141,141c152,152 < //System.out.println("OffsetConnector(" + owner.toString()+","+offsetX +","+offsetY+")"); --- > //System.out.println("OffsetConnector(" + owner.toString()+","+offsetX 145,145c157,157 < * Returns a newly created OffsetConnector for tracking connectors. --- > * Returns a newly created OffsetConnector for tracking connectors. The 145a158,162 > * tracking connector's owner and offsets are copied to the new connector. > *

> * Existing non-tracking connectors are returned unchanged without side > * effects. > *

146,149d157 < * The tracking connector's owner and offsets are copied to the < * new connector. < *

Existing non-tracking connectors are returned unchanged < * without side effects. 150,150c163,163 < *

This method is called by the connectStart(Connector) and the --- > * This method is called by the connectStart(Connector) and the 153a168,170 > * @param start - > * a boolean indicating whether the receiver is a start or end > * Connector 154,154d167 < * @param start - a boolean indicating whether the receiver is a start or end Connector 155,155c171,171 < * @return - the receiver unchanged if it is not a tracking connector; --- > * @return - the receiver unchanged if it is not a tracking connector; a 156,156c172,172 < * a new Offset connector if this is a tracking connector. --- > * new Offset connector if this is a tracking connector. 159a176,176 > && (this != OffsetConnector.trackingConnector2)) { 159,159c175,175 < if (this != OffsetConnector.trackingConnector1 && this != OffsetConnector.trackingConnector2) --- > if ((this != OffsetConnector.trackingConnector1) 163a182,183 > // an adjustment to the end connector that helps draw vertical or > // horizontal lines. 164,164d181 < // an adjustment to the end connector that helps draw vertical or horizontal lines. 165,165c184,184 < // This adjustment applies only to the initial rendering of the line and has no --- > // This adjustment applies only to the initial rendering of the line 165a185,185 > // and has no 167a188,188 > // connection 167,167c187,187 < // N.B. trackingConnector2 is used iff 2 connectors needed ... new line connection --- > // N.B. trackingConnector2 is used iff 2 connectors needed ... new line 173,173c194,194 < if (Math.abs(p1X - p2X) <= 8) --- > if (Math.abs(p1X - p2X) <= 8) p2X = p1X; 174,174d194 < p2X = p1X; 175,175c195,195 < if (Math.abs(p1Y - p2Y) <= 8 ) --- > if (Math.abs(p1Y - p2Y) <= 8) p2Y = p1Y; 176,176d195 < p2Y = p1Y; 183a255,255 > } 184,186d254 < < < 188,188c204,204 < * Resets offsets for an existing OffsetConnector. Called when dragging --- > * Resets offsets for an existing OffsetConnector. Called when dragging a 189,189c205,205 < * a ChangeConnectionHandle. --- > * ChangeConnectionHandle. 189a206,206 > * 191a209,209 > * @param x - 192a211,211 > * @param y - 192,192c210,210 < * @param x - x coordinate of point moved to --- > * x coordinate of point moved to 193,193c212,212 < * @param y - y coordinate of point moved to --- > * y coordinate of point moved to 200,200c219,219 < // will use x or y parameters under certain conditions overriding calculated point --- > // will use x or y parameters under certain conditions overriding 200a220,220 > // calculated point 201a222,222 > // on appropriate side 201,201c221,221 < // only applies to sides of figure & the adjusted point will still lie on appropriate side --- > // only applies to sides of figure & the adjusted point will still lie 207,207c228,228 < if (l.fOffsetX == 0 || l.fOffsetX == fOwnerBox.width) --- > if (l.fOffsetX == 0 || l.fOffsetX == fOwnerBox.width) { 212,212c234,234 < if (l.fOffsetY == 0 || l.fOffsetY == fOwnerBox.height) --- > if (l.fOffsetY == 0 || l.fOffsetY == fOwnerBox.height) { 219a282,282 > } 220,221d281 < < 223,223c244,244 < * Gets the connection point. If the owner is resized the connection --- > * Gets the connection point. If the owner is resized the connection points 224,224c245,245 < * points are (visually) preserved provided they lie on the box of the --- > * are (visually) preserved provided they lie on the box of the resized 225a247,247 > * 225,225c246,246 < * resized figure. --- > * figure. 230a253,253 > // for deSerialization 230,230c252,252 < if (fOwnerBox.width == 0 && fOwnerBox.height == 0) // for deSerialization --- > if (fOwnerBox.width == 0 && fOwnerBox.height == 0) { 238,238c262,262 < //System.out.println("findPoint - " +this.toString() +":"+ p1.toString()); --- > //System.out.println("findPoint - " +this.toString() +":"+ 238a263,263 > // p1.toString()); 252,252c277,277 < if (l.fOffsetX==0) --- > if (l.fOffsetX == 0) { 253a279,279 > } 254,254d278 < else 255,255c280,280 < if (l.fOffsetX == fOwnerBox.width) --- > else if (l.fOffsetX == fOwnerBox.width) { 258,258c284,284 < if (l.fOffsetY==0) --- > if (l.fOffsetY == 0) { 259a286,286 > } 260,260d285 < else 261,261c287,287 < if (l.fOffsetY == fOwnerBox.height) --- > else if (l.fOffsetY == fOwnerBox.height) { 264,264c291,291 < if (view != null && view.getConstrainer() != null) --- > if (view != null && view.getConstrainer() != null) { 269a298,298 > // p1.toString()); 269,269c297,297 < //System.out.println("findPoint(x) - " +this.toString() +":"+ p1.toString()); --- > //System.out.println("findPoint(x) - " +this.toString() +":"+ 274,274c303,303 < * returns the connector Point --- > * @return the connector Point 275,276d303 < * < * 281a289,289 > } 282,282d288 < 284,284c310,310 < * returns the x-coordinate of this connector --- > * @return the x-coordinate of this connector 285,286d310 < * < * 293,293c318,318 < * returns the y-coordinate of this connector --- > * @return the y-coordinate of this connector 301,301c326,326 < * Constrains the point (x,y) to the figure and calculates the offsets --- > * Constrains the point (x,y) to the figure and calculates the offsets for 302,302c327,327 < * for the resulting constrained point. --- > * the resulting constrained point. 302a328,328 > * 315a293,293 > } 316,317d292 < < 321a346,346 > *

322a348,350 > * every call. Be careful not to publicly expose this internal tracking > * point when overriding. > *

322,322c347,347 < *

For efficiency reasons the same point object is returned --- > * For efficiency reasons the same point object is returned from 323,324d347 < * from every call. Be careful not to publicly expose this internal < * tracking point when overriding. 325,325c351,351 < *

This method is NOT thread safe. --- > * This method is NOT thread safe. 335,335c361,361 < if (view != null && view.getConstrainer() != null) --- > if (view != null && view.getConstrainer() != null) { 336a363,363 > } 338a366,369 > trackingPoint = Geom.angleToPoint(fOwnerBox, Geom > .pointToAngle(fOwnerBox, trackingPoint)); > } > else { 338,338c365,365 < if (!(owner() instanceof EllipseFigure)) --- > if (!(owner() instanceof EllipseFigure)) { 339,340d365 < trackingPoint = Geom.angleToPoint(fOwnerBox, Geom.pointToAngle(fOwnerBox, trackingPoint)); < else 341a371,372 > trackingPoint)); > } 341,341c370,370 < trackingPoint = Geom.ovalAngleToPoint(fOwnerBox, Geom.pointToAngle(fOwnerBox, trackingPoint)); --- > trackingPoint = Geom.ovalAngleToPoint(fOwnerBox, Geom.pointToAngle(fOwnerBox, 345,345c316,316 < --- >