1 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 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 89 if (dialog.isOk) 90 { 91 try 92 { 93 tree.bindObject( dialog.getName(), dialog.getIOR(), dialog.isRebind()); 94 } 95 catch ( org.omg.CORBA.UserException 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 contextName = 110 JOptionPane.showInputDialog(frame, 111 "Name of the new context", 112 "BindNewContext", 113 JOptionPane.QUESTION_MESSAGE); 114 115 if (contextName != null && contextName.length() > 0) 117 tree.bind(contextName); 118 } 119 catch ( org.omg.CORBA.UserException 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 ("Should not happen"); 145 } 146 147 150 151 public void keyPressed(KeyEvent k) {} 152 153 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 172 173 public void mouseReleased(MouseEvent e) 174 { 175 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 public void windowClosing(WindowEvent e) 195 { 196 System.exit(0); 197 } 198 } 199 200 | Popular Tags |