Przeglądaj źródła

Add events for statusbar stuff.

Change-Id: I12e1a5e7b190c0a54da7a9b205c9446ecc5728e5
Reviewed-on: http://gerrit.dmdirc.com/3767
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
pull/1/head
Greg Holmes 9 lat temu
rodzic
commit
62ea1af99e

+ 35
- 0
src/com/dmdirc/events/StatusBarComponentAddedEvent.java Wyświetl plik

@@ -0,0 +1,35 @@
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
+import com.dmdirc.interfaces.ui.StatusBarComponent;
26
+
27
+/**
28
+ * Fired when a component is to be added to a status bar.
29
+ */
30
+public class StatusBarComponentAddedEvent extends StatusBarComponentEvent {
31
+
32
+    public StatusBarComponentAddedEvent(final StatusBarComponent component) {
33
+        super(component);
34
+    }
35
+}

+ 41
- 0
src/com/dmdirc/events/StatusBarComponentEvent.java Wyświetl plik

@@ -0,0 +1,41 @@
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
+import com.dmdirc.interfaces.ui.StatusBarComponent;
26
+
27
+/**
28
+ * Base class for status bar component messages
29
+ */
30
+public abstract class StatusBarComponentEvent extends StatusBarEvent {
31
+
32
+    private final StatusBarComponent component;
33
+
34
+    public StatusBarComponentEvent(final StatusBarComponent component) {
35
+        this.component = component;
36
+    }
37
+
38
+    public StatusBarComponent getComponent() {
39
+        return component;
40
+    }
41
+}

+ 35
- 0
src/com/dmdirc/events/StatusBarComponentRemovedEvent.java Wyświetl plik

@@ -0,0 +1,35 @@
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
+import com.dmdirc.interfaces.ui.StatusBarComponent;
26
+
27
+/**
28
+ * Fired when a component is to be removed from a status bar.
29
+ */
30
+public class StatusBarComponentRemovedEvent extends StatusBarComponentEvent {
31
+
32
+    public StatusBarComponentRemovedEvent(final StatusBarComponent component) {
33
+        super(component);
34
+    }
35
+}

+ 29
- 0
src/com/dmdirc/events/StatusBarEvent.java Wyświetl plik

@@ -0,0 +1,29 @@
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
+ * Base class for all status bar events.
27
+ */
28
+public abstract class StatusBarEvent {
29
+}

+ 29
- 0
src/com/dmdirc/events/StatusBarMessageClearEvent.java Wyświetl plik

@@ -0,0 +1,29 @@
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
+ * Fired to clear the status bar message.
27
+ */
28
+public class StatusBarMessageClearEvent extends StatusBarEvent {
29
+}

+ 41
- 0
src/com/dmdirc/events/StatusBarMessageEvent.java Wyświetl plik

@@ -0,0 +1,41 @@
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
+import com.dmdirc.ui.StatusMessage;
26
+
27
+/**
28
+ * Fired when a status bar message is to be presented to a user.
29
+ */
30
+public class StatusBarMessageEvent extends StatusBarEvent {
31
+
32
+    private final StatusMessage message;
33
+
34
+    public StatusBarMessageEvent(final StatusMessage message) {
35
+        this.message = message;
36
+    }
37
+
38
+    public StatusMessage getMessage() {
39
+        return message;
40
+    }
41
+}

+ 14
- 8
src/com/dmdirc/ui/core/components/StatusBarManager.java Wyświetl plik

@@ -22,6 +22,10 @@
22 22
 
23 23
 package com.dmdirc.ui.core.components;
24 24
 
25
+import com.dmdirc.events.StatusBarComponentAddedEvent;
26
+import com.dmdirc.events.StatusBarComponentRemovedEvent;
27
+import com.dmdirc.events.StatusBarMessageClearEvent;
28
+import com.dmdirc.events.StatusBarMessageEvent;
25 29
 import com.dmdirc.interfaces.ui.StatusBar;
26 30
 import com.dmdirc.interfaces.ui.StatusBarComponent;
27 31
 import com.dmdirc.ui.StatusMessage;
@@ -32,6 +36,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
32 36
 import javax.inject.Inject;
33 37
 import javax.inject.Singleton;
34 38
 
39
+import net.engio.mbassy.bus.MBassador;
40
+
35 41
 /**
36 42
  * A manager for status bars or status bar like components.
37 43
  *
@@ -42,12 +48,12 @@ public class StatusBarManager implements StatusBar {
42 48
 
43 49
     /** A collection of known status bars. */
44 50
     private final Collection<StatusBar> statusBars = new CopyOnWriteArraySet<>();
51
+    /** Event bus to fire status bar events on. */
52
+    private final MBassador eventBus;
45 53
 
46
-    /**
47
-     * Creates a new instance of {@link StatusBarManager}.
48
-     */
49 54
     @Inject
50
-    public StatusBarManager() {
55
+    public StatusBarManager(final MBassador eventBus) {
56
+        this.eventBus = eventBus;
51 57
     }
52 58
 
53 59
     /**
@@ -69,33 +75,33 @@ public class StatusBarManager implements StatusBar {
69 75
         statusBars.remove(statusBar);
70 76
     }
71 77
 
72
-    /** {@inheritDoc} */
73 78
     @Override
74 79
     public void setMessage(final StatusMessage message) {
80
+        eventBus.publishAsync(new StatusBarMessageEvent(message));
75 81
         for (StatusBar statusBar : statusBars) {
76 82
             statusBar.setMessage(message);
77 83
         }
78 84
     }
79 85
 
80
-    /** {@inheritDoc} */
81 86
     @Override
82 87
     public void clearMessage() {
88
+        eventBus.publishAsync(new StatusBarMessageClearEvent());
83 89
         for (StatusBar statusBar : statusBars) {
84 90
             statusBar.clearMessage();
85 91
         }
86 92
     }
87 93
 
88
-    /** {@inheritDoc} */
89 94
     @Override
90 95
     public void addComponent(final StatusBarComponent component) {
96
+        eventBus.publishAsync(new StatusBarComponentAddedEvent(component));
91 97
         for (StatusBar statusBar : statusBars) {
92 98
             statusBar.addComponent(component);
93 99
         }
94 100
     }
95 101
 
96
-    /** {@inheritDoc} */
97 102
     @Override
98 103
     public void removeComponent(final StatusBarComponent component) {
104
+        eventBus.publishAsync(new StatusBarComponentRemovedEvent(component));
99 105
         for (StatusBar statusBar : statusBars) {
100 106
             statusBar.removeComponent(component);
101 107
         }

+ 18
- 7
test/com/dmdirc/ui/core/components/StatusBarManagerTest.java Wyświetl plik

@@ -26,15 +26,26 @@ import com.dmdirc.interfaces.ui.StatusBarComponent;
26 26
 import com.dmdirc.ui.StatusMessage;
27 27
 
28 28
 import org.junit.Test;
29
+import org.junit.runner.RunWith;
30
+import org.mockito.Mock;
31
+import org.mockito.runners.MockitoJUnitRunner;
29 32
 
30
-import static org.mockito.Mockito.*;
33
+import net.engio.mbassy.bus.MBassador;
31 34
 
35
+import static org.mockito.Mockito.mock;
36
+import static org.mockito.Mockito.verify;
37
+import static org.mockito.Mockito.verifyZeroInteractions;
38
+
39
+@RunWith(MockitoJUnitRunner.class)
32 40
 public class StatusBarManagerTest {
33 41
 
42
+    @Mock
43
+    private MBassador eventBus;
44
+
34 45
     @Test
35 46
     public void testRegisterStatusBar() {
36 47
         final StatusBar sb = mock(StatusBar.class);
37
-        StatusBarManager instance = new StatusBarManager();
48
+        StatusBarManager instance = new StatusBarManager(eventBus);
38 49
         instance.registerStatusBar(sb);
39 50
         instance.clearMessage();
40 51
         verify(sb).clearMessage();
@@ -43,7 +54,7 @@ public class StatusBarManagerTest {
43 54
     @Test
44 55
     public void testUnregisterStatusBar() {
45 56
         final StatusBar sb = mock(StatusBar.class);
46
-        StatusBarManager instance = new StatusBarManager();
57
+        StatusBarManager instance = new StatusBarManager(eventBus);
47 58
         instance.registerStatusBar(sb);
48 59
         instance.unregisterStatusBar(sb);
49 60
         instance.clearMessage();
@@ -54,7 +65,7 @@ public class StatusBarManagerTest {
54 65
     public void testSetMessage() {
55 66
         final StatusMessage message = mock(StatusMessage.class);
56 67
         final StatusBar sb = mock(StatusBar.class);
57
-        StatusBarManager instance = new StatusBarManager();
68
+        StatusBarManager instance = new StatusBarManager(eventBus);
58 69
         instance.registerStatusBar(sb);
59 70
         instance.setMessage(message);
60 71
         verify(sb).setMessage(message);
@@ -63,7 +74,7 @@ public class StatusBarManagerTest {
63 74
     @Test
64 75
     public void testClearMessage() {
65 76
         final StatusBar sb = mock(StatusBar.class);
66
-        StatusBarManager instance = new StatusBarManager();
77
+        StatusBarManager instance = new StatusBarManager(eventBus);
67 78
         instance.registerStatusBar(sb);
68 79
         instance.clearMessage();
69 80
         verify(sb).clearMessage();
@@ -73,7 +84,7 @@ public class StatusBarManagerTest {
73 84
     public void testAddComponent() {
74 85
         final StatusBarComponent comp = mock(StatusBarComponent.class);
75 86
         final StatusBar sb = mock(StatusBar.class);
76
-        StatusBarManager instance = new StatusBarManager();
87
+        StatusBarManager instance = new StatusBarManager(eventBus);
77 88
         instance.registerStatusBar(sb);
78 89
         instance.addComponent(comp);
79 90
         verify(sb).addComponent(comp);
@@ -83,7 +94,7 @@ public class StatusBarManagerTest {
83 94
     public void testRemoveComponent() {
84 95
         final StatusBarComponent comp = mock(StatusBarComponent.class);
85 96
         final StatusBar sb = mock(StatusBar.class);
86
-        StatusBarManager instance = new StatusBarManager();
97
+        StatusBarManager instance = new StatusBarManager(eventBus);
87 98
         instance.registerStatusBar(sb);
88 99
         instance.removeComponent(comp);
89 100
         verify(sb).removeComponent(comp);

Ładowanie…
Anuluj
Zapisz