2c2 < * @(#)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 8,9d13 < import java.awt.*; < 11a16,18 > import CH.ifa.draw.util.Undoable; > import CH.ifa.draw.util.UndoableAdapter; > import java.awt.*; 18a26,27 > * > * @version <$CURRENT_VERSION$> 22,25c31,34 < protected Connector fOriginalTarget; < protected Figure fTarget; < protected ConnectionFigure fConnection; < protected Point fStart; --- > private Connector fOriginalTarget; > private Figure myTarget; > private ConnectionFigure myConnection; > private Point fStart; 32,33c41,42 < fConnection = (ConnectionFigure) owner(); < fTarget = null; --- > setConnection((ConnectionFigure) owner()); > setTarget(null); 61,63c70,73 < if (target() == fConnection.start()) < return fConnection.end(); < return fConnection.start(); --- > if (target() == getConnection().getStartConnector()) { > return getConnection().getEndConnector(); > } > return getConnection().getStartConnector(); 71a82,85 > > setUndoActivity(createUndoActivity()); > ((ChangeConnectionHandle.UndoActivity)getUndoActivity()).setOldConnector(target()); > 82,87c96,103 < if (f != fTarget) { < if (fTarget != null) < fTarget.connectorVisibility(false); < fTarget = f; < if (fTarget != null) < fTarget.connectorVisibility(true); --- > if (f != getTarget()) { > if (getTarget() != null) { > getTarget().connectorVisibility(false); > } > setTarget(f); > if (getTarget() != null) { > getTarget().connectorVisibility(true); > } 91c107 < if (target != null) --- > if (target != null) { 92a109 > } 102c119 < if (target == null) --- > if (target == null) { 103a121 > } 107,110c125,141 < fConnection.updateConnection(); < if (fTarget != null) { < fTarget.connectorVisibility(false); < fTarget = null; --- > 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); 120c151 < && fConnection.canConnect(source().owner(), target)) { --- > && getConnection().canConnect(source().owner(), target)) { 147,148c178,179 < if (!figure.includes(fConnection) && figure.canConnect()) { < if (figure.containsPoint(x, y)) --- > if (!figure.includes(getConnection()) && figure.canConnect()) { > if (figure.containsPoint(x, y)) { 151a183 > } 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; > } > }