KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > actor > namingBrowser > NameTree


1 /***************************************************************************/
2 /* COACH: Component Based Open Source Architecture for */
3 /* Distributed Telecom Applications */
4 /* See: http://www.objectweb.org/ */
5 /* */
6 /* Copyright (C) 2003 Lucent Technologies Nederland BV */
7 /* Bell Labs Advanced Technologies - EMEA */
8 /* */
9 /* Initial developer(s): Harold Batteram */
10 /* */
11 /* This library is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public */
13 /* License as published by the Free Software Foundation; either */
14 /* version 2.1 of the License, or (at your option) any later version. */
15 /* */
16 /* This library is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
19 /* Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public */
22 /* License along with this library; if not, write to the Free Software */
23 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
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 JavaDoc;
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 JavaDoc orb;
44
45     public NameTree(org.omg.CORBA.ORB JavaDoc 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 JavaDoc 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