1 28 package org.objectweb.openccm.explorer.menu; 29 30 import java.awt.event.KeyEvent ; 31 import java.awt.Event ; 32 import javax.swing.JPanel ; 33 import javax.swing.JMenuBar ; 34 import javax.swing.JMenu ; 35 import javax.swing.JMenuItem ; 36 import javax.swing.JToolBar ; 37 import javax.swing.ImageIcon ; 38 import javax.swing.Action ; 39 import javax.swing.JButton ; 40 import javax.swing.KeyStroke ; 41 42 import org.objectweb.fractal.api.Component; 43 44 import java.net.URL ; 45 46 53 public class Menu extends JPanel { 54 55 56 protected JMenuBar menuBar_; 57 58 59 protected JToolBar toolBar_; 60 61 62 protected Component tree_; 63 64 65 protected java.awt.Frame parent_ = null; 66 67 68 public static ImageIcon createIcon(String imageName) { 69 if (imageName != null) { 70 URL urlFile = null; 71 urlFile = Thread.currentThread().getContextClassLoader().getResource(imageName); 72 if(urlFile==null){ 73 try { 74 urlFile = new URL (imageName); 75 } catch (java.net.MalformedURLException e) { 76 System.out.println(imageName + ": Malformed URL !"); 77 } 78 } 79 if(urlFile!=null){ 80 return new ImageIcon (urlFile); 81 } 82 } 83 return null; 84 } 85 86 protected void createExplorerMenu() { 87 JMenu explorerMenu = new JMenu ("Explorer"); 88 explorerMenu.setMnemonic(KeyEvent.VK_E); 89 90 JMenuItem menuItem = null; 91 JButton button = null; 92 93 Action loadConfigurationFileAction = new LoadConfigurationFileAction("Load a configuration file", createIcon("empty.png"), "Load a new configuration file", new Integer (KeyEvent.VK_O), tree_, this); 94 Action refreshAction = new RefreshAction("Refresh the tree", createIcon("icons/reload.png"), "Refreshes the tree", new Integer (KeyEvent.VK_R), tree_); 95 Action debugConsoleAction = new DisplayDebugConsoleAction("Display the debug console", createIcon("empty.png"), "Display the debug console", new Integer (KeyEvent.VK_D), tree_); 96 Action displayAboutDialogAction = new DisplayAboutDialogAction(parent_,"About...", createIcon("empty.png"), "About the OpenCCM Explorer", new Integer (KeyEvent.VK_H), tree_); 97 Action loadIORFileAction = new LoadIORFileAction("Add a CORBA Object", createIcon("empty.png"), "Load a new IOR file", new Integer (KeyEvent.VK_L), tree_, this); 98 Action quitAction = new QuitAction("Quit", createIcon("icons/power.png"), "Quit the application", new Integer (KeyEvent.VK_Q), tree_); 99 100 102 menuItem = new JMenuItem (loadConfigurationFileAction); 103 menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK)); 104 explorerMenu.add(menuItem); 105 106 menuItem = new JMenuItem (loadIORFileAction); 107 menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)); 108 explorerMenu.add(menuItem); 109 110 menuItem = new JMenuItem (refreshAction); 111 menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK)); 112 explorerMenu.add(menuItem); 113 114 menuItem = new JMenuItem (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 (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 (quitAction); 127 menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.ALT_MASK)); 128 explorerMenu.add(menuItem); 129 130 132 button = new JButton (quitAction); 133 button.setText(""); 134 toolBar_.add(button); 135 136 button = new JButton (refreshAction); 137 button.setText(""); 138 toolBar_.add(button); 139 140 menuBar_.add(explorerMenu); 141 } 142 143 146 public Menu(java.awt.Frame parent, Component tree) { 147 parent_ = parent; 148 tree_ = tree; 149 menuBar_ = new JMenuBar (); 150 toolBar_ = new JToolBar (); 151 toolBar_.setFloatable(false); 152 createExplorerMenu(); 153 } 154 155 160 public JMenuBar getMenuBar() { 161 return menuBar_; 162 } 163 164 169 public JToolBar getToolBar() { 170 return toolBar_; 171 } 172 173 } 174 | Popular Tags |