浏览代码

Switch to Notification*Events.

Change-Id: I9bc5c5321065969f68bd9c5ae0e9d3a47653f713
Reviewed-on: http://gerrit.dmdirc.com/3819
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/19/3819/2
Greg Holmes 9 年前
父节点
当前提交
37e9df44d5

+ 15
- 29
src/com/dmdirc/addons/ui_swing/framemanager/buttonbar/ButtonBar.java 查看文件

@@ -38,7 +38,8 @@ import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
38 38
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
39 39
 import com.dmdirc.events.FrameIconChangedEvent;
40 40
 import com.dmdirc.events.FrameNameChangedEvent;
41
-import com.dmdirc.interfaces.NotificationListener;
41
+import com.dmdirc.events.NotificationClearedEvent;
42
+import com.dmdirc.events.NotificationSetEvent;
42 43
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
43 44
 import com.dmdirc.interfaces.config.ConfigChangeListener;
44 45
 import com.dmdirc.interfaces.ui.Window;
@@ -80,9 +81,8 @@ import net.engio.mbassy.listener.Invoke;
80 81
 /**
81 82
  * The button bar manager is a grid of buttons that presents a manager similar to that used by mIRC.
82 83
  */
83
-public final class ButtonBar implements FrameManager, ActionListener,
84
-        ComponentListener, Serializable, NotificationListener,
85
-        MouseListener, ConfigChangeListener {
84
+public final class ButtonBar implements FrameManager, ActionListener, ComponentListener,
85
+        Serializable, MouseListener, ConfigChangeListener {
86 86
 
87 87
     /** Serial version UID. */
88 88
     private static final long serialVersionUID = 3;
@@ -341,13 +341,11 @@ public final class ButtonBar implements FrameManager, ActionListener,
341 341
         final TextFrame window = event.getChildWindow();
342 342
         addButton(window);
343 343
         relayout();
344
-        window.getContainer().addNotificationListener(ButtonBar.this);
345 344
     }
346 345
 
347 346
     @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
348 347
     public void windowDeleted(final SwingWindowDeletedEvent event) {
349 348
         final TextFrame window = event.getChildWindow();
350
-        window.getContainer().removeNotificationListener(ButtonBar.this);
351 349
         if (buttons.containsKey(window)) {
352 350
             buttonPanel.setVisible(false);
353 351
             buttonPanel.remove(buttons.get(window));
@@ -388,31 +386,19 @@ public final class ButtonBar implements FrameManager, ActionListener,
388 386
         // Do nothing
389 387
     }
390 388
 
391
-    @Override
392
-    public void notificationSet(final FrameContainer window,
393
-            final Colour colour) {
394
-        UIUtilities.invokeLater(new Runnable() {
395
-
396
-            @Override
397
-            public void run() {
398
-                final FrameToggleButton button = getButton(window);
399
-                if (button != null) {
400
-                    button.setForeground(UIUtilities.convertColour(colour));
401
-                }
402
-            }
403
-        });
389
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
390
+    public void notificationSet(final NotificationSetEvent event) {
391
+        final FrameToggleButton button = getButton(event.getWindow());
392
+        if (button != null) {
393
+            button.setForeground(UIUtilities.convertColour(event.getColour()));
394
+        }
404 395
     }
405 396
 
406
-    @Override
407
-    public void notificationCleared(final FrameContainer window) {
408
-        UIUtilities.invokeLater(new Runnable() {
409
-
410
-            @Override
411
-            public void run() {
412
-                // TODO: Should this colour be configurable?
413
-                notificationSet(window, window.getNotification().or(Colour.BLACK));
414
-            }
415
-        });
397
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
398
+    public void notificationCleared(final NotificationClearedEvent event) {
399
+        // TODO: Should this colour be configurable?
400
+        notificationSet(new NotificationSetEvent(event.getWindow(),
401
+                event.getWindow().getNotification().or(Colour.BLACK)));
416 402
     }
417 403
 
418 404
     @Override

+ 6
- 16
src/com/dmdirc/addons/ui_swing/framemanager/tree/NodeLabel.java 查看文件

@@ -29,8 +29,8 @@ import com.dmdirc.addons.ui_swing.components.ImageButton;
29 29
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
30 30
 import com.dmdirc.events.FrameIconChangedEvent;
31 31
 import com.dmdirc.events.FrameNameChangedEvent;
32
-import com.dmdirc.interfaces.NotificationListener;
33
-import com.dmdirc.ui.Colour;
32
+import com.dmdirc.events.NotificationClearedEvent;
33
+import com.dmdirc.events.NotificationSetEvent;
34 34
 import com.dmdirc.ui.messages.Styliser;
35 35
 
36 36
 import java.awt.Color;
@@ -49,8 +49,7 @@ import net.engio.mbassy.listener.Handler;
49 49
 /**
50 50
  * Node label.
51 51
  */
52
-public class NodeLabel extends JPanel implements SelectionListener,
53
-        NotificationListener {
52
+public class NodeLabel extends JPanel implements SelectionListener {
54 53
 
55 54
     /** A version number for this class. */
56 55
     private static final long serialVersionUID = 1;
@@ -75,8 +74,6 @@ public class NodeLabel extends JPanel implements SelectionListener,
75 74
      * @param window Window for this node
76 75
      */
77 76
     public NodeLabel(final FrameContainer window) {
78
-        super();
79
-
80 77
         this.window = window;
81 78
 
82 79
         init();
@@ -109,19 +106,12 @@ public class NodeLabel extends JPanel implements SelectionListener,
109 106
         selected = equals(window.getContainer());
110 107
     }
111 108
 
112
-    @Override
113
-    public void notificationSet(final FrameContainer window,
114
-            final Colour colour) {
115
-        if (equals(window)) {
116
-            notificationColour = UIUtilities.convertColour(colour);
117
-        }
109
+    public void notificationSet(final NotificationSetEvent event) {
110
+            notificationColour = UIUtilities.convertColour(event.getColour());
118 111
     }
119 112
 
120
-    @Override
121
-    public void notificationCleared(final FrameContainer window) {
122
-        if (equals(window)) {
113
+    public void notificationCleared(final NotificationClearedEvent event) {
123 114
             notificationColour = null;
124
-        }
125 115
     }
126 116
 
127 117
     @Handler

+ 18
- 29
src/com/dmdirc/addons/ui_swing/framemanager/tree/TreeFrameManager.java 查看文件

@@ -25,6 +25,7 @@ package com.dmdirc.addons.ui_swing.framemanager.tree;
25 25
 import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.DMDircMBassador;
27 27
 import com.dmdirc.FrameContainer;
28
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
28 29
 import com.dmdirc.addons.ui_swing.SwingController;
29 30
 import com.dmdirc.addons.ui_swing.SwingWindowFactory;
30 31
 import com.dmdirc.addons.ui_swing.UIUtilities;
@@ -36,8 +37,9 @@ import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
36 37
 import com.dmdirc.addons.ui_swing.injection.SwingEventBus;
37 38
 import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
38 39
 import com.dmdirc.events.FrameIconChangedEvent;
40
+import com.dmdirc.events.NotificationClearedEvent;
41
+import com.dmdirc.events.NotificationSetEvent;
39 42
 import com.dmdirc.events.UserErrorEvent;
40
-import com.dmdirc.interfaces.NotificationListener;
41 43
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
42 44
 import com.dmdirc.interfaces.config.ConfigChangeListener;
43 45
 import com.dmdirc.logger.ErrorLevel;
@@ -67,12 +69,12 @@ import javax.swing.tree.TreePath;
67 69
 import net.miginfocom.swing.MigLayout;
68 70
 
69 71
 import net.engio.mbassy.listener.Handler;
72
+import net.engio.mbassy.listener.Invoke;
70 73
 
71 74
 /**
72 75
  * Manages open windows in the application in a tree style view.
73 76
  */
74
-public class TreeFrameManager implements FrameManager, Serializable, ConfigChangeListener,
75
-        NotificationListener {
77
+public class TreeFrameManager implements FrameManager, Serializable, ConfigChangeListener {
76 78
 
77 79
     /** Serial version UID. */
78 80
     private static final long serialVersionUID = 5;
@@ -178,6 +180,7 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
178 180
 
179 181
                 setColours();
180 182
 
183
+                eventBus.subscribe(TreeFrameManager.this);
181 184
                 swingEventBus.subscribe(TreeFrameManager.this);
182 185
                 redoTreeView();
183 186
             }
@@ -220,8 +223,6 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
220 223
                     eventBus.unsubscribe(nodes.get(window.getContainer()).getLabel());
221 224
                     nodes.remove(window.getContainer());
222 225
                 }
223
-                window.getContainer().removeNotificationListener(
224
-                        TreeFrameManager.this);
225 226
             }
226 227
         });
227 228
     }
@@ -256,10 +257,10 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
256 257
                     tree.scrollRectToVisible(new Rectangle(0, (int) view.getY(),
257 258
                             0, 0));
258 259
                 }
259
-                window.addNotificationListener(TreeFrameManager.this);
260 260
 
261 261
                 // TODO: Should this colour be configurable?
262
-                node.getLabel().notificationSet(window, window.getNotification().or(Colour.BLACK));
262
+                node.getLabel().notificationSet(new NotificationSetEvent(window,
263
+                        window.getNotification().or(Colour.BLACK)));
263 264
                 node.getLabel().iconChanged(new FrameIconChangedEvent(window, window.getIcon()));
264 265
             }
265 266
         });
@@ -378,44 +379,32 @@ public class TreeFrameManager implements FrameManager, Serializable, ConfigChang
378 379
         }
379 380
     }
380 381
 
381
-    @Override
382
-    public void notificationSet(final FrameContainer window, final Colour colour) {
383
-        SwingUtilities.invokeLater(new Runnable() {
384
-
385
-            @Override
386
-            public void run() {
382
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
383
+    public void notificationSet(final NotificationSetEvent event) {
387 384
                 synchronized (nodes) {
388
-                    final TreeViewNode node = nodes.get(window);
389
-                    if (window != null && node != null) {
385
+                    final TreeViewNode node = nodes.get(event.getWindow());
386
+                    if (event.getWindow() != null && node != null) {
390 387
                         final NodeLabel label = node.getLabel();
391 388
                         if (label != null) {
392
-                            label.notificationSet(window, colour);
389
+                            label.notificationSet(event);
393 390
                             tree.repaint();
394 391
                         }
395 392
                     }
396 393
                 }
397
-            }
398
-        });
399 394
     }
400 395
 
401
-    @Override
402
-    public void notificationCleared(final FrameContainer window) {
403
-        SwingUtilities.invokeLater(new Runnable() {
404
-
405
-            @Override
406
-            public void run() {
396
+    @Handler(invocation = EdtHandlerInvocation.class, delivery = Invoke.Asynchronously)
397
+    public void notificationCleared(final NotificationClearedEvent event) {
407 398
                 synchronized (nodes) {
408
-                    final TreeViewNode node = nodes.get(window);
409
-                    if (window != null && node != null) {
399
+                    final TreeViewNode node = nodes.get(event.getWindow());
400
+                    if (event.getWindow() != null && node != null) {
410 401
                         final NodeLabel label = node.getLabel();
411 402
                         if (label != null) {
412
-                            label.notificationCleared(window);
403
+                            label.notificationCleared(event);
413 404
                             tree.repaint();
414 405
                         }
415 406
                     }
416 407
                 }
417
-            }
418
-        });
419 408
     }
420 409
 
421 410
 }

正在加载...
取消
保存