KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.coach.actor.componentBrowser.*;
28 import java.awt.*;
29 import javax.swing.*;
30 import javax.swing.border.*;
31 import java.awt.event.*;
32 import javax.swing.tree.*;
33 import java.io.*;
34 import org.omg.Components.*;
35 import org.coach.util.IorPrinter;
36
37 public class ControlPanel extends JPanel {
38     BorderLayout borderLayout1 = new BorderLayout();
39     JScrollPane jScrollPane1 = new JScrollPane();
40     JTextArea iorTextArea = new JTextArea();
41     JPanel buttonPanel = new JPanel();
42     JButton deleteButton = new JButton();
43     JButton refreshButton = new JButton();
44     TitledBorder titledBorder1;
45     NameModel model;
46     JPanel iorPanel = new JPanel();
47     FlowLayout flowLayout1 = new FlowLayout();
48     JLabel typeLabel = new JLabel();
49     JTextField typeTextField = new JTextField();
50     JLabel hostLabel = new JLabel();
51     JTextField hostTextField = new JTextField();
52     JLabel portLabel = new JLabel();
53     JTextField portTextField = new JTextField();
54     JButton pingButton = new JButton();
55     JLabel pingLabel = new JLabel();
56     JButton tclButton = new JButton();
57     JButton showButton = new JButton();
58     org.omg.CORBA.ORB JavaDoc orb;
59         
60     public ControlPanel() {
61         try {
62             jbInit();
63         }
64         catch(Exception JavaDoc ex) {
65             ex.printStackTrace();
66         }
67     }
68
69     public ControlPanel(NameModel model, org.omg.CORBA.ORB JavaDoc orb) {
70         this.model = model;
71         this.orb = orb;
72         try {
73             jbInit();
74         }
75         catch(Exception JavaDoc ex) {
76             ex.printStackTrace();
77         }
78     }
79
80     private void jbInit() throws Exception JavaDoc {
81         titledBorder1 = new TitledBorder("");
82         this.setLayout(borderLayout1);
83         iorTextArea.setRows(3);
84         iorTextArea.setBackground(Color.lightGray);
85         iorTextArea.setBorder(titledBorder1);
86         deleteButton.setSelected(true);
87         deleteButton.setText("delete");
88         deleteButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
89
90             public void actionPerformed(ActionEvent e) {
91                 deleteButton_actionPerformed(e);
92             }
93         });
94         refreshButton.setText("refresh");
95         refreshButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
96
97             public void actionPerformed(ActionEvent e) {
98                 refreshButton_actionPerformed(e);
99             }
100         });
101         titledBorder1.setTitle("IOR");
102         jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
103         jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
104         iorPanel.setLayout(flowLayout1);
105         typeLabel.setText("Type Id");
106         hostLabel.setText("Host");
107         hostTextField.setText(" ");
108         typeTextField.setText(" ");
109         portLabel.setText("Port");
110         portTextField.setText(" ");
111         iorPanel.setBorder(BorderFactory.createEtchedBorder());
112
113         tclButton.setText("tcl shell");
114         tclButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
115             public void actionPerformed(ActionEvent e) {
116                 tclButton_actionPerformed(e);
117             }
118         });
119
120         pingButton.setText("ping");
121         pingButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
122
123             public void actionPerformed(ActionEvent e) {
124                 pingButton_actionPerformed(e);
125             }
126         });
127         pingLabel.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 12));
128         pingLabel.setText(" ");
129         showButton.setText("show");
130         showButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
131
132             public void actionPerformed(ActionEvent e) {
133                 showButton_actionPerformed(e);
134             }
135         });
136         this.add(jScrollPane1, BorderLayout.CENTER);
137         this.add(buttonPanel, BorderLayout.SOUTH);
138         buttonPanel.add(refreshButton, null);
139         buttonPanel.add(deleteButton, null);
140         buttonPanel.add(showButton, null);
141         buttonPanel.add(tclButton, null);
142         buttonPanel.add(pingButton, null);
143         buttonPanel.add(pingLabel, null);
144         this.add(iorPanel, BorderLayout.NORTH);
145         iorPanel.add(typeLabel, null);
146         iorPanel.add(typeTextField, null);
147         iorPanel.add(hostLabel, null);
148         iorPanel.add(hostTextField, null);
149         iorPanel.add(portLabel, null);
150         iorPanel.add(portTextField, null);
151         jScrollPane1.getViewport().add(iorTextArea, null);
152     }
153
154     void refreshButton_actionPerformed(ActionEvent e) {
155         model.refresh();
156     }
157
158     void deleteButton_actionPerformed(ActionEvent e) {
159         TreePath path = model.getSelection();
160         NameNode node = (NameNode)path.getLastPathComponent();
161         if (node.getParent() != null) {
162             node.removeBinding();
163             model.refresh();
164         }
165     }
166
167     void pingButton_actionPerformed(ActionEvent e) {
168         TreePath path = model.getSelection();
169         if (path != null) {
170             NameNode node = (NameNode)path.getLastPathComponent();
171             if (node.ping()) {
172                 pingLabel.setForeground(Color.green);
173                 pingLabel.setText("alive! ");
174             } else {
175                 pingLabel.setForeground(Color.red);
176                 pingLabel.setText("no reply!");
177             }
178         }
179     }
180
181     void tclButton_actionPerformed(ActionEvent e) {
182         TreePath path = model.getSelection();
183         if (path != null) {
184             NameNode node = (NameNode)path.getLastPathComponent();
185             if (!node.isContext()) {
186                 String JavaDoc ior = node.getIor();
187                 IorPrinter iorPrinter = new IorPrinter(ior);
188                 String JavaDoc id = iorPrinter.getTypeId();
189                 try {
190                     TclFrame mf = new TclFrame(this, id, node.toString(), node.getObject());
191                 } catch (Exception JavaDoc ex) {
192                     ex.printStackTrace();
193                     JOptionPane.showMessageDialog(null, ex.toString());
194                 }
195             }
196         }
197     }
198     
199     void showButton_actionPerformed(ActionEvent e) {
200         TreePath path = model.getSelection();
201         if (path != null) {
202             NameNode node = (NameNode)path.getLastPathComponent();
203             if (!node.isContext()) {
204
205                 CCMObject i_cmp = null;
206                 try {
207                     // test is this is an Component reference
208
// i_cmp = CCMObjectHelper.narrow(node.getObject());
209
} catch (Exception JavaDoc ex) {
210                 }
211                 if (i_cmp != null) {
212                     try {
213                         ComponentBrowser b = new ComponentBrowser(this, NameNode.getOrb(), node.toString(), i_cmp);
214                     } catch (Exception JavaDoc ex) {
215                         ex.printStackTrace();
216                         JOptionPane.showMessageDialog(null, ex.toString());
217                     }
218                 } else {
219                     String JavaDoc ior = node.getIor();
220                     IorPrinter iorPrinter = new IorPrinter(ior);
221                     String JavaDoc id = iorPrinter.getTypeId();
222                     try {
223                         MethodFrame mf = new MethodFrame(this, id, node.toString(), node.getObject(), orb);
224                     } catch (Exception JavaDoc ex) {
225                         ex.printStackTrace();
226                         JOptionPane.showMessageDialog(null, ex.toString());
227                     }
228                 }
229             }
230         }
231     }
232 }
233
Popular Tags