2,2c2,2 < * @(#)ConnectedTextTool.java 5.2 --- > * @(#)ConnectedTextTool.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.UndoableAdapter; > import CH.ifa.draw.util.Undoable; 8,8d15 < import java.awt.*; 9,9c18,18 < import java.awt.event.MouseEvent; --- > import java.awt.event.MouseEvent; 17a25,26 > * > * @version <$CURRENT_VERSION$> 21,21c30,30 < boolean fConnected = false; --- > private boolean fConnected = false; 35a45,46 > System.out.println("pressedFigure: " + pressedFigure); > System.out.println("textHolder: " + textHolder); 38a50,50 > ((ConnectedTextTool.UndoActivity)getUndoActivity()).setConnectedFigure(pressedFigure); 43a56,56 > * Activate this tool 44,45d55 < * If the pressed figure is a TextHolder it can be edited otherwise < * a new text figure is created. 49a61,126 > > /** > * Factory method for undo activity > */ > protected Undoable createUndoActivity() { > return new ConnectedTextTool.UndoActivity(view(), getTypingTarget().getText()); > } > > public static class UndoActivity extends TextTool.UndoActivity { > private Figure myConnectedFigure; > > public UndoActivity(DrawingView newDrawingView, String newOriginalText) { > super(newDrawingView, newOriginalText); > } > > /* > * Undo the activity > * @return true if the activity could be undone, false otherwise > */ > public boolean undo() { > if (!super.undo()) { > return false; > } > > FigureEnumeration fe = getAffectedFigures(); > while (fe.hasMoreElements()) { > Figure currentFigure = fe.nextFigure(); > if (currentFigure instanceof TextHolder) { > TextHolder currentTextHolder = (TextHolder)currentFigure; > // the text figure didn't exist before > if (!isValidText(getOriginalText())) { > currentTextHolder.disconnect(getConnectedFigure()); > } > // the text figure did exist but was remove > else if (!isValidText(getBackupText())) { > currentTextHolder.connect(getConnectedFigure()); > } > } > } > > return true; > } > > /* > * Redo the activity > * @return true if the activity could be redone, false otherwise > */ > public boolean redo() { > if (!super.redo()) { > return false; > } > > FigureEnumeration fe = getAffectedFigures(); > while (fe.hasMoreElements()) { > Figure currentFigure = fe.nextFigure(); > if (currentFigure instanceof TextHolder) { > TextHolder currentTextHolder = (TextHolder)currentFigure; > // the text figure did exist but was remove > if (!isValidText(getBackupText())) { > currentTextHolder.disconnect(getConnectedFigure()); > } > // the text figure didn't exist before > else if (!isValidText(getOriginalText())) { > currentTextHolder.connect(getConnectedFigure()); > } > } 51a129,140 > return true; > } > > public void setConnectedFigure(Figure newConnectedFigure) { > myConnectedFigure = newConnectedFigure; > } > > public Figure getConnectedFigure() { > return myConnectedFigure; > } > } > }