Selaa lähdekoodia

Use listeners for nicklist updates

Fixes CLIENT-81

Change-Id: I212bbe435df34981d3cde17a2d042f3662bec6c3
Reviewed-on: http://gerrit.dmdirc.com/1624
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.5b1
Chris Smith 13 vuotta sitten
vanhempi
commit
2a2355a537

+ 31
- 10
src/com/dmdirc/Channel.java Näytä tiedosto

@@ -29,6 +29,7 @@ import com.dmdirc.commandparser.CommandType;
29 29
 import com.dmdirc.commandparser.parsers.ChannelCommandParser;
30 30
 import com.dmdirc.config.ConfigManager;
31 31
 import com.dmdirc.interfaces.ConfigChangeListener;
32
+import com.dmdirc.interfaces.NicklistListener;
32 33
 import com.dmdirc.interfaces.TopicChangeListener;
33 34
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
34 35
 import com.dmdirc.parser.interfaces.ChannelInfo;
@@ -319,8 +320,8 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
319 320
 
320 321
         setIcon("channel-inactive");
321 322
 
322
-        for (ChannelWindow window : getWindows()) {
323
-            window.updateNames(new ArrayList<ChannelClientInfo>());
323
+        for (NicklistListener listener : listeners.get(NicklistListener.class)) {
324
+            listener.clientListUpdated(new ArrayList<ChannelClientInfo>());
324 325
         }
325 326
     }
326 327
 
@@ -365,14 +366,34 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
365 366
         }
366 367
     }
367 368
 
369
+    /**
370
+     * Registers a new nicklist listener for this channel.
371
+     *
372
+     * @since 0.6.5
373
+     * @param listener The listener to be added
374
+     */
375
+    public void addNicklistListener(final NicklistListener listener) {
376
+        listeners.add(NicklistListener.class, listener);
377
+    }
378
+
379
+    /**
380
+     * Removes the specified nicklist listener from this channel.
381
+     *
382
+     * @since 0.6.5
383
+     * @param listener The listener to be removed
384
+     */
385
+    public void removeNicklistListener(final NicklistListener listener) {
386
+        listeners.remove(NicklistListener.class, listener);
387
+    }
388
+
368 389
     /**
369 390
      * Adds a ChannelClient to this Channel.
370 391
      *
371 392
      * @param client The client to be added
372 393
      */
373 394
     public void addClient(final ChannelClientInfo client) {
374
-        for (ChannelWindow window : getWindows()) {
375
-            window.addName(client);
395
+        for (NicklistListener listener : listeners.get(NicklistListener.class)) {
396
+            listener.clientAdded(client);
376 397
         }
377 398
 
378 399
         tabCompleter.addEntry(TabCompletionType.CHANNEL_NICK, client.getClient().getNickname());
@@ -384,8 +405,8 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
384 405
      * @param client The client to be removed
385 406
      */
386 407
     public void removeClient(final ChannelClientInfo client) {
387
-        for (ChannelWindow window : getWindows()) {
388
-            window.removeName(client);
408
+        for (NicklistListener listener : listeners.get(NicklistListener.class)) {
409
+            listener.clientRemoved(client);
389 410
         }
390 411
 
391 412
         tabCompleter.removeEntry(TabCompletionType.CHANNEL_NICK, client.getClient().getNickname());
@@ -402,8 +423,8 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
402 423
      * @param clients The list of clients to use
403 424
      */
404 425
     public void setClients(final Collection<ChannelClientInfo> clients) {
405
-        for (ChannelWindow window : getWindows()) {
406
-            window.updateNames(clients);
426
+        for (NicklistListener listener : listeners.get(NicklistListener.class)) {
427
+            listener.clientListUpdated(clients);
407 428
         }
408 429
 
409 430
         tabCompleter.clear(TabCompletionType.CHANNEL_NICK);
@@ -434,8 +455,8 @@ public class Channel extends MessageTarget<ChannelWindow> implements ConfigChang
434 455
             return;
435 456
         }
436 457
 
437
-        for (ChannelWindow window : getWindows()) {
438
-            window.updateNames();
458
+        for (NicklistListener listener : listeners.get(NicklistListener.class)) {
459
+            listener.clientListUpdated();
439 460
         }
440 461
     }
441 462
 

+ 2
- 6
src/com/dmdirc/commandparser/commands/channel/SetNickColour.java Näytä tiedosto

@@ -93,9 +93,7 @@ public final class SetNickColour extends Command implements IntelligentCommand,
93 93
                 target.getMap().remove(ChannelClientProperty.TEXT_FOREGROUND);
94 94
             }
95 95
 
96
-            for (ChannelWindow window : channel.getWindows()) {
97
-                window.redrawNicklist();
98
-            }
96
+            channel.refreshClients();
99 97
         } else {
100 98
             // We're setting the colour
101 99
             final Color newColour = ColourManager.parseColour(args.getArguments()[offset], null);
@@ -112,9 +110,7 @@ public final class SetNickColour extends Command implements IntelligentCommand,
112 110
                 target.getMap().put(ChannelClientProperty.TEXT_FOREGROUND, newColour);
113 111
             }
114 112
 
115
-            for (ChannelWindow window : channel.getWindows()) {
116
-                window.redrawNicklist();
117
-            }
113
+            channel.refreshClients();
118 114
         }
119 115
     }
120 116
 

+ 67
- 0
src/com/dmdirc/interfaces/NicklistListener.java Näytä tiedosto

@@ -0,0 +1,67 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.interfaces;
24
+
25
+import com.dmdirc.parser.interfaces.ChannelClientInfo;
26
+import java.util.Collection;
27
+
28
+/**
29
+ * Interface for objects interested in receiving updates pertaining to a
30
+ * channel's list of active users (the 'nicklist').
31
+ *
32
+ * @since 0.6.5
33
+ * @author chris
34
+ */
35
+public interface NicklistListener {
36
+
37
+    /**
38
+     * Called to indicate the client list has been extensively updated,
39
+     * and any cached data should be discarded and replaced with the specified
40
+     * set of clients.
41
+     * 
42
+     * @param clients The new set of clients for the channel
43
+     */
44
+    void clientListUpdated(Collection<ChannelClientInfo> clients);
45
+    
46
+    /**
47
+     * Called to indicate a member of the channel has had their nicklist entry
48
+     * changed in some manner, and their display text, colours, etc, should be
49
+     * re-read from the object.
50
+     */
51
+    void clientListUpdated();
52
+    
53
+    /**
54
+     * Called to indicate a new client has been added to the nicklist
55
+     * 
56
+     * @param client The new client that has been added
57
+     */
58
+    void clientAdded(ChannelClientInfo client);
59
+    
60
+    /**
61
+     * Called to indicate a client has been removed from the nicklist
62
+     * 
63
+     * @param client The client that has been removed
64
+     */
65
+    void clientRemoved(ChannelClientInfo client);
66
+
67
+}

+ 13
- 1
src/com/dmdirc/ui/interfaces/ChannelWindow.java Näytä tiedosto

@@ -23,8 +23,9 @@
23 23
 package com.dmdirc.ui.interfaces;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-
26
+import com.dmdirc.interfaces.NicklistListener;
27 27
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
+
28 29
 import java.util.Collection;
29 30
 
30 31
 /**
@@ -38,27 +39,35 @@ public interface ChannelWindow extends InputWindow {
38 39
      * Updates the channel's name list to the specified list of clients.
39 40
      * 
40 41
      * @param clients The new list of clients for this channel
42
+     * @deprecated Use a {@link NicklistListener}
41 43
      */
44
+    @Deprecated
42 45
     void updateNames(Collection<ChannelClientInfo> clients);
43 46
     
44 47
     /**
45 48
      * Adds the specified client to this channel's name list.
46 49
      * 
47 50
      * @param client The new client to be added
51
+     * @deprecated Use a {@link NicklistListener}
48 52
      */
53
+    @Deprecated
49 54
     void addName(ChannelClientInfo client);
50 55
     
51 56
     /**
52 57
      * Removes the specified client from this channel's name list.
53 58
      * 
54 59
      * @param client The client to be removed
60
+     * @deprecated Use a {@link NicklistListener}
55 61
      */
62
+    @Deprecated
56 63
     void removeName(ChannelClientInfo client);
57 64
     
58 65
     /**
59 66
      * Requests that the channel window updates the displayed list of channel
60 67
      * clients, to take into account mode or nickname changes.
68
+     * @deprecated Use a {@link NicklistListener}
61 69
      */
70
+    @Deprecated
62 71
     void updateNames();
63 72
     
64 73
     /**
@@ -72,7 +81,10 @@ public interface ChannelWindow extends InputWindow {
72 81
     
73 82
     /**
74 83
      * Redraws the nicklist belonging to this channel.
84
+     *
85
+     * @deprecated Use a {@link NicklistListener}
75 86
      */
87
+    @Deprecated
76 88
     void redrawNicklist();
77 89
 
78 90
 }

Loading…
Peruuta
Tallenna