KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > actions > RedoAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.actions;
20
21 import org.openide.awt.UndoRedo;
22 import org.openide.util.HelpCtx;
23 import org.openide.util.NbBundle;
24 import org.openide.util.actions.CallableSystemAction;
25
26 import javax.swing.UIManager JavaDoc;
27 import javax.swing.undo.CannotRedoException JavaDoc;
28 import org.openide.util.Exceptions;
29
30
31 /** Redo an edit.
32 *
33 * @see UndoAction
34 * @author Ian Formanek, Jaroslav Tulach
35 */

36 public class RedoAction extends CallableSystemAction {
37     private static String JavaDoc SWING_DEFAULT_LABEL = UIManager.getString("AbstractUndoableEdit.redoText"); //NOI18N
38

39     public boolean isEnabled() {
40         UndoAction.initializeUndoRedo();
41
42         return super.isEnabled();
43     }
44
45     public String JavaDoc getName() {
46         //#40823 related. AbstractUndoableEdit prepends "Undo/Redo" strings before the custom text,
47
// resulting in repetitive text in UndoAction/RedoAction. attempt to remove the AbstractUndoableEdit text
48
// keeping our text because it has mnemonics.
49
String JavaDoc redo = UndoAction.getUndoRedo().getRedoPresentationName();
50
51         if ((redo != null) && (SWING_DEFAULT_LABEL != null) && redo.startsWith(SWING_DEFAULT_LABEL)) {
52             redo = redo.substring(SWING_DEFAULT_LABEL.length()).trim();
53         }
54
55         return NbBundle.getMessage(RedoAction.class, "Redo", redo);
56     }
57
58     public HelpCtx getHelpCtx() {
59         return new HelpCtx(RedoAction.class);
60     }
61
62     protected String JavaDoc iconResource() {
63         return "org/openide/resources/actions/redo.gif"; // NOI18N
64
}
65
66     public void performAction() {
67         try {
68             UndoRedo undoRedo = UndoAction.getUndoRedo();
69
70             if (undoRedo.canRedo()) {
71                 undoRedo.redo();
72             }
73         } catch (CannotRedoException JavaDoc ex) {
74             Exceptions.printStackTrace(ex);
75         }
76
77         UndoAction.updateStatus();
78     }
79
80     protected boolean asynchronous() {
81         return false;
82     }
83 }
84
Popular Tags