diff options
author | Michael Koch <konqueror@gmx.de> | 2003-03-31 06:30:01 +0000 |
---|---|---|
committer | Michael Koch <mkoch@gcc.gnu.org> | 2003-03-31 06:30:01 +0000 |
commit | 2ce0d0b097225538935a0ac9e1b713c024183547 (patch) | |
tree | 14b48288634510a2d92d2fedc668b585e82853f6 /libjava/javax/swing/undo | |
parent | 98d3d336205c751fcf2f6a31a5b5553994556060 (diff) | |
download | gcc-2ce0d0b097225538935a0ac9e1b713c024183547.zip gcc-2ce0d0b097225538935a0ac9e1b713c024183547.tar.gz gcc-2ce0d0b097225538935a0ac9e1b713c024183547.tar.bz2 |
AbstractCellEditor.java, [...]: Merges from classpath.
2003-03-31 Michael Koch <konqueror@gmx.de>
* javax/swing/AbstractCellEditor.java,
javax/swing/AbstractListModel.java,
javax/swing/ActionMap.java,
javax/swing/BorderFactory.java,
javax/swing/ButtonGroup.java,
javax/swing/DefaultBoundedRangeModel.java,
javax/swing/DefaultButtonModel.java,
javax/swing/DefaultCellEditor.java,
javax/swing/DefaultComboBoxModel.java,
javax/swing/DefaultDesktopManager.java,
javax/swing/DefaultListCellRenderer.java,
javax/swing/DefaultSingleSelectionModel.java,
javax/swing/InputMap.java,
javax/swing/JComponent.java,
javax/swing/JMenu.java,
javax/swing/JSlider.java,
javax/swing/KeyStroke.java,
javax/swing/OverlayLayout.java,
javax/swing/ScrollPaneLayout.java,
javax/swing/SizeRequirements.java,
javax/swing/UIManager.java,
javax/swing/ViewportLayout.java,
javax/swing/border/AbstractBorder.java,
javax/swing/colorchooser/DefaultColorSelectionModel.java,
javax/swing/event/EventListenerList.java,
javax/swing/table/AbstractTableModel.java,
javax/swing/table/DefaultTableCellRenderer.java,
javax/swing/table/DefaultTableColumnModel.java,
javax/swing/table/DefaultTableModel.java,
javax/swing/table/TableColumn.java,
javax/swing/text/StyledEditorKit.java,
javax/swing/tree/DefaultMutableTreeNode.java,
javax/swing/tree/DefaultTreeModel.java,
javax/swing/tree/DefaultTreeSelectionModel.java,
javax/swing/tree/TreePath.java,
javax/swing/undo/AbstractUndoableEdit.java,
javax/swing/undo/StateEdit.java,
javax/swing/undo/StateEditable.java,
javax/swing/undo/UndoableEditSupport.java:
Merges from classpath.
From-SVN: r65077
Diffstat (limited to 'libjava/javax/swing/undo')
-rw-r--r-- | libjava/javax/swing/undo/AbstractUndoableEdit.java | 340 | ||||
-rw-r--r-- | libjava/javax/swing/undo/StateEdit.java | 239 | ||||
-rw-r--r-- | libjava/javax/swing/undo/StateEditable.java | 18 | ||||
-rw-r--r-- | libjava/javax/swing/undo/UndoableEditSupport.java | 293 |
4 files changed, 481 insertions, 409 deletions
diff --git a/libjava/javax/swing/undo/AbstractUndoableEdit.java b/libjava/javax/swing/undo/AbstractUndoableEdit.java index e98b87c..68c2813 100644 --- a/libjava/javax/swing/undo/AbstractUndoableEdit.java +++ b/libjava/javax/swing/undo/AbstractUndoableEdit.java @@ -1,5 +1,5 @@ /* AbstractTableModel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,171 +44,175 @@ import java.io.Serializable; * AbstractUndoableEdit * @author Andrew Selkirk */ -public class AbstractUndoableEdit extends Object - implements UndoableEdit, - Serializable { - - //------------------------------------------------------------- - // Constants -------------------------------------------------- - //------------------------------------------------------------- - - /** - * String returned by getRedoPresentationName() - */ - protected static String RedoName = "Redo"; - - /** - * String returned by getUndoPresentationName() - */ - protected static String UndoName = "Undo"; - - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * TODO - */ - private boolean hasBeenDone = false; - - /** - * The edit is alive - */ - private boolean alive = true; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Create new AbstractUndoableEdit - */ - public AbstractUndoableEdit() { - } // AbstractUndoableEdit() - - - //------------------------------------------------------------- - // Interface: UndoableEdit ------------------------------------ - //------------------------------------------------------------- - - /** - * addEdit - * @param anEdit TODO - * @returns TODO - */ - public boolean addEdit(UndoableEdit anEdit) { - return false; - } // addEdit() - - /** - * canRedo() - * @returns true if redoable, false otherwise - */ - public boolean canRedo() { - if (alive == true && hasBeenDone == false) { - return true; - } // if - return false; - } // canRedo() - - /** - * canUndo() - * @returns true if undoable, false otherwise - */ - public boolean canUndo() { - if (alive == true && hasBeenDone == true) { - return true; - } // if - return false; - } // canUndo() - - /** - * die - */ - public void die() { - alive = false; - } // die() - - /** - * getPresentation - * @returns TODO - */ - public String getPresentationName() { - return ""; - } // getPresentationName() - - /** - * getRedoPresentationName - * @returns TODO - */ - public String getRedoPresentationName() { - if (getPresentationName().equals("") == true) { - return RedoName; - } else { - return RedoName + " " + getPresentationName(); - } - } // getRedoPresentationName() - - /** - * getUndoPresentationName - * @returns TODO - */ - public String getUndoPresentationName() { - if (getPresentationName().equals("") == true) { - return UndoName; - } else { - return UndoName + " " + getPresentationName(); - } - } // getUndoPresentationName() - - /** - * isSignificant - * @returns true - */ - public boolean isSignificant() { - return true; - } // isSignificant() - - /** - * redo - * @throws CannotRedoException TODO - */ - public void redo() throws CannotRedoException { - if (canRedo() == false) { - throw new CannotRedoException(); - } - hasBeenDone = true; - } // redo() - - /** - * replaceEdit - * @param anEdit TODO - * @returns TODO - */ - public boolean replaceEdit(UndoableEdit anEdit) { - return false; - } // replaceEdit() - - /** - * String representation - * @returns String representation - */ - public String toString() { - return null; // TODO - } // toString() - - /** - * undo - * @throws CannotUndoException TODO - */ - public void undo() throws CannotUndoException { - if (canUndo() == false) { - throw new CannotUndoException(); - } - hasBeenDone = false; - } // undo() - - +public class AbstractUndoableEdit implements UndoableEdit, Serializable +{ + static final long serialVersionUID = 580150227676302096L; + + //------------------------------------------------------------- + // Constants -------------------------------------------------- + //------------------------------------------------------------- + + /** + * String returned by getRedoPresentationName() + */ + protected static final String RedoName = "Redo"; + + /** + * String returned by getUndoPresentationName() + */ + protected static final String UndoName = "Undo"; + + + //------------------------------------------------------------- + // Variables -------------------------------------------------- + //------------------------------------------------------------- + + /** + * TODO + */ + private boolean hasBeenDone = false; + + /** + * The edit is alive + */ + private boolean alive = true; + + + //------------------------------------------------------------- + // Initialization --------------------------------------------- + //------------------------------------------------------------- + + /** + * Create new AbstractUndoableEdit + */ + public AbstractUndoableEdit() + { + } // AbstractUndoableEdit() + + + //------------------------------------------------------------- + // Interface: UndoableEdit ------------------------------------ + //------------------------------------------------------------- + + /** + * addEdit + * @param anEdit TODO + * @returns TODO + */ + public boolean addEdit(UndoableEdit anEdit) + { + return false; + } // addEdit() + + /** + * canRedo() + * @returns true if redoable, false otherwise + */ + public boolean canRedo() + { + if (alive == true && hasBeenDone == false) + return true; + return false; + } // canRedo() + + /** + * canUndo() + * @returns true if undoable, false otherwise + */ + public boolean canUndo() + { + if (alive == true && hasBeenDone == true) + return true; + return false; + } // canUndo() + + /** + * die + */ + public void die() + { + alive = false; + } // die() + + /** + * getPresentation + * @returns TODO + */ + public String getPresentationName() + { + return ""; + } // getPresentationName() + + /** + * getRedoPresentationName + * @returns TODO + */ + public String getRedoPresentationName() + { + if (getPresentationName().equals("")) + return RedoName; + return RedoName + " " + getPresentationName(); + } // getRedoPresentationName() + + /** + * getUndoPresentationName + * @returns TODO + */ + public String getUndoPresentationName() + { + if (getPresentationName().equals("")) + return UndoName; + return UndoName + " " + getPresentationName(); + } // getUndoPresentationName() + + /** + * isSignificant + * @returns true + */ + public boolean isSignificant() + { + return true; + } // isSignificant() + + /** + * redo + * @throws CannotRedoException TODO + */ + public void redo() throws CannotRedoException + { + if (! canRedo()) + throw new CannotRedoException(); + hasBeenDone = true; + } // redo() + + /** + * replaceEdit + * @param anEdit TODO + * @returns TODO + */ + public boolean replaceEdit(UndoableEdit anEdit) + { + return false; + } // replaceEdit() + + /** + * String representation + * @returns String representation + */ + public String toString() + { + return (super.toString() + " hasBeenDone: " + hasBeenDone + + " alive: " + alive); + } + + /** + * undo + * @throws CannotUndoException TODO + */ + public void undo() throws CannotUndoException + { + if (! canUndo()) + throw new CannotUndoException(); + hasBeenDone = false; + } // undo() } // AbstractUndoableEdit diff --git a/libjava/javax/swing/undo/StateEdit.java b/libjava/javax/swing/undo/StateEdit.java index a56564b..f617bc3 100644 --- a/libjava/javax/swing/undo/StateEdit.java +++ b/libjava/javax/swing/undo/StateEdit.java @@ -1,5 +1,5 @@ -/* AbstractTableModel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* StateEdit.java -- + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -44,108 +44,133 @@ import java.util.*; * StateEdit * @author Andrew Selkirk */ -public class StateEdit extends AbstractUndoableEdit { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * RCSID - */ - protected static final String RCSID = ""; // TODO - - /** - * object - */ - protected StateEditable object; - - /** - * preState - */ - protected Hashtable preState; - - /** - * postState - */ - protected Hashtable postState; - - /** - * undoRedoName - */ - protected String undoRedoName; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor StateEdit - * @param value0 TODO - */ - public StateEdit(StateEditable value0) { - // TODO - } // StateEdit() - - /** - * Constructor StateEdit - * @param value0 TODO - * @param value1 TODO - */ - public StateEdit(StateEditable value0, String value1) { - // TODO - } // StateEdit() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * init - * @param value0 TODO - * @param value1 TODO - */ - protected void init(StateEditable value0, String value1) { - // TODO - } // init() - - /** - * end - */ - public void end() { - // TODO - } // end() - - /** - * undo - */ - public void undo() { - // TODO - } // undo() - - /** - * redo - */ - public void redo() { - // TODO - } // redo() - - /** - * getPresentationName - * @returns String - */ - public String getPresentationName() { - return null; // TODO - } // getPresentationName() - - /** - * removeRedundantState - */ - protected void removeRedundantState() { - // TODO - } // removeRedundantState() - - -} // StateEdit +public class StateEdit extends AbstractUndoableEdit +{ + + //------------------------------------------------------------- + // Variables -------------------------------------------------- + //------------------------------------------------------------- + + /** + * RCSID + */ + protected static final String RCSID = ""; // TODO + + /** + * object + */ + protected StateEditable object; + + /** + * preState + */ + protected Hashtable preState; + + /** + * postState + */ + protected Hashtable postState; + + /** + * undoRedoName + */ + protected String undoRedoName; + + + //------------------------------------------------------------- + // Initialization --------------------------------------------- + //------------------------------------------------------------- + + /** + * Constructor StateEdit + * @param obj Object to edit + */ + public StateEdit(StateEditable obj) + { + init(obj, null); + } + + /** + * Constructor StateEdit + * @param obj Object to edit + * @param name Presentation name + */ + public StateEdit(StateEditable obj, String name) + { + init(obj, name); + } + + + //------------------------------------------------------------- + // Methods ---------------------------------------------------- + //------------------------------------------------------------- + + /** + * Initialize this object. + * @param obj Object to edit + * @param name Presentation name + */ + protected void init(StateEditable obj, String name) + { + object = obj; + undoRedoName = name; + preState = new Hashtable(); + postState = new Hashtable(); + obj.storeState(preState); + } + + /** + * Indicate that all edits are finished, and update this object + * with final state. + */ + public void end() + { + object.storeState(postState); + removeRedundantState(); + } + + /** + * Undo this edit by applying the initial state to the edited object. + */ + public void undo() + { + object.restoreState(preState); + } + + /** + * Undo this edit by applying the final state to the edited object. + */ + public void redo() + { + object.restoreState(postState); + } + + /** + * Return the presentation name of this object. + * @returns The name, or null if not set + */ + public String getPresentationName() + { + return undoRedoName; + } + + /** + * removeRedundantState + */ + protected void removeRedundantState() + { + Iterator i = preState.keySet().iterator(); + while (i.hasNext()) + { + Object key = i.next(); + if (postState.containsKey(key)) + { + if (preState.get(key).equals(postState.get(key))) + { + i.remove(); + postState.remove(key); + } + } + } + } +} diff --git a/libjava/javax/swing/undo/StateEditable.java b/libjava/javax/swing/undo/StateEditable.java index 76eedad..d757438 100644 --- a/libjava/javax/swing/undo/StateEditable.java +++ b/libjava/javax/swing/undo/StateEditable.java @@ -1,5 +1,5 @@ -/* AbstractTableModel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* StateEditable.java -- + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -46,20 +46,20 @@ import java.util.Hashtable; */ public interface StateEditable { - /** - * Upon receiving this message the receiver should extract any relevant - * state out of state - * + * Restore State * @param state State */ public void restoreState(Hashtable state); /** - * Upon receiving this message the receiver should place any relevant state - * into state - * + * Store State * @param state State */ public void storeState(Hashtable state); + + /** + * For some reason, Sun made the RCS IDs visible. + */ + public static final String RCSID = "We aren't compatible"; } // StateEditable diff --git a/libjava/javax/swing/undo/UndoableEditSupport.java b/libjava/javax/swing/undo/UndoableEditSupport.java index 6f87398..f09f3ff 100644 --- a/libjava/javax/swing/undo/UndoableEditSupport.java +++ b/libjava/javax/swing/undo/UndoableEditSupport.java @@ -1,5 +1,5 @@ -/* AbstractTableModel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. +/* UndoableEditSupport.java -- + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,126 +45,169 @@ import javax.swing.event.*; * UndoableEditSupport * @author Andrew Selkirk */ -public class UndoableEditSupport { - - //------------------------------------------------------------- - // Variables -------------------------------------------------- - //------------------------------------------------------------- - - /** - * updateLevel - */ - protected int updateLevel; - - /** - * compoundEdit - */ - protected CompoundEdit compoundEdit; - - /** - * listeners - */ - protected Vector listeners = new Vector(); - - /** - * realSource - */ - protected Object realSource; - - - //------------------------------------------------------------- - // Initialization --------------------------------------------- - //------------------------------------------------------------- - - /** - * Constructor UndoableEditSupport - */ - public UndoableEditSupport() { - // TODO - } // UndoableEditSupport() - - /** - * Constructor UndoableEditSupport - * @param object TODO - */ - public UndoableEditSupport(Object object) { - realSource = object; - } // UndoableEditSupport() - - - //------------------------------------------------------------- - // Methods ---------------------------------------------------- - //------------------------------------------------------------- - - /** - * toString - * @returns String - */ - public String toString() { - return null; // TODO - } // toString() - - /** - * addUndoableEditListener - * @param value0 TODO - */ - public synchronized void addUndoableEditListener(UndoableEditListener value0) { - // TODO - } // addUndoableEditListener() - - /** - * removeUndoableEditListener - * @param value0 TODO - */ - public synchronized void removeUndoableEditListener(UndoableEditListener value0) { - // TODO - } // removeUndoableEditListener() - - /** - * _postEdit - * @param value0 TODO - */ - protected void _postEdit(UndoableEdit value0) { - // TODO - } // _postEdit() - - /** - * postEdit - * @param value0 TODO - */ - public synchronized void postEdit(UndoableEdit value0) { - // TODO - } // postEdit() - - /** - * getUpdateLevel - * @returns int - */ - public int getUpdateLevel() { - return 0; // TODO - } // getUpdateLevel() - - /** - * beginUpdate - */ - public synchronized void beginUpdate() { - // TODO - } // beginUpdate() - - /** - * createCompoundEdit - * @returns CompoundEdit - */ - protected CompoundEdit createCompoundEdit() { - return null; // TODO - } // createCompoundEdit() - - /** - * endUpdate - */ - public synchronized void endUpdate() { - // TODO - } // endUpdate() - - -} // UndoableEditSupport +public class UndoableEditSupport +{ + + //------------------------------------------------------------- + // Variables -------------------------------------------------- + //------------------------------------------------------------- + + /** + * updateLevel + */ + protected int updateLevel; + + /** + * compoundEdit + */ + protected CompoundEdit compoundEdit; + + /** + * listeners + */ + protected Vector listeners = new Vector(); + + /** + * realSource + */ + protected Object realSource; + + + //------------------------------------------------------------- + // Initialization --------------------------------------------- + //------------------------------------------------------------- + + /** + * Constructor UndoableEditSupport + */ + public UndoableEditSupport() + { + } + + /** + * Constructor UndoableEditSupport + * @param object TODO + */ + public UndoableEditSupport(Object object) + { + realSource = object; + } + + + //------------------------------------------------------------- + // Methods ---------------------------------------------------- + //------------------------------------------------------------- + + /** + * toString + * @returns String + */ + public String toString() + { + return (super.toString() + " realSource: " + realSource + + " updateLevel: " + updateLevel); + } + + /** + * Add a listener. + * @param val the listener + */ + public synchronized void addUndoableEditListener(UndoableEditListener val) + { + listeners.add(val); + } + + /** + * Remove a listener. + * @param val the listener + */ + public synchronized void removeUndoableEditListener(UndoableEditListener val) + { + listeners.removeElement(val); + } + + /** + * Return an array of all listeners. + * @returns all the listeners + */ + public synchronized UndoableEditListener[] getUndoableEditListeners() + { + UndoableEditListener[] result = new UndoableEditListener[listeners.size()]; + return (UndoableEditListener[]) listeners.toArray(result); + } + + /** + * _postEdit + * @param value0 TODO + */ + protected void _postEdit(UndoableEdit edit) + { + UndoableEditEvent event = new UndoableEditEvent(realSource, edit); + int max = listeners.size(); + for (int i = 0; i < max; ++i) + { + UndoableEditListener l + = (UndoableEditListener) (listeners.elementAt(i)); + l.undoableEditHappened(event); + } + } + + /** + * postEdit + * @param value0 TODO + */ + public synchronized void postEdit(UndoableEdit edit) + { + if (compoundEdit == null) + compoundEdit.addEdit(edit); + else + _postEdit(edit); + } + + /** + * getUpdateLevel + * @returns int + */ + public int getUpdateLevel() + { + return updateLevel; + } + + /** + * beginUpdate + */ + public synchronized void beginUpdate() + { + if (compoundEdit != null) + { + // FIXME: what? We can't push a new one. This isn't even + // documented anyway. + endUpdate(); + } + + compoundEdit = createCompoundEdit(); + ++updateLevel; + } + + /** + * createCompoundEdit + * @returns CompoundEdit + */ + protected CompoundEdit createCompoundEdit() + { + return new CompoundEdit(); + } + + /** + * endUpdate + */ + public synchronized void endUpdate() + { + // FIXME: assert updateLevel == 1; + compoundEdit.end(); + CompoundEdit c = compoundEdit; + compoundEdit = null; + --updateLevel; + _postEdit(c); + } +} |