KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > menu > Menu


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@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): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================
26 $Id: Menu.java,v 1.3 2005/07/01 15:51:11 moroy Exp $
27 ====================================================================*/

28 package org.objectweb.openccm.explorer.menu;
29
30 import java.awt.event.KeyEvent JavaDoc;
31 import java.awt.Event JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JMenuBar JavaDoc;
34 import javax.swing.JMenu JavaDoc;
35 import javax.swing.JMenuItem JavaDoc;
36 import javax.swing.JToolBar JavaDoc;
37 import javax.swing.ImageIcon JavaDoc;
38 import javax.swing.Action JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.KeyStroke JavaDoc;
41
42 import org.objectweb.fractal.api.Component;
43
44 import java.net.URL JavaDoc;
45
46 /**
47  * This class represents the menu,
48  * it creates a JMenu and its associated JToolBar.
49  *
50  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
51  * @version 0.1
52  */

53 public class Menu extends JPanel JavaDoc {
54
55     /** The menuBar */
56     protected JMenuBar JavaDoc menuBar_;
57
58     /** The menuToolBar */
59     protected JToolBar JavaDoc toolBar_;
60
61     /** The tree */
62     protected Component tree_;
63
64     /** The graphical parent */
65     protected java.awt.Frame JavaDoc parent_ = null;
66
67     /** Returns an ImageIcon, or null if the path is invalid. */
68     public static ImageIcon JavaDoc createIcon(String JavaDoc imageName) {
69         if (imageName != null) {
70             URL JavaDoc urlFile = null;
71             urlFile = Thread.currentThread().getContextClassLoader().getResource(imageName);
72             if(urlFile==null){
73                 try {
74                     urlFile = new URL JavaDoc(imageName);
75                 } catch (java.net.MalformedURLException JavaDoc e) {
76                     System.out.println(imageName + ": Malformed URL !");
77                 }
78             }
79             if(urlFile!=null){
80                 return new ImageIcon JavaDoc(urlFile);
81             }
82         }
83         return null;
84     }
85
86     protected void createExplorerMenu() {
87         JMenu JavaDoc explorerMenu = new JMenu JavaDoc("Explorer");
88         explorerMenu.setMnemonic(KeyEvent.VK_E);
89
90         JMenuItem JavaDoc menuItem = null;
91         JButton JavaDoc button = null;
92
93         Action JavaDoc loadConfigurationFileAction = new LoadConfigurationFileAction("Load a configuration file", createIcon("empty.png"), "Load a new configuration file", new Integer JavaDoc(KeyEvent.VK_O), tree_, this);
94         Action JavaDoc refreshAction = new RefreshAction("Refresh the tree", createIcon("icons/reload.png"), "Refreshes the tree", new Integer JavaDoc(KeyEvent.VK_R), tree_);
95         Action JavaDoc debugConsoleAction = new DisplayDebugConsoleAction("Display the debug console", createIcon("empty.png"), "Display the debug console", new Integer JavaDoc(KeyEvent.VK_D), tree_);
96         Action JavaDoc displayAboutDialogAction = new DisplayAboutDialogAction(parent_,"About...", createIcon("empty.png"), "About the OpenCCM Explorer", new Integer JavaDoc(KeyEvent.VK_H), tree_);
97         Action JavaDoc loadIORFileAction = new LoadIORFileAction("Add a CORBA Object", createIcon("empty.png"), "Load a new IOR file", new Integer JavaDoc(KeyEvent.VK_L), tree_, this);
98         Action JavaDoc quitAction = new QuitAction("Quit", createIcon("icons/power.png"), "Quit the application", new Integer JavaDoc(KeyEvent.VK_Q), tree_);
99         
100         // Add to the menubar
101

102         menuItem = new JMenuItem JavaDoc(loadConfigurationFileAction);
103         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
104         explorerMenu.add(menuItem);
105
106         menuItem = new JMenuItem JavaDoc(loadIORFileAction);
107         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK));
108         explorerMenu.add(menuItem);
109                 
110         menuItem = new JMenuItem JavaDoc(refreshAction);
111         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
112         explorerMenu.add(menuItem);
113
114         menuItem = new JMenuItem JavaDoc(debugConsoleAction);
115         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
116         explorerMenu.add(menuItem);
117
118         explorerMenu.addSeparator();
119
120         menuItem = new JMenuItem JavaDoc(displayAboutDialogAction);
121         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK));
122         explorerMenu.add(menuItem);
123
124         explorerMenu.addSeparator();
125
126         menuItem = new JMenuItem JavaDoc(quitAction);
127         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.ALT_MASK));
128         explorerMenu.add(menuItem);
129
130         // Adding to the toolbar
131

132         button = new JButton JavaDoc(quitAction);
133         button.setText("");
134         toolBar_.add(button);
135
136         button = new JButton JavaDoc(refreshAction);
137         button.setText("");
138         toolBar_.add(button);
139
140         menuBar_.add(explorerMenu);
141     }
142
143     /**
144      * Constructor
145      */

146     public Menu(java.awt.Frame JavaDoc parent, Component tree) {
147         parent_ = parent;
148         tree_ = tree;
149         menuBar_ = new JMenuBar JavaDoc();
150         toolBar_ = new JToolBar JavaDoc();
151         toolBar_.setFloatable(false);
152         createExplorerMenu();
153     }
154
155     /**
156      * Gets the GUI menu bar
157      *
158      * @return The associated JMenuBar
159      */

160     public JMenuBar JavaDoc getMenuBar() {
161         return menuBar_;
162     }
163
164     /**
165      * Gets the GUI tool bar
166      *
167      * @return The associated JToolBar
168      */

169     public JToolBar JavaDoc getToolBar() {
170         return toolBar_;
171     }
172
173 }
174
Popular Tags