1 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 52 public class DrJavaErrorPopup extends JDialog { 53 54 private JComponent _errorInfo; 55 56 private JCheckBox _keepDisplaying; 57 58 private JPanel _bottomPanel; 59 60 private JPanel _buttonPanel; 61 62 private JButton _okButton; 63 64 private JButton _moreButton; 65 66 private Throwable _error; 67 68 private static JFrame _parentFrame = new JFrame(); 69 70 71 public DrJavaErrorPopup(JFrame parent, Throwable error) { 72 super(parent, "DrJava Error"); 73 74 _parentFrame = parent; 75 _error = error; 76 77 this.setSize(500,150); 78 79 _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 [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 114 private Action _okAction = new AbstractAction("OK") { 115 public void actionPerformed(ActionEvent e) { 116 DrJavaErrorPopup.this.dispose(); 117 } 118 }; 119 120 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 132 private final String [] msg = { 133 "An error occurred in DrJava:", 134 "", 135 "You may wish to save all your work and restart DrJava."}; 136 } | Popular Tags |