KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > popup > DefaultAction


1 /*===========================================================================
2
3 ObjectWeb Naming Context Framework
4 Copyright (C) 2002 USTL - LIFL - GOAL
5 Contact: architecture@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jérôme Moroy.
23 Contributor(s): ______________________________________.
24
25 ===========================================================================*/

26
27 package org.objectweb.util.browser.core.popup;
28
29 /** The Java API's imports */
30 import java.awt.event.ActionEvent JavaDoc;
31
32 import javax.swing.AbstractAction JavaDoc;
33 import javax.swing.Icon JavaDoc;
34 import javax.swing.JOptionPane JavaDoc;
35 import javax.swing.KeyStroke JavaDoc;
36
37 /** The Console's imports */
38 import org.objectweb.util.browser.api.MenuItem;
39 import org.objectweb.util.browser.api.MenuItemTreeView;
40 import org.objectweb.util.browser.core.api.MenuItemTreeViewConfiguration;
41 import org.objectweb.util.browser.core.common.DynamicTree;
42
43 /**
44  * Defines the default action which wraps the ExtendedActionListener.
45  *
46  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
47  * @version 0.1
48  */

49 public class DefaultAction extends AbstractAction JavaDoc {
50
51     protected DynamicTree tree_ = null;
52     protected MenuItem delegate_ = null;
53     protected MenuItemTreeView treeView_ = null;
54     protected boolean isUserIcon_ = false;
55
56     protected void init(DynamicTree tree, MenuItem actionListener, MenuItemTreeView treeView){
57         tree_ = tree;
58         delegate_ = actionListener;
59         treeView_ = treeView;
60     }
61
62     public DefaultAction(DynamicTree tree, MenuItem actionListener, MenuItemTreeView treeView, String JavaDoc name, Icon JavaDoc icon, KeyStroke JavaDoc keyStroke, Character JavaDoc mnemonic, boolean isUserIcon, int itemState) {
63         super(name, icon);
64         init(tree,actionListener,treeView);
65         // Fixes the short description of the action.
66
putValue(SHORT_DESCRIPTION, name);
67         // Fixes the mnemonic value.
68
if(mnemonic!=null){
69             putValue(MNEMONIC_KEY, new Integer JavaDoc(Character.toUpperCase(mnemonic.charValue())));
70         }
71         // Fixes the accelerator key.
72
if(keyStroke!=null){
73             putValue(ACCELERATOR_KEY, keyStroke);
74         }
75         isUserIcon_ = isUserIcon;
76         if (itemState == MenuItem.DISABLED_STATUS)
77             setEnabled(false);
78     }
79
80     public boolean isUserIcon(){
81         return isUserIcon_;
82     }
83
84     public void actionPerformed(ActionEvent JavaDoc e) {
85         try {
86             ((MenuItemTreeViewConfiguration)treeView_).setActionEvent(e);
87             delegate_.actionPerformed(treeView_);
88         } catch (Exception JavaDoc e1) {
89             //e1.printStackTrace();
90
JOptionPane.showMessageDialog(null, e1.getClass().getName() + ":\n" + e1.getMessage(), "Exception (" + e.getActionCommand() + ")", JOptionPane.ERROR_MESSAGE);
91         }
92         tree_.refreshAll();
93     }
94
95 }
96
Popular Tags