KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > coach > actor > componentBrowser > ComponentBrowser


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.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 JavaDoc;
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 JavaDoc orb;
40
41     public ComponentBrowser(Component parent, org.omg.CORBA.ORB JavaDoc orb, String JavaDoc name, org.omg.CORBA.Object JavaDoc 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 JavaDoc 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