Sfoglia il codice sorgente

Add a base class for events with a WindowModel source.

For #662, it makes sense to have a standard way to
get the source from events we may wish to filter.

This introduces a SourcedEvent interface, and adapts classes
to use it.
pull/663/head
Chris Smith 8 anni fa
parent
commit
8cd93c8c7e

+ 1
- 1
src/com/dmdirc/Server.java Vedi File

@@ -705,7 +705,7 @@ public class Server implements Connection {
705 705
 
706 706
     @Handler
707 707
     private void handleClose(final FrameClosingEvent event) {
708
-        if (event.getContainer() == windowModel) {
708
+        if (event.getSource() == windowModel) {
709 709
             synchronized (myStateLock) {
710 710
                 eventHandler.unregisterCallbacks();
711 711
                 windowModel.getConfigManager().removeListener(configListener);

+ 2
- 2
src/com/dmdirc/ServerManager.java Vedi File

@@ -222,8 +222,8 @@ public class ServerManager implements ConnectionManager {
222 222
 
223 223
     @Handler
224 224
     void handleWindowClosing(final FrameClosingEvent event) {
225
-        if (event.getContainer() instanceof Server) {
226
-            unregisterServer((Server) event.getContainer());
225
+        if (event.getSource() instanceof Server) {
226
+            unregisterServer((Server) event.getSource());
227 227
         }
228 228
     }
229 229
 

+ 1
- 8
src/com/dmdirc/events/DisplayableEvent.java Vedi File

@@ -22,15 +22,13 @@
22 22
 
23 23
 package com.dmdirc.events;
24 24
 
25
-import com.dmdirc.interfaces.WindowModel;
26
-
27 25
 import java.time.LocalDateTime;
28 26
 import java.util.Optional;
29 27
 
30 28
 /**
31 29
  * Describes an event which is rendered in the client to the user.
32 30
  */
33
-public interface DisplayableEvent {
31
+public interface DisplayableEvent extends SourcedEvent {
34 32
 
35 33
     /**
36 34
      * Sets a property relating to how this event should be displayed.
@@ -78,9 +76,4 @@ public interface DisplayableEvent {
78 76
      */
79 77
     LocalDateTime getTimestamp();
80 78
 
81
-    /**
82
-     * Gets the source of the displayable event.
83
-     */
84
-    WindowModel getSource();
85
-
86 79
 }

+ 8
- 6
src/com/dmdirc/events/FrameEvent.java Vedi File

@@ -27,15 +27,17 @@ import com.dmdirc.interfaces.WindowModel;
27 27
 /**
28 28
  * Base class for window related events in the client.
29 29
  */
30
-public abstract class FrameEvent extends DMDircEvent {
30
+public abstract class FrameEvent extends DMDircEvent implements SourcedEvent {
31 31
 
32
-    private final WindowModel container;
32
+    private final WindowModel source;
33 33
 
34
-    public FrameEvent(final WindowModel container) {
35
-        this.container = container;
34
+    public FrameEvent(final WindowModel source) {
35
+        this.source = source;
36 36
     }
37 37
 
38
-    public WindowModel getContainer() {
39
-        return container;
38
+    @Override
39
+    public WindowModel getSource() {
40
+        return source;
40 41
     }
42
+
41 43
 }

+ 37
- 0
src/com/dmdirc/events/SourcedEvent.java Vedi File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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
+import com.dmdirc.interfaces.WindowModel;
26
+
27
+/**
28
+ * An event that is attached to a {@link WindowModel} source.
29
+ */
30
+public interface SourcedEvent {
31
+
32
+    /**
33
+     * Gets the source of the event.
34
+     */
35
+    WindowModel getSource();
36
+
37
+}

+ 2
- 1
src/com/dmdirc/events/UnreadStatusChangedEvent.java Vedi File

@@ -31,7 +31,7 @@ import java.util.Optional;
31 31
 /**
32 32
  * Event raised when the unread status of a window has changed.
33 33
  */
34
-public class UnreadStatusChangedEvent extends DMDircEvent {
34
+public class UnreadStatusChangedEvent extends DMDircEvent implements SourcedEvent {
35 35
 
36 36
     private final WindowModel source;
37 37
     private final UnreadStatusManager manager;
@@ -46,6 +46,7 @@ public class UnreadStatusChangedEvent extends DMDircEvent {
46 46
         this.unreadCount = unreadCount;
47 47
     }
48 48
 
49
+    @Override
49 50
     public WindowModel getSource() {
50 51
         return source;
51 52
     }

+ 1
- 1
src/com/dmdirc/ui/WindowManager.java Vedi File

@@ -411,7 +411,7 @@ public class WindowManager {
411 411
 
412 412
     @Handler
413 413
     public void frameClosing(final FrameClosingEvent event) {
414
-        removeWindow(event.getContainer());
414
+        removeWindow(event.getSource());
415 415
     }
416 416
 
417 417
 }

+ 1
- 1
src/com/dmdirc/ui/input/InputHandler.java Vedi File

@@ -675,7 +675,7 @@ public abstract class InputHandler implements ConfigChangeListener {
675 675
 
676 676
     @Handler
677 677
     void parentClosing(final FrameClosingEvent event) {
678
-        if (event.getContainer().equals(parentWindow)) {
678
+        if (event.getSource().equals(parentWindow)) {
679 679
             executorService.shutdown();
680 680
             eventBus.unsubscribe(this);
681 681
         }

Loading…
Annulla
Salva