|
@@ -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
|
|