Bladeren bron

Statusbar now shows the highest priority error until the error list is shown

git-svn-id: http://svn.dmdirc.com/trunk@2273 00569f92-eb28-0410-84fd-f71c24880f
tags/0.5.1
Gregory Holmes 16 jaren geleden
bovenliggende
commit
370e00c3bd

+ 36
- 0
src/com/dmdirc/logger/ErrorLevel.java Bestand weergeven

@@ -54,4 +54,40 @@ public enum ErrorLevel {
54 54
     public String toString() {
55 55
         return value;
56 56
     }
57
+    
58
+    /**
59
+     * Returns if the specified error is more important than this one
60
+     *
61
+     * @param level Error level to compare
62
+     *
63
+     * @return true iif the error is more important
64
+     */
65
+    public boolean moreImportant(final ErrorLevel level) {
66
+        switch (level) {
67
+            case FATAL:
68
+                return true;
69
+            case HIGH:
70
+                if (this == FATAL) {
71
+                    return true;
72
+                }
73
+                return false;
74
+            case MEDIUM:
75
+                if (this == HIGH || this == FATAL) {
76
+                    return true;
77
+                }
78
+                return false;
79
+            case LOW:
80
+                if (this == MEDIUM || this == HIGH || this == FATAL) {
81
+                    return true;
82
+                }
83
+                return false;
84
+            case UNKNOWN:
85
+                if (this == LOW || this == MEDIUM || this == HIGH || this == FATAL) {
86
+                    return true;
87
+                }
88
+                return false;
89
+            default:
90
+                return false;
91
+        }
92
+    }
57 93
 }

+ 0
- 15
src/com/dmdirc/ui/dummy/DummyStatusBar.java Bestand weergeven

@@ -62,21 +62,6 @@ public final class DummyStatusBar implements StatusBar {
62 62
         System.out.println("DummyStatusBar: message cleared");
63 63
     }
64 64
 
65
-    /** {@inheritDoc} */
66
-    public void setError(final Icon newIcon) {
67
-        // Do nothing
68
-    }
69
-
70
-    /** {@inheritDoc} */
71
-    public void setError(final Icon newIcon, final StatusErrorNotifier newNotifier) {
72
-        // Do nothing
73
-    }
74
-
75
-    /** {@inheritDoc} */
76
-    public void clearError() {
77
-        // Do nothing
78
-    }
79
-
80 65
     /** {@inheritDoc} */
81 66
     public void addComponent(final Component component) {
82 67
         // Do nothing

+ 0
- 22
src/com/dmdirc/ui/interfaces/StatusBar.java Bestand weergeven

@@ -66,28 +66,6 @@ public interface StatusBar {
66 66
      */
67 67
     void clearMessage();
68 68
     
69
-    /**
70
-     * sets the icon in the status bar.
71
-     *
72
-     * @param newIcon Icon to display
73
-     */
74
-    void setError(final Icon newIcon);
75
-    
76
-    /**
77
-     * sets the icon in the status bar with a specified callback event.
78
-     *
79
-     * @param newIcon Icon to display
80
-     * @param newNotifier status error notifier to be notified for events on
81
-     * this error
82
-     */
83
-    void setError(final Icon newIcon,
84
-            final StatusErrorNotifier newNotifier);
85
-    
86
-    /**
87
-     * Removes the error state from the status bar.
88
-     */
89
-    void clearError();
90
-    
91 69
     /**
92 70
      * Adds a component to the status bar.
93 71
      *

+ 18
- 46
src/com/dmdirc/ui/swing/components/SwingStatusBar.java Bestand weergeven

@@ -24,11 +24,11 @@ package com.dmdirc.ui.swing.components;
24 24
 
25 25
 import com.dmdirc.IconManager;
26 26
 import com.dmdirc.config.IdentityManager;
27
+import com.dmdirc.logger.ErrorLevel;
27 28
 import com.dmdirc.logger.ErrorListener;
28 29
 import com.dmdirc.logger.ErrorManager;
29 30
 import com.dmdirc.logger.ProgramError;
30 31
 import com.dmdirc.ui.interfaces.StatusBar;
31
-import com.dmdirc.ui.interfaces.StatusErrorNotifier;
32 32
 import com.dmdirc.ui.interfaces.StatusMessageNotifier;
33 33
 import com.dmdirc.ui.swing.dialogs.error.ErrorListDialog;
34 34
 import static com.dmdirc.ui.swing.UIUtilities.SMALL_BORDER;
@@ -76,15 +76,12 @@ public final class SwingStatusBar extends JPanel implements MouseListener,
76 76
     /** current status bar message notifier. */
77 77
     private transient StatusMessageNotifier messageNotifier;
78 78
     
79
-    /** current status bar error notifier. */
80
-    private transient StatusErrorNotifier errorNotifier;
81
-    
82
-    /** Timer to clear the error. */
83
-    private transient TimerTask errorTimer;
84
-    
85 79
     /** Timer to clear the message. */
86 80
     private transient TimerTask messageTimer;
87 81
     
82
+    /** Currently showing error level. */
83
+    private ErrorLevel errorLevel;
84
+    
88 85
     /**
89 86
      * Creates a new instance of SwingStatusBar.
90 87
      */
@@ -103,6 +100,7 @@ public final class SwingStatusBar extends JPanel implements MouseListener,
103 100
         messageLabel.addMouseListener(this);
104 101
         iconLabel.addMouseListener(this);
105 102
         ErrorManager.getErrorManager().addErrorListener(this);
103
+        clearError();
106 104
         
107 105
         setLayout(new SpringLayout());
108 106
         
@@ -155,57 +153,30 @@ public final class SwingStatusBar extends JPanel implements MouseListener,
155 153
     }
156 154
     
157 155
     /** {@inheritDoc} */
158
-    public void setError(final Icon newIcon) {
159
-        setError(newIcon, null);
156
+    public void clearError() {
157
+        iconLabel.setIcon(DEFAULT_ICON);
158
+        errorLevel = ErrorLevel.UNKNOWN;
160 159
     }
161 160
     
162 161
     /** {@inheritDoc} */
163
-    public synchronized void setError(final Icon newIcon,
164
-            final StatusErrorNotifier newNotifier) {
165
-        iconLabel.setIcon(newIcon);
166
-        errorNotifier = newNotifier;
167
-        
168
-        if (errorTimer != null && (System.currentTimeMillis()
169
-        - errorTimer.scheduledExecutionTime()) <= 0) {
170
-            errorTimer.cancel();
171
-        }
172
-        
173
-        final int displayLength = IdentityManager.getGlobalConfig().getOptionInt("statusBar", "errorDisplayLength", 10000);
174
-        
175
-        if (!DEFAULT_ICON.equals(newIcon)) {
176
-            errorTimer = new TimerTask() {
177
-                public void run() {
178
-                    clearError();
179
-                }
180
-            };
181
-            new Timer("SwingStatusBar errorTimer").schedule(errorTimer,
182
-                    new Date(System.currentTimeMillis() + 250  + displayLength));
162
+    public void errorAdded(final ProgramError error) {
163
+        if (error.getLevel().moreImportant(errorLevel)) {
164
+            errorLevel = error.getLevel();
165
+            iconLabel.setIcon(getIcon(error));
183 166
         }
184 167
     }
185 168
     
186
-    /** {@inheritDoc} */
187
-    public void clearError() {
188
-        setError(DEFAULT_ICON);
189
-    }
190
-    
191
-    /** {@inheritDoc} */
192
-    public void errorAdded(final ProgramError error) {
193
-        final Icon icon;
169
+    private Icon getIcon(final ProgramError error) {
194 170
         switch (error.getLevel()) {
195 171
             case HIGH:
196
-                icon = IconManager.getIconManager().getIcon("error");
197
-                break;
172
+                return IconManager.getIconManager().getIcon("error");
198 173
             case MEDIUM:
199
-                icon = IconManager.getIconManager().getIcon("warning");
200
-                break;
174
+                return IconManager.getIconManager().getIcon("warning");
201 175
             case LOW:
202
-                icon = IconManager.getIconManager().getIcon("info");
203
-                break;
176
+                return IconManager.getIconManager().getIcon("info");
204 177
             default:
205
-                icon = IconManager.getIconManager().getIcon("info");
206
-                break;
178
+                return IconManager.getIconManager().getIcon("info");
207 179
         }
208
-        setError(icon);
209 180
     }
210 181
     
211 182
     /** {@inheritDoc} */
@@ -248,6 +219,7 @@ public final class SwingStatusBar extends JPanel implements MouseListener,
248 219
         if (mouseEvent.getButton() == MouseEvent.BUTTON1
249 220
                 && mouseEvent.getSource() == iconLabel) {
250 221
             ErrorListDialog.getErrorListDialog().setVisible(true);
222
+            clearError();
251 223
         }
252 224
     }
253 225
     

Laden…
Annuleren
Opslaan