Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/gui4j/exception/Gui4jDefaultErrorHandler.java


1   package org.gui4j.exception;
2   
3   import javax.swing.JOptionPane;
4   
5   
6   
7   /**
8    * Default Implementierung für <code>Gui4jErrorHandler</code>. Diese
9    * Implementierung zeigt ein Fenster mit einem <b>Ok</b> und
10   * einem <b>Abort</b> Button an.
11   */
12  public class Gui4jDefaultErrorHandler implements Gui4jErrorHandler
13  {
14      private static final Gui4jErrorHandler DEFAULT_HANDLER = new Gui4jDefaultErrorHandler();
15      private boolean dialogAlreadyOpen;
16  
17      /**
18       * Constructor for Gui4jDefaultErrorHandler.
19       */
20      private Gui4jDefaultErrorHandler()
21      {
22          super();
23      }
24  
25      /**
26       * @return immer die gleiche Instanz von <code>Gui4jErrorHandler</code>, welche
27       * ein Dialogfenster mit <code>Ok</code> und <code>Abort</code> Button enthält.
28      */
29      public static Gui4jErrorHandler getInstance()
30      {
31          return DEFAULT_HANDLER;
32      }
33  
34      /**
35       * @see org.gui4j.exception.Gui4jErrorHandler#internalError(Throwable)
36       */
37      public void internalError(final Throwable e)
38      {
39          final Gui4jErrorHandler THIS = this;
40          synchronized (THIS)
41          {
42              if (dialogAlreadyOpen)
43              {
44                  // do not show more dialogs
45                  return;
46              }
47              else
48              {
49                  dialogAlreadyOpen = true;
50              }
51          }
52          Object[] options = { "OK", "ABORT" };
53          int result =
54              JOptionPane.showOptionDialog(
55                  null,
56                  "Internal Error occured. Click OK to continue.\n\nDetails:\n" + e,
57                  "Warning",
58                  JOptionPane.DEFAULT_OPTION,
59                  JOptionPane.WARNING_MESSAGE,
60                  null,
61                  options,
62                  options[0]);
63          dialogAlreadyOpen = false;
64          if (result == 1)
65          {
66              System.exit(1);
67          }
68      }
69  
70  }