Java Swing O Reilly 18.1.11 The CannotUndoException Class (Web server info)
Java Swing O Reilly 18.1.11 The CannotUndoException Class This class is an extension of RuntimeException thrown when an attempt is made to undo an UndoableEdit that cannot be undone (typically because it has already been undone, or because it has been “killed”). There are no properties, constructors (other than the implicit default), or methods defined in this class. 18.1.12 Extending UndoManager Now that we’ve looked at all of the classes and interfaces in the undo framework, we’ll look at a few ideas for extending the functionality it provides. In this example, we’ll extend UndoManager to add a few extra features. The first thing we’ll add is the ability to get a list of the edits stored in the manager. This is a simple task of returning the contents of the edits vector inherited from CompoundEdit. We also provide access to an array of significant undoable edits and an array of significant redoable edits. These might be useful in a game like chess in which we want to provide a list of past moves. The next major feature we’ll add in this extended UndoManager is support for listeners. At the time of this writing, the current UndoManager did not have any way of notifying you when it received edits. As we saw in an earlier example, this means that you have to listen to each edit-generating component if you want to update the user interface to reflect new undoable or redoable edits as they occur. In our manager, we simply add the ability to add and remove undoable edit listeners to the undo manager itself. Each time an edit is added, the undo manager fires an UndoableEditEvent to any registered listeners. This way, we can just add the undo manager as a listener to each edit- generating component and then add a single listener to the undo manager to update the UI. The methods of our new undo manager can be divided into two groups, each supporting one of the two features we’re adding. We’ll split the source code listing along these lines so we can talk about each set of methods independently. Here’s the first half. // ExtendedUndoManager.java // import javax.swing.event.*; import javax.swing.undo.*; import java.util.Enumeration; import java.util.Vector; // An extension of UndoManager that provides two additional features: // (1) The ability to add & remove listeners and (2) the ability to gain more // extensive access to the edits being managed. public class ExtendedUndoManager extends UndoManager implements UndoableEditListener { // Return the complete list of edits in an array. public synchronized UndoableEdit[] getEdits() { UndoableEdit[] array = new UndoableEdit[edits.size()]; edits.copyInto(array); return array; } // Return all currently significant undoable edits. The first edit will be the // next one to be undone. public synchronized UndoableEdit[] getUndoableEdits() { - 575 -
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.