KickJava   Java API By Example, From Geeks To Geeks.

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


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
package org.columba.core.gui.globalactions;
17
18 import java.awt.KeyboardFocusManager JavaDoc;
19 import java.awt.Toolkit JavaDoc;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.KeyEvent JavaDoc;
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24
25 import javax.swing.Action JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.KeyStroke JavaDoc;
28 import javax.swing.TransferHandler JavaDoc;
29
30 import org.columba.api.gui.frame.IFrameMediator;
31 import org.columba.core.gui.action.AbstractColumbaAction;
32 import org.columba.core.resourceloader.GlobalResourceLoader;
33 import org.columba.core.resourceloader.IconKeys;
34 import org.columba.core.resourceloader.ImageLoader;
35
36 public class CutAction extends AbstractColumbaAction implements
37         PropertyChangeListener JavaDoc {
38
39     private JComponent JavaDoc focusOwner = null;
40
41     public CutAction(IFrameMediator controller) {
42         super(controller, GlobalResourceLoader.getString(null, null,
43                 "menu_edit_cut"));
44
45         // tooltip text
46
putValue(SHORT_DESCRIPTION, GlobalResourceLoader.getString(null, null,
47                 "menu_edit_cut_tooltip").replaceAll("&", ""));
48
49         // small icon for menu
50
putValue(SMALL_ICON, ImageLoader.getSmallIcon(IconKeys.EDIT_CUT));
51
52         // large icon for toolbar
53
putValue(LARGE_ICON, ImageLoader.getIcon(IconKeys.EDIT_CUT));
54
55         // disable toolbar text
56
setShowToolBarText(false);
57
58         // short cut key
59
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X,
60                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
61
62         setEnabled(true);
63
64         putValue(Action.ACTION_COMMAND_KEY, (String JavaDoc) TransferHandler
65                 .getCutAction().getValue(Action.NAME));
66
67         KeyboardFocusManager JavaDoc manager = KeyboardFocusManager
68                 .getCurrentKeyboardFocusManager();
69         
70         manager.addPropertyChangeListener("permanentFocusOwner", this);
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     /**
83      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
84      */

85     public void actionPerformed(ActionEvent JavaDoc e) {
86
87         if (focusOwner == null)
88             return;
89         String JavaDoc action = (String JavaDoc) e.getActionCommand();
90         Action JavaDoc a = focusOwner.getActionMap().get(action);
91         if (a != null)
92             a.actionPerformed(new ActionEvent JavaDoc(focusOwner,
93                     ActionEvent.ACTION_PERFORMED, null));
94
95     }
96
97     /**
98      * @see org.columba.core.gui.action.AbstractColumbaAction#isSingleton()
99      */

100     public boolean isSingleton() {
101         return true;
102     }
103 }
104
Popular Tags