KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > globalactions > UndoAction


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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 JavaDoc;
20 import java.awt.Toolkit JavaDoc;
21 import java.awt.event.ActionEvent JavaDoc;
22 import java.awt.event.KeyEvent JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.KeyStroke JavaDoc;
28 import javax.swing.text.Document JavaDoc;
29 import javax.swing.text.JTextComponent JavaDoc;
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 JavaDoc {
40
41     private JComponent JavaDoc 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(null, null,
49                 "menu_edit_undo_tooltip").replaceAll("&", ""));
50
51         // small icon for menu
52
putValue(SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.EDIT_UNDO));
53
54         // large icon for toolbar
55
putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.EDIT_UNDO));
56
57         // shortcut key
58
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Z,
59                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
60
61         // disable toolbar text
62
setShowToolBarText(false);
63
64         setEnabled(true);
65         KeyboardFocusManager JavaDoc manager = KeyboardFocusManager
66                 .getCurrentKeyboardFocusManager();
67
68         manager.addPropertyChangeListener("permanentFocusOwner", this);
69
70     }
71
72     public void propertyChange(PropertyChangeEvent JavaDoc e) {
73         Object JavaDoc o = e.getNewValue();
74         if (o instanceof JComponent JavaDoc)
75             focusOwner = (JComponent JavaDoc) o;
76         else
77             focusOwner = null;
78
79     }
80
81     public void actionPerformed(ActionEvent JavaDoc evt) {
82         if (focusOwner == null)
83             return;
84
85         if (focusOwner instanceof JTextComponent JavaDoc) {
86             Document JavaDoc doc = ((JTextComponent JavaDoc)focusOwner).getDocument();
87             
88             if ( doc instanceof UndoDocument) {
89                 ((UndoDocument)doc).undo();
90             }
91         }
92     }
93
94 }
95
Popular Tags