1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.actor.namingBrowser; 26 27 import javax.swing.*; 28 import javax.swing.event.*; 29 import javax.swing.tree.*; 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.util.EventObject ; 33 import org.coach.util.IorPrinter; 34 35 import org.omg.CosNaming.*; 36 import org.omg.CosNaming.NamingContextPackage.*; 37 import org.omg.CORBA.*; 38 39 public class NameTree extends JFrame { 40 private static NamingContext rootCtx; 41 private TreePath selection; 42 private NameModel model; 43 private final org.omg.CORBA.ORB orb; 44 45 public NameTree(org.omg.CORBA.ORB orb, NameModel m) { 46 this.orb = orb; 47 model = m; 48 49 JTree tree = new JTree(model); 50 JScrollPane scrollPane = new JScrollPane(tree); 51 52 getContentPane().add(scrollPane, BorderLayout.CENTER); 53 54 final ControlPanel p = new ControlPanel(model, orb); 55 getContentPane().add(p, BorderLayout.SOUTH); 56 57 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 58 59 tree.addTreeExpansionListener(new TreeExpansionListener(){ 60 public void treeCollapsed(TreeExpansionEvent e) { 61 } 62 63 public void treeExpanded(TreeExpansionEvent e) { 64 TreePath path = e.getPath(); 65 NameNode node = (NameNode)path.getLastPathComponent(); 66 node.explore(true); 67 model.nodeStructureChanged(node); 68 } 69 }); 70 71 tree.addTreeSelectionListener(new TreeSelectionListener() { 72 public void valueChanged(TreeSelectionEvent e) { 73 TreePath selection = e.getNewLeadSelectionPath(); 74 model.setSelection(selection); 75 p.iorTextArea.setText(""); 76 p.hostTextField.setText(" "); 77 p.portTextField.setText(" "); 78 p.typeTextField.setText(" "); 79 p.pingLabel.setText(" "); 80 if(selection != null) { 81 NameNode node = (NameNode)selection.getLastPathComponent(); 82 if (!node.isContext()) { 83 String ior = node.getIor(); 84 p.iorTextArea.setText(ior); 85 p.iorTextArea.setCaretPosition(0); 86 87 IorPrinter iorPrinter = new IorPrinter(ior); 88 p.hostTextField.setText(iorPrinter.getHost()); 89 p.portTextField.setText(iorPrinter.getPort()); 90 p.typeTextField.setText(iorPrinter.getTypeId()); 91 p.hostTextField.setCaretPosition(0); 92 p.portTextField.setCaretPosition(0); 93 p.typeTextField.setCaretPosition(0); 94 95 } 96 } 97 } 98 }); 99 100 addWindowListener(new WindowAdapter() { 101 public void windowClosed(WindowEvent e) { 102 System.exit(0); 103 } 104 }); 105 106 pack(); 107 setVisible(true); 108 } 109 } 110 | Popular Tags |