|
@@ -22,7 +22,9 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.osd;
|
24
|
24
|
|
|
25
|
+import com.dmdirc.addons.ui_swing.UIUtilities;
|
25
|
26
|
import com.dmdirc.config.IdentityManager;
|
|
27
|
+import com.dmdirc.util.ReturnableThread;
|
26
|
28
|
import java.util.ArrayList;
|
27
|
29
|
import java.util.LinkedList;
|
28
|
30
|
import java.util.List;
|
|
@@ -38,13 +40,10 @@ public class OsdManager {
|
38
|
40
|
|
39
|
41
|
/** The Plugin that owns this OSD Manager. */
|
40
|
42
|
private final OsdPlugin plugin;
|
41
|
|
-
|
42
|
43
|
/** List of OSD Windows. */
|
43
|
44
|
private final List<OsdWindow> windowList = new ArrayList<OsdWindow>();
|
44
|
|
-
|
45
|
45
|
/** List of messages to be queued. */
|
46
|
46
|
private final Queue<String> windowQueue = new LinkedList<String>();
|
47
|
|
-
|
48
|
47
|
/** The spacing between the windows. */
|
49
|
48
|
private static final int WINDOW_GAP = 5;
|
50
|
49
|
|
|
@@ -71,8 +70,8 @@ public class OsdManager {
|
71
|
70
|
* Displays as many windows as appropriate.
|
72
|
71
|
*/
|
73
|
72
|
private synchronized void displayWindows() {
|
74
|
|
- final Integer maxWindows = IdentityManager.getGlobalConfig().getOptionInt(
|
75
|
|
- plugin.getDomain(), "maxWindows");
|
|
73
|
+ final Integer maxWindows = IdentityManager.getGlobalConfig().
|
|
74
|
+ getOptionInt(plugin.getDomain(), "maxWindows");
|
76
|
75
|
|
77
|
76
|
String nextItem;
|
78
|
77
|
|
|
@@ -88,10 +87,17 @@ public class OsdManager {
|
88
|
87
|
* @param message Text to display in the OSD window.
|
89
|
88
|
*/
|
90
|
89
|
private void displayWindow(final String message) {
|
91
|
|
- OsdWindow currentWindow = new OsdWindow(message, false,
|
92
|
|
- IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
|
93
|
|
- "locationX"), getYPosition(), plugin, this);
|
94
|
|
- windowList.add(currentWindow);
|
|
90
|
+ windowList.add(UIUtilities.invokeAndWait(
|
|
91
|
+ new ReturnableThread<OsdWindow>() {
|
|
92
|
+
|
|
93
|
+ /** {@inheritDoc} */
|
|
94
|
+ @Override
|
|
95
|
+ public void run() {
|
|
96
|
+ setObject(new OsdWindow(message, false,
|
|
97
|
+ IdentityManager.getGlobalConfig().getOptionInt(
|
|
98
|
+ plugin.getDomain(), "locationX"), getYPosition(),
|
|
99
|
+ plugin, OsdManager.this));
|
|
100
|
+ }}));
|
95
|
101
|
}
|
96
|
102
|
|
97
|
103
|
/**
|
|
@@ -103,25 +109,33 @@ public class OsdManager {
|
103
|
109
|
public void closeWindow(final OsdWindow window) {
|
104
|
110
|
final String policy = IdentityManager.getGlobalConfig().getOption(
|
105
|
111
|
plugin.getDomain(), "newbehaviour");
|
106
|
|
- final int startY = IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
|
107
|
|
- "locationY");
|
108
|
|
-
|
109
|
|
- windowList.remove(window);
|
110
|
|
- window.dispose();
|
111
|
|
-
|
112
|
|
- synchronized (this) {
|
113
|
|
- for (OsdWindow otherWindow : getWindowList()) {
|
114
|
|
- if (otherWindow.isVisible()) {
|
115
|
|
- if ("down".equals(policy)) {
|
116
|
|
- otherWindow.setLocation(otherWindow.getX(), Math.max(startY,
|
117
|
|
- otherWindow.getY() - otherWindow.getHeight() - WINDOW_GAP));
|
118
|
|
- } else if ("up".equals(policy)) {
|
119
|
|
- otherWindow.setLocation(otherWindow.getX(), Math.min(startY,
|
120
|
|
- otherWindow.getY() + otherWindow.getHeight() + WINDOW_GAP));
|
|
112
|
+ final int startY = IdentityManager.getGlobalConfig().getOptionInt(plugin.
|
|
113
|
+ getDomain(), "locationY");
|
|
114
|
+
|
|
115
|
+ UIUtilities.invokeAndWait(new Runnable() {
|
|
116
|
+
|
|
117
|
+ /** {@inheritDoc} */
|
|
118
|
+ @Override
|
|
119
|
+ public void run() {
|
|
120
|
+ synchronized (OsdManager.this) {
|
|
121
|
+ windowList.remove(window);
|
|
122
|
+ window.dispose();
|
|
123
|
+ for (OsdWindow otherWindow : getWindowList()) {
|
|
124
|
+ if (otherWindow.isVisible()) {
|
|
125
|
+ if ("down".equals(policy)) {
|
|
126
|
+ otherWindow.setLocation(otherWindow.getX(), Math.
|
|
127
|
+ max(startY, otherWindow.getY()
|
|
128
|
+ - otherWindow.getHeight() - WINDOW_GAP));
|
|
129
|
+ } else if ("up".equals(policy)) {
|
|
130
|
+ otherWindow.setLocation(otherWindow.getX(), Math.
|
|
131
|
+ min(startY, otherWindow.getY()
|
|
132
|
+ + otherWindow.getHeight() + WINDOW_GAP));
|
|
133
|
+ }
|
|
134
|
+ }
|
121
|
135
|
}
|
122
|
136
|
}
|
123
|
137
|
}
|
124
|
|
- }
|
|
138
|
+ });
|
125
|
139
|
displayWindows();
|
126
|
140
|
}
|
127
|
141
|
|
|
@@ -185,4 +199,4 @@ public class OsdManager {
|
185
|
199
|
|
186
|
200
|
return y;
|
187
|
201
|
}
|
188
|
|
-}
|
|
202
|
+}
|