001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1997-2004 Gerald Brose.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: */
020:
021: package org.jacorb.naming.namemanager;
022:
023: import java.awt.*;
024: import java.awt.event.*;
025:
026: import javax.swing.*;
027: import org.omg.CosNaming.*;
028: import org.jacorb.naming.*;
029:
030: /**
031: * A graphical user interface for the Naming Service.
032: * If invoked with a file name argument, the NameManager
033: * will create and use its own root context and print its
034: * IOR to the given file such that it complies with the
035: * JacORB mechanism for locating the root naming context
036: *
037: * @author Gerald Brose
038: * @author Wei-Ju Wu
039: * @author Volker Siegel
040: */
041:
042: public class NameManager {
043: public static void main(String args[]) {
044: org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);
045:
046: JFrame frame = new JFrame("JacORB NameManager");
047:
048: // set up menu bars and menu
049: JMenuBar menubar = new JMenuBar();
050:
051: JMenu fileMenu = new JMenu("File");
052: JMenu editMenu = new JMenu("Edit");
053: JMenu helpMenu = new JMenu("Help");
054:
055: JMenuItem quit = new JMenuItem("Quit", KeyEvent.VK_Q);
056: quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
057: ActionEvent.CTRL_MASK));
058: fileMenu.add(quit);
059:
060: JMenuItem options = new JMenuItem("Options");
061:
062: JMenuItem create = new JMenuItem("BindNewContext",
063: KeyEvent.VK_N);
064: create.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
065: ActionEvent.CTRL_MASK));
066:
067: JMenuItem bindObject = new JMenuItem("Bind Object",
068: KeyEvent.VK_B);
069: bindObject.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,
070: ActionEvent.CTRL_MASK));
071:
072: JMenuItem unbind = new JMenuItem("Unbind name", KeyEvent.VK_U);
073: unbind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U,
074: ActionEvent.CTRL_MASK));
075:
076: editMenu.add(options);
077: editMenu.add(create);
078: editMenu.add(bindObject);
079: editMenu.add(unbind);
080:
081: JMenuItem about = new JMenuItem("About...");
082: helpMenu.add(about);
083:
084: menubar.add(fileMenu);
085: menubar.add(editMenu);
086: menubar.add(helpMenu);
087:
088: NamingContextExt rootContext = null;
089: try {
090: rootContext = NamingContextExtHelper.narrow(orb
091: .resolve_initial_references("NameService"));
092: } catch (Exception e) {
093: JOptionPane.showMessageDialog(frame,
094: "Could not find name service",
095: "Initialization error", JOptionPane.ERROR_MESSAGE);
096: usage();
097: System.exit(1);
098: }
099:
100: if (rootContext == null) {
101: System.err
102: .println("Narrow for name service failed, exiting...");
103: usage();
104: System.exit(1);
105: }
106:
107: // set up tree and table
108:
109: NSTable nstable = new NSTable();
110: JScrollPane tableScrollPane = new JScrollPane(nstable);
111: nstable.setPreferredScrollableViewportSize(new Dimension(300,
112: 250));
113:
114: NSTree tree = new NSTree(300, 200, nstable, rootContext, orb);
115: JScrollPane treeScrollPane = new JScrollPane(tree);
116:
117: JSplitPane splitPane = new JSplitPane(
118: JSplitPane.HORIZONTAL_SPLIT);
119: splitPane.setLeftComponent(treeScrollPane);
120: splitPane.setRightComponent(tableScrollPane);
121: splitPane.setDividerLocation(200);
122: splitPane.setDividerSize(2);
123: frame.getContentPane().setBackground(Color.white);
124: frame.getContentPane().add(splitPane);
125: tree.update();
126:
127: Handler handler = new Handler(frame, tree);
128: TableHandler tableHandler = new TableHandler(frame, nstable);
129: quit.addActionListener(handler);
130: options.addActionListener(handler);
131: create.addActionListener(handler);
132: bindObject.addActionListener(handler);
133: unbind.addActionListener(handler);
134: about.addActionListener(handler);
135:
136: tree.addMouseListener(handler);
137: tree.addKeyListener(handler);
138:
139: frame.addWindowListener(handler);
140: nstable.addMouseListener(tableHandler);
141: nstable.addKeyListener(tableHandler);
142:
143: frame.setJMenuBar(menubar);
144: frame.pack();
145: frame.show();
146:
147: orb.run();
148: }
149:
150: public static void usage() {
151: System.out.println("Usage: NameManager [orb_options]");
152: System.out
153: .println(" e.g. nmg -ORBInitRef NameService=file:///c:/ns.ior");
154: }
155: }
|