瀏覽代碼

Add channel topic listeners

Change-Id: Id72f5f4ca191592ff0b04883e62de2263b3ebbdc
Reviewed-on: http://gerrit.dmdirc.com/656
Automatic-Compile: Gregory Holmes <greg@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 年之前
父節點
當前提交
0c74703169
共有 2 個檔案被更改,包括 121 行新增33 行删除
  1. 76
    33
      src/com/dmdirc/Channel.java
  2. 45
    0
      src/com/dmdirc/interfaces/TopicChangeListener.java

+ 76
- 33
src/com/dmdirc/Channel.java 查看文件

@@ -28,6 +28,7 @@ import com.dmdirc.commandparser.CommandManager;
28 28
 import com.dmdirc.commandparser.CommandType;
29 29
 import com.dmdirc.config.ConfigManager;
30 30
 import com.dmdirc.interfaces.ConfigChangeListener;
31
+import com.dmdirc.interfaces.TopicChangeListener;
31 32
 import com.dmdirc.parser.interfaces.ChannelClientInfo;
32 33
 import com.dmdirc.parser.interfaces.ChannelInfo;
33 34
 import com.dmdirc.parser.interfaces.ClientInfo;
@@ -461,39 +462,6 @@ public class Channel extends MessageTarget implements ConfigChangeListener,
461 462
         }
462 463
     }
463 464
 
464
-    /**
465
-     * Adds the specified topic to this channel's topic list.
466
-     *
467
-     * @param topic The topic to be added.
468
-     */
469
-    public void addTopic(final Topic topic) {
470
-        topics.add(topic);
471
-        updateTitle();
472
-    }
473
-
474
-    /**
475
-     * Retrieve the topics that have been seen on this channel.
476
-     *
477
-     * @return A list of topics that have been seen on this channel, including
478
-     * the current one.
479
-     */
480
-    public List<Topic> getTopics() {
481
-        return topics.getList();
482
-    }
483
-
484
-    /**
485
-     * Returns the current topic for this channel.
486
-     * 
487
-     * @return Current channel topic
488
-     */
489
-    public Topic getCurrentTopic() {
490
-        if (channelInfo.getTopic().isEmpty()) {
491
-            return null;
492
-        }
493
-        return new Topic(channelInfo.getTopic(), channelInfo.getTopicSetter(),
494
-                channelInfo.getTopicTime());
495
-    }
496
-
497 465
     /** {@inheritDoc} */
498 466
     @Override
499 467
     public void configChanged(final String domain, final String key) {
@@ -592,6 +560,71 @@ public class Channel extends MessageTarget implements ConfigChangeListener,
592 560
         messageArgs.add(channelInfo.getName());
593 561
     }
594 562
 
563
+    // ---------------------------------------------------- TOPIC HANDLING -----
564
+
565
+    /**
566
+     * Adds the specified topic to this channel's topic list.
567
+     *
568
+     * @param topic The topic to be added.
569
+     */
570
+    public void addTopic(final Topic topic) {
571
+        topics.add(topic);
572
+        updateTitle();
573
+
574
+        synchronized (listeners) {
575
+            for (TopicChangeListener listener : listeners.get(TopicChangeListener.class)) {
576
+                listener.topicChanged(this, topic);
577
+            }
578
+        }
579
+    }
580
+
581
+    /**
582
+     * Retrieve the topics that have been seen on this channel.
583
+     *
584
+     * @return A list of topics that have been seen on this channel, including
585
+     * the current one.
586
+     */
587
+    public List<Topic> getTopics() {
588
+        return topics.getList();
589
+    }
590
+
591
+    /**
592
+     * Returns the current topic for this channel.
593
+     *
594
+     * @return Current channel topic
595
+     */
596
+    public Topic getCurrentTopic() {
597
+        if (channelInfo.getTopic().isEmpty()) {
598
+            return null;
599
+        }
600
+        return new Topic(channelInfo.getTopic(), channelInfo.getTopicSetter(),
601
+                channelInfo.getTopicTime());
602
+    }
603
+
604
+    /**
605
+     * Adds a new topic change listener to this channel.
606
+     *
607
+     * @param listener The listener to be added
608
+     * @since 0.6.3
609
+     */
610
+    public void addTopicChangeListener(final TopicChangeListener listener) {
611
+        synchronized (listeners) {
612
+            listeners.add(TopicChangeListener.class, listener);
613
+        }
614
+    }
615
+
616
+    /**
617
+     * Removes an existing topic change listener from this channel.
618
+     *
619
+     * @param listener The listener to be removed
620
+     * @since 0.6.3
621
+     */
622
+    public void removeTopicChangeListener(final TopicChangeListener listener) {
623
+        synchronized (listeners) {
624
+            listeners.remove(TopicChangeListener.class, listener);
625
+        }
626
+    }
627
+
595 628
     // ------------------------------------------ PARSER METHOD DELEGATION -----
596 629
 
597 630
     /**
@@ -603,4 +636,14 @@ public class Channel extends MessageTarget implements ConfigChangeListener,
603 636
     public void setTopic(final String topic) {
604 637
         channelInfo.setTopic(topic);
605 638
     }
639
+
640
+    /**
641
+     * Retrieves the maximum length that a topic on this channel can be.
642
+     *
643
+     * @return The maximum length that this channel's topic may be
644
+     * @since 0.6.3
645
+     */
646
+    public int getMaxTopicLength() {
647
+        return server.getParser().getMaxTopicLength();
648
+    }
606 649
 }

+ 45
- 0
src/com/dmdirc/interfaces/TopicChangeListener.java 查看文件

@@ -0,0 +1,45 @@
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.Channel;
26
+import com.dmdirc.Topic;
27
+
28
+/**
29
+ * An interface for objects interested in receiving topic change events from
30
+ * a {@link Channel}.
31
+ *
32
+ * @since 0.6.3
33
+ * @author chris
34
+ */
35
+public interface TopicChangeListener {
36
+
37
+    /**
38
+     * Called whenever a topic is changed.
39
+     *
40
+     * @param channel The channel whose topic has been changed
41
+     * @param topic The new topic of the channel
42
+     */
43
+    void topicChanged(final Channel channel, final Topic topic);
44
+
45
+}

Loading…
取消
儲存