KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > debugger > applet > DebuggerApplet


1 /*-----------------------------------------------------------------------------
2  * Enhydra Java Application Server
3  * Copyright 1997-2000 Lutris Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  * must display the following acknowledgement:
16  * This product includes Enhydra software developed by Lutris
17  * Technologies, Inc. and its contributors.
18  * 4. Neither the name of Lutris Technologies nor the names of its contributors
19  * may be used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *-----------------------------------------------------------------------------
34  * $Id: DebuggerApplet.java,v 1.1 2004/04/06 15:24:32 rale Exp $
35  *-----------------------------------------------------------------------------
36  */

37
38
39
40
41
42 package com.lutris.appserver.debugger.applet;
43
44 import java.util.Vector JavaDoc;
45
46
47 import java.io.*;
48 import java.net.*;
49 import java.awt.*;
50 import java.awt.event.*;
51 import java.applet.AppletContext JavaDoc;
52 import javax.swing.*;
53 import javax.swing.event.*;
54 import javax.swing.border.*;
55 import javax.swing.table.*;
56 import com.lutris.appserver.debugger.applet.io.*;
57
58
59 public class DebuggerApplet extends JApplet
60              implements ActionListener, ListSelectionListener, MouseListener {
61
62
63     public void init() {
64         
65         System.out.println("INIT " + this);
66         
67         showStatus("Starting debugger, please wait...");
68         Globals.japplet = this;
69         setBackground(Color.lightGray);
70         Container contentPane = getContentPane();
71         contentPane.setLayout(new BorderLayout());
72         contentPane.add(createApplicationsPane(), BorderLayout.NORTH);
73         contentPane.add(createTransactionsPane(), BorderLayout.CENTER);
74         contentPane.add(createControlsPane(), BorderLayout.SOUTH);
75     }
76
77     public void start() {
78         super.start();
79         System.out.println("START " + this);
80         initializeUI();
81     }
82
83     public void stop() {
84         super.stop();
85         System.out.println("STOP " + this);
86         Updater.killThread();
87     }
88
89     public void destroy() {
90         super.destroy();
91         System.out.println("DESTROY " + this);
92     }
93
94
95     private JPanel createApplicationsPane() {
96         JPanel result = new JPanel();
97         result.setLayout(new BorderLayout());
98         result.setBorder(new TitledBorder("Enhydra Applications"));
99         Globals.servletModel = new ServletTableModel();
100         Globals.applicationTable = new JTable(Globals.servletModel);
101         Globals.applicationTable.addMouseListener(this);
102         Globals.applicationTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
103         Globals.applicationTable.setShowGrid(false);
104         Globals.applicationTable.setRowSelectionAllowed(false);
105         Globals.applicationTable.setCellSelectionEnabled(false);
106         TableColumnModel tcm = Globals.applicationTable.getColumnModel();
107         TableColumn tc = tcm.getColumn(0);
108         FontMetrics fm = Globals.applicationTable.getFontMetrics(Globals.applicationTable.getFont());
109         int width = fm.stringWidth("Debug");
110         //tc.setPreferredWidth(width + 10);
111
//????
112
Dimension d = Globals.applicationTable.getPreferredSize();
113 //
114
JScrollPane sp = new JScrollPane(Globals.applicationTable);
115         d.height = 60;
116         sp.setPreferredSize(d);
117         sp.setBackground(Globals.applicationTable.getBackground());
118         result.add(sp, BorderLayout.CENTER);
119         return result;
120     }
121
122     private JPanel createTransactionsPane() {
123         JPanel result = new JPanel();
124         result.setBorder(new TitledBorder("Transactions"));
125         result.setLayout(new BorderLayout());
126         Globals.transactionModel = new TransactionListModel();
127         Globals.transactionList = new JList(Globals.transactionModel);
128         Globals.transactionList.addListSelectionListener(this);
129         JScrollPane sp = new JScrollPane(Globals.transactionList);
130         sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
131         sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
132         result.add(sp, BorderLayout.CENTER);
133         return result;
134     }
135
136
137     private JPanel createControlsPane() {
138         JPanel result = new JPanel();
139         result.setBorder(new TitledBorder("Controls"));
140         result.setLayout(new BorderLayout());
141         Globals.serverButton = new JButton();
142         updateButtonLabel();
143         result.add(Globals.serverButton, BorderLayout.CENTER);
144         Globals.serverButton.addActionListener(this);
145         Globals.updateButton = new JButton("Update");
146         result.add(Globals.updateButton, BorderLayout.WEST);
147         Globals.updateButton.addActionListener(this);
148         return result;
149     }
150
151
152     private void updateButtonLabel() {
153         if (Updater.threadRunning())
154             Globals.serverButton.setText(Globals.activeTitle);
155         else
156             Globals.serverButton.setText(Globals.inactiveTitle);
157     }
158
159
160     private static void initializeUI() {
161         Updater.updateState(0);
162     }
163
164     //---------------------------------
165

166
167     public void actionPerformed(ActionEvent actionEvent) {
168         System.out.println("BUTTON HANDLER " + actionEvent);
169         Object JavaDoc source = actionEvent.getSource();
170         if (source == Globals.serverButton) {
171             System.out.println(" flipping");
172             if (Updater.threadRunning()) {
173                 Updater.killThread();
174                 Globals.serverButton.setText(Globals.inactiveTitle);
175                 Globals.updateButton.setEnabled(true);
176             } else {
177                 Updater.startThread();
178                 Globals.serverButton.setText(Globals.activeTitle);
179                 Globals.updateButton.setEnabled(false);
180             }
181 System.out.println("BUTTON HANDLER DONE");
182         } else if (source == Globals.updateButton) {
183             Updater.updateState(0);
184         }
185     }
186
187
188
189     //---------------------------------
190

191     public void valueChanged(ListSelectionEvent e) {
192         if ((e.getSource() != Globals.transactionList) ||
193              e.getValueIsAdjusting())
194             return;
195 System.out.println("LIST HANDLER " + e);
196         showSelectedTransaction();
197 System.out.println("LIST HANDLER DONE");
198     }
199
200     private static int currentTransId = -1;
201
202     private void showSelectedTransaction() {
203         int sel = Globals.transactionList.getSelectedIndex();
204 System.out.println("sel = " + sel);
205         if (sel < 0)
206             return;
207         try {
208             TransactionDescription t = (TransactionDescription) Globals.transactionList.getModel().getElementAt(sel);
209             if (t.id != currentTransId) {
210                 URL target = new URL(getDocumentBase(), "StatusFrame.po?id=" + t.id);
211                 AppletContext JavaDoc context = getAppletContext();
212                 context.showDocument(target, "StatusFrame");
213                 currentTransId = t.id;
214             }
215         } catch (Throwable JavaDoc t) {
216 System.err.println(t);
217         }
218     }
219
220     //---------------------------------
221

222     public void mouseClicked(MouseEvent e) {
223         if (e.getSource() != Globals.applicationTable)
224             return;
225         if (e.getClickCount() != 2)
226             return;
227 System.out.println("MOUSE HANDLER");
228         int sel = Globals.applicationTable.getSelectedRow();
229         if (sel >= 0)
230             Globals.servletModel.toggleRow(sel);
231 System.out.println("MOUSE HANDLER DONE");
232     }
233
234     public void mousePressed(MouseEvent e) {}
235     public void mouseReleased(MouseEvent e) {}
236     public void mouseEntered(MouseEvent e) {}
237     public void mouseExited(MouseEvent e) {}
238
239
240
241
242 }
243
Popular Tags