001: /*
002: * JdbDialog.java
003: *
004: * Copyright (C) 2000-2003 Peter Graves
005: * $Id: JdbDialog.java,v 1.2 2003/05/15 01:18:18 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j.jdb;
023:
024: import java.util.Iterator;
025: import java.util.List;
026: import javax.swing.Box;
027: import javax.swing.JCheckBox;
028: import javax.swing.JLabel;
029: import javax.swing.JPanel;
030: import javax.swing.JTextField;
031: import javax.swing.border.EmptyBorder;
032: import org.armedbear.j.AbstractDialog;
033: import org.armedbear.j.Editor;
034: import org.armedbear.j.File;
035: import org.armedbear.j.History;
036: import org.armedbear.j.HistoryTextField;
037: import org.armedbear.j.MessageDialog;
038: import org.armedbear.j.Utilities;
039:
040: public final class JdbDialog extends AbstractDialog {
041: // History.
042: private static final String mainClassKey = "jdb.mainClass";
043: private static final String mainClassArgsKey = "jdb.mainClassArgs";
044: private static final String classPathKey = "jdb.classPath";
045: private static final String sourcePathKey = "jdb.sourcePath";
046: private static final String javaHomeKey = "jdb.javaHome";
047: private static final String javaExecutableKey = "jdb.javaExecutable";
048: private static final String vmArgsKey = "jdb.vmArgs";
049:
050: private final Editor editor;
051: private final HistoryTextField classPathTextField;
052: private final HistoryTextField mainClassArgsTextField;
053: private final HistoryTextField mainClassTextField;
054: private final HistoryTextField sourcePathTextField;
055: private final HistoryTextField javaHomeTextField;
056: private final HistoryTextField javaExecutableTextField;
057: private final HistoryTextField vmArgsTextField;
058: private final History mainClassHistory;
059: private final History mainClassArgsHistory;
060: private final History classPathHistory;
061: private final History sourcePathHistory;
062: private final History javaHomeHistory;
063: private final History javaExecutableHistory;
064: private final History vmArgsHistory;
065: private final JCheckBox startSuspendedCheckBox;
066: private final JdbSession session;
067:
068: public JdbDialog(Editor editor) {
069: super (editor, "Jdb", true);
070: this .editor = editor;
071: JLabel label;
072: JPanel panel;
073: JPanel applicationPanel = Utilities.createPanel("Application");
074: mainClassTextField = new HistoryTextField(30);
075: mainClassHistory = new History(mainClassKey);
076: mainClassTextField.setHistory(mainClassHistory);
077: label = new JLabel("Main class:");
078: label.setDisplayedMnemonic('M');
079: addLabelAndTextField(applicationPanel, label,
080: mainClassTextField);
081: addVerticalStrut(applicationPanel);
082: mainClassArgsTextField = new HistoryTextField(30);
083: mainClassArgsHistory = new History(mainClassArgsKey);
084: mainClassArgsTextField.setHistory(mainClassArgsHistory);
085: label = new JLabel("Arguments for main class:");
086: label.setDisplayedMnemonic('A');
087: addLabelAndTextField(applicationPanel, label,
088: mainClassArgsTextField);
089: mainPanel.add(applicationPanel);
090: JPanel debuggeeVMPanel = Utilities.createPanel("Debuggee VM");
091: classPathTextField = new HistoryTextField(30);
092: classPathHistory = new History(classPathKey);
093: classPathTextField.setHistory(classPathHistory);
094: label = new JLabel("Class path:");
095: label.setDisplayedMnemonic('C');
096: addLabelAndTextField(debuggeeVMPanel, label, classPathTextField);
097: addVerticalStrut(debuggeeVMPanel);
098: javaHomeTextField = new HistoryTextField(30);
099: javaHomeHistory = new History(javaHomeKey);
100: javaHomeTextField.setHistory(javaHomeHistory);
101: label = new JLabel("Java home:");
102: label.setDisplayedMnemonic('J');
103: addLabelAndTextField(debuggeeVMPanel, label, javaHomeTextField);
104: addVerticalStrut(debuggeeVMPanel);
105: javaExecutableTextField = new HistoryTextField(30);
106: javaExecutableHistory = new History(javaExecutableKey);
107: javaExecutableTextField.setHistory(javaExecutableHistory);
108: label = new JLabel("Java executable:");
109: label.setDisplayedMnemonic('X');
110: addLabelAndTextField(debuggeeVMPanel, label,
111: javaExecutableTextField);
112: addVerticalStrut(debuggeeVMPanel);
113: vmArgsTextField = new HistoryTextField(30);
114: vmArgsHistory = new History(vmArgsKey);
115: vmArgsTextField.setHistory(vmArgsHistory);
116: label = new JLabel("Arguments for Java executable:");
117: label.setDisplayedMnemonic('R');
118: addLabelAndTextField(debuggeeVMPanel, label, vmArgsTextField);
119: debuggeeVMPanel.add(Box.createVerticalStrut(3));
120: startSuspendedCheckBox = new JCheckBox("Start suspended");
121: startSuspendedCheckBox.setMnemonic('U');
122: startSuspendedCheckBox.addKeyListener(this );
123: debuggeeVMPanel.add(startSuspendedCheckBox);
124: mainPanel.add(debuggeeVMPanel);
125: JPanel sourcePanel = Utilities.createPanel("Source");
126: sourcePathTextField = new HistoryTextField(30);
127: sourcePathHistory = new History(sourcePathKey);
128: sourcePathTextField.setHistory(sourcePathHistory);
129: label = new JLabel("Source path:");
130: label.setDisplayedMnemonic('S');
131: addLabelAndTextField(sourcePanel, label, sourcePathTextField);
132: mainPanel.add(sourcePanel);
133: addOKCancel();
134: Jdb jdb = Jdb.findJdb();
135: if (jdb != null) {
136: session = jdb.getSession();
137: } else {
138: session = new JdbSession();
139: // Load default session.
140: session.loadDefaults();
141: }
142: setDialogDefaults(session);
143: pack();
144: mainClassTextField.requestFocus();
145: }
146:
147: private void addLabelAndTextField(JPanel panel, JLabel label,
148: JTextField textField) {
149: label.setLabelFor(textField);
150: if (label.getBorder() == null)
151: label.setBorder(new EmptyBorder(0, 0, 3, 0));
152: panel.add(label);
153: panel.add(textField);
154: textField.addKeyListener(this );
155: }
156:
157: private void addVerticalStrut(JPanel panel) {
158: panel.add(Box.createVerticalStrut(6));
159: }
160:
161: private void setDialogDefaults(JdbSession session) {
162: mainClassTextField.setText(session.getMainClass());
163: mainClassArgsTextField.setText(session.getMainClassArgs());
164: String classPath = session.getClassPath();
165: if (classPath == null || classPath.length() < 1)
166: classPath = System.getProperty("class.path");
167: classPathTextField.setText(classPath);
168: String javaHome = session.getJavaHome();
169: if (javaHome == null || javaHome.length() == 0)
170: javaHome = System.getProperty("java.home");
171: javaHomeTextField.setText(javaHome);
172: String javaExecutable = session.getJavaExecutable();
173: if (javaExecutable == null || javaExecutable.length() == 0)
174: javaExecutable = "java";
175: javaExecutableTextField.setText(javaExecutable);
176: vmArgsTextField.setText(session.getVMArgs());
177: startSuspendedCheckBox.setSelected(session.getStartSuspended());
178: sourcePathTextField.setText(session.getSourcePath());
179: }
180:
181: public JdbSession getSession() {
182: return session;
183: }
184:
185: protected void ok() {
186: String mainClass = mainClassTextField.getText();
187: if (mainClass == null || mainClass.length() < 1) {
188: mainClassTextField.requestFocus();
189: MessageDialog.showMessageDialog("No main class specified",
190: "Error");
191: return;
192: }
193: mainClassHistory.append(mainClass);
194: mainClassHistory.save();
195: String mainClassArgs = mainClassArgsTextField.getText();
196: mainClassArgsHistory.append(mainClassArgs);
197: mainClassArgsHistory.save();
198: String classPath = classPathTextField.getText();
199: List list = Utilities.getDirectoriesInPath(classPath);
200: for (Iterator it = list.iterator(); it.hasNext();) {
201: String s = (String) it.next();
202: File file = File.getInstance(s);
203: if (file == null) {
204: classPathTextField.requestFocus();
205: MessageDialog.showMessageDialog(
206: "Invalid class path component \"" + s + '"',
207: "Error");
208: return;
209: }
210: // File might be directory or jar file.
211: if (!file.exists()) {
212: classPathTextField.requestFocus();
213: MessageDialog.showMessageDialog(
214: "Class path component \"" + s
215: + "\" does not exist", "Error");
216: return;
217: }
218: }
219: classPathHistory.append(classPath);
220: classPathHistory.save();
221: String javaHome = javaHomeTextField.getText();
222: javaHomeHistory.append(javaHome);
223: javaHomeHistory.save();
224: String javaExecutable = javaExecutableTextField.getText();
225: javaExecutableHistory.append(javaExecutable);
226: javaExecutableHistory.save();
227: String vmArgs = vmArgsTextField.getText();
228: vmArgsHistory.append(vmArgs);
229: vmArgsHistory.save();
230: String sourcePath = sourcePathTextField.getText();
231: list = Utilities.getDirectoriesInPath(sourcePath);
232: for (Iterator it = list.iterator(); it.hasNext();) {
233: String s = (String) it.next();
234: File file = File.getInstance(s);
235: if (file == null) {
236: sourcePathTextField.requestFocus();
237: MessageDialog.showMessageDialog(
238: "Invalid source path component \"" + s + '"',
239: "Error");
240: return;
241: }
242: if (!file.isDirectory()) {
243: sourcePathTextField.requestFocus();
244: MessageDialog.showMessageDialog(
245: "Source path component \"" + s
246: + "\" does not exist", "Error");
247: return;
248: }
249: }
250: sourcePathHistory.append(sourcePath);
251: sourcePathHistory.save();
252: session.setMainClass(mainClass);
253: session.setMainClassArgs(mainClassArgs);
254: session.setClassPath(classPath);
255: session.setJavaHome(javaHome);
256: session.setJavaExecutable(javaExecutable);
257: session.setVMArgs(vmArgs);
258: session.setStartSuspended(startSuspendedCheckBox.isSelected());
259: session.setSourcePath(sourcePath);
260: dispose();
261: }
262: }
|