Browse Source

Initial pass at an UnreadStatusManager.

Needs to allow configuring of the colours, and provide events
for notifying the UI.
pull/304/head
Chris Smith 9 years ago
parent
commit
6546a7a3fb
1 changed files with 117 additions and 0 deletions
  1. 117
    0
      src/com/dmdirc/ui/messages/UnreadStatusManager.java

+ 117
- 0
src/com/dmdirc/ui/messages/UnreadStatusManager.java View File

@@ -0,0 +1,117 @@
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.ui.messages;
24
+
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.FrameContainer;
27
+import com.dmdirc.events.BaseChannelTextEvent;
28
+import com.dmdirc.events.BaseQueryTextEvent;
29
+import com.dmdirc.events.ChannelHighlightEvent;
30
+import com.dmdirc.events.DisplayableEvent;
31
+import com.dmdirc.events.QueryHighlightEvent;
32
+import com.dmdirc.util.colours.Colour;
33
+
34
+import java.util.Optional;
35
+
36
+import net.engio.mbassy.listener.Handler;
37
+
38
+/**
39
+ * Tracks unread messages and other notifications.
40
+ */
41
+public class UnreadStatusManager {
42
+
43
+    private final DMDircMBassador eventBus;
44
+    private final FrameContainer container;
45
+    private int unreadLines;
46
+    private Optional<Colour> notificationColour;
47
+
48
+    private Colour miscellaneousColour = Colour.GREEN;
49
+    private Colour messageColour = Colour.BLACK;
50
+    private Colour highlightColour = Colour.RED;
51
+
52
+    public UnreadStatusManager(final FrameContainer container) {
53
+        this.container = container;
54
+        this.eventBus = container.getEventBus();
55
+    }
56
+
57
+    @Handler
58
+    public void handleDisplayableEvent(final DisplayableEvent event) {
59
+        if (event.getSource().equals(container)) {
60
+            unreadLines++;
61
+            raiseNotificationColour(miscellaneousColour);
62
+        }
63
+    }
64
+
65
+    @Handler
66
+    public void handleChannelTextEvent(final BaseChannelTextEvent event) {
67
+        if (event.getSource().equals(container)) {
68
+            raiseNotificationColour(messageColour);
69
+        }
70
+    }
71
+
72
+    @Handler
73
+    public void handleQueryTextEvent(final BaseQueryTextEvent event) {
74
+        if (event.getSource().equals(container)) {
75
+            raiseNotificationColour(messageColour);
76
+        }
77
+    }
78
+
79
+    @Handler
80
+    public void handleChannelHighlightEvent(final ChannelHighlightEvent event) {
81
+        if (event.getCause().getChannel().equals(container)) {
82
+            raiseNotificationColour(highlightColour);
83
+        }
84
+    }
85
+
86
+    @Handler
87
+    public void handleQueryHighlightEvent(final QueryHighlightEvent event) {
88
+        if (event.getCause().getQuery().equals(container)) {
89
+            raiseNotificationColour(highlightColour);
90
+        }
91
+    }
92
+
93
+    public int getUnreadLines() {
94
+        return unreadLines;
95
+    }
96
+
97
+    public Optional<Colour> getNotificationColour() {
98
+        return notificationColour;
99
+    }
100
+
101
+    public void clearStatus() {
102
+        unreadLines = 0;
103
+        notificationColour = Optional.empty();
104
+    }
105
+
106
+    private void raiseNotificationColour(final Colour colour) {
107
+        if (notificationColour.isPresent()) {
108
+            if (notificationColour.get().equals(miscellaneousColour)
109
+                    || colour.equals(highlightColour)) {
110
+                notificationColour = Optional.of(colour);
111
+            }
112
+        } else {
113
+            notificationColour = Optional.of(colour);
114
+        }
115
+    }
116
+
117
+}

Loading…
Cancel
Save