KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > ui > DrJavaErrorPopup


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;
35
36 import javax.swing.*;
37 import javax.swing.event.*;
38 import javax.swing.text.*;
39 import javax.swing.border.*;
40 import java.awt.event.*;
41 import java.awt.*;
42
43 import edu.rice.cs.drjava.DrJava;
44 import edu.rice.cs.drjava.config.OptionConstants;
45 import edu.rice.cs.util.UnexpectedException;
46 import edu.rice.cs.util.StringOps;
47 import edu.rice.cs.util.swing.BorderlessScrollPane;
48
49 /** Displays a popup window for the first uncaught exception or logged conditions.
50  * @version $Id$
51  */

52 public class DrJavaErrorPopup extends JDialog {
53   /** information about the error */
54   private JComponent _errorInfo;
55   /** contains the stack trace */
56   private JCheckBox _keepDisplaying;
57   /** compresses the buttonPanel into the east */
58   private JPanel _bottomPanel;
59   /** contains the butons */
60   private JPanel _buttonPanel;
61   /** the button that closes this window */
62   private JButton _okButton;
63   /** the button that shows the error window */
64   private JButton _moreButton;
65   /** the error */
66   private Throwable JavaDoc _error;
67   /** the parent frame */
68   private static JFrame _parentFrame = new JFrame();
69   
70   /** Creates a window to graphically display the current error that has occurred in the code of DrJava. */
71   public DrJavaErrorPopup(JFrame parent, Throwable JavaDoc error) {
72     super(parent, "DrJava Error");
73     
74     _parentFrame = parent;
75     _error = error;
76
77     this.setSize(500,150);
78
79     // If we set this pane to be of type text/rtf, it wraps based on words
80
// as opposed to based on characters.
81
_keepDisplaying = new JCheckBox("Keep showing this notification",
82                                     DrJava.getConfig().getSetting(OptionConstants.DIALOG_DRJAVA_ERROR_POPUP_ENABLED).booleanValue());
83     _keepDisplaying.addChangeListener(new ChangeListener() {
84       public void stateChanged(ChangeEvent e) {
85         DrJava.getConfig().setSetting(OptionConstants.DIALOG_DRJAVA_ERROR_POPUP_ENABLED, _keepDisplaying.isSelected());
86       }
87     });
88
89     _moreButton = new JButton(_moreAction);
90     _okButton = new JButton(_okAction);
91
92     _bottomPanel = new JPanel(new BorderLayout());
93     _buttonPanel = new JPanel();
94     _buttonPanel.add(_moreButton);
95     _buttonPanel.add(_okButton);
96     _bottomPanel.add(_keepDisplaying, BorderLayout.WEST);
97     _bottomPanel.add(_buttonPanel, BorderLayout.EAST);
98
99     if (_error instanceof DrJavaErrorHandler.LoggedCondition) { msg[1] = "Logged condition: " + _error.getMessage(); }
100     else { msg[1] = _error.toString(); }
101     _errorInfo = new JOptionPane(msg,JOptionPane.ERROR_MESSAGE,
102                                  JOptionPane.DEFAULT_OPTION,null,
103                                  new Object JavaDoc[0]);
104
105     JPanel cp = new JPanel(new BorderLayout(5,5));
106     cp.setBorder(new EmptyBorder(5,5,5,5));
107     setContentPane(cp);
108     cp.add(_errorInfo, BorderLayout.CENTER);
109     cp.add(_bottomPanel, BorderLayout.SOUTH);
110     getRootPane().setDefaultButton(_okButton);
111   }
112   
113   /* Close the window. */
114   private Action _okAction = new AbstractAction("OK") {
115     public void actionPerformed(ActionEvent e) {
116       DrJavaErrorPopup.this.dispose();
117     }
118   };
119
120   /** Close this window, but display the full DrJava Errors window. */
121   private Action _moreAction = new AbstractAction("More Information") {
122     public void actionPerformed(ActionEvent e) {
123       _okAction.actionPerformed(e);
124       MainFrame.setPopupLoc(DrJavaErrorWindow.singleton(), DrJavaErrorWindow.singleton().getFrame());
125       DrJavaErrorWindow.singleton().setVisible(true);
126     }
127   };
128
129   /**
130    * Contains the canned message for the user
131    */

132   private final String JavaDoc[] msg = {
133     "An error occurred in DrJava:",
134     "",
135     "You may wish to save all your work and restart DrJava."};
136 }
Popular Tags