01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16:
17: package org.columba.core.gui.globalactions;
18:
19: import java.awt.KeyboardFocusManager;
20: import java.awt.Toolkit;
21: import java.awt.event.ActionEvent;
22: import java.awt.event.KeyEvent;
23: import java.beans.PropertyChangeEvent;
24: import java.beans.PropertyChangeListener;
25:
26: import javax.swing.JComponent;
27: import javax.swing.KeyStroke;
28: import javax.swing.text.Document;
29: import javax.swing.text.JTextComponent;
30:
31: import org.columba.api.gui.frame.IFrameMediator;
32: import org.columba.core.gui.action.AbstractColumbaAction;
33: import org.columba.core.gui.base.UndoDocument;
34: import org.columba.core.resourceloader.GlobalResourceLoader;
35: import org.columba.core.resourceloader.IconKeys;
36: import org.columba.core.resourceloader.ImageLoader;
37:
38: public class RedoAction extends AbstractColumbaAction implements
39: PropertyChangeListener {
40:
41: private JComponent focusOwner = null;
42:
43: public RedoAction(IFrameMediator controller) {
44: super (controller, GlobalResourceLoader.getString(null, null,
45: "menu_edit_redo"));
46:
47: // tooltip text
48: putValue(SHORT_DESCRIPTION, GlobalResourceLoader.getString(
49: null, null, "menu_edit_redo_tooltip").replaceAll("&",
50: ""));
51:
52: // small icon for menu
53: putValue(SMALL_ICON, ImageLoader
54: .getSmallIcon(IconKeys.EDIT_REDO));
55:
56: // large icon for toolbar
57: putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.EDIT_REDO));
58:
59: // disable toolbar text
60: setShowToolBarText(false);
61:
62: // shortcut key
63: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Y,
64: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
65:
66: setEnabled(true);
67:
68: KeyboardFocusManager manager = KeyboardFocusManager
69: .getCurrentKeyboardFocusManager();
70:
71: manager.addPropertyChangeListener("permanentFocusOwner", this );
72:
73: }
74:
75: public void propertyChange(PropertyChangeEvent e) {
76: Object o = e.getNewValue();
77: if (o instanceof JComponent)
78: focusOwner = (JComponent) o;
79: else
80: focusOwner = null;
81:
82: }
83:
84: public void actionPerformed(ActionEvent evt) {
85: if (focusOwner == null)
86: return;
87:
88: if (focusOwner instanceof JTextComponent) {
89: Document doc = ((JTextComponent) focusOwner).getDocument();
90:
91: if (doc instanceof UndoDocument) {
92: ((UndoDocument) doc).redo();
93: }
94: }
95: }
96:
97: }
|