2,2c2,2 < * @(#)FontSizeHandle.java 5.2 --- > * @(#)FontSizeHandle.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.*; 13a22,23 > * > * @version <$CURRENT_VERSION$> 17,19d26 < private Font fFont; < private int fSize; < 24a32,33 > setUndoActivity(createUndoActivity()); > getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(owner())); 25,27d31 < TextFigure textOwner = (TextFigure) owner(); < fFont = textOwner.getFont(); < fSize = fFont.getSize(); 31a38,54 > > FontSizeHandle.UndoActivity activity = (FontSizeHandle.UndoActivity)getUndoActivity(); > int newSize = activity.getFont().getSize() + y-anchorY; > //System.out.println("newSize: " + newSize + " .. y: " + y + " .. anchorY: " + anchorY); > textOwner.setFont(new Font(activity.getFont().getName(), activity.getFont().getStyle(), newSize)); > } > > public void invokeEnd(int x, int y, int anchorX, int anchorY, DrawingView view) { > TextFigure textOwner = (TextFigure) owner(); > FontSizeHandle.UndoActivity activity = (FontSizeHandle.UndoActivity)getUndoActivity(); > // there has been no change so there is nothing to undo > if (textOwner.getFont().getSize() == activity.getOldFontSize()) { > setUndoActivity(null); > } > else { > activity.setFont(textOwner.getFont()); > } 32,33d37 < int newSize = fSize + y-anchorY; < textOwner.setFont(new Font(fFont.getName(), fFont.getStyle(), newSize) ); 44a66,134 > > /** > * Factory method for undo activity > */ > protected Undoable createUndoActivity() { > TextFigure textOwner = (TextFigure) owner(); > return new FontSizeHandle.UndoActivity(textOwner.getFont()); > } > > public static class UndoActivity extends UndoableAdapter { > private Font myFont; > private int myOldFontSize; > > public UndoActivity(Font newFont) { > super(null); > setFont(newFont); > setOldFontSize(getFont().getSize()); > setUndoable(true); > setRedoable(true); > } > > public boolean undo() { > if (!super.undo()) { > return false; > } > swapFont(); > System.out.println("FontSizeHandle.undo()"); > return true; > } > > public boolean redo() { > // do not call execute directly as the selection might has changed > if (!isRedoable()) { > return false; > } > swapFont(); > System.out.println("FontSizeHandle.redo()"); > return true; > } > > protected void swapFont() { > setOldFontSize(replaceFontSize()); > FigureEnumeration fe = getAffectedFigures(); > while (fe.hasMoreElements()) { > ((TextFigure)fe.nextFigure()).setFont(getFont()); > } > } > > private int replaceFontSize() { > int tempFontSize = getFont().getSize(); > setFont(new Font(getFont().getName(), getFont().getStyle(), getOldFontSize())); > return tempFontSize; > } > protected void setFont(Font newFont) { > myFont = newFont; > } > > public Font getFont() { > return myFont; > } > > protected void setOldFontSize(int newOldFontSize) { > myOldFontSize = newOldFontSize; > } > > public int getOldFontSize() { > return myOldFontSize; > } > }