Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 138   Methods: 4
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DrJavaErrorPopup.java 0% 0% 0% 0%
coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.ui;
 38   
 39    import javax.swing.*;
 40    import javax.swing.event.*;
 41    import javax.swing.border.*;
 42    import java.awt.event.*;
 43    import java.awt.*;
 44   
 45    import edu.rice.cs.drjava.DrJava;
 46    import edu.rice.cs.drjava.config.OptionConstants;
 47    import edu.rice.cs.util.swing.Utilities;
 48   
 49    /** Displays a popup window for the first uncaught exception or logged conditions.
 50    * @version $Id: DrJavaErrorPopup.java 5236 2010-04-27 01:43:36Z mgricken $
 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 buttons */
 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 _error;
 67    // /** the parent frame */
 68    // private JFrame _parentFrame = new JFrame();
 69   
 70    /** Creates a window to graphically display the current error that has occurred in the code of DrJava. */
 71  0 public DrJavaErrorPopup(JFrame parent, Throwable error) {
 72  0 super(parent, "DrJava Error");
 73   
 74    // _parentFrame = parent;
 75  0 _error = error;
 76   
 77  0 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  0 _keepDisplaying = new JCheckBox("Keep showing this notification",
 82    DrJava.getConfig().getSetting(OptionConstants.DIALOG_DRJAVA_ERROR_POPUP_ENABLED).booleanValue());
 83  0 _keepDisplaying.addChangeListener(new ChangeListener() {
 84  0 public void stateChanged(ChangeEvent e) {
 85  0 DrJava.getConfig().setSetting(OptionConstants.DIALOG_DRJAVA_ERROR_POPUP_ENABLED, _keepDisplaying.isSelected());
 86    }
 87    });
 88   
 89  0 _moreButton = new JButton(_moreAction);
 90  0 _okButton = new JButton(_okAction);
 91   
 92  0 _bottomPanel = new JPanel(new BorderLayout());
 93  0 _buttonPanel = new JPanel();
 94  0 _buttonPanel.add(_moreButton);
 95  0 _buttonPanel.add(_okButton);
 96  0 _bottomPanel.add(_keepDisplaying, BorderLayout.WEST);
 97  0 _bottomPanel.add(_buttonPanel, BorderLayout.EAST);
 98   
 99  0 if (_error instanceof DrJavaErrorHandler.LoggedCondition) { msg[1] = "Logged condition: " + _error.getMessage(); }
 100  0 else { msg[1] = _error.toString(); }
 101  0 _errorInfo = new JOptionPane(msg,JOptionPane.ERROR_MESSAGE,
 102    JOptionPane.DEFAULT_OPTION,null,
 103    new Object[0]);
 104   
 105  0 JPanel cp = new JPanel(new BorderLayout(5,5));
 106  0 cp.setBorder(new EmptyBorder(5,5,5,5));
 107  0 setContentPane(cp);
 108  0 cp.add(_errorInfo, BorderLayout.CENTER);
 109  0 cp.add(_bottomPanel, BorderLayout.SOUTH);
 110  0 getRootPane().setDefaultButton(_okButton);
 111    }
 112   
 113    /* Close the window. */
 114    private Action _okAction = new AbstractAction("OK") {
 115  0 public void actionPerformed(ActionEvent e) {
 116  0 DrJavaErrorPopup.this.dispose();
 117  0 if (DrJavaErrorHandler.getButton() == null) { System.exit(1); }
 118    }
 119    };
 120   
 121    /** Close this window, but display the full DrJava Errors window. */
 122    private Action _moreAction = new AbstractAction("More Information") {
 123  0 public void actionPerformed(ActionEvent e) {
 124  0 if (! Utilities.TEST_MODE) {
 125  0 DrJavaErrorPopup.this.dispose();
 126  0 Utilities.setPopupLoc(DrJavaErrorWindow.singleton(), DrJavaErrorWindow.getFrame());
 127  0 DrJavaErrorWindow.singleton().setVisible(true);
 128    }
 129    }
 130    };
 131   
 132    /** Contains the canned message for the user
 133    */
 134    private final String[] msg = {
 135    "An error occurred in DrJava:",
 136    "",
 137    "You may wish to save all your work and restart DrJava."};
 138    }