1 package jde.debugger.gui;
3 import java.awt.Component;
4 import java.awt.GridLayout;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.beans.PropertyVetoException;
8 import javax.swing.JDesktopPane;
9 import javax.swing.JFrame;
10 import javax.swing.JInternalFrame;
11 import javax.swing.JMenu;
12 import javax.swing.JMenuBar;
13 import javax.swing.JMenuItem;
14 import javax.swing.JPanel;
16 import jde.debugger.Debugger;
17 import jde.debugger.JDE;
18 import jde.debugger.Protocol;
22 * This is a first shot at trying to produce a GUI that displays debugging info from
23 * JDEbug. I recommend a redesign, either after studying this a bit more, or straight
24 * away, depending on the experience of the developer. The main things I am unhappy with
28 * <li>it feels unelegant to have the commands (GetLocals, etc) be
29 * aware of who is the recipient of their results. A better design
30 * would be to let the Debugger decide where to send certain events,
31 * command results, etc.</li>
33 * <li>this class itself is a hack - for instance, there's been very
34 * little thought on member variables are actually necessary, what
35 * JTree-related classes to use, and so on. I've been using it to
36 * learn more about JTree, but wasn't able to finish.</li>
38 * <li>there is (maybe was, now) a bug in the AWT threads, meaning
39 * that it hasn't been possible to shut them down in any other way
40 * than with a System.exit() command. The Quit command does that
41 * now, which is bad since it can hide other problems. Also, the
42 * whole shutdown sequence is a little messy, maybe due to an
43 * unclear division of labour between the SessionManager, Debugger
44 * and command classes.</li>
49 * Created: Thu Jan 31 13:13:39 2002
51 * @author <a href="mailto:petter.mahlen@chello.se">Petter Måhlén</a>
52 * @author <a href="mailto:udalrich@carolingia.org">Troy Daniels</a>
56 public class GUI implements Protocol {
57 private final JFrame m_frame;
58 private final JMenuBar m_menuBar;
59 private final JMenu m_menuWindow;
61 public GUI(final Debugger debugger) {
62 m_frame = new JFrame("JDEbug " + debugger.getProcID());
63 m_frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
64 JDesktopPane desktop = new JDesktopPane();
65 m_frame.setContentPane(desktop);
67 // Initialize the frame
68 m_menuBar = new JMenuBar();
69 m_frame.setJMenuBar(m_menuBar);
70 m_menuWindow = new JMenu("Window");
71 m_menuBar.add(m_menuWindow);
73 // Set up the GUI stuff
74 addComponent("Local Variables",
75 new LocalVariableDisplay(debugger));
76 addComponent("Threads", new ThreadDisplay(debugger));
79 // Finally, add the base panel to the content pane of the frame.
80 m_frame.setSize(350, 400);
83 JDE.debug(FRAMEWORK, "GUI constructor done");
86 private void addComponent(String title, Component comp) {
87 final JInternalFrame internalFrame =
88 new JInternalFrame(title,
95 JPanel basePanel = new JPanel();
96 basePanel.setLayout(new GridLayout(0, 1));
98 internalFrame.getContentPane().add(basePanel);
100 internalFrame.show();
101 m_frame.getContentPane().add(internalFrame);
102 int offset = 10 * m_frame.getContentPane().getComponentCount();
103 internalFrame.setLocation(offset, offset);
104 internalFrame.setSize(200, 300);
106 JMenuItem menuItem = new JMenuItem(title);
107 m_menuWindow.add(menuItem);
108 menuItem.addActionListener(new ActionListener() {
109 public void actionPerformed(ActionEvent evt) {
111 internalFrame.setIcon(false);
112 internalFrame.toFront();
113 } catch (PropertyVetoException exc) {
114 JDE.signalException(exc);
120 /** Shutdown the GUI */
121 public synchronized void shutdown() {
125 protected void finalize() throws Throwable {