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.event.*;
024: import java.awt.*;
025: import javax.swing.tree.*;
026: import javax.swing.*;
027:
028: import org.jacorb.naming.Name;
029: import org.omg.CosNaming.*;
030:
031: /**
032: * This class handles the events on the tree
033: *
034: * @author Gerald Brose, FU Berlin
035: * @version $Id: Handler.java,v 1.10 2004/05/06 12:39:59 nicolas Exp $
036: */
037:
038: public class Handler extends WindowAdapter implements ActionListener,
039: MouseListener, KeyListener {
040: int updateInterval;
041: NSTree tree;
042: Component frame;
043: JDialog dlg;
044: JTextField editName;
045: JPopupMenu popup;
046: Updater updater;
047:
048: public Handler(Component fr, NSTree tr) {
049: frame = fr;
050: tree = tr;
051:
052: popup = new JPopupMenu();
053: JMenuItem bindContext = new JMenuItem("BindNewContext");
054: JMenuItem bindObject = new JMenuItem("Bind Object");
055: JMenuItem unbind = new JMenuItem("Unbind name");
056:
057: popup.add(bindContext);
058: popup.add(bindObject);
059: popup.add(unbind);
060:
061: bindContext.addActionListener(this );
062: bindObject.addActionListener(this );
063: unbind.addActionListener(this );
064:
065: updateInterval = 10;
066: updater = new Updater(tree, updateInterval);
067: updater.start();
068: }
069:
070: public void actionPerformed(ActionEvent e) {
071: if (e.getActionCommand().equals("Quit")) {
072: System.exit(0);
073: } else if (e.getActionCommand().equals("Unbind name")) {
074: tree.unbind();
075: } else if (e.getActionCommand().equals("Bind Object")) {
076: ObjectDialog dialog = new ObjectDialog((Frame) frame);
077: //dialog.pack();
078: //dialog.show();
079:
080: if (dialog.isOk) {
081: try {
082: tree.bindObject(dialog.getName(), dialog.getIOR(),
083: dialog.isRebind());
084: } catch (org.omg.CORBA.UserException ue) {
085: JOptionPane.showMessageDialog(frame, ue.getClass()
086: .getName()
087: + (ue.getMessage() != null ? (":" + ue
088: .getMessage()) : ""), "Exception",
089: JOptionPane.INFORMATION_MESSAGE);
090: }
091: }
092: } else if (e.getActionCommand().equals("BindNewContext")) {
093: try {
094: String contextName = JOptionPane.showInputDialog(frame,
095: "Name of the new context", "BindNewContext",
096: JOptionPane.QUESTION_MESSAGE);
097:
098: // check if user input is okay or if CANCEL was hit
099: if (contextName != null && contextName.length() > 0)
100: tree.bind(contextName);
101: } catch (org.omg.CORBA.UserException ue) {
102: JOptionPane.showMessageDialog(frame, ue.getClass()
103: .getName()
104: + (ue.getMessage() != null ? (":" + ue
105: .getMessage()) : ""), "Exception",
106: JOptionPane.INFORMATION_MESSAGE);
107: }
108: } else if (e.getActionCommand().equals("About...")) {
109: JOptionPane
110: .showMessageDialog(
111: frame,
112: "JacORB NameManager 1.2\n(C) 1998-2004 Gerald Brose, Wei-ju Wu & Volker Siegel\nFreie Universitaet Berlin",
113: "About", JOptionPane.INFORMATION_MESSAGE);
114: } else if (e.getActionCommand().equals("Options")) {
115: NSPrefsDlg dlg = new NSPrefsDlg((Frame) frame,
116: updateInterval);
117: dlg.pack();
118: dlg.show();
119: if (dlg.isOk)
120: updater.setSeconds(dlg.updateInterval);
121: } else
122: throw new RuntimeException("Should not happen");
123: }
124:
125: /**
126: * @param k java.awt.event.KeyEvent
127: */
128:
129: public void keyPressed(KeyEvent k) {
130: }
131:
132: /**
133: * @param k java.awt.event.KeyEvent
134: */
135:
136: public void keyReleased(KeyEvent k) {
137: if (k.getKeyCode() == KeyEvent.VK_DELETE)
138: tree.unbind();
139: }
140:
141: public void keyTyped(KeyEvent k) {
142: }
143:
144: public void mouseClicked(MouseEvent e) {
145: }
146:
147: public void mouseEntered(MouseEvent e) {
148: }
149:
150: public void mouseExited(MouseEvent e) {
151: }
152:
153: public void mousePressed(MouseEvent e) {
154: }
155:
156: /**
157: * opens pop-up menu or displays context node content
158: */
159:
160: public void mouseReleased(MouseEvent e) {
161: // on Solaris, the right mouse button somehow seems not be a popup trigger, so we
162: // accept mouse 3 explicitly
163: if (e.isPopupTrigger()
164: || e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK) {
165: popup.pack();
166: popup.show(tree, e.getX(), e.getY());
167: } else {
168: TreePath path = tree.getPathForLocation(e.getX(), e.getY());
169: if (path != null) {
170: DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
171: .getPathComponent(path.getPathCount() - 1);
172: ((ContextNode) node.getUserObject()).display();
173: }
174: }
175: }
176:
177: // WindowListener
178: public void windowClosing(WindowEvent e) {
179: System.exit(0);
180: }
181: }
|