2,2c2,2 < * @(#)ChangeConnectionHandle.java 5.2 --- > * @(#)ChangeConnectionHandle.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 7a16,17 > import CH.ifa.draw.util.Undoable; > import CH.ifa.draw.util.UndoableAdapter; 8,8c18,18 < import java.awt.*; --- > import java.awt.*; 9,9d18 < 18a26,27 > * > * @version <$CURRENT_VERSION$> 21a31,34 > private Connector fOriginalTarget; > private Figure myTarget; > private ConnectionFigure myConnection; > private Point fStart; 22,25d30 < protected Connector fOriginalTarget; < protected Figure fTarget; < protected ConnectionFigure fConnection; < protected Point fStart; 32,32c41,41 < fConnection = (ConnectionFigure) owner(); --- > setConnection((ConnectionFigure) owner()); 33,33c42,42 < fTarget = null; --- > setTarget(null); 60a70,73 > if (target() == getConnection().getStartConnector()) { > return getConnection().getEndConnector(); > } > return getConnection().getStartConnector(); 61,63d69 < if (target() == fConnection.start()) < return fConnection.end(); < return fConnection.start(); 71a82,85 > > setUndoActivity(createUndoActivity()); > ((ChangeConnectionHandle.UndoActivity)getUndoActivity()).setOldConnector(target()); > 81a96,97 > if (f != getTarget()) { > if (getTarget() != null) { 82,83d95 < if (f != fTarget) { < if (fTarget != null) 84,84c98,98 < fTarget.connectorVisibility(false); --- > getTarget().connectorVisibility(false); 84a99,101 > } > setTarget(f); > if (getTarget() != null) { 85,86d98 < fTarget = f; < if (fTarget != null) 87a103,103 > } 87,87c102,102 < fTarget.connectorVisibility(true); --- > getTarget().connectorVisibility(true); 91,91c107,107 < if (target != null) --- > if (target != null) { 92a109,109 > } 102,102c119,119 < if (target == null) --- > if (target == null) { 103a121,121 > } 106a125,141 > getConnection().updateConnection(); > > Connector oldConnector = ((ChangeConnectionHandle.UndoActivity) > getUndoActivity()).getOldConnector(); > // there has been no change so there is nothing to undo > if ((oldConnector == null) > || (target() == null) > || (oldConnector.owner() == target().owner())) { > setUndoActivity(null); > } > else { > getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(getConnection())); > } > > if (getTarget() != null) { > getTarget().connectorVisibility(false); > setTarget(null); 107,110d124 < fConnection.updateConnection(); < if (fTarget != null) { < fTarget.connectorVisibility(false); < fTarget = null; 120,120c151,151 < && fConnection.canConnect(source().owner(), target)) { --- > && getConnection().canConnect(source().owner(), target)) { 147,147c178,178 < if (!figure.includes(fConnection) && figure.canConnect()) { --- > if (!figure.includes(getConnection()) && figure.canConnect()) { 148,148c179,179 < if (figure.containsPoint(x, y)) --- > if (figure.containsPoint(x, y)) { 151a183,183 > } 153a186,254 > > protected void setConnection(ConnectionFigure newConnection) { > myConnection = newConnection; > } > > protected ConnectionFigure getConnection() { > return myConnection; > } > > protected void setTarget(Figure newTarget) { > myTarget = newTarget; > } > > protected Figure getTarget() { > return myTarget; > } > > /** > * Factory method for undo activity. To be overriden by subclasses. > */ > protected abstract Undoable createUndoActivity(); > > public static abstract class UndoActivity extends UndoableAdapter { > private Connector myOldConnector; > > public UndoActivity() { > super(null); > setUndoable(true); > setRedoable(true); > } > > public boolean undo() { > if (!super.undo()) { > return false; > } > > swapConnectors(); > return true; > } > > public boolean redo() { > // do not call execute directly as the selection might has changed > if (!isRedoable()) { > return false; > } > > swapConnectors(); > return true; > } > > private void swapConnectors() { > FigureEnumeration fe = getAffectedFigures(); > if (fe.hasMoreElements()) { > ConnectionFigure connection = (ConnectionFigure)fe.nextFigure(); > setOldConnector(replaceConnector(connection)); > connection.updateConnection(); > } > } > > protected abstract Connector replaceConnector(ConnectionFigure connection); > > public void setOldConnector(Connector newOldConnector) { > myOldConnector = newOldConnector; > } > > public Connector getOldConnector() { > return myOldConnector; > } > }