Bläddra i källkod

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 år sedan
förälder
incheckning
8cd93c8c7e

+ 1
- 1
src/com/dmdirc/Server.java Visa fil

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

+ 2
- 2
src/com/dmdirc/ServerManager.java Visa fil

222
 
222
 
223
     @Handler
223
     @Handler
224
     void handleWindowClosing(final FrameClosingEvent event) {
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 Visa fil

22
 
22
 
23
 package com.dmdirc.events;
23
 package com.dmdirc.events;
24
 
24
 
25
-import com.dmdirc.interfaces.WindowModel;
26
-
27
 import java.time.LocalDateTime;
25
 import java.time.LocalDateTime;
28
 import java.util.Optional;
26
 import java.util.Optional;
29
 
27
 
30
 /**
28
 /**
31
  * Describes an event which is rendered in the client to the user.
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
      * Sets a property relating to how this event should be displayed.
34
      * Sets a property relating to how this event should be displayed.
78
      */
76
      */
79
     LocalDateTime getTimestamp();
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 Visa fil

27
 /**
27
 /**
28
  * Base class for window related events in the client.
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 Visa fil

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 Visa fil

31
 /**
31
 /**
32
  * Event raised when the unread status of a window has changed.
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
     private final WindowModel source;
36
     private final WindowModel source;
37
     private final UnreadStatusManager manager;
37
     private final UnreadStatusManager manager;
46
         this.unreadCount = unreadCount;
46
         this.unreadCount = unreadCount;
47
     }
47
     }
48
 
48
 
49
+    @Override
49
     public WindowModel getSource() {
50
     public WindowModel getSource() {
50
         return source;
51
         return source;
51
     }
52
     }

+ 1
- 1
src/com/dmdirc/ui/WindowManager.java Visa fil

411
 
411
 
412
     @Handler
412
     @Handler
413
     public void frameClosing(final FrameClosingEvent event) {
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 Visa fil

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

Laddar…
Avbryt
Spara