|
@@ -44,8 +44,6 @@ public class OsdManager {
|
44
|
44
|
private final List<OsdWindow> windowList = new ArrayList<OsdWindow>();
|
45
|
45
|
/** List of messages to be queued. */
|
46
|
46
|
private final Queue<String> windowQueue = new LinkedList<String>();
|
47
|
|
- /** The spacing between the windows. */
|
48
|
|
- private static final int WINDOW_GAP = 5;
|
49
|
47
|
|
50
|
48
|
/**
|
51
|
49
|
* Create a new OSD Manager.
|
|
@@ -85,13 +83,20 @@ public class OsdManager {
|
85
|
83
|
* Create a new OSD window with "message".
|
86
|
84
|
* <p>
|
87
|
85
|
* This method needs to be synchronised to ensure that the window list is
|
88
|
|
- * not modified in between the invocation of {@link #getYPosition()} and
|
89
|
|
- * the point at which the {@link OSDWindow} is added to the windowList.
|
|
86
|
+ * not modified in between the invocation of
|
|
87
|
+ * {@link OsdPolicy#getYPosition(com.dmdirc.addons.osd.OsdManager, int)}
|
|
88
|
+ * and the point at which the {@link OsdWindow} is added to the windowList.
|
90
|
89
|
*
|
91
|
|
- * @see #getYPosition()
|
|
90
|
+ * @see OsdPolicy#getYPosition(com.dmdirc.addons.osd.OsdManager, int)
|
92
|
91
|
* @param message Text to display in the OSD window.
|
93
|
92
|
*/
|
94
|
93
|
private synchronized void displayWindow(final String message) {
|
|
94
|
+ final OsdPolicy policy = OsdPolicy.valueOf(IdentityManager.
|
|
95
|
+ getGlobalConfig().getOption(plugin.getDomain(), "newbehaviour").
|
|
96
|
+ toUpperCase());
|
|
97
|
+ final int startY = IdentityManager.getGlobalConfig().getOptionInt(
|
|
98
|
+ plugin.getDomain(), "locationY");
|
|
99
|
+
|
95
|
100
|
windowList.add(UIUtilities.invokeAndWait(
|
96
|
101
|
new ReturnableThread<OsdWindow>() {
|
97
|
102
|
|
|
@@ -100,8 +105,8 @@ public class OsdManager {
|
100
|
105
|
public void run() {
|
101
|
106
|
setObject(new OsdWindow(message, false,
|
102
|
107
|
IdentityManager.getGlobalConfig().getOptionInt(
|
103
|
|
- plugin.getDomain(), "locationX"), getYPosition(),
|
104
|
|
- plugin, OsdManager.this));
|
|
108
|
+ plugin.getDomain(), "locationX"), policy.getYPosition(
|
|
109
|
+ OsdManager.this, startY), plugin, OsdManager.this));
|
105
|
110
|
}
|
106
|
111
|
}));
|
107
|
112
|
}
|
|
@@ -113,8 +118,9 @@ public class OsdManager {
|
113
|
118
|
* @param window The window that we are destroying.
|
114
|
119
|
*/
|
115
|
120
|
public synchronized void closeWindow(final OsdWindow window) {
|
116
|
|
- final String policy = IdentityManager.getGlobalConfig().getOption(
|
117
|
|
- plugin.getDomain(), "newbehaviour");
|
|
121
|
+ final OsdPolicy policy = OsdPolicy.valueOf(IdentityManager.
|
|
122
|
+ getGlobalConfig().getOption(plugin.getDomain(), "newbehaviour").
|
|
123
|
+ toUpperCase());
|
118
|
124
|
|
119
|
125
|
int oldY = window.getDesiredY();
|
120
|
126
|
final int closedIndex = windowList.indexOf(window);
|
|
@@ -136,13 +142,11 @@ public class OsdManager {
|
136
|
142
|
final List<OsdWindow> newList = getWindowList();
|
137
|
143
|
for (OsdWindow otherWindow : newList.subList(closedIndex, newList.size())) {
|
138
|
144
|
final int currentY = otherWindow.getDesiredY();
|
139
|
|
-
|
140
|
|
- if ("down".equals(policy) || "up".equals(policy)) {
|
|
145
|
+ if (policy.changesPosition()) {
|
141
|
146
|
otherWindow.setDesiredLocation(otherWindow.getDesiredX(), oldY);
|
142
|
147
|
oldY = currentY;
|
143
|
148
|
}
|
144
|
149
|
}
|
145
|
|
-
|
146
|
150
|
displayWindows();
|
147
|
151
|
}
|
148
|
152
|
|
|
@@ -172,44 +176,4 @@ public class OsdManager {
|
172
|
176
|
public int getWindowCount() {
|
173
|
177
|
return windowList.size();
|
174
|
178
|
}
|
175
|
|
-
|
176
|
|
- /**
|
177
|
|
- * Get the Y position for the next window.
|
178
|
|
- * <p>
|
179
|
|
- * In order to ensure that windows are displayed at the correct position,
|
180
|
|
- * the calling party MUST ensure that the window list is not altered between
|
181
|
|
- * this method's invocation and the time at which the window is displayed.
|
182
|
|
- * If the window list is altered, multiple windows may appear on top of
|
183
|
|
- * each other instead of stacking correctly, or there may be gaps in up/down
|
184
|
|
- * policy layouts.
|
185
|
|
- *
|
186
|
|
- * @return the Y position for the next window.
|
187
|
|
- */
|
188
|
|
- private int getYPosition() {
|
189
|
|
- final String policy = IdentityManager.getGlobalConfig().getOption(
|
190
|
|
- plugin.getDomain(), "newbehaviour");
|
191
|
|
- int y = IdentityManager.getGlobalConfig().getOptionInt(plugin.getDomain(),
|
192
|
|
- "locationY");
|
193
|
|
-
|
194
|
|
- if ("down".equals(policy)) {
|
195
|
|
- // Place our new window below old windows
|
196
|
|
- for (OsdWindow window : getWindowList()) {
|
197
|
|
- if (window.isVisible()) {
|
198
|
|
- y = Math.max(y, window.getY() + window.getHeight() + WINDOW_GAP);
|
199
|
|
- }
|
200
|
|
- }
|
201
|
|
- } else if ("up".equals(policy)) {
|
202
|
|
- // Place our new window above old windows
|
203
|
|
- for (OsdWindow window : getWindowList()) {
|
204
|
|
- if (window.isVisible()) {
|
205
|
|
- y = Math.min(y, window.getY() - window.getHeight() - WINDOW_GAP);
|
206
|
|
- }
|
207
|
|
- }
|
208
|
|
- } else if ("close".equals(policy)) {
|
209
|
|
- // Close existing windows and use their place
|
210
|
|
- closeAll();
|
211
|
|
- }
|
212
|
|
-
|
213
|
|
- return y;
|
214
|
|
- }
|
215
|
179
|
}
|