|
@@ -39,6 +39,7 @@ import java.util.HashMap;
|
39
|
39
|
import java.util.Map;
|
40
|
40
|
import java.util.Optional;
|
41
|
41
|
import java.util.concurrent.CopyOnWriteArrayList;
|
|
42
|
+import java.util.concurrent.atomic.AtomicLong;
|
42
|
43
|
|
43
|
44
|
import javax.inject.Inject;
|
44
|
45
|
import javax.inject.Singleton;
|
|
@@ -60,8 +61,12 @@ public class WindowManager {
|
60
|
61
|
private final Map<WindowModel, WindowModel> parents = new HashMap<>();
|
61
|
62
|
/** Mapping of parents to their children. */
|
62
|
63
|
private final Multimap<WindowModel, WindowModel> children = ArrayListMultimap.create();
|
|
64
|
+ /** Mapping of IDs to windows. */
|
|
65
|
+ private final Map<String, WindowModel> windowsById = new HashMap<>();
|
63
|
66
|
/** A list of frame listeners. */
|
64
|
67
|
private final ListenerList listeners = new ListenerList();
|
|
68
|
+ /** Counter to use for ID assignments. */
|
|
69
|
+ private final AtomicLong nextId = new AtomicLong(0L);
|
65
|
70
|
|
66
|
71
|
/**
|
67
|
72
|
* Creates a new instance of {@link WindowManager}.
|
|
@@ -182,7 +187,7 @@ public class WindowManager {
|
182
|
187
|
checkArgument(!rootWindows.contains(window));
|
183
|
188
|
|
184
|
189
|
rootWindows.add(window);
|
185
|
|
-
|
|
190
|
+ assignId(window);
|
186
|
191
|
fireAddWindow(window, focus);
|
187
|
192
|
}
|
188
|
193
|
|
|
@@ -220,7 +225,7 @@ public class WindowManager {
|
220
|
225
|
|
221
|
226
|
parents.put(child, parent);
|
222
|
227
|
children.put(parent, child);
|
223
|
|
-
|
|
228
|
+ assignId(child);
|
224
|
229
|
fireAddWindow(parent, child, focus);
|
225
|
230
|
}
|
226
|
231
|
|
|
@@ -256,6 +261,7 @@ public class WindowManager {
|
256
|
261
|
|
257
|
262
|
children.get(window).forEach(WindowModel::close);
|
258
|
263
|
children.removeAll(window);
|
|
264
|
+ windowsById.remove(window.getId());
|
259
|
265
|
|
260
|
266
|
if (rootWindows.contains(window)) {
|
261
|
267
|
fireDeleteWindow(window);
|
|
@@ -332,6 +338,27 @@ public class WindowManager {
|
332
|
338
|
return Collections.unmodifiableCollection(rootWindows);
|
333
|
339
|
}
|
334
|
340
|
|
|
341
|
+ /**
|
|
342
|
+ * Retrieves the window with the specified ID.
|
|
343
|
+ *
|
|
344
|
+ * @param id The ID of the window to retrieve
|
|
345
|
+ * @return The window with the given ID, if it exists.
|
|
346
|
+ */
|
|
347
|
+ public Optional<WindowModel> getWindowById(final String id) {
|
|
348
|
+ return Optional.ofNullable(windowsById.get(id));
|
|
349
|
+ }
|
|
350
|
+
|
|
351
|
+ /**
|
|
352
|
+ * Assigns a unique ID to the given window.
|
|
353
|
+ *
|
|
354
|
+ * @param window The window to assign an ID to.
|
|
355
|
+ */
|
|
356
|
+ private void assignId(final WindowModel window) {
|
|
357
|
+ final String id = "WINDOW/" + nextId.getAndIncrement();
|
|
358
|
+ window.setId(id);
|
|
359
|
+ windowsById.put(id, window);
|
|
360
|
+ }
|
|
361
|
+
|
335
|
362
|
/**
|
336
|
363
|
* Fires the addWindow(Window) callback.
|
337
|
364
|
*
|