Pārlūkot izejas kodu

If the UI is not visible (well, if there are no "ready" error listeners) the logger will now output errors to System.err

git-svn-id: http://svn.dmdirc.com/trunk@2373 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.5
Gregory Holmes 16 gadus atpakaļ
vecāks
revīzija
aaca7e7800

+ 7
- 0
src/com/dmdirc/logger/ErrorListener.java Parādīt failu

@@ -57,4 +57,11 @@ public interface ErrorListener extends EventListener {
57 57
      * @param error Error that has been altered
58 58
      */
59 59
     void errorStatusChanged(final ProgramError error);
60
+    
61
+    /**
62
+     * Returns true if the error listener is ready to receive errors
63
+     *
64
+     * @return true iif the error listener is ready for errors
65
+     */
66
+    boolean isReady();
60 67
 }

+ 24
- 7
src/com/dmdirc/logger/ErrorManager.java Parādīt failu

@@ -147,11 +147,10 @@ public final class ErrorManager implements Serializable {
147 147
      *
148 148
      * @param error error to be sent
149 149
      */
150
-    @SuppressWarnings("PMD.SystemPrintln")
151 150
     public static void sendError(final ProgramError error) {
152 151
         new Timer("ErrorManager Timer").schedule(new TimerTask() {
153 152
             public void run() {
154
-                sendErrorInternal(error);
153
+                getErrorManager().sendErrorInternal(error);
155 154
             }
156 155
         }, 0);
157 156
     }
@@ -161,8 +160,7 @@ public final class ErrorManager implements Serializable {
161 160
      *
162 161
      * @param error ProgramError to be sent
163 162
      */
164
-    @SuppressWarnings("PMD.SystemPrintln")
165
-    private static void sendErrorInternal(final ProgramError error) {
163
+    private void sendErrorInternal(final ProgramError error) {
166 164
         final Map<String, String> postData = new HashMap<String, String>();
167 165
         List<String> response = new ArrayList<String>();
168 166
         int tries = 0;
@@ -191,7 +189,7 @@ public final class ErrorManager implements Serializable {
191 189
             
192 190
             tries++;
193 191
         } while((response.isEmpty() || !response.get(response.size() - 1).
194
-                equalsIgnoreCase("Error report submitted. Thank you.")) 
192
+                equalsIgnoreCase("Error report submitted. Thank you."))
195 193
                 || tries >= 5);
196 194
         
197 195
         checkResponses(error, response);
@@ -253,12 +251,22 @@ public final class ErrorManager implements Serializable {
253 251
      * @param error Error that occurred
254 252
      */
255 253
     protected void fireErrorAdded(final ProgramError error) {
254
+        int firedListeners = 0;
256 255
         final Object[] listeners = errorListeners.getListenerList();
257 256
         for (int i = 0; i < listeners.length; i += 2) {
258 257
             if (listeners[i] == ErrorListener.class) {
259
-                ((ErrorListener) listeners[i + 1]).errorAdded(error);
258
+                final ErrorListener thisListener = ((ErrorListener) listeners[i + 1]);
259
+                if (thisListener.isReady()) {
260
+                    thisListener.errorAdded(error);
261
+                    firedListeners++;
262
+                }
260 263
             }
261 264
         }
265
+        
266
+        if (firedListeners == 0) {
267
+            System.err.println("An error has occurred: " + error.getLevel()
268
+            + ": " + error.getMessage());
269
+        }
262 270
     }
263 271
     
264 272
     /**
@@ -267,12 +275,21 @@ public final class ErrorManager implements Serializable {
267 275
      * @param error Error that occurred
268 276
      */
269 277
     protected void fireFatalError(final ProgramError error) {
278
+        int firedListeners = 0;
270 279
         final Object[] listeners = errorListeners.getListenerList();
271 280
         for (int i = 0; i < listeners.length; i += 2) {
272 281
             if (listeners[i] == ErrorListener.class) {
273
-                ((ErrorListener) listeners[i + 1]).fatalError(error);
282
+                final ErrorListener thisListener = ((ErrorListener) listeners[i + 1]);
283
+                if (thisListener.isReady()) {
284
+                    thisListener.fatalError(error);
285
+                    firedListeners++;
286
+                }
274 287
             }
275 288
         }
289
+         
290
+        if (firedListeners == 0) {
291
+            System.err.println("A fatal has occurred: " + error.getMessage());
292
+        }
276 293
     }
277 294
     
278 295
     /**

+ 5
- 0
src/com/dmdirc/ui/dummy/DummyStatusBar.java Parādīt failu

@@ -72,4 +72,9 @@ public final class DummyStatusBar implements StatusBar {
72 72
         // Do nothing
73 73
     }
74 74
 
75
+    /** {@inheritDoc} */
76
+    public boolean isVisible() {
77
+        return true;
78
+    }
79
+
75 80
 }

+ 7
- 0
src/com/dmdirc/ui/interfaces/StatusBar.java Parādīt failu

@@ -80,4 +80,11 @@ public interface StatusBar {
80 80
      */
81 81
     void removeComponent(final Component component);
82 82
     
83
+    /**
84
+     * Returns true if the status bar is visible.
85
+     *
86
+     * @return true iff the status bar is visible
87
+     */
88
+    boolean isVisible();
89
+    
83 90
 }

+ 5
- 0
src/com/dmdirc/ui/swing/components/SwingStatusBar.java Parādīt failu

@@ -269,4 +269,9 @@ public final class SwingStatusBar extends JPanel implements MouseListener,
269 269
         constraints.setWidth(constraints.getWidth());
270 270
         this.setVisible(true);
271 271
     }
272
+    
273
+    /** {@inheritDoc} */
274
+    public boolean isReady() {
275
+        return isValid();
276
+    }
272 277
 }

+ 5
- 0
src/com/dmdirc/ui/swing/dialogs/error/ErrorDetailPanel.java Parādīt failu

@@ -223,5 +223,10 @@ public final class ErrorDetailPanel extends JPanel implements ErrorListener {
223 223
             errorStatus.setText(error.getFixedStatus().toString());
224 224
         }
225 225
     }
226
+
227
+    /** {@inheritDoc} */
228
+    public boolean isReady() {
229
+        return isVisible();
230
+    }
226 231
     
227 232
 }

+ 5
- 0
src/com/dmdirc/ui/swing/dialogs/error/ErrorListDialog.java Parādīt failu

@@ -341,4 +341,9 @@ public final class ErrorListDialog extends StandardDialog implements
341 341
             me = null;
342 342
         }
343 343
     }
344
+
345
+    /** {@inheritDoc} */
346
+    public boolean isReady() {
347
+        return Main.getUI().getStatusBar().isVisible();
348
+    }
344 349
 }

Notiek ielāde…
Atcelt
Saglabāt