|
@@ -24,12 +24,15 @@ package com.dmdirc.addons.osd;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.config.IdentityManager;
|
26
|
26
|
import java.util.ArrayList;
|
|
27
|
+import java.util.LinkedList;
|
27
|
28
|
import java.util.List;
|
|
29
|
+import java.util.Queue;
|
28
|
30
|
|
29
|
31
|
/**
|
30
|
32
|
* Class to manage OSD Windows.
|
31
|
33
|
*
|
32
|
34
|
* @author Simon
|
|
35
|
+ * @since 0.6.3
|
33
|
36
|
*/
|
34
|
37
|
public class OsdManager {
|
35
|
38
|
|
|
@@ -37,7 +40,10 @@ public class OsdManager {
|
37
|
40
|
private final OsdPlugin plugin;
|
38
|
41
|
|
39
|
42
|
/** List of OSD Windows. */
|
40
|
|
- private List<OsdWindow> windowList = new ArrayList<OsdWindow>();
|
|
43
|
+ private final List<OsdWindow> windowList = new ArrayList<OsdWindow>();
|
|
44
|
+
|
|
45
|
+ /** List of messages to be queued. */
|
|
46
|
+ private final Queue<String> windowQueue = new LinkedList<String>();
|
41
|
47
|
|
42
|
48
|
/** The spacing between the windows. */
|
43
|
49
|
private static final int WINDOW_GAP = 5;
|
|
@@ -45,15 +51,43 @@ public class OsdManager {
|
45
|
51
|
/**
|
46
|
52
|
* Create a new OSD Manager.
|
47
|
53
|
*
|
48
|
|
- * @param plugin The plugin that owns this OSD Manager
|
|
54
|
+ * @param plugin The plugin that owns this OSD Manager.
|
49
|
55
|
*/
|
50
|
56
|
public OsdManager(final OsdPlugin plugin) {
|
51
|
|
- //Constructor
|
52
|
57
|
this.plugin = plugin;
|
53
|
58
|
}
|
54
|
59
|
|
55
|
|
- public void createOSDWindow(final String title, final String message) {
|
56
|
|
- //Check some form of queue.
|
|
60
|
+ /**
|
|
61
|
+ * Add messages to the queue and call displayWindows.
|
|
62
|
+ *
|
|
63
|
+ * @param message Message to be displayed.
|
|
64
|
+ */
|
|
65
|
+ public void showWindow(final String message) {
|
|
66
|
+ windowQueue.add(message);
|
|
67
|
+ displayWindows();
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ /**
|
|
71
|
+ * Displays as many windows as appropriate.
|
|
72
|
+ */
|
|
73
|
+ private synchronized void displayWindows() {
|
|
74
|
+ final Integer maxWindows = IdentityManager.getGlobalConfig().getOptionInt(
|
|
75
|
+ plugin.getDomain(), "maxWindows");
|
|
76
|
+
|
|
77
|
+ String nextItem;
|
|
78
|
+
|
|
79
|
+ while ((maxWindows == null || getWindowCount() < maxWindows)
|
|
80
|
+ && (nextItem = windowQueue.poll()) != null) {
|
|
81
|
+ displayWindow(nextItem);
|
|
82
|
+ }
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ /**
|
|
86
|
+ * Create a new OSD window with "message".
|
|
87
|
+ *
|
|
88
|
+ * @param message Text to display in the OSD window.
|
|
89
|
+ */
|
|
90
|
+ private void displayWindow(final String message) {
|
57
|
91
|
OsdWindow currentWindow = new OsdWindow(message, false,
|
58
|
92
|
IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
|
59
|
93
|
"locationX"), getYPosition(), plugin, this);
|
|
@@ -62,29 +96,32 @@ public class OsdManager {
|
62
|
96
|
}
|
63
|
97
|
|
64
|
98
|
/**
|
65
|
|
- * Destroy the given OSD Window.
|
|
99
|
+ * Destroy the given OSD Window and check if the Queue has items, if so
|
|
100
|
+ * Display them.
|
66
|
101
|
*
|
67
|
102
|
* @param window The window that we are destroying.
|
68
|
103
|
*/
|
69
|
|
- public void destroyOSDWindow(OsdWindow window) {
|
|
104
|
+ public void closeWindow(final OsdWindow window) {
|
70
|
105
|
windowList.remove(window);
|
71
|
106
|
window.dispose();
|
|
107
|
+
|
|
108
|
+ displayWindows();
|
72
|
109
|
}
|
73
|
110
|
|
74
|
111
|
/**
|
75
|
|
- * Destropy all OSD Windows
|
|
112
|
+ * Destroy all OSD Windows.
|
76
|
113
|
*/
|
77
|
|
- public void destroyAllOSDWindows() {
|
|
114
|
+ public void closeAll() {
|
78
|
115
|
for (OsdWindow window : new ArrayList<OsdWindow>(windowList)) {
|
79
|
116
|
window.setVisible(false);
|
80
|
|
- destroyOSDWindow(window);
|
|
117
|
+ closeWindow(window);
|
81
|
118
|
}
|
82
|
119
|
}
|
83
|
120
|
|
84
|
121
|
/**
|
85
|
122
|
* Get the list of current OSDWindows.
|
86
|
123
|
*
|
87
|
|
- * @return a List of all currently open OSDWindows
|
|
124
|
+ * @return a List of all currently open OSDWindows.
|
88
|
125
|
*/
|
89
|
126
|
public List<OsdWindow> getWindowList() {
|
90
|
127
|
return new ArrayList<OsdWindow>(windowList);
|
|
@@ -105,8 +142,8 @@ public class OsdManager {
|
105
|
142
|
* @return the Y position for the next window.
|
106
|
143
|
*/
|
107
|
144
|
public int getYPosition() {
|
108
|
|
- final String policy = IdentityManager.getGlobalConfig()
|
109
|
|
- .getOption(plugin.getDomain(), "newbehaviour");
|
|
145
|
+ final String policy = IdentityManager.getGlobalConfig().getOption(
|
|
146
|
+ plugin.getDomain(), "newbehaviour");
|
110
|
147
|
int y = IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
|
111
|
148
|
"locationY");
|
112
|
149
|
|
|
@@ -126,7 +163,7 @@ public class OsdManager {
|
126
|
163
|
}
|
127
|
164
|
} else if ("close".equals(policy)) {
|
128
|
165
|
// Close existing windows and use their place
|
129
|
|
- destroyAllOSDWindows();
|
|
166
|
+ closeAll();
|
130
|
167
|
}
|
131
|
168
|
|
132
|
169
|
return y;
|