2,2c2,2 < * @(#)ConnectionTool.java 5.2 --- > * @(#)ConnectionTool.java 3a4,9 > * 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 12,12c14,14 < import CH.ifa.draw.framework.*; --- > import CH.ifa.draw.framework.*; 13a16,17 > import CH.ifa.draw.util.UndoableAdapter; > import CH.ifa.draw.util.Undoable; 13,13c15,15 < import CH.ifa.draw.util.Geom; --- > import CH.ifa.draw.util.Geom; 14,14d15 < 29a37,38 > * > * @version <$CURRENT_VERSION$> 30a151,151 > } 31,31d150 < 37,37c45,45 < private Connector fStartConnector; --- > private Connector myStartConnector; 38,38c46,46 < private Connector fEndConnector; --- > private Connector myEndConnector; 39,39c47,47 < private Connector fConnectorTarget = null; --- > private Connector myTargetConnector; 41,41c49,49 < private Figure fTarget = null; --- > private Figure myTarget; 46,46c54,54 < private ConnectionFigure fConnection; --- > private ConnectionFigure myConnection; 55a64,70 > private ConnectionFigure fEditedConnection; > > /** > * the figure that was actually added > * Note, this can be a different figure from the one which has been created. > */ > private Figure myAddedFigure; 56,56d63 < private ConnectionFigure fEditedConnection = null; 86a101,101 > if (getTarget() != null) { 86,86c100,100 < fTarget = findConnectionStart(ex, ey, drawing()); --- > setTarget(findConnectionStart(ex, ey, drawing())); 87,87d100 < if (fTarget != null) { 88,88c102,102 < fStartConnector = findConnector(ex, ey, fTarget); --- > setStartConnector(findConnector(ex, ey, getTarget())); 89,89c103,103 < if (fStartConnector != null) { --- > if (getStartConnector() != null) { 90a105,105 > setConnection(createConnection()); 91,91d104 < fConnection = createConnection(); 92,92c106,106 < fConnection.startPoint(p.x, p.y); --- > getConnection().startPoint(p.x, p.y); 93,93c107,107 < fConnection.endPoint(p.x, p.y); --- > getConnection().endPoint(p.x, p.y); 94,94c108,108 < view().add(fConnection); --- > setAddedFigure(view().add(getConnection())); 102a117,118 > } > else { 103,103d116 < } else { 115,115c130,130 < if (fConnection != null) { --- > if (getConnection() != null) { 116a132,134 > if (getTargetConnector() != null) { > p = Geom.center(getTargetConnector().displayBox()); > } 117,118d131 < if (fConnectorTarget != null) < p = Geom.center(fConnectorTarget.displayBox()); 119,119c135,135 < fConnection.endPoint(p.x, p.y); --- > getConnection().endPoint(p.x, p.y); 133,133c149,149 < if (fStartConnector != null) --- > if (getStartConnector() != null) { 136a154,166 > setEndConnector(findConnector(e.getX(), e.getY(), c)); > if (getEndConnector() != null) { > getConnection().connectStart(getStartConnector()); > getConnection().connectEnd(getEndConnector()); > getConnection().updateConnection(); > > setUndoActivity(createUndoActivity()); > getUndoActivity().setAffectedFigures( > new SingleFigureEnumerator(getAddedFigure())); > } > } > else if (getConnection() != null) { > view().remove(getConnection()); 137,141d153 < fEndConnector = findConnector(e.getX(), e.getY(), c); < if (fEndConnector != null) { < fConnection.connectStart(fStartConnector); < fConnection.connectEnd(fEndConnector); < fConnection.updateConnection(); 143,144d167 < } else if (fConnection != null) < view().remove(fConnection); 146,147d168 < fConnection = null; < fStartConnector = fEndConnector = null; 152a177,177 > if (getTarget() != null) { 153,153d176 < if (fTarget != null) 154a179,179 > } 154,154c178,178 < fTarget.connectorVisibility(false); --- > getTarget().connectorVisibility(false); 177,177c202,202 < Figure start = fStartConnector.owner(); --- > Figure start = getStartConnector().owner(); 179a205,205 > && getConnection() != null 179a169,171 > setConnection(null); > setStartConnector(null); > setEndConnector(null); 180,180d168 < && fConnection != null 183,183c208,208 < && fConnection.canConnect(start, target)) --- > && getConnection().canConnect(start, target)) { 184a210,210 > } 196,196c222,222 < if (figure != null && (figure instanceof ConnectionFigure)) --- > if (figure != null && (figure instanceof ConnectionFigure)) { 198a225,225 > } 201a229,232 > private void setConnection(ConnectionFigure newConnection) { > myConnection = newConnection; > } > 205,205c236,236 < protected ConnectionFigure createdFigure() { --- > protected ConnectionFigure getConnection() { 206,206c237,237 < return fConnection; --- > return myConnection; 212,212c243,243 < if (fStartConnector == null) --- > if (getStartConnector() == null) { 213a245,246 > } > else { 214,214d244 < else 215a248,248 > } 217a251,252 > if (c != getTarget()) { > if (getTarget() != null) { 218,219d250 < if (c != fTarget) { < if (fTarget != null) 220,220c253,253 < fTarget.connectorVisibility(false); --- > getTarget().connectorVisibility(false); 220a254,256 > } > setTarget(c); > if (getTarget() != null) { 221,222d253 < fTarget = c; < if (fTarget != null) 223a258,258 > } 223,223c257,257 < fTarget.connectorVisibility(true); --- > getTarget().connectorVisibility(true); 227,227c262,262 < if (c != null) --- > if (c != null) { 228a264,267 > } > if (cc != getTargetConnector()) { > setTargetConnector(cc); > } 229,230d263 < if (cc != fConnectorTarget) < fConnectorTarget = cc; 244,244c281,281 < if ((target != null) && target.canConnect()) --- > if ((target != null) && target.canConnect()) { 245a283,283 > } 253,253c291,291 < if (!figure.includes(fConnection) && figure.canConnect()) { --- > if (!figure.includes(getConnection()) && figure.canConnect() 254,254c292,292 < if (figure.containsPoint(x, y)) --- > && figure.containsPoint(x, y)) { 260a299,302 > private void setStartConnector(Connector newStartConnector) { > myStartConnector = newStartConnector; > } > 261a304,308 > return myStartConnector; > } > > private void setEndConnector(Connector newEndConnector) { > myEndConnector = newEndConnector; 262,262c312,312 < return fStartConnector; --- > return myEndConnector; 266,266d311 < return fEndConnector; 268a315,316 > private void setTargetConnector(Connector newTargetConnector) { > myTargetConnector = newTargetConnector; 269,270d314 < protected Connector getTarget() { < return fConnectorTarget; 272a319,415 > protected Connector getTargetConnector() { > return myTargetConnector; > } > > private void setTarget(Figure newTarget) { > myTarget = newTarget; > } > > protected Figure getTarget() { > return myTarget; > } > > /** > * Gets the figure that was actually added > * Note, this can be a different figure from the one which has been created. > */ > protected Figure getAddedFigure() { > return myAddedFigure; > } > > private void setAddedFigure(Figure newAddedFigure) { > myAddedFigure = newAddedFigure; > } > > /** > * Factory method for undo activity > */ > protected Undoable createUndoActivity() { > return new ConnectionTool.UndoActivity(view(), getConnection()); > } > > public static class UndoActivity extends UndoableAdapter { > > private ConnectionFigure myConnection; > private Connector myStartConnector; > private Connector myEndConnector; > > public UndoActivity(DrawingView newDrawingView, ConnectionFigure newConnection) { > super(newDrawingView); > setConnection(newConnection); > myStartConnector = getConnection().getStartConnector(); > myEndConnector = getConnection().getEndConnector(); > setUndoable(true); > setRedoable(true); > } > > /* > * Undo the activity > * @return true if the activity could be undone, false otherwise > */ > public boolean undo() { > if (!super.undo()) { > return false; > } > > getConnection().disconnectStart(); > getConnection().disconnectEnd(); > > FigureEnumeration fe = getAffectedFigures(); > while (fe.hasMoreElements()) { > getDrawingView().drawing().orphan(fe.nextFigure()); > } > > getDrawingView().clearSelection(); > > return true; > } > > /* > * Redo the activity > * @return true if the activity could be redone, false otherwise > */ > public boolean redo() { > if (!super.redo()) { > return false; > } > > getConnection().connectStart(myStartConnector); > getConnection().connectEnd(myEndConnector); > getConnection().updateConnection(); > > getDrawingView().insertFigures(getAffectedFigures(), 0, 0, false); > > return true; > } > > private void setConnection(ConnectionFigure newConnection) { > myConnection = newConnection; > } > > /** > * Gets the currently created figure > */ > protected ConnectionFigure getConnection() { > return myConnection; > } > }