KickJava   Java API By Example, From Geeks To Geeks.

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


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.event.*;
24 import java.awt.*;
25 import javax.swing.tree.*;
26 import javax.swing.*;
27
28 import org.jacorb.naming.Name;
29 import org.omg.CosNaming.*;
30
31 /**
32  * This class handles the events on the tree
33  *
34  * @author Gerald Brose, FU Berlin
35  * @version $Id: Handler.java,v 1.10 2004/05/06 12:39:59 nicolas Exp $
36  */

37
38 public class Handler
39     extends WindowAdapter
40     implements ActionListener, MouseListener, KeyListener
41 {
42     int updateInterval;
43     NSTree tree;
44     Component frame;
45     JDialog dlg;
46     JTextField editName;
47     JPopupMenu popup;
48     Updater updater;
49
50     public Handler(Component fr,NSTree tr)
51     {
52     frame = fr;
53     tree = tr;
54         
55     popup = new JPopupMenu();
56     JMenuItem bindContext = new JMenuItem("BindNewContext");
57     JMenuItem bindObject = new JMenuItem("Bind Object");
58     JMenuItem unbind=new JMenuItem("Unbind name");
59
60     popup.add(bindContext);
61     popup.add(bindObject);
62     popup.add(unbind);
63         
64     bindContext.addActionListener(this);
65     bindObject.addActionListener(this);
66     unbind.addActionListener(this);
67
68     updateInterval = 10;
69     updater = new Updater( tree, updateInterval);
70     updater.start();
71     }
72
73     public void actionPerformed(ActionEvent e)
74     {
75     if (e.getActionCommand().equals("Quit"))
76     {
77         System.exit(0);
78     }
79     else if (e.getActionCommand().equals("Unbind name"))
80     {
81         tree.unbind();
82     }
83     else if (e.getActionCommand().equals("Bind Object"))
84     {
85         ObjectDialog dialog = new ObjectDialog((Frame)frame);
86         //dialog.pack();
87
//dialog.show();
88

89         if (dialog.isOk)
90             {
91                 try
92                 {
93                     tree.bindObject( dialog.getName(), dialog.getIOR(), dialog.isRebind());
94                 }
95                 catch ( org.omg.CORBA.UserException JavaDoc ue )
96                 {
97                     JOptionPane.showMessageDialog( frame,
98                                                    ue.getClass().getName() +
99                                                   (ue.getMessage() != null ? (":" + ue.getMessage()):""),
100                                                   "Exception",
101                                                    JOptionPane.INFORMATION_MESSAGE);
102                 }
103             }
104     }
105     else if (e.getActionCommand().equals("BindNewContext"))
106     {
107         try
108         {
109                 String JavaDoc contextName =
110                     JOptionPane.showInputDialog(frame,
111                                                 "Name of the new context",
112                                                 "BindNewContext",
113                                                 JOptionPane.QUESTION_MESSAGE);
114
115                 // check if user input is okay or if CANCEL was hit
116
if (contextName != null && contextName.length() > 0)
117                     tree.bind(contextName);
118         }
119         catch ( org.omg.CORBA.UserException JavaDoc ue )
120         {
121         JOptionPane.showMessageDialog(frame,
122                                               ue.getClass().getName() +
123                           (ue.getMessage() != null ? (":" + ue.getMessage()):""),
124                           "Exception",
125                                               JOptionPane.INFORMATION_MESSAGE);
126         }
127     }
128     else if (e.getActionCommand().equals("About..."))
129     {
130         JOptionPane.showMessageDialog(frame,
131                       "JacORB NameManager 1.2\n(C) 1998-2004 Gerald Brose, Wei-ju Wu & Volker Siegel\nFreie Universitaet Berlin",
132                       "About",
133                                           JOptionPane.INFORMATION_MESSAGE);
134     }
135     else if (e.getActionCommand().equals("Options"))
136     {
137         NSPrefsDlg dlg = new NSPrefsDlg((Frame) frame, updateInterval);
138         dlg.pack();
139         dlg.show();
140         if (dlg.isOk)
141         updater.setSeconds(dlg.updateInterval);
142     }
143     else
144         throw new RuntimeException JavaDoc("Should not happen");
145     }
146
147     /**
148      * @param k java.awt.event.KeyEvent
149      */

150     
151     public void keyPressed(KeyEvent k) {}
152
153     /**
154      * @param k java.awt.event.KeyEvent
155      */

156
157     public void keyReleased(KeyEvent k)
158     {
159     if( k.getKeyCode() == KeyEvent.VK_DELETE )
160         tree.unbind();
161     }
162
163     public void keyTyped(KeyEvent k) {}
164     public void mouseClicked(MouseEvent e) {}
165     public void mouseEntered(MouseEvent e) {}
166     public void mouseExited(MouseEvent e) {}
167     public void mousePressed(MouseEvent e) {}
168
169     /**
170      * opens pop-up menu or displays context node content
171      */

172
173     public void mouseReleased(MouseEvent e)
174     {
175     // on Solaris, the right mouse button somehow seems not be a popup trigger, so we
176
// accept mouse 3 explicitly
177
if (e.isPopupTrigger() || e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK )
178     {
179         popup.pack();
180         popup.show(tree, e.getX(), e.getY());
181     }
182     else
183     {
184         TreePath path = tree.getPathForLocation(e.getX(), e.getY());
185         if (path != null)
186         {
187         DefaultMutableTreeNode node=(DefaultMutableTreeNode)path.getPathComponent(path.getPathCount()-1);
188         ((ContextNode)node.getUserObject()).display();
189         }
190     }
191     }
192
193     // WindowListener
194
public void windowClosing(WindowEvent e)
195     {
196     System.exit(0);
197     }
198 }
199
200
Popular Tags