KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > naming > namemanager > NameManager


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

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 /**
31  * A graphical user interface for the Naming Service.
32  * If invoked with a file name argument, the NameManager
33  * will create and use its own root context and print its
34  * IOR to the given file such that it complies with the
35  * JacORB mechanism for locating the root naming context
36  *
37  * @author Gerald Brose
38  * @author Wei-Ju Wu
39  * @author Volker Siegel
40  */

41
42 public class NameManager
43 {
44     public static void main(String JavaDoc args[])
45     {
46         org.omg.CORBA.ORB JavaDoc orb = org.omg.CORBA.ORB.init(args,null);
47
48         JFrame frame = new JFrame("JacORB NameManager");
49
50         // set up menu bars and menu
51
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 JavaDoc 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         // set up tree and table
108

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