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.componentBrowser; 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.omg.CORBA.*; 34 import org.coach.util.IorPrinter; 35 36 public class ComponentBrowser extends JFrame { 37 private TreePath selection; 38 private ComponentModel model; 39 private final org.omg.CORBA.ORB orb; 40 41 public ComponentBrowser(Component parent, org.omg.CORBA.ORB orb, String name, org.omg.CORBA.Object obj) { 42 this.orb = orb; 43 model = new ComponentModel(new ComponentNode(name, obj)); 44 ComponentNode.setOrb(orb); 45 46 JTree tree = new JTree(model); 47 JScrollPane scrollPane = new JScrollPane(tree); 48 49 getContentPane().add(scrollPane, BorderLayout.CENTER); 50 51 final ComponentControlPanel p = new ComponentControlPanel(model, orb); 52 getContentPane().add(p, BorderLayout.SOUTH); 53 54 tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 55 56 tree.addTreeExpansionListener(new TreeExpansionListener() { 57 public void treeCollapsed(TreeExpansionEvent e) { 58 } 59 60 public void treeExpanded(TreeExpansionEvent e) { 61 TreePath path = e.getPath(); 62 ComponentNode node = (ComponentNode)path.getLastPathComponent(); 63 64 node.explore(true); 65 model.nodeStructureChanged(node); 66 } 67 }); 68 tree.addTreeSelectionListener(new TreeSelectionListener() { 69 public void valueChanged(TreeSelectionEvent e) { 70 TreePath selection = e.getNewLeadSelectionPath(); 71 model.setSelection(selection); 72 p.iorTextArea.setText(""); 73 p.hostTextField.setText(" "); 74 p.portTextField.setText(" "); 75 p.typeTextField.setText(" "); 76 p.pingLabel.setText(" "); 77 if(selection != null) { 78 ComponentNode node = (ComponentNode)selection.getLastPathComponent(); 79 if (node.isLeaf()) { 80 String ior = node.getIor(); 81 p.iorTextArea.setText(ior); 82 p.iorTextArea.setCaretPosition(0); 83 84 IorPrinter iorPrinter = new IorPrinter(ior); 85 p.hostTextField.setText(iorPrinter.getHost()); 86 p.portTextField.setText(iorPrinter.getPort()); 87 p.typeTextField.setText(iorPrinter.getTypeId()); 88 p.hostTextField.setCaretPosition(0); 89 p.portTextField.setCaretPosition(0); 90 p.typeTextField.setCaretPosition(0); 91 p.repaint(); 92 } 93 } 94 } 95 }); 96 97 setTitle(name); 98 while(!(parent instanceof JFrame || parent instanceof Frame)) { 99 parent = parent.getParent(); 100 } 101 Point pp = parent.getLocationOnScreen(); 102 setLocation(pp.x + 10, pp.y + 10); 103 setVisible(true); 104 105 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 106 pack(); 107 } 108 } 109 | Popular Tags |