KickJava   Java API By Example, From Geeks To Geeks.

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


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