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 UndoAction extends AbstractColumbaAction implements
39: PropertyChangeListener {
40:
41: private JComponent focusOwner = null;
42:
43: public UndoAction(IFrameMediator controller) {
44: super (controller, GlobalResourceLoader.getString(null, null,
45: "menu_edit_undo"));
46:
47: // tooltip text
48: putValue(SHORT_DESCRIPTION, GlobalResourceLoader.getString(
49: null, null, "menu_edit_undo_tooltip").replaceAll("&",
50: ""));
51:
52: // small icon for menu
53: putValue(SMALL_ICON, ImageLoader
54: .getSmallIcon(IconKeys.EDIT_UNDO));
55:
56: // large icon for toolbar
57: putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.EDIT_UNDO));
58:
59: // shortcut key
60: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z,
61: Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
62:
63: // disable toolbar text
64: setShowToolBarText(false);
65:
66: setEnabled(true);
67: KeyboardFocusManager manager = KeyboardFocusManager
68: .getCurrentKeyboardFocusManager();
69:
70: manager.addPropertyChangeListener("permanentFocusOwner", this );
71:
72: }
73:
74: public void propertyChange(PropertyChangeEvent e) {
75: Object o = e.getNewValue();
76: if (o instanceof JComponent)
77: focusOwner = (JComponent) o;
78: else
79: focusOwner = null;
80:
81: }
82:
83: public void actionPerformed(ActionEvent evt) {
84: if (focusOwner == null)
85: return;
86:
87: if (focusOwner instanceof JTextComponent) {
88: Document doc = ((JTextComponent) focusOwner).getDocument();
89:
90: if (doc instanceof UndoDocument) {
91: ((UndoDocument) doc).undo();
92: }
93: }
94: }
95:
96: }
|