KickJava   Java API By Example, From Geeks To Geeks.

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


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