1 33 34 package edu.rice.cs.drjava.ui; 35 36 import javax.swing.JButton ; 37 import java.util.List ; 38 import java.util.ArrayList ; 39 40 import edu.rice.cs.drjava.DrJava; 41 import edu.rice.cs.util.UnexpectedException; 42 import edu.rice.cs.drjava.config.OptionConstants; 43 44 51 public class DrJavaErrorHandler { 52 53 private static ArrayList <Throwable > _errors = new ArrayList <Throwable >(); 54 55 56 private static JButton _errorsButton; 57 58 59 public static void setButton(JButton b) { _errorsButton = b; } 60 61 62 public static JButton getButton() { return _errorsButton; } 63 64 65 public static int getErrorCount() { return _errors.size(); } 66 67 68 public static Throwable getError(int index) { 69 if ((index>=0) && (index<_errors.size())) { 70 return _errors.get(index); 71 } 72 else { 73 return new UnexpectedException("Error in DrJavaErrorHandler"); 74 } 75 } 76 77 78 public static void clearErrors() { _errors.clear(); } 79 80 81 public void handle(Throwable thrown) { 82 System.out.println("Unhandled exception: " + thrown); 83 record(thrown); 84 } 85 86 87 public static void record(Throwable thrown) { 88 _errors.add(thrown); 89 if (_errorsButton!=null) { 90 _errorsButton.setVisible(true); 91 } 92 if ((_errors.size()==1) && (DrJava.getConfig().getSetting(OptionConstants.DIALOG_DRJAVA_ERROR_POPUP_ENABLED).booleanValue())) { 93 DrJavaErrorPopup popup = new DrJavaErrorPopup(DrJavaErrorWindow.getFrame(), thrown); 94 MainFrame.setPopupLoc(popup, popup.getOwner()); 95 popup.setVisible(true); 96 } 97 } 98 99 100 public static void log(String message) { 101 record(new LoggedCondition(message)); 102 } 103 104 105 public static class LoggedCondition extends Throwable { 106 public LoggedCondition(String s) { super(s); } 107 } 108 } 109 | Popular Tags |