Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / debugger / command / GUI.java
1 package jde.debugger.gui;
2
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;
15
16 import jde.debugger.Debugger;
17 import jde.debugger.JDE;
18 import jde.debugger.Protocol;
19
20
21 /**
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
25  * are:
26  * <ul>
27  *
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>
32  *
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>
37  *
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>
45  *
46  * </ul>
47  *
48  * <p>
49  * Created: Thu Jan 31 13:13:39 2002
50  *
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>
53  * @version
54  */
55
56 public class GUI implements Protocol {
57   private final JFrame   m_frame;
58   private final JMenuBar m_menuBar;
59   private final JMenu m_menuWindow;
60
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);
66
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);
72
73     // Set up the GUI stuff
74     addComponent("Local Variables",
75                  new LocalVariableDisplay(debugger));
76     addComponent("Threads", new ThreadDisplay(debugger));
77
78
79     // Finally, add the base panel to the content pane of the frame.
80     m_frame.setSize(350, 400);
81     m_frame.show();
82
83     JDE.debug(FRAMEWORK, "GUI constructor done");
84   }
85
86   private void addComponent(String title, Component comp) {
87     final JInternalFrame internalFrame =
88       new JInternalFrame(title,
89                          true, // resizable,
90                          false, // closable,
91                          true, //  maximizable,
92                          true // iconifiable
93                          );
94
95     JPanel basePanel = new JPanel();
96     basePanel.setLayout(new GridLayout(0, 1));
97     basePanel.add(comp);
98     internalFrame.getContentPane().add(basePanel);
99     internalFrame.pack();
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);
105
106     JMenuItem menuItem = new JMenuItem(title);
107     m_menuWindow.add(menuItem);
108     menuItem.addActionListener(new ActionListener() {
109         public void actionPerformed(ActionEvent evt) {
110           try {
111             internalFrame.setIcon(false);
112             internalFrame.toFront();
113           } catch (PropertyVetoException exc) {
114             JDE.signalException(exc);
115           }
116         }
117       });
118   }
119
120   /** Shutdown the GUI */
121   public synchronized void shutdown() {
122     if (null != m_frame)
123       m_frame.dispose();
124   }
125   protected void finalize() throws Throwable {
126     super.finalize();
127     shutdown();
128   }
129
130
131 }// GUI