Переглянути джерело

Add concept of Displayable events.

These are events which are going to cause a line to be added to a
client window. They allow actions, plugins, or other listeners
to change the formatter line.

Eventually the UI model will just be able to listen for displayable
events on the local event bus to figure out what needs to be displayed.

Change-Id: Ia86c593df66f8bff13574714c45464a2634c02ba
Reviewed-on: http://gerrit.dmdirc.com/3390
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 роки тому
джерело
коміт
b08519cf63

+ 9
- 8
src/com/dmdirc/ChannelEventHandler.java Переглянути файл

@@ -26,6 +26,7 @@ import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27 27
 import com.dmdirc.events.ChannelUserAwayEvent;
28 28
 import com.dmdirc.events.ChannelUserBackEvent;
29
+import com.dmdirc.events.DisplayableEvent;
29 30
 import com.dmdirc.interfaces.Connection;
30 31
 import com.dmdirc.interfaces.actions.ActionType;
31 32
 import com.dmdirc.parser.common.AwayState;
@@ -315,14 +316,14 @@ public class ChannelEventHandler extends EventHandler implements
315 316
             final boolean away = state == AwayState.AWAY;
316 317
             final boolean discovered = oldState == AwayState.UNKNOWN;
317 318
 
318
-            // TODO: The events should take a formatter.
319
-            owner.doNotification(date, (away ? "channelUserAway" : "channelUserBack")
320
-                    + (discovered ? "Discovered" : ""), channelClient);
321
-            if (away) {
322
-                eventBus.post(new ChannelUserAwayEvent(owner, channelClient));
323
-            } else {
324
-                eventBus.post(new ChannelUserBackEvent(owner, channelClient));
325
-            }
319
+            final DisplayableEvent event = away
320
+                    ? new ChannelUserAwayEvent(date.getTime(), owner, channelClient)
321
+                    : new ChannelUserBackEvent(date.getTime(), owner, channelClient);
322
+            event.setDisplayFormat((away ? "channelUserAway" : "channelUserBack")
323
+                    + (discovered ? "Discovered" : ""));
324
+            eventBus.post(event);
325
+            owner.doNotification(date, event.getDisplayFormat(), channelClient);
326
+
326 327
         }
327 328
     }
328 329
 

+ 13
- 1
src/com/dmdirc/actions/ActionManager.java Переглянути файл

@@ -28,6 +28,7 @@ import com.dmdirc.actions.internal.WhoisNumericFormatter;
28 28
 import com.dmdirc.config.ConfigBinding;
29 29
 import com.dmdirc.events.ClientClosedEvent;
30 30
 import com.dmdirc.events.DMDircEvent;
31
+import com.dmdirc.events.DisplayableEvent;
31 32
 import com.dmdirc.interfaces.ActionController;
32 33
 import com.dmdirc.interfaces.ActionListener;
33 34
 import com.dmdirc.interfaces.actions.ActionComparison;
@@ -457,7 +458,18 @@ public class ActionManager implements ActionController {
457 458
         final Class[] argTypes = type.getType().getArgTypes();
458 459
         final Object[] arguments = getLegacyArguments(event, argTypes);
459 460
 
460
-        triggerEvent(type, null, arguments);
461
+        final StringBuffer buffer;
462
+        if (event instanceof DisplayableEvent) {
463
+            buffer = new StringBuffer(((DisplayableEvent) event).getDisplayFormat());
464
+        } else {
465
+            buffer = null;
466
+        }
467
+
468
+        triggerEvent(type, buffer, arguments);
469
+
470
+        if (event instanceof DisplayableEvent) {
471
+            ((DisplayableEvent) event).setDisplayFormat(buffer.toString());
472
+        }
461 473
     }
462 474
 
463 475
     /**

+ 15
- 1
src/com/dmdirc/events/ChannelEvent.java Переглянути файл

@@ -24,15 +24,19 @@ package com.dmdirc.events;
24 24
 
25 25
 import com.dmdirc.Channel;
26 26
 
27
+import java.util.concurrent.atomic.AtomicReference;
28
+
27 29
 import static com.google.common.base.Preconditions.checkNotNull;
28 30
 
29 31
 /**
30 32
  * Base type for events that occur in channels.
31 33
  */
32
-public abstract class ChannelEvent extends DMDircEvent {
34
+public abstract class ChannelEvent extends DMDircEvent implements DisplayableEvent {
33 35
 
34 36
     /** The channel that this event occurred on. */
35 37
     private final Channel channel;
38
+    /** The display format to use for this event. */
39
+    private final AtomicReference<String> displayFormatRef = new AtomicReference<>("");
36 40
 
37 41
     public ChannelEvent(final long timestamp, final Channel channel) {
38 42
         super(timestamp);
@@ -47,4 +51,14 @@ public abstract class ChannelEvent extends DMDircEvent {
47 51
         return channel;
48 52
     }
49 53
 
54
+    @Override
55
+    public String getDisplayFormat() {
56
+        return displayFormatRef.get();
57
+    }
58
+
59
+    @Override
60
+    public void setDisplayFormat(String format) {
61
+        this.displayFormatRef.set(format);
62
+    }
63
+
50 64
 }

+ 44
- 0
src/com/dmdirc/events/DisplayableEvent.java Переглянути файл

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
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.events;
24
+
25
+/**
26
+ * Describes an event which is rendered in the client to the user.
27
+ */
28
+public interface DisplayableEvent {
29
+
30
+    /**
31
+     * Gets the format name that will be used to display the event.
32
+     *
33
+     * @return The format name to use for the event.
34
+     */
35
+    String getDisplayFormat();
36
+
37
+    /**
38
+     * Sets the format name that should be used to display the event.
39
+     *
40
+     * @param format The format name to use for the event.
41
+     */
42
+    void setDisplayFormat(String format);
43
+
44
+}

Завантаження…
Відмінити
Зберегти