1 20 21 package org.jacorb.naming.namemanager; 22 23 import java.awt.*; 24 import java.awt.event.*; 25 26 import javax.swing.*; 27 import org.omg.CosNaming.*; 28 import org.jacorb.naming.*; 29 30 41 42 public class NameManager 43 { 44 public static void main(String args[]) 45 { 46 org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null); 47 48 JFrame frame = new JFrame("JacORB NameManager"); 49 50 JMenuBar menubar = new JMenuBar(); 52 53 JMenu fileMenu = new JMenu("File"); 54 JMenu editMenu = new JMenu("Edit"); 55 JMenu helpMenu = new JMenu("Help"); 56 57 JMenuItem quit = new JMenuItem("Quit", KeyEvent.VK_Q); 58 quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK)); 59 fileMenu.add(quit); 60 61 JMenuItem options = new JMenuItem("Options"); 62 63 JMenuItem create = new JMenuItem("BindNewContext", KeyEvent.VK_N); 64 create.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); 65 66 JMenuItem bindObject = new JMenuItem("Bind Object", KeyEvent.VK_B); 67 bindObject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK)); 68 69 JMenuItem unbind = new JMenuItem("Unbind name", KeyEvent.VK_U); 70 unbind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, ActionEvent.CTRL_MASK)); 71 72 editMenu.add(options); 73 editMenu.add(create); 74 editMenu.add(bindObject); 75 editMenu.add(unbind); 76 77 JMenuItem about = new JMenuItem("About..."); 78 helpMenu.add(about); 79 80 menubar.add(fileMenu); 81 menubar.add(editMenu); 82 menubar.add(helpMenu); 83 84 NamingContextExt rootContext = null; 85 try 86 { 87 rootContext = 88 NamingContextExtHelper.narrow( orb.resolve_initial_references("NameService")); 89 } 90 catch (Exception e) 91 { 92 JOptionPane.showMessageDialog(frame, 93 "Could not find name service", 94 "Initialization error", 95 JOptionPane.ERROR_MESSAGE); 96 usage(); 97 System.exit(1); 98 } 99 100 if( rootContext == null ) 101 { 102 System.err.println("Narrow for name service failed, exiting..."); 103 usage(); 104 System.exit(1); 105 } 106 107 109 NSTable nstable = new NSTable(); 110 JScrollPane tableScrollPane= new JScrollPane(nstable); 111 nstable.setPreferredScrollableViewportSize(new Dimension(300,250)); 112 113 NSTree tree= new NSTree(300, 200, nstable, rootContext, orb); 114 JScrollPane treeScrollPane = new JScrollPane(tree); 115 116 JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 117 splitPane.setLeftComponent( treeScrollPane ); 118 splitPane.setRightComponent( tableScrollPane ); 119 splitPane.setDividerLocation(200); 120 splitPane.setDividerSize(2); 121 frame.getContentPane().setBackground(Color.white); 122 frame.getContentPane().add(splitPane); 123 tree.update(); 124 125 Handler handler= new Handler(frame,tree); 126 TableHandler tableHandler = new TableHandler(frame, nstable); 127 quit.addActionListener(handler); 128 options.addActionListener(handler); 129 create.addActionListener(handler); 130 bindObject.addActionListener(handler); 131 unbind.addActionListener(handler); 132 about.addActionListener(handler); 133 134 tree.addMouseListener(handler); 135 tree.addKeyListener(handler); 136 137 frame.addWindowListener(handler); 138 nstable.addMouseListener(tableHandler); 139 nstable.addKeyListener(tableHandler); 140 141 frame.setJMenuBar(menubar); 142 frame.pack(); 143 frame.show(); 144 145 orb.run(); 146 } 147 148 public static void usage() 149 { 150 System.out.println("Usage: NameManager [orb_options]"); 151 System.out.println(" e.g. nmg -ORBInitRef NameService=file:///c:/ns.ior"); 152 } 153 } 154 155 | Popular Tags |