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 > */ 5d14 < import java.util.*; 10,11d18 < < 13,18c20,28 < * 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. < *

This class is not thread safe --- > * 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. > *

> * This class is not thread safe 20d29 < 22,24c31,34 < * Design Patterns

< *  o < * Proxy
--- > * Design Patterns > *

> *  o * href=../pattlets/sld036.htm>Proxy
26,30c36,40 < * Tracking connectors are Proxy Objects that are provided by the trackConnector < * method when new connectors need to be created. The tracking 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). --- > * Tracking connectors are Proxy Objects that are provided by the > * trackConnector method when new connectors need to be created. The tracking > * 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). 31a42 > * 35a47 > 42,44c54,57 < // variables used in trackConnector() to control what trackingConnector to use < static private OffsetConnector firstConnector = null; < static private OffsetConnector lastConnector = null; --- > // variables used in trackConnector() to control what trackingConnector to > // use > static private OffsetConnector firstConnector; > static private OffsetConnector lastConnector; 47c60 < static private DrawingView view = null; --- > static private DrawingView view; 54,56d66 < < < 58,59c68,69 < * Called when a ConnectionTool starts a new connection. < * (ConnectionTool MouseDown event). --- > * Called when a ConnectionTool starts a new connection. (ConnectionTool > * MouseDown event). 61c71,72 < * @param drawingView - the current DrawingView; needed for it's GridConstrainer --- > * @param drawingView - > * the current DrawingView; needed for it's GridConstrainer 73d83 < 77,79c87,90 < *

Returns a tracking Connector initialized to the required < * owner and location. The trackingConnector will create a new < * connector when it's method finalizeConnector() is called. --- > *

> * Returns a tracking Connector initialized to the required owner and > * location. The trackingConnector will create a new connector when it's > * method finalizeConnector() is called. 81c92,93 < *

This method depends on trackingConnector1.reset() resetting the --- > *

> * This method depends on trackingConnector1.reset() resetting the 84d95 < * 91d101 < * 97,99c107,111 < //being set to null in reset(). Otherwise fOwner and fOwnerBox would have < // to be set unconditionally and would then create a Rectangle on every call. < if (firstConnector != null && owner != trackingConnector1.owner()) --- > //being set to null in reset(). Otherwise fOwner and fOwnerBox would > // have > // to be set unconditionally and would then create a Rectangle on every > // call. > if (firstConnector != null && owner != trackingConnector1.owner()) { 100a113 > } 106c119 < if (firstConnector == null) --- > if (firstConnector == null) { 107a121 > } 112d125 < 114,117c127,129 < * Constructs a connector that has no owner. It is < * used internally to resurrect a connector from a < * StorableOutput and to create the static tracking < * connectors. --- > * Constructs a connector that has no owner. It is used internally to > * resurrect a connector from a StorableOutput and to create the static > * tracking connectors. 127d138 < 129,130c140,141 < * Constructs an OffsetConnector with the given owner and given < * location. It is called only by the finalizeConnector method; --- > * Constructs an OffsetConnector with the given owner and given location. > * It is called only by the finalizeConnector method; 141c152,153 < //System.out.println("OffsetConnector(" + owner.toString()+","+offsetX +","+offsetY+")"); --- > //System.out.println("OffsetConnector(" + owner.toString()+","+offsetX > // +","+offsetY+")"); 145,150c157,163 < * Returns a newly created OffsetConnector for tracking connectors. < * The tracking connector's owner and offsets are copied to the < * new connector. < *

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

This method is called by the connectStart(Connector) and the --- > * Returns a newly created OffsetConnector for tracking connectors. The > * tracking connector's owner and offsets are copied to the new connector. > *

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

> * This method is called by the connectStart(Connector) and the 151a165 > * 154,156c168,172 < * @param start - a boolean indicating whether the receiver is a start or end Connector < * @return - the receiver unchanged if it is not a tracking connector; < * a new Offset connector if this is a tracking connector. --- > * @param start - > * a boolean indicating whether the receiver is a start or end > * Connector > * @return - the receiver unchanged if it is not a tracking connector; a > * new Offset connector if this is a tracking connector. 159c175,176 < if (this != OffsetConnector.trackingConnector1 && this != OffsetConnector.trackingConnector2) --- > if ((this != OffsetConnector.trackingConnector1) > && (this != OffsetConnector.trackingConnector2)) { 160a178 > } 164,165c182,185 < // an adjustment to the end connector that helps draw vertical or horizontal lines. < // This adjustment applies only to the initial rendering of the line and has no --- > // an adjustment to the end connector that helps draw vertical or > // horizontal lines. > // This adjustment applies only to the initial rendering of the line > // and has no 167c187,188 < // N.B. trackingConnector2 is used iff 2 connectors needed ... new line connection --- > // N.B. trackingConnector2 is used iff 2 connectors needed ... new line > // connection 173,176c194,195 < if (Math.abs(p1X - p2X) <= 8) < p2X = p1X; < if (Math.abs(p1Y - p2Y) <= 8 ) < p2Y = p1Y; --- > if (Math.abs(p1X - p2X) <= 8) p2X = p1X; > if (Math.abs(p1Y - p2Y) <= 8) p2Y = p1Y; 184,186d202 < < < 188,189c204,206 < * Resets offsets for an existing OffsetConnector. Called when dragging < * a ChangeConnectionHandle. --- > * Resets offsets for an existing OffsetConnector. Called when dragging a > * ChangeConnectionHandle. > * 192,193c209,212 < * @param x - x coordinate of point moved to < * @param y - y coordinate of point moved to --- > * @param x - > * x coordinate of point moved to > * @param y - > * y coordinate of point moved to 200,201c219,222 < // will use x or y parameters under certain conditions overriding calculated point < // only applies to sides of figure & the adjusted point will still lie on appropriate side --- > // will use x or y parameters under certain conditions overriding > // calculated point > // only applies to sides of figure & the adjusted point will still lie > // on appropriate side 207c228 < if (l.fOffsetX == 0 || l.fOffsetX == fOwnerBox.width) --- > if (l.fOffsetX == 0 || l.fOffsetX == fOwnerBox.width) { 210a232 > } 212c234 < if (l.fOffsetY == 0 || l.fOffsetY == fOwnerBox.height) --- > if (l.fOffsetY == 0 || l.fOffsetY == fOwnerBox.height) { 216a239 > } 220,221d242 < < 223,225c244,247 < * Gets the connection point. If the owner is resized the connection < * points are (visually) preserved provided they lie on the box of the < * resized figure. --- > * Gets the connection point. If the owner is resized the connection points > * are (visually) preserved provided they lie on the box of the resized > * figure. > * 230c252,253 < if (fOwnerBox.width == 0 && fOwnerBox.height == 0) // for deSerialization --- > if (fOwnerBox.width == 0 && fOwnerBox.height == 0) { > // for deSerialization 231a255 > } 238c262,263 < //System.out.println("findPoint - " +this.toString() +":"+ p1.toString()); --- > //System.out.println("findPoint - " +this.toString() +":"+ > // p1.toString()); 252c277 < if (l.fOffsetX==0) --- > if (l.fOffsetX == 0) { 254,255c279,280 < else < if (l.fOffsetX == fOwnerBox.width) --- > } > else if (l.fOffsetX == fOwnerBox.width) { 256a282 > } 258c284 < if (l.fOffsetY==0) --- > if (l.fOffsetY == 0) { 260,261c286,287 < else < if (l.fOffsetY == fOwnerBox.height) --- > } > else if (l.fOffsetY == fOwnerBox.height) { 262a289 > } 264c291 < if (view != null && view.getConstrainer() != null) --- > if (view != null && view.getConstrainer() != null) { 265a293 > } 269c297,298 < //System.out.println("findPoint(x) - " +this.toString() +":"+ p1.toString()); --- > //System.out.println("findPoint(x) - " +this.toString() +":"+ > // p1.toString()); 274,276c303 < * returns the connector Point < * < * --- > * @return the connector Point 282d308 < 284,286c310 < * returns the x-coordinate of this connector < * < * --- > * @return the x-coordinate of this connector 291a316 > 293c318 < * returns the y-coordinate of this connector --- > * @return the y-coordinate of this connector 301,302c326,328 < * Constrains the point (x,y) to the figure and calculates the offsets < * for the resulting constrained point. --- > * Constrains the point (x,y) to the figure and calculates the offsets for > * the resulting constrained point. > * 316,317d341 < < 322,325c346,351 < *

For efficiency reasons the same point object is returned < * from every call. Be careful not to publicly expose this internal < * tracking point when overriding. < *

This method is NOT thread safe. --- > *

> * For efficiency reasons the same point object is returned from > * every call. Be careful not to publicly expose this internal tracking > * point when overriding. > *

> * This method is NOT thread safe. 335c361 < if (view != null && view.getConstrainer() != null) --- > if (view != null && view.getConstrainer() != null) { 336a363 > } 338,341c365,372 < if (!(owner() instanceof EllipseFigure)) < trackingPoint = Geom.angleToPoint(fOwnerBox, Geom.pointToAngle(fOwnerBox, trackingPoint)); < else < trackingPoint = Geom.ovalAngleToPoint(fOwnerBox, Geom.pointToAngle(fOwnerBox, trackingPoint)); --- > if (!(owner() instanceof EllipseFigure)) { > trackingPoint = Geom.angleToPoint(fOwnerBox, Geom > .pointToAngle(fOwnerBox, trackingPoint)); > } > else { > trackingPoint = Geom.ovalAngleToPoint(fOwnerBox, Geom.pointToAngle(fOwnerBox, > trackingPoint)); > } 345d375 <