KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > enode > ComponentAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Nokia. Portions Copyright 2003 Nokia.
17  * All Rights Reserved.
18  */

19
20 package org.netbeans.modules.enode;
21
22 import javax.swing.*;
23
24 /**
25  * Special action serving as a wrapper for JComponents added to the popup
26  * menu.
27  * @author David Strupl
28  */

29 public class ComponentAction extends AbstractAction implements org.openide.util.actions.Presenter.Popup {
30
31     private JComponent myComponent;
32
33     /** Creates a new instance of ComponentAction */
34     public ComponentAction(JComponent comp) {
35         myComponent = comp;
36     }
37
38     /**
39      * This action should not be performed as an action.
40      */

41     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
42         throw new IllegalStateException JavaDoc("ComponentAction should not be performed as action."); // NOI18N
43
}
44
45     /**
46      * The popup presenter returns either directly
47      * the myComponent if it is a JMenuItem or
48      * creates a new JMenuItem and adds myComponent to it.
49      */

50     public JMenuItem getPopupPresenter() {
51         if (myComponent instanceof JMenuItem) {
52             return (JMenuItem)myComponent;
53         }
54         JMenuItem newItem = new JMenuItem();
55         newItem.add(myComponent);
56         return newItem;
57     }
58     
59 }
60
Popular Tags