KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > ui > config > ConfigFrame


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.ui.config;
35
36 import javax.swing.*;
37 import javax.swing.event.*;
38 import javax.swing.border.EmptyBorder JavaDoc;
39 import java.awt.event.*;
40 import java.awt.*;
41 import java.util.Enumeration JavaDoc;
42 import java.io.IOException JavaDoc;
43 import java.io.File JavaDoc;
44 import java.util.TreeSet JavaDoc;
45 import java.util.Iterator JavaDoc;
46
47 import javax.swing.tree.*;
48
49 import edu.rice.cs.drjava.DrJava;
50 import edu.rice.cs.drjava.CodeStatus;
51 import edu.rice.cs.drjava.config.FileOption;
52 import edu.rice.cs.drjava.config.*;
53 import edu.rice.cs.drjava.ui.*;
54 import edu.rice.cs.drjava.ui.KeyBindingManager.KeyStrokeData;
55 import edu.rice.cs.util.swing.DirectoryChooser;
56
57 /** The frame for setting Configuration options on the fly
58  * @version $Id: ConfigFrame.java 4070 2007-01-18 21:45:25Z dlsmith $
59  */

60 public class ConfigFrame extends JFrame {
61
62   private static final int FRAME_WIDTH = 750;
63   private static final int FRAME_HEIGHT = 500;
64
65   private final MainFrame _mainFrame;
66
67 // private JSplitPane _splitPane;
68
private final JTree _tree;
69   private final DefaultTreeModel _treeModel;
70   private final PanelTreeNode _rootNode;
71
72   private final JButton _okButton;
73   private final JButton _applyButton;
74   private final JButton _cancelButton;
75 // private final JButton _saveSettingsButton;
76
private final JPanel _mainPanel;
77   private final JFileChooser _fileOptionChooser;
78   private final JFileChooser _browserChooser;
79   private final DirectoryChooser _dirChooser;
80   
81   private OptionComponent.ChangeListener _changeListener = new OptionComponent.ChangeListener() {
82     public Object JavaDoc apply(Object JavaDoc oc) {
83       _applyButton.setEnabled(true);
84       return null;
85     }
86   };
87   
88   /** Sets up the frame and displays it. This a Swing view class! With the exception of initialization,
89    * this code should only be executed in the event-handling thread. */

90   public ConfigFrame(MainFrame frame) {
91     super("Preferences");
92
93     _mainFrame = frame;
94     
95     Action applyAction = new AbstractAction("Apply") {
96       public void actionPerformed(ActionEvent e) {
97         // Always save settings
98
try {
99 // _mainFrame.enableResetInteractions();
100
saveSettings();
101           _applyButton.setEnabled(false);
102           
103         }
104         catch (IOException JavaDoc ioe) {
105         }
106       }
107     };
108
109     _applyButton = new JButton(applyAction);
110     _applyButton.setEnabled(false);
111     
112     Action okAction = new AbstractAction("OK") {
113       public void actionPerformed(ActionEvent e) {
114         // Always apply and save settings
115
boolean successful = true;
116         try {
117 // _mainFrame.enableResetInteractions();
118
successful = saveSettings();
119         }
120         catch (IOException JavaDoc ioe) {
121           // oh well...
122
}
123         if (successful) _applyButton.setEnabled(false);
124         ConfigFrame.this.setVisible(false);
125       }
126     };
127     _okButton = new JButton(okAction);
128
129
130     Action cancelAction = new AbstractAction("Cancel") {
131       public void actionPerformed(ActionEvent e) {
132         cancel();
133       }
134     };
135     _cancelButton = new JButton(cancelAction);
136
137
138     File JavaDoc workDir = _getWorkDir();
139     _fileOptionChooser = new JFileChooser(workDir);
140
141     _browserChooser = new JFileChooser(workDir);
142     
143
144     _dirChooser = new DirectoryChooser(this);
145   
146     
147     /* Create tree and initialize tree. */
148     _rootNode = new PanelTreeNode("Preferences");
149     _treeModel = new DefaultTreeModel(_rootNode);
150     _tree = new JTree(_treeModel);
151     
152     _initTree();
153     
154     /* Create Panels. */
155     _createPanels();
156
157     _mainPanel= new JPanel();
158     _mainPanel.setLayout(new BorderLayout());
159     _tree.addTreeSelectionListener(new PanelTreeSelectionListener());
160
161     Container cp = getContentPane();
162     cp.setLayout(new BorderLayout());
163
164     // Select the first panel by default
165
if (_rootNode.getChildCount() != 0) {
166       PanelTreeNode firstChild = (PanelTreeNode)_rootNode.getChildAt(0);
167       TreeNode[] firstChildPath = firstChild.getPath();
168       TreePath path = new TreePath(firstChildPath);
169       _tree.expandPath(path);
170       _tree.setSelectionPath(path);
171     }
172
173     JScrollPane treeScroll = new JScrollPane(_tree);
174     JPanel treePanel = new JPanel();
175     treePanel.setLayout(new BorderLayout());
176     treeScroll.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Categories"));
177     treePanel.add(treeScroll, BorderLayout.CENTER);
178     cp.add(treePanel, BorderLayout.WEST);
179     cp.add(_mainPanel, BorderLayout.CENTER);
180
181     // Add buttons
182
JPanel bottom = new JPanel();
183     bottom.setBorder(new EmptyBorder JavaDoc(5,5,5,5));
184     bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS));
185     bottom.add(Box.createHorizontalGlue());
186     //bottom.add(_saveSettingsButton);
187
//bottom.add(Box.createHorizontalGlue());
188
bottom.add(_applyButton);
189     bottom.add(_okButton);
190     bottom.add(_cancelButton);
191     bottom.add(Box.createHorizontalGlue());
192
193     cp.add(bottom, BorderLayout.SOUTH);
194
195     // Set all dimensions ----
196
setSize(FRAME_WIDTH, FRAME_HEIGHT);
197
198     _mainFrame.setPopupLoc(this);
199
200     addWindowListener(new WindowAdapter() {
201       public void windowClosing(java.awt.event.WindowEvent JavaDoc e) { cancel(); }
202     });
203
204     // Make sure each row is expanded (this is harder than it seems...)
205
_tree.expandRow(0);
206     _tree.expandRow(1);
207     _tree.expandRow(2);
208   }
209   
210   /** Performs deferred initialization. Only runs in the event thread. Some of this code occasionally generated swing
211    * exceptions when run in themain thread as part of MainFrame construction prior to making MainFrame visible. */

212   public void setUp() {
213     assert EventQueue.isDispatchThread();
214     /* Set up _fileOptionChooser, _browserChooser, and _dirChooser. The line _dirChooser.setSelectedFile(...) caused
215      * java.lang.ArrayIndexOutOfBoundsException within swing code in a JUnit test setUp() routine that constructed a
216      * a MainFrame.
217      */

218
219     _fileOptionChooser.setDialogTitle("Select");
220     _fileOptionChooser.setApproveButtonText("Select");
221     _fileOptionChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
222     _fileOptionChooser.setFileFilter(ClassPathFilter.ONLY);
223     
224     _browserChooser.setDialogTitle("Select Web Browser");
225     _browserChooser.setApproveButtonText("Select");
226     _browserChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
227     
228     _dirChooser.setSelectedFile(_getWorkDir());
229     _dirChooser.setDialogTitle("Select");
230     _dirChooser.setApproveButtonText("Select");
231     _dirChooser.setMultiSelectionEnabled(false);
232
233     
234   }
235
236   /** Returns the current master working directory, or the user's current directory if none is set. 20040213 Changed default
237    * value to user's current directory.
238    */

239   private File JavaDoc _getWorkDir() {
240     File JavaDoc workDir = _mainFrame.getModel().getMasterWorkingDirectory(); // cannot be null
241
if (workDir.isDirectory()) return workDir;
242     
243     if (workDir.getParent() != null) workDir = workDir.getParentFile();
244     return workDir;
245   }
246
247   /** Call the update method to propagate down the tree, parsing input values into their config options. */
248   public boolean apply() {
249     // returns false if the update did not succeed
250
return _rootNode.update();
251   }
252
253   /** Resets the field of each option in the Preferences window to its actual stored value. */
254   public void resetToCurrent() {
255     _rootNode.resetToCurrent();
256   }
257
258   /** Resets the frame and hides it. */
259   public void cancel() {
260     resetToCurrent();
261     _applyButton.setEnabled(false);
262     ConfigFrame.this.setVisible(false);
263   }
264
265   /** Write the configured option values to disk. */
266   public boolean saveSettings() throws IOException JavaDoc {
267     boolean successful = apply();
268     if (successful) {
269       try {
270         DrJava.getConfig().saveConfiguration();
271       }
272       catch (IOException JavaDoc ioe) {
273         JOptionPane.showMessageDialog(this,"Could not save changes to your '.drjava' file in your home directory. \n\n" + ioe,
274                                       "Could Not Save Changes",
275                                       JOptionPane.ERROR_MESSAGE);
276         //return false;
277
throw ioe;
278       }
279     }
280     return successful;
281   }
282
283   /** Sets the given ConfigPanel as the visible panel. */
284   private void _displayPanel(ConfigPanel cf) {
285
286     _mainPanel.removeAll();
287     _mainPanel.add(cf, BorderLayout.CENTER);
288     _mainPanel.revalidate();
289     _mainPanel.repaint();
290   }
291
292   /** Creates the JTree to display preferences categories. */
293   private void _initTree() {
294     _tree.setEditable(false);
295     _tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
296     _tree.setShowsRootHandles(true);
297     _tree.setRootVisible(false);
298
299     DefaultTreeCellRenderer dtcr = new DefaultTreeCellRenderer();
300     dtcr.setLeafIcon(null);
301     dtcr.setOpenIcon(null);
302     dtcr.setClosedIcon(null);
303     _tree.setCellRenderer(dtcr);
304   }
305
306   /**Creates an individual panel, adds it to the JTree and the list of panels, and returns the tree node.
307    * @param t the title of this panel
308    * @param parent the parent tree node
309    * @return this tree node
310    */

311   private PanelTreeNode _createPanel(String JavaDoc t, PanelTreeNode parent) {
312     PanelTreeNode ptNode = new PanelTreeNode(t);
313     //parent.add(ptNode);
314
_treeModel.insertNodeInto(ptNode, parent, parent.getChildCount());
315
316     // Make sure tree node is visible
317
TreeNode[] pathArray = ptNode.getPath();
318     TreePath path = new TreePath(pathArray);
319 // System.out.println("path has class " + pathArray.getClass());
320
// System.out.println("last path compenent has class " + path.getLastPathComponent().getClass());
321
_tree.expandPath(path);
322
323     return ptNode;
324   }
325
326   /** Creates an individual panel, adds it to the JTree and the list of panels, and returns the tree node. Adds to the root node.
327    * @param t the title of this panel
328    * @return this tree node
329    */

330   private PanelTreeNode _createPanel(String JavaDoc t) { return _createPanel(t, _rootNode); }
331
332   /** Creates all of the panels contained within the frame. */
333   private void _createPanels() {
334
335     PanelTreeNode resourceLocNode = _createPanel("Resource Locations");
336     _setupResourceLocPanel(resourceLocNode.getPanel());
337
338     PanelTreeNode displayNode = _createPanel("Display Options");
339     _setupDisplayPanel(displayNode.getPanel());
340     
341     PanelTreeNode fontNode = _createPanel("Fonts", displayNode);
342     _setupFontPanel(fontNode.getPanel());
343
344     PanelTreeNode colorNode = _createPanel("Colors", displayNode);
345     _setupColorPanel(colorNode.getPanel());
346
347     PanelTreeNode keystrokesNode = _createPanel("Key Bindings");
348     _setupKeyBindingsPanel(keystrokesNode.getPanel());
349     
350     PanelTreeNode compilerOptionsNode = _createPanel("Compiler Options");
351     _setupCompilerPanel(compilerOptionsNode.getPanel());
352     
353     PanelTreeNode debugNode = _createPanel("Debugger");
354     _setupDebugPanel(debugNode.getPanel());
355
356     PanelTreeNode javadocNode = _createPanel("Javadoc");
357     _setupJavadocPanel(javadocNode.getPanel());
358
359     PanelTreeNode notificationsNode = _createPanel("Notifications");
360     _setupNotificationsPanel(notificationsNode.getPanel());
361     
362     PanelTreeNode miscNode = _createPanel("Miscellaneous");
363     _setupMiscPanel(miscNode.getPanel());
364     
365     // Expand the display options node
366
//DrJava.consoleOut().println("expanding path...");
367
//_tree.expandPath(new TreePath(fontNode.getPath()));
368
}
369
370   public <X> void addOptionComponent(ConfigPanel panel, OptionComponent<X> oc) {
371     panel.addComponent(oc);
372     oc.addChangeListener(_changeListener);
373   }
374   
375   /** Add all of the components for the Resource Locations panel of the preferences window. */
376   private void _setupResourceLocPanel(ConfigPanel panel) {
377     FileOptionComponent browserLoc =
378       new FileOptionComponent(OptionConstants.BROWSER_FILE, "Web Browser", this,
379                               "<html>Location of a web browser to use for Javadoc and Help links.<br>" +
380                               "If left blank, only the Web Browser Command will be used.<br>" +
381                               "This is not necessary if a default browser is available on your system.",
382                               _browserChooser);
383     addOptionComponent(panel, browserLoc);
384
385     StringOptionComponent browserCommand =
386       new StringOptionComponent(OptionConstants.BROWSER_STRING, "Web Browser Command", this,
387                               "<html>Command to send to the web browser to view a web location.<br>" +
388                               "The string <code>&lt;URL&gt;</code> will be replaced with the URL address.<br>" +
389                               "This is not necessary if a default browser is available on your system.");
390     addOptionComponent(panel, browserCommand);
391
392     FileOptionComponent javacLoc =
393       new FileOptionComponent(OptionConstants.JAVAC_LOCATION, "Tools.jar Location", this,
394                               "Optional location of the JDK's tools.jar, which contains the compiler and debugger.",
395                               _fileOptionChooser);
396     javacLoc.setFileFilter(ClassPathFilter.ONLY);
397     addOptionComponent(panel, javacLoc);
398    
399     addOptionComponent(panel, new VectorFileOptionComponent(OptionConstants.EXTRA_CLASSPATH,
400                                                      "Extra Classpath", this,
401                                                      "<html>Any directories or jar files to add to the classpath<br>"+
402                                                      "of the Compiler and Interactions Pane.</html>"));
403     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.STICKY_INTERACTIONS_DIRECTORY,
404                                                          "Restore last working directory of the Interactions pane on start up", this,
405                                                          "<html>Whether to restore the last working directory of the Interaction pane on start up,<br>"+
406                                                          "or to always use the value of the \"user.home\" Java property<br>"+
407                                                          "(currently "+System.getProperty("user.home")+")."));
408
409     panel.displayComponents();
410   }
411
412   /** Add all of the components for the Display Options panel of the preferences window. */
413   private void _setupDisplayPanel(ConfigPanel panel) {
414
415     addOptionComponent(panel, new ForcedChoiceOptionComponent(OptionConstants.LOOK_AND_FEEL, "Look and Feel", this,
416                                                               "Changes the general appearance of DrJava."));
417
418     //ToolbarOptionComponent is a degenerate option component
419
addOptionComponent(panel, new ToolbarOptionComponent("Toolbar Buttons", this,
420                                                   "How to display the toolbar buttons."));
421     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.LINEENUM_ENABLED,
422                                                   "Show All Line Numbers", this,
423                                                   "Whether to show line numbers on the left side of the Definitions Pane."));
424     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.WINDOW_STORE_POSITION,
425                                                   "Save Main Window Position", this,
426                                                   "Whether to save and restore the size and position of the main window."));
427     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_CLIPBOARD_HISTORY_STORE_POSITION,
428                                                   "Save \"Clipboard History\" Dialog Position", this,
429                                                   "Whether to save and restore the size and position of the \"Clipboard History\" dialog."));
430     addOptionComponent(panel, new ButtonComponent(new ActionListener() {
431       public void actionPerformed(ActionEvent e) { _mainFrame.resetClipboardHistoryDialogPosition(); }
432     }, "Reset \"Clipboard History\" Dialog Position and Size", this, "This resets the dialog position and size to its default values."));
433     addOptionComponent(panel, new IntegerOptionComponent(OptionConstants.CLIPBOARD_HISTORY_SIZE,
434                                                   "Size of Clipboard History", this,
435                                                   "Determines how many entries are kept in the clipboard history."));
436     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_GOTOFILE_STORE_POSITION,
437                                                   "Save \"Go to File\" Dialog Position", this,
438                                                   "Whether to save and restore the size and position of the \"Go to File\" dialog."));
439     addOptionComponent(panel, new ButtonComponent(new ActionListener() {
440       public void actionPerformed(ActionEvent e) { _mainFrame.resetGotoFileDialogPosition(); }
441     }, "Reset \"Go to File\" Dialog Position and Size", this, "This resets the dialog position and size to its default values."));
442     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_GOTOFILE_FULLY_QUALIFIED,
443                                                   "Display Fully-Qualified Class Names in \"Go to File\" Dialog", this,
444                                                   "Whether to also display fully-qualified class names in the \"Go to File\" dialog.\n"+
445                                                          "Enabling this option on network drives might cause the dialog to display after a slight delay."));
446     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_COMPLETE_WORD_STORE_POSITION,
447                                                   "Save \"Auto-Complete Word\" Dialog Position", this,
448                                                   "Whether to save and restore the size and position of the \"Auto-Complete Word\" dialog."));
449     addOptionComponent(panel, new ButtonComponent(new ActionListener() {
450       public void actionPerformed(ActionEvent e) { _mainFrame.resetCompleteWordDialogPosition(); }
451     }, "Reset \"Auto-Complete Word\" Dialog Position and Size", this, "This resets the dialog position and size to its default values."));
452     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_COMPLETE_SCAN_CLASS_FILES,
453                                                   "Scan Class Files For Auto-Completion After Each Compile", this,
454                                                   "Whether to scan the class files after a compile to generate auto-completion class names.\n"+
455                                                          "Enabling this option will slow compiles down."));
456     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_JAROPTIONS_STORE_POSITION,
457                                                   "Save \"Create Jar File from Project\" Dialog Position", this,
458                                                   "Whether to save and restore the position of the \"Create Jar File from Project\" dialog."));
459     addOptionComponent(panel, new ButtonComponent(new ActionListener() {
460       public void actionPerformed(ActionEvent e) {
461         _mainFrame.resetJarOptionsDialogPosition();
462       }
463     }, "Reset \"Create Jar File from Project\" Dialog Position", this, "This resets the dialog position to its default values."));
464     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_OPENJAVADOC_STORE_POSITION,
465                                                   "Save \"Open Javadoc\" Dialog Position", this,
466                                                   "Whether to save and restore the size and position of the \"Open Javadoc\" dialog."));
467     addOptionComponent(panel, new ButtonComponent(new ActionListener() {
468       public void actionPerformed(ActionEvent e) { _mainFrame.resetOpenJavadocDialogPosition(); }
469     }, "Reset \"Open Javadoc\" Dialog Position and Size", this, "This resets the dialog position and size to its default values."));
470     panel.displayComponents();
471   }
472
473   /** Add all of the components for the Font panel of the preferences window. */
474   private void _setupFontPanel(ConfigPanel panel) {
475     addOptionComponent(panel, new FontOptionComponent(OptionConstants.FONT_MAIN, "Main Font", this,
476                                                "The font used for most text in DrJava."));
477     addOptionComponent(panel, new FontOptionComponent(OptionConstants.FONT_LINE_NUMBERS, "Line Numbers Font", this,
478                                                "<html>The font for displaying line numbers on the left side of<br>" +
479                                                "the Definitions Pane if Show All Line Numbers is enabled.<br>" +
480                                                "Cannot be displayed larger than the Main Font.</html>"));
481     addOptionComponent(panel, new FontOptionComponent(OptionConstants.FONT_DOCLIST, "Document List Font", this,
482                                                "The font used in the list of open documents."));
483     addOptionComponent(panel, new FontOptionComponent(OptionConstants.FONT_TOOLBAR, "Toolbar Font", this,
484                                                "The font used in the toolbar buttons."));
485     if (CodeStatus.DEVELOPMENT) {
486       addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.TEXT_ANTIALIAS, "Use anti-aliased text", this,
487                                                     "Whether to graphically smooth the text."));
488     }
489     panel.displayComponents();
490   }
491
492   /**
493    * Adds all of the components for the Color panel of the preferences window.
494    */

495   private void _setupColorPanel(ConfigPanel panel) {
496     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_NORMAL_COLOR, "Normal Color", this,
497                                                 "The default color for text in the Definitions Pane."));
498     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_KEYWORD_COLOR, "Keyword Color", this,
499                                                 "The color for Java keywords in the Definitions Pane."));
500     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_TYPE_COLOR, "Type Color", this,
501                                                 "The color for classes and types in the Definitions Pane."));
502     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_COMMENT_COLOR, "Comment Color", this,
503                                                 "The color for comments in the Definitions Pane."));
504     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_DOUBLE_QUOTED_COLOR, "Double-quoted Color", this,
505                                                 "The color for quoted strings (eg. \"...\") in the Definitions Pane."));
506     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_SINGLE_QUOTED_COLOR, "Single-quoted Color", this,
507                                                 "The color for quoted characters (eg. 'a') in the Definitions Pane."));
508     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_NUMBER_COLOR, "Number Color", this,
509                                                 "The color for numbers in the Definitions Pane."));
510     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_BACKGROUND_COLOR, "Background Color", this,
511                                                 "The background color of the Definitions Pane.", true));
512     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEFINITIONS_MATCH_COLOR, "Brace-matching Color", this,
513                                                 "The color for matching brace highlights in the Definitions Pane.", true));
514     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.COMPILER_ERROR_COLOR, "Compiler Error Color", this,
515                                                 "The color for compiler error highlights in the Definitions Pane.", true));
516     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.BOOKMARK_COLOR, "Bookmark Color", this,
517                                                 "The color for bookmarks in the Definitions Pane.", true));
518     for (int i=0; i<OptionConstants.FIND_RESULTS_COLORS.length; ++i) {
519       addOptionComponent(panel, new ColorOptionComponent(OptionConstants.FIND_RESULTS_COLORS[i], "Find Results Color "+(i+1), this,
520                                                          "A color for highlighting find results in the Definitions Pane.", true));
521     }
522     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEBUG_BREAKPOINT_COLOR, "Debugger Breakpoint Color", this,
523                                                 "The color for breakpoints in the Definitions Pane.", true));
524     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEBUG_BREAKPOINT_DISABLED_COLOR, "Disabled Debugger Breakpoint Color", this,
525                                                 "The color for disabled breakpoints in the Definitions Pane.", true));
526     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEBUG_THREAD_COLOR, "Debugger Location Color", this,
527                                                 "The color for the location of the current suspended thread in the Definitions Pane.", true));
528     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.SYSTEM_OUT_COLOR, "System.out Color", this,
529                                                 "The color for System.out in the Interactions and Console Panes."));
530     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.SYSTEM_ERR_COLOR, "System.err Color", this,
531                                                 "The color for System.err in the Interactions and Console Panes."));
532     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.SYSTEM_IN_COLOR, "System.in Color", this,
533                                                 "The color for System.in in the Interactions Pane."));
534     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.INTERACTIONS_ERROR_COLOR, "Interactions Error Color", this,
535                                                 "The color for interactions errors in the Interactions Pane.", false, true));
536     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DEBUG_MESSAGE_COLOR, "Debug Message Color", this,
537                                                 "The color for debugger messages in the Interactions Pane.", false, true));
538     addOptionComponent(panel, new ColorOptionComponent(OptionConstants.DRJAVA_ERRORS_BUTTON_COLOR, "DrJava Errors Button Background Color", this,
539                                                 "The background color of the \"Errors\" button used to show internal DrJava errors.", true));
540
541     panel.displayComponents();
542   }
543
544   /**
545    * Adds all of the components for the Key Bindings panel of the preferences window.
546    */

547   private void _setupKeyBindingsPanel(ConfigPanel panel) {
548     // using a treeset because it automatically sorts element upon insertion
549
TreeSet JavaDoc<KeyStrokeOptionComponent> _comps = new TreeSet JavaDoc<KeyStrokeOptionComponent>();
550
551     KeyStrokeData tmpKsd;
552     KeyStrokeOptionComponent tmpKsoc;
553
554     Enumeration JavaDoc e = KeyBindingManager.Singleton.getKeyStrokeData();
555     while (e.hasMoreElements()) {
556       tmpKsd = (KeyStrokeData) e.nextElement();
557       if (tmpKsd.getOption() != null) {
558         // Get the tooltip, or default to its name, if none
559
// KeyStroke ks = tmpKsd.getKeyStroke();
560
// Action a = KeyBindingManager.Singleton.get(ks);
561
Action a = tmpKsd.getAction();
562         String JavaDoc desc = (String JavaDoc) a.getValue(Action.SHORT_DESCRIPTION);
563         if ((desc == null) || (desc.equals(""))) {
564           desc = tmpKsd.getName();
565         }
566
567         tmpKsoc = new KeyStrokeOptionComponent((KeyStrokeOption)tmpKsd.getOption(),
568                                                tmpKsd.getName(), this, desc);
569         if (tmpKsoc != null) {
570           _comps.add(tmpKsoc);
571         }
572       }
573     }
574
575     Iterator JavaDoc<KeyStrokeOptionComponent> iter = _comps.iterator();
576     while (iter.hasNext()) {
577       KeyStrokeOptionComponent x = iter.next();
578       addOptionComponent(panel, x);
579     }
580     panel.displayComponents();
581   }
582
583   /**
584    * Add all of the components for the Debugger panel of the preferences window.
585    */

586   private void _setupDebugPanel(ConfigPanel panel) {
587     if (!_mainFrame.getModel().getDebugger().isAvailable()) {
588       // Explain how to use debugger
589
String JavaDoc howto =
590         "\nThe debugger is not currently active. To use the debugger, you\n" +
591         "must include Sun's tools.jar or jpda.jar on your classpath when\n" +
592         "starting DrJava. Do not use the \"-jar\" option, because it\n" +
593         "overrides the classpath and will not include tools.jar.\n" +
594         "For example, in Windows you might type:\n\n" +
595         " java -classpath drjava.jar;c:\\path\\tools.jar edu.rice.cs.drjava.DrJava\n\n" +
596         "(Substituting the correct path for tools.jar.)\n" +
597         "See the user documentation for more details.\n";
598         addOptionComponent(panel, new LabelComponent(howto, this));
599     }
600
601     VectorFileOptionComponent sourcePath =
602       new VectorFileOptionComponent(OptionConstants.DEBUG_SOURCEPATH, "Sourcepath", this,
603                                     "<html>Any directories in which to search for source<br>" +
604                                     "files when stepping in the Debugger.</html>");
605     // Source path can only include directories
606
sourcePath.setFileFilter(new DirectoryFilter("Source Directories"));
607     addOptionComponent(panel, sourcePath);
608     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DEBUG_STEP_JAVA,
609                                                   "Step Into Java Classes", this,
610                                                   "<html>Whether the Debugger should step into Java library classes,<br>" +
611                                                   "including java.*, javax.*, sun.*, com.sun.*, com.apple.eawt.*, and com.apple.eio.*</html>"));
612     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DEBUG_STEP_INTERPRETER,
613                                                   "Step Into Interpreter Classes", this,
614                                                   "<html>Whether the Debugger should step into the classes<br>" +
615                                                   "used by the Interactions Pane (DynamicJava).</html>"));
616     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DEBUG_STEP_DRJAVA,
617                                                   "Step Into DrJava Classes", this,
618                                                   "Whether the Debugger should step into DrJava's own class files."));
619     addOptionComponent(panel, new StringOptionComponent(OptionConstants.DEBUG_STEP_EXCLUDE,
620                                                  "Classes/Packages To Exclude", this,
621                                                  "<html>Any classes that the debuggger should not step into.<br>" +
622                                                  "Should be a COMMA-separated list of fully-qualified class names.<br>" +
623                                                  "To exclude a package, specify <code>packagename.*</code> in the list.</html>"));
624
625     panel.displayComponents();
626   }
627
628   /** Add all of the components for the Javadoc panel of the preferences window. */
629   private void _setupJavadocPanel(ConfigPanel panel) {
630     addOptionComponent(panel,
631                        new ForcedChoiceOptionComponent(OptionConstants.JAVADOC_ACCESS_LEVEL,
632                                                        "Access Level", this,
633                                                        "<html>Fields and methods with access modifiers at this level<br>" +
634                                                        "or higher will be included in the generated Javadoc.</html>"));
635     addOptionComponent(panel,
636                        new ForcedChoiceOptionComponent(OptionConstants.JAVADOC_LINK_VERSION,
637                                                        "Java Version for Javadoc Links", this,
638                                                        "The version of Java for generating links to online Javadoc documentation."));
639     addOptionComponent(panel,
640                        new StringOptionComponent(OptionConstants.JAVADOC_1_3_LINK,
641                                                  "Javadoc 1.3 URL", this,
642                                                  "The URL to the Java 1.3 API, for generating links to library classes."));
643     addOptionComponent(panel,
644                        new StringOptionComponent(OptionConstants.JAVADOC_1_4_LINK,
645                                                  "Javadoc 1.4 URL", this,
646                                                  "The URL to the Java 1.4 API, for generating links to library classes."));
647     addOptionComponent(panel,
648                        new StringOptionComponent(OptionConstants.JAVADOC_1_5_LINK,
649                                                  "Javadoc 1.5 URL", this,
650                                                  "The URL to the Java 1.5 API, for generating links to library classes."));
651     
652     addOptionComponent(panel,
653                        new DirectoryOptionComponent(OptionConstants.JAVADOC_DESTINATION,
654                                                     "Default Destination Directory", this,
655                                                     "Optional default directory for saving Javadoc documentation.",
656                                                     _dirChooser));
657     
658     addOptionComponent(panel,
659                        new StringOptionComponent(OptionConstants.JAVADOC_CUSTOM_PARAMS,
660                                                  "Custom Javadoc Parameters", this,
661                                                  "Any extra flags or parameters to pass to Javadoc."));
662     
663     addOptionComponent(panel,
664                        new BooleanOptionComponent(OptionConstants.JAVADOC_FROM_ROOTS,
665                                                   "Generate Javadoc From Source Roots", this,
666                                                   "<html>Whether 'Javadoc All' should generate Javadoc for all packages<br>" +
667                                                   "in an open document's source tree, rather than just the document's<br>" +
668                                                   "own package and sub-packages.</html>"));
669     
670     panel.displayComponents();
671   }
672
673   /** Adds all of the components for the Prompts panel of the preferences window. */
674   private void _setupNotificationsPanel(ConfigPanel panel) {
675     // Quit
676
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.QUIT_PROMPT, "Prompt Before Quit", this,
677                                                   "Whether DrJava should prompt the user before quitting."));
678
679     // Interactions
680
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.INTERACTIONS_RESET_PROMPT,
681                                                   "Prompt Before Resetting Interactions Pane", this,
682                                                   "<html>Whether DrJava should prompt the user before<br>" +
683                                                   "manually resetting the interactions pane.</html>"));
684     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.INTERACTIONS_EXIT_PROMPT,
685                                                   "Prompt if Interactions Pane Exits Unexpectedly", this,
686                                                   "<html>Whether DrJava should show a dialog box if a program<br>" +
687                                                   "in the Interactions Pane exits without the user clicking Reset.</html>"));
688
689     // Javadoc
690
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.JAVADOC_PROMPT_FOR_DESTINATION,
691                                                   "Prompt for Javadoc Destination", this,
692                                                   "<html>Whether Javadoc should always prompt the user<br>" +
693                                                   "to select a destination directory.</html>"));
694
695
696     // Clean
697
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.PROMPT_BEFORE_CLEAN,
698                                                   "Prompt before Cleaning Build Directory", this,
699                                                   "<html>Whether DrJava should prompt before cleaning the<br>" +
700                                                     "build directory of a project</html>"));
701
702     
703     // Save before X
704
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.ALWAYS_SAVE_BEFORE_COMPILE,
705                                                   "Automatically Save Before Compiling", this,
706                                                   "<html>Whether DrJava should automatically save before<br>" +
707                                                   "recompiling or ask the user each time.</html>"));
708     
709     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.ALWAYS_COMPILE_BEFORE_JUNIT, "Automatically Compile Before Testing", this,
710                                                   "<html>Whether DrJava should automatically compile before<br>" +
711                                                   "testing with JUnit or ask the user each time.</html>"));
712     
713     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.ALWAYS_SAVE_BEFORE_JAVADOC,
714                                                   "Automatically Save Before Generating Javadoc", this,
715                                                   "<html>Whether DrJava should automatically save before<br>" +
716                                                   "generating Javadoc or ask the user each time.</html>"));
717
718
719     // These are very problematic features, and so are disabled for the forseeable future.
720
// addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.ALWAYS_SAVE_BEFORE_RUN, "Automatically Save and Compile Before Running Main Method", this,
721
// "<html>Whether DrJava should automatically save and compile before running<br>" +
722
// "a document's main method, or instead should ask the user each time.</html>"));
723
// addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.ALWAYS_SAVE_BEFORE_DEBUG, "Automatically Save and Compile Before Debugging", this,
724
// "<html>Whether DrJava should automatically save and compile before<br>" +
725
// "debugging or ask the user each time.</html>"));
726

727
728     // Warnings
729
addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.WARN_BREAKPOINT_OUT_OF_SYNC,
730                                                   "Warn on Breakpoint if Out of Sync", this,
731                                                   "<html>Whether DrJava should warn the user if the class file<br>" +
732                                                   "is out of sync before setting a breakpoint in that file.</html>"));
733     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.WARN_DEBUG_MODIFIED_FILE,
734                                                   "Warn if Debugging Modified File", this,
735                                                   "<html>Whether DrJava should warn the user if the file being<br>" +
736                                                   "debugged has been modified since its last save.</html>"));
737     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.WARN_CHANGE_LAF,
738                                                   "Warn to Restart to Change Look and Feel", this,
739                                                   "<html>Whether DrJava should warn the user that look and feel<br>" +
740                                                   "changes will not be applied until DrJava is restarted.</html>."));
741     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.WARN_PATH_CONTAINS_POUND,
742                                                   "Warn if File's Path Contains a '#' Symbol", this,
743                                                   "<html>Whether DrJava should warn the user if the file being<br>" +
744                                                   "saved has a path that contains a '#' symbol.<br>" +
745                                                   "Users cannot use such files in the Interactions Pane<br>" +
746                                                   "because of a bug in Java.</html>"));
747
748     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DIALOG_DRJAVA_ERROR_POPUP_ENABLED,
749                                                   "Show a notification window when the first DrJava error occurs", this,
750                                                   "<html>Whether to show a notification window when the first DrJava error occurs.<br>"+
751                                                   "If this is disabled, only the \"DrJava Error\" button will appear.</html>"));
752
753     panel.displayComponents();
754   }
755
756   /** Adds all of the components for the Miscellaneous panel of the preferences window. */
757   private void _setupMiscPanel(ConfigPanel panel) {
758     /* Dialog box options */
759     addOptionComponent(panel, new IntegerOptionComponent(OptionConstants.INDENT_LEVEL,
760                                                   "Indent Level", this,
761                                                   "The number of spaces to use for each level of indentation."));
762     addOptionComponent(panel, new IntegerOptionComponent(OptionConstants.HISTORY_MAX_SIZE, "Size of Interactions History", this,
763                                                   "The number of interactions to remember in the history."));
764     addOptionComponent(panel, new IntegerOptionComponent(OptionConstants.RECENT_FILES_MAX_SIZE, "Recent Files List Size", this,
765                                                   "<html>The number of files to remember in<br>" +
766                                                   "the recently used files list in the File menu.</html>"));
767     addOptionComponent(panel, new StringOptionComponent(OptionConstants.MASTER_JVM_ARGS, "JVM Args for Main JVM", this,
768                                                  "The command-line arguments to pass to the Main JVM."));
769     addOptionComponent(panel, new StringOptionComponent(OptionConstants.SLAVE_JVM_ARGS, "JVM Args for Interactions JVM", this,
770                                                  "The command-line arguments to pass to the Interactions JVM."));
771     addOptionComponent(panel, new IntegerOptionComponent(OptionConstants.BROWSER_HISTORY_MAX_SIZE,
772                                                          "Maximum Size of Browser History", this,
773                                                          "Determines how many entries are kept in the browser history."));
774     
775     /* Check box options */
776     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.AUTO_CLOSE_COMMENTS, "Automatically Close Block Comments", this,
777                                                   "<html>Whether to automatically insert a closing comment tag (\"*/\")<br>" +
778                                                   "when the enter key is pressed after typing a new block comment<br>" +
779                                                   "tag (\"/*\" or \"/**\").</html>"));
780     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.RUN_WITH_ASSERT, "Enable Assert Statement Execution", this,
781                                                   "<html>Whether to execute <code>assert</code> statements in classes running in the interactions pane.</html>"));
782     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.BACKUP_FILES, "Keep Emacs-style Backup Files", this,
783                                                   "<html>Whether DrJava should keep a backup copy of each file that<br>" +
784                                                   "the user modifies, saved with a '~' at the end of the filename.</html>"));
785     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.RESET_CLEAR_CONSOLE, "Clear Console After Interactions Reset", this,
786                                                   "Whether to clear the Console output after resetting the Interactions Pane."));
787     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.ALLOW_PRIVATE_ACCESS, "Allow Access of Private Members in Interactions Pane", this,
788                                                   "Whether to allow users to access private (and protected) fields and methods."));
789     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_SOURCE_WHEN_SWITCHING, "Show sample of source code when fast switching", this,
790                                                   "Whether to show a sample of the source code under the document's filename when fast switching documents."));
791     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.FORCE_TEST_SUFFIX,
792                                                   "Require test classes in projects to end in \"Test\"", this,
793                                                   "Whether to force test classes in projects to end in \"Test\"."));
794     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.FIND_REPLACE_FOCUS_IN_DEFPANE,
795                                                   "Put the focus in the definitions pane after find/replace", this,
796                                                   "<html>Whether to put the focus in the definitions pane after doing a find or replace operation.<br>"+
797                                                   "If this is not selected, the focus will be in the Find/Replace pane.</html>"));
798     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_CODE_PREVIEW_POPUPS,
799                                                   "Show Code Preview Popups", this,
800                                                   "<html>Whether to show a popup window with a code preview when the mouse is hovering<br>"+
801                                                   "over an item in the Breakpoints, Bookmarks and Find All panes.</html>"));
802     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.DRJAVA_USE_FORCE_QUIT,
803                                                   "Forcefully Quit DrJava", this,
804                                                   "<html>On some platforms, DrJava does not shut down properly when files are open<br>"+
805                                                   "(namely tablet PCs). Check this option to force DrJava to close.</html>"));
806     
807 // Any lightweight parsing has been disabled until we have something that is beneficial and works better in the background.
808
// addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.LIGHTWEIGHT_PARSING_ENABLED,
809
// "Perform lightweight parsing", this,
810
// "<html>Whether to continuously parse the source file for useful information.<br>" +
811
// "Enabling this option might introduce delays when editing files.<html>"));
812
// addOptionComponent(panel, new IntegerOptionComponent(OptionConstants.DIALOG_LIGHTWEIGHT_PARSING_DELAY, "Light-weight parsing delay in milliseconds", this,
813
// "The amount of time DrJava will wait after the last keypress before beginning to parse."));
814

815     panel.displayComponents();
816   }
817   
818   /**
819    * Adds all of the components for the Compiler Options Panel of the preferences window
820    */

821   private void _setupCompilerPanel(ConfigPanel panel) {
822     addOptionComponent(panel, new LabelComponent("Note: Compiler warnings not shown if compiling any Java language level files", this));
823     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_UNCHECKED_WARNINGS, "Show Unchecked Warnings", this,
824                                                   "<html>Warn about unchecked conversions involving parameterized types.</html>"));
825     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_DEPRECATION_WARNINGS, "Show Deprecation Warnings", this,
826                                                   "<html>Warn about each use or override of a deprecated method, field, or class.</html>"));
827     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_PATH_WARNINGS, "Show Path Warnings", this,
828                                                   "<html>Warn about nonexistent members of the classpath and sourcepath.</html>"));
829     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_SERIAL_WARNINGS, "Show Serial Warnings", this,
830                                                   "<html>Warn about missing <code>serialVersionUID</code> definitions on serializable classes.</html>"));
831     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_FINALLY_WARNINGS, "Show Finally Warnings", this,
832                                                   "<html>Warn about <code>finally</code> clauses that cannot complete normally.</html>"));
833     addOptionComponent(panel, new BooleanOptionComponent(OptionConstants.SHOW_FALLTHROUGH_WARNINGS, "Show Fall-Through Warnings", this,
834                                                   "<html>Warn about <code>switch</code> block cases that fall through to the next case.</html>"));
835     panel.displayComponents();
836     
837   }
838   
839   /** Private class to handle rendering of tree nodes, each of which
840    * corresponds to a ConfigPanel. These nodes should only be accessed
841    * from the event handling thread.
842    */

843   private class PanelTreeNode extends DefaultMutableTreeNode {
844
845     private final ConfigPanel _panel;
846
847     public PanelTreeNode(String JavaDoc t) {
848       super(t);
849       _panel = new ConfigPanel(t);
850     }
851
852     public PanelTreeNode(ConfigPanel c) {
853       super(c.getTitle());
854       _panel = c;
855     }
856     private ConfigPanel getPanel() { return _panel; }
857
858     /** Tells its panel to update, and tells all of its child nodes to update their panels.
859      * @return whether the update succeeded.
860      */

861     private boolean update() {
862       
863       boolean isValidUpdate = _panel.update();
864        
865       //if this panel encountered an error while attempting to update, return false
866
if (!isValidUpdate) {
867         //System.out.println("Panel.update() returned false");
868

869         //TreePath path = new TreePath(this.getPath());
870
// causes ClassCastException under jsr14 v2.0 for no apparent reason.
871
// Workaround: store result of getPath() to temporary array.
872

873         TreeNode[] nodes = getPath();
874         TreePath path = new TreePath(nodes);
875         _tree.expandPath(path);
876         _tree.setSelectionPath(path);
877         return false;
878       }
879
880       Enumeration JavaDoc childNodes = children();
881       while (childNodes.hasMoreElements()) {
882         boolean isValidUpdateChildren = ((PanelTreeNode)childNodes.nextElement()).update();
883         //if any of the children nodes encountered an error, return false
884
if (!isValidUpdateChildren) {
885           return false;
886         }
887       }
888
889       return true;
890     }
891
892     /**
893      * Tells its panel to reset its displayed value to the currently set value
894      * for this component, and tells all of its children to reset their panels.
895      */

896     public void resetToCurrent() {
897       _panel.resetToCurrent();
898
899       Enumeration JavaDoc childNodes = this.children();
900       while (childNodes.hasMoreElements()) {
901         ((PanelTreeNode)childNodes.nextElement()).resetToCurrent();
902       }
903     }
904   }
905
906   private class PanelTreeSelectionListener implements TreeSelectionListener {
907     public void valueChanged(TreeSelectionEvent e) {
908       Object JavaDoc o = _tree.getLastSelectedPathComponent();
909       //System.out.println("Object o : "+o);
910
if (o instanceof PanelTreeNode) {
911         //System.out.println("o is instanceof PanelTreeNode");
912
PanelTreeNode child = (PanelTreeNode) _tree.getLastSelectedPathComponent();
913         _displayPanel(child.getPanel());
914       }
915     }
916   }
917 }
918
Popular Tags