January 2005
Intermediate to advanced
256 pages
6h 34m
English
Fortunately,
QTJ offers a unique opportunity to combine
Swing’s thoughtfully designed
undo API,
javax.swing.undo, with
QuickTime’s support for reverting a movie to a
previous state. Combined, these features provide the ability to
support a long trail of undoes and redoes.
RedoableQTEditor again builds on
BasicQTEditor, adding a Swing
UndoManager
that is used by both the doUndo( ) and doRedo( ) methods:
Compile and run this example with ant run-ch03-redoableqteditor.
public void doUndo( ) throws QTException {
if (! undoanager.canUndo( )) {
System.out.println ("can't undo");
return;
}
undoManager.undo( );
}
public void doRedo( ) throws QTException {
if (! undoManager.canRedo( )) {
System.out.println ("can't redo");
return;
}
undoManager.redo( );
}The information about a destructive edit is encapsulated by an inner
class called QTEdit
:
class QTEdit extends AbstractUndoableEdit { MovieEditState previousState; MovieEditState newState; String name; public QTEdit (MovieEditState pState, MovieEditState nState, String n) { previousState = pState; newState = nState; this.name = n; } public String getPresentationName( ) { return name; } public void redo( ) throws CannotRedoException { super.redo( ); try { movie.useEditState (newState); controller.movieChanged( ); } catch (QTException qte) { qte.printStackTrace( ); } } public void undo ( ) throws CannotUndoException { super.undo( ); try { movie.useEditState (previousState); controller.movieChanged( ...Read now
Unlock full access