|
@@ -25,13 +25,12 @@ package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
|
25
|
25
|
import com.dmdirc.FrameContainer;
|
26
|
26
|
import com.dmdirc.FrameContainerComparator;
|
27
|
27
|
import com.dmdirc.addons.ui_swing.SwingController;
|
|
28
|
+import com.dmdirc.addons.ui_swing.SwingWindowListener;
|
28
|
29
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
29
|
30
|
import com.dmdirc.config.IdentityManager;
|
30
|
31
|
import com.dmdirc.interfaces.SelectionListener;
|
31
|
32
|
import com.dmdirc.ui.IconManager;
|
32
|
|
-import com.dmdirc.ui.WindowManager;
|
33
|
33
|
import com.dmdirc.ui.interfaces.Window;
|
34
|
|
-import com.dmdirc.ui.interfaces.FrameListener;
|
35
|
34
|
import com.dmdirc.util.ReturnableThread;
|
36
|
35
|
|
37
|
36
|
import java.awt.Component;
|
|
@@ -56,7 +55,7 @@ import javax.swing.event.MenuListener;
|
56
|
55
|
* Manages the window menu window list.
|
57
|
56
|
*/
|
58
|
57
|
public final class WindowMenuFrameManager extends JMenu implements
|
59
|
|
- FrameListener, ActionListener, SelectionListener, MenuListener {
|
|
58
|
+ SwingWindowListener, ActionListener, SelectionListener, MenuListener {
|
60
|
59
|
|
61
|
60
|
/**
|
62
|
61
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -102,7 +101,7 @@ public final class WindowMenuFrameManager extends JMenu implements
|
102
|
101
|
|
103
|
102
|
setText("Window");
|
104
|
103
|
setMnemonic('w');
|
105
|
|
- WindowManager.addFrameListener(this);
|
|
104
|
+ controller.getWindowFactory().addWindowListener(this);
|
106
|
105
|
addMenuListener(this);
|
107
|
106
|
|
108
|
107
|
minimiseMenuItem = new JMenuItem(IconManager.getIconManager().getIcon(
|
|
@@ -152,123 +151,125 @@ public final class WindowMenuFrameManager extends JMenu implements
|
152
|
151
|
|
153
|
152
|
/** {@inheritDoc} */
|
154
|
153
|
@Override
|
155
|
|
- public void addWindow(final FrameContainer window, final boolean focus) {
|
156
|
|
- final FrameContainerMenuItem item = UIUtilities.invokeAndWait(
|
157
|
|
- new ReturnableThread<FrameContainerMenuItem>() {
|
|
154
|
+ public void windowAdded(final Window parent, final Window window) {
|
|
155
|
+ if (parent == null) {
|
|
156
|
+ final FrameContainerMenuItem item = UIUtilities.invokeAndWait(
|
|
157
|
+ new ReturnableThread<FrameContainerMenuItem>() {
|
158
|
158
|
|
159
|
|
- /** {@inheritDoc} */
|
160
|
|
- @Override
|
161
|
|
- public void run() {
|
162
|
|
- setObject(new FrameContainerMenuItem(window,
|
163
|
|
- WindowMenuFrameManager.this));
|
|
159
|
+ /** {@inheritDoc} */
|
|
160
|
+ @Override
|
|
161
|
+ public void run() {
|
|
162
|
+ setObject(new FrameContainerMenuItem(window.
|
|
163
|
+ getContainer(), WindowMenuFrameManager.this));
|
164
|
164
|
}
|
165
|
|
- });
|
166
|
|
- items.put(window, item);
|
167
|
|
- final int index = getIndex(window, this);
|
168
|
|
- window.addSelectionListener(this);
|
169
|
|
- UIUtilities.invokeLater(new Runnable() {
|
170
|
|
-
|
171
|
|
- /** {@inheritDoc} */
|
172
|
|
- @Override
|
173
|
|
- public void run() {
|
174
|
|
- add(item, index);
|
175
|
|
- }
|
176
|
|
- });
|
177
|
|
- }
|
|
165
|
+ });
|
|
166
|
+ items.put(window.getContainer(), item);
|
|
167
|
+ final int index = getIndex(window.getContainer(), this);
|
|
168
|
+ window.getContainer().addSelectionListener(this);
|
|
169
|
+ UIUtilities.invokeLater(new Runnable() {
|
178
|
170
|
|
179
|
|
- /** {@inheritDoc} */
|
180
|
|
- @Override
|
181
|
|
- public void delWindow(final FrameContainer window) {
|
182
|
|
- final AbstractButton item;
|
183
|
|
- if (items.containsKey(window)) {
|
184
|
|
- item = items.get(window);
|
185
|
|
- items.remove(window);
|
186
|
|
- } else if (menus.containsKey(window)) {
|
187
|
|
- item = menus.get(window);
|
188
|
|
- menus.remove(window);
|
|
171
|
+ /** {@inheritDoc} */
|
|
172
|
+ @Override
|
|
173
|
+ public void run() {
|
|
174
|
+ add(item, index);
|
|
175
|
+ }
|
|
176
|
+ });
|
189
|
177
|
} else {
|
190
|
|
- item = null;
|
191
|
|
- }
|
192
|
|
- UIUtilities.invokeLater(new Runnable() {
|
193
|
|
-
|
194
|
|
- /** {@inheritDoc} */
|
195
|
|
- @Override
|
196
|
|
- public void run() {
|
197
|
|
- remove(item);
|
198
|
|
- }
|
199
|
|
- });
|
200
|
|
- window.removeSelectionListener(this);
|
201
|
|
- }
|
202
|
|
-
|
203
|
|
- /** {@inheritDoc} */
|
204
|
|
- @Override
|
205
|
|
- public void addWindow(final FrameContainer parent,
|
206
|
|
- final FrameContainer window, final boolean focus) {
|
207
|
|
- final FrameContainerMenuItem item = UIUtilities.invokeAndWait(
|
208
|
|
- new ReturnableThread<FrameContainerMenuItem>() {
|
209
|
|
-
|
210
|
|
- /** {@inheritDoc} */
|
211
|
|
- @Override
|
212
|
|
- public void run() {
|
213
|
|
- setObject(new FrameContainerMenuItem(window,
|
214
|
|
- WindowMenuFrameManager.this));
|
215
|
|
- }
|
216
|
|
- });
|
217
|
|
- final JMenu parentMenu;
|
218
|
|
- if (!menus.containsKey(parent)) {
|
219
|
|
- final FrameContainerMenu replacement = UIUtilities.invokeAndWait(
|
220
|
|
- new ReturnableThread<FrameContainerMenu>() {
|
|
178
|
+ final FrameContainerMenuItem item = UIUtilities.invokeAndWait(
|
|
179
|
+ new ReturnableThread<FrameContainerMenuItem>() {
|
221
|
180
|
|
222
|
181
|
/** {@inheritDoc} */
|
223
|
182
|
@Override
|
224
|
183
|
public void run() {
|
225
|
|
- setObject(new FrameContainerMenu(parent, controller));
|
|
184
|
+ setObject(new FrameContainerMenuItem(window.
|
|
185
|
+ getContainer(),
|
|
186
|
+ WindowMenuFrameManager.this));
|
226
|
187
|
}
|
227
|
188
|
});
|
228
|
|
- replaceItemWithMenu(getParentMenu(parent), items.get(parent),
|
229
|
|
- replacement);
|
230
|
|
- parentMenu = replacement;
|
231
|
|
- } else {
|
232
|
|
- parentMenu = menus.get(parent);
|
233
|
|
- }
|
234
|
|
- items.put(window, item);
|
235
|
|
- window.addSelectionListener(this);
|
236
|
|
- UIUtilities.invokeLater(new Runnable() {
|
237
|
|
-
|
238
|
|
- /** {@inheritDoc} */
|
239
|
|
- @Override
|
240
|
|
- public void run() {
|
241
|
|
- parentMenu.add(item, getIndex(window, parentMenu));
|
|
189
|
+ final JMenu parentMenu;
|
|
190
|
+ if (!menus.containsKey(parent.getContainer())) {
|
|
191
|
+ final FrameContainerMenu replacement = UIUtilities.invokeAndWait(
|
|
192
|
+ new ReturnableThread<FrameContainerMenu>() {
|
|
193
|
+
|
|
194
|
+ /** {@inheritDoc} */
|
|
195
|
+ @Override
|
|
196
|
+ public void run() {
|
|
197
|
+ setObject(new FrameContainerMenu(parent.
|
|
198
|
+ getContainer(), controller));
|
|
199
|
+ }
|
|
200
|
+ });
|
|
201
|
+ replaceItemWithMenu(getParentMenu(parent.getContainer()),
|
|
202
|
+ items.get(parent.getContainer()), replacement);
|
|
203
|
+ parentMenu = replacement;
|
|
204
|
+ } else {
|
|
205
|
+ parentMenu = menus.get(parent.getContainer());
|
242
|
206
|
}
|
243
|
|
- });
|
|
207
|
+ items.put(window.getContainer(), item);
|
|
208
|
+ window.getContainer().addSelectionListener(this);
|
|
209
|
+ UIUtilities.invokeLater(new Runnable() {
|
|
210
|
+
|
|
211
|
+ /** {@inheritDoc} */
|
|
212
|
+ @Override
|
|
213
|
+ public void run() {
|
|
214
|
+ parentMenu.add(item, getIndex(window.getContainer(),
|
|
215
|
+ parentMenu));
|
|
216
|
+ }
|
|
217
|
+ });
|
|
218
|
+ }
|
244
|
219
|
}
|
245
|
220
|
|
246
|
221
|
/** {@inheritDoc} */
|
247
|
222
|
@Override
|
248
|
|
- public void delWindow(final FrameContainer parent,
|
249
|
|
- final FrameContainer window) {
|
250
|
|
- if (items.containsKey(window)) {
|
251
|
|
- final JMenu menu = getParentMenu(window);
|
252
|
|
- final FrameContainerMenuItem item = items.get(window);
|
253
|
|
- items.remove(window);
|
254
|
|
- UIUtilities.invokeAndWait(new Runnable() {
|
|
223
|
+ public void windowDeleted(final Window parent, final Window window) {
|
|
224
|
+ if (parent == null) {
|
|
225
|
+ final AbstractButton item;
|
|
226
|
+ if (items.containsKey(window.getContainer())) {
|
|
227
|
+ item = items.get(window.getContainer());
|
|
228
|
+ items.remove(window.getContainer());
|
|
229
|
+ } else if (menus.containsKey(window.getContainer())) {
|
|
230
|
+ item = menus.get(window.getContainer());
|
|
231
|
+ menus.remove(window.getContainer());
|
|
232
|
+ } else {
|
|
233
|
+ item = null;
|
|
234
|
+ }
|
|
235
|
+ UIUtilities.invokeLater(new Runnable() {
|
255
|
236
|
|
256
|
237
|
/** {@inheritDoc} */
|
257
|
238
|
@Override
|
258
|
239
|
public void run() {
|
259
|
|
- menu.remove(item);
|
260
|
|
- if (menu.getMenuComponentCount() == 1) {
|
261
|
|
- replaceMenuWithItem(getParentMenu(parent),
|
262
|
|
- menus.get(parent), new FrameContainerMenuItem(
|
263
|
|
- parent, WindowMenuFrameManager.this));
|
264
|
|
- }
|
|
240
|
+ remove(item);
|
265
|
241
|
}
|
266
|
242
|
});
|
267
|
|
- } else if (menus.containsKey(window)) {
|
268
|
|
- menus.get(parent).remove(menus.get(window));
|
269
|
|
- menus.remove(window);
|
|
243
|
+ window.getContainer().removeSelectionListener(this);
|
|
244
|
+ } else {
|
|
245
|
+ if (items.containsKey(window.getContainer())) {
|
|
246
|
+ final JMenu menu = getParentMenu(window.getContainer());
|
|
247
|
+ final FrameContainerMenuItem item = items.get(window.
|
|
248
|
+ getContainer());
|
|
249
|
+ items.remove(window.getContainer());
|
|
250
|
+ UIUtilities.invokeAndWait(new Runnable() {
|
|
251
|
+
|
|
252
|
+ /** {@inheritDoc} */
|
|
253
|
+ @Override
|
|
254
|
+ public void run() {
|
|
255
|
+ menu.remove(item);
|
|
256
|
+ if (menu.getMenuComponentCount() == 1) {
|
|
257
|
+ replaceMenuWithItem(getParentMenu(parent.
|
|
258
|
+ getContainer()),
|
|
259
|
+ menus.get(parent.getContainer()),
|
|
260
|
+ new FrameContainerMenuItem(parent.
|
|
261
|
+ getContainer(),
|
|
262
|
+ WindowMenuFrameManager.this));
|
|
263
|
+ }
|
|
264
|
+ }
|
|
265
|
+ });
|
|
266
|
+ } else if (menus.containsKey(window.getContainer())) {
|
|
267
|
+ menus.get(parent.getContainer()).remove(menus.get(window.
|
|
268
|
+ getContainer()));
|
|
269
|
+ menus.remove(window.getContainer());
|
|
270
|
+ }
|
|
271
|
+ window.getContainer().removeSelectionListener(this);
|
270
|
272
|
}
|
271
|
|
- window.removeSelectionListener(this);
|
272
|
273
|
}
|
273
|
274
|
|
274
|
275
|
private JMenu getParentMenu(final FrameContainer window) {
|
|
@@ -331,8 +332,8 @@ public final class WindowMenuFrameManager extends JMenu implements
|
331
|
332
|
synchronized (menus) {
|
332
|
333
|
synchronized (items) {
|
333
|
334
|
synchronized (menuItems) {
|
334
|
|
- activeWindow = controller.getWindowFactory()
|
335
|
|
- .getSwingWindow(window);
|
|
335
|
+ activeWindow = controller.getWindowFactory().getSwingWindow(
|
|
336
|
+ window);
|
336
|
337
|
values.addAll(menus.values());
|
337
|
338
|
values.addAll(items.values());
|
338
|
339
|
values.addAll(menuItems.values());
|
|
@@ -416,7 +417,8 @@ public final class WindowMenuFrameManager extends JMenu implements
|
416
|
417
|
if (!(component instanceof FrameContainerMenuInterface)) {
|
417
|
418
|
continue;
|
418
|
419
|
}
|
419
|
|
- final FrameContainer child = ((FrameContainerMenuInterface) component).getFrame();
|
|
420
|
+ final FrameContainer child = ((FrameContainerMenuInterface) component).
|
|
421
|
+ getFrame();
|
420
|
422
|
if (sortBefore(newChild, child)) {
|
421
|
423
|
return i;
|
422
|
424
|
} else if (!sortAfter(newChild, child) && IdentityManager.
|