KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > gui > GUI


1 /*
2  * @(#)GUI.java 1.13 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.gui;
36
37 import java.io.*;
38 import java.util.*;
39
40 import javax.swing.*;
41 import javax.swing.border.*;
42 import java.awt.*;
43 import java.awt.event.*;
44
45 import com.sun.jdi.*;
46 import com.sun.tools.example.debug.bdi.*;
47
48 public class GUI extends JPanel {
49
50     private CommandTool cmdTool;
51     private ApplicationTool appTool;
52     //###HACK##
53
//### There is currently dirty code in Environment that
54
//### accesses this directly.
55
//private SourceTool srcTool;
56
public static SourceTool srcTool;
57
58     private SourceTreeTool sourceTreeTool;
59     private ClassTreeTool classTreeTool;
60     private ThreadTreeTool threadTreeTool;
61     private StackTraceTool stackTool;
62     private MonitorTool monitorTool;
63
64     public static final String JavaDoc progname = "javadt";
65     public static final String JavaDoc version = "1.0Beta"; //### FIX ME.
66
public static final String JavaDoc windowBanner = "Java(tm) platform Debug Tool";
67
68     private Font fixedFont = new Font("monospaced", Font.PLAIN, 10);
69
70     private GUI(Environment env) {
71     setLayout(new BorderLayout());
72
73         setBorder(new EmptyBorder(5, 5, 5, 5));
74
75     add(new JDBToolBar(env), BorderLayout.NORTH);
76
77     srcTool = new SourceTool(env);
78     srcTool.setPreferredSize(new java.awt.Dimension JavaDoc(500, 300));
79     srcTool.setTextFont(fixedFont);
80
81     stackTool = new StackTraceTool(env);
82     stackTool.setPreferredSize(new java.awt.Dimension JavaDoc(500, 100));
83
84     monitorTool = new MonitorTool(env);
85     monitorTool.setPreferredSize(new java.awt.Dimension JavaDoc(500, 50));
86
87     JSplitPane right = new JSplitPane(JSplitPane.VERTICAL_SPLIT, srcTool,
88             new JSplitPane(JSplitPane.VERTICAL_SPLIT, stackTool, monitorTool));
89
90     sourceTreeTool = new SourceTreeTool(env);
91     sourceTreeTool.setPreferredSize(new java.awt.Dimension JavaDoc(200, 450));
92
93     classTreeTool = new ClassTreeTool(env);
94     classTreeTool.setPreferredSize(new java.awt.Dimension JavaDoc(200, 450));
95
96     threadTreeTool = new ThreadTreeTool(env);
97     threadTreeTool.setPreferredSize(new java.awt.Dimension JavaDoc(200, 450));
98
99     JTabbedPane treePane = new JTabbedPane(JTabbedPane.BOTTOM);
100     treePane.addTab("Source", null, sourceTreeTool);
101     treePane.addTab("Classes", null, classTreeTool);
102     treePane.addTab("Threads", null, threadTreeTool);
103
104     JSplitPane centerTop = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treePane, right);
105
106     cmdTool = new CommandTool(env);
107         cmdTool.setPreferredSize(new java.awt.Dimension JavaDoc(700, 150));
108
109     appTool = new ApplicationTool(env);
110         appTool.setPreferredSize(new java.awt.Dimension JavaDoc(700, 200));
111
112     JSplitPane centerBottom = new JSplitPane(JSplitPane.VERTICAL_SPLIT, cmdTool, appTool);
113     // centerBottom.setPreferredSize(new java.awt.Dimension(700, 350));
114

115     JSplitPane center = new JSplitPane(JSplitPane.VERTICAL_SPLIT, centerTop, centerBottom);
116
117     add(center, BorderLayout.CENTER);
118
119
120     }
121
122     private static void usage() {
123         String JavaDoc separator = File.pathSeparator;
124         System.out.println("Usage: " + progname + " <options> <class> <arguments>");
125         System.out.println();
126         System.out.println("where options include:");
127         System.out.println(" -help print out this message and exit");
128         System.out.println(" -sourcepath <directories separated by \"" +
129                            separator + "\">");
130         System.out.println(" list directories in which to look for source files");
131         System.out.println(" -remote <hostname>:<port-number>");
132         System.out.println(" host machine and port number of interpreter to attach to");
133         System.out.println(" -dbgtrace [flags] print info for debugging " + progname);
134         System.out.println();
135         System.out.println("options forwarded to debuggee process:");
136         System.out.println(" -v -verbose[:class|gc|jni]");
137         System.out.println(" turn on verbose mode");
138         System.out.println(" -D<name>=<value> set a system property");
139         System.out.println(" -classpath <directories separated by \"" +
140                            separator + "\">");
141         System.out.println(" list directories in which to look for classes");
142         System.out.println(" -X<option> non-standard debuggee VM option");
143         System.out.println();
144         System.out.println("<class> is the name of the class to begin debugging");
145         System.out.println("<arguments> are the arguments passed to the main() method of <class>");
146         System.out.println();
147         System.out.println("For command help type 'help' at " + progname + " prompt");
148     }
149
150     public static void main(String JavaDoc argv[]) {
151     String JavaDoc remote = null;
152     String JavaDoc clsName = "";
153     String JavaDoc progArgs = "";
154     String JavaDoc javaArgs = "";
155         boolean verbose = false; //### Not implemented.
156

157     final Environment env = new Environment();
158     
159     JPanel mainPanel = new GUI(env);
160
161     ContextManager context = env.getContextManager();
162     ExecutionManager runtime = env.getExecutionManager();
163
164     for (int i = 0; i < argv.length; i++) {
165         String JavaDoc token = argv[i];
166         if (token.equals("-dbgtrace")) {
167             if ((i == argv.length - 1) ||
168                 ! Character.isDigit(argv[i+1].charAt(0))) {
169         runtime.setTraceMode(VirtualMachine.TRACE_ALL);
170             } else {
171                 String JavaDoc flagStr = argv[++i];
172         runtime.setTraceMode(Integer.decode(flagStr).intValue());
173             }
174         } else if (token.equals("-X")) {
175                 System.out.println(
176                        "Use 'java -X' to see the available non-standard options");
177                 System.out.println();
178                 usage();
179                 System.exit(1);
180         } else if (
181                    // Standard VM options passed on
182
token.equals("-v") || token.startsWith("-v:") || // -v[:...]
183
token.startsWith("-verbose") || // -verbose[:...]
184
token.startsWith("-D") ||
185                    // NonStandard options passed on
186
token.startsWith("-X") ||
187                    // Old-style options
188
// (These should remain in place as long as the standard VM accepts them)
189
token.equals("-noasyncgc") || token.equals("-prof") ||
190            token.equals("-verify") || token.equals("-noverify") ||
191            token.equals("-verifyremote") ||
192            token.equals("-verbosegc") ||
193            token.startsWith("-ms") || token.startsWith("-mx") ||
194            token.startsWith("-ss") || token.startsWith("-oss") ) {
195         javaArgs += token + " ";
196         } else if (token.equals("-sourcepath")) {
197         if (i == (argv.length - 1)) {
198             System.out.println("No sourcepath specified.");
199             usage();
200             System.exit(1);
201         }
202         env.getSourceManager().setSourcePath(new SearchPath(argv[++i]));
203         } else if (token.equals("-classpath")) {
204         if (i == (argv.length - 1)) {
205             System.out.println("No classpath specified.");
206             usage();
207             System.exit(1);
208         }
209         env.getClassManager().setClassPath(new SearchPath(argv[++i]));
210         } else if (token.equals("-remote")) {
211         if (i == (argv.length - 1)) {
212             System.out.println("No remote specified.");
213             usage();
214             System.exit(1);
215         }
216         env.getContextManager().setRemotePort(argv[++i]);
217         } else if (token.equals("-help")) {
218         usage();
219         System.exit(0);
220         } else if (token.equals("-version")) {
221         System.out.println(progname + " version " + version);
222         System.exit(0);
223         } else if (token.startsWith("-")) {
224         System.out.println("invalid option: " + token);
225         usage();
226         System.exit(1);
227         } else {
228                 // Everything from here is part of the command line
229
clsName = token;
230                 for (i++; i < argv.length; i++) {
231                     progArgs += argv[i] + " ";
232                 }
233                 break;
234         }
235     }
236
237     context.setMainClassName(clsName);
238     context.setProgramArguments(progArgs);
239     context.setVmArguments(javaArgs);
240
241     // Force Cross Platform L&F
242
try {
243         UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
244         // If you want the System L&F instead, comment out the above line and
245
// uncomment the following:
246
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
247
} catch (Exception JavaDoc exc) {
248         System.err.println("Error loading L&F: " + exc);
249     }
250     
251         JFrame frame = new JFrame();
252     frame.setBackground(Color.lightGray);
253         frame.setTitle(windowBanner);
254     frame.setJMenuBar(new JDBMenuBar(env));
255     frame.setContentPane(mainPanel);
256
257     frame.addWindowListener(new WindowAdapter() {
258         public void windowClosing(WindowEvent e) {
259         env.terminate();
260         }
261     });
262
263     frame.pack();
264         frame.show();
265
266     }
267
268 }
269
Popular Tags