Browse Source

Fix some EDT violations.

pull/389/head
Greg Holmes 9 years ago
parent
commit
d56bc1005c

+ 42
- 40
ui_swing/src/com/dmdirc/addons/ui_swing/MainFrame.java View File

23
 package com.dmdirc.addons.ui_swing;
23
 package com.dmdirc.addons.ui_swing;
24
 
24
 
25
 import com.dmdirc.DMDircMBassador;
25
 import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.addons.ui_swing.components.IconManager;
26
 import com.dmdirc.addons.ui_swing.components.SplitPane;
27
 import com.dmdirc.addons.ui_swing.components.SplitPane;
27
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
28
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
29
 import com.dmdirc.addons.ui_swing.components.menubar.MenuBar;
29
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
30
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
30
 import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
31
 import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
32
+import com.dmdirc.addons.ui_swing.events.ClientMinimisedEvent;
33
+import com.dmdirc.addons.ui_swing.events.ClientUnminimisedEvent;
31
 import com.dmdirc.addons.ui_swing.events.SwingActiveWindowChangeRequestEvent;
34
 import com.dmdirc.addons.ui_swing.events.SwingActiveWindowChangeRequestEvent;
32
 import com.dmdirc.addons.ui_swing.events.SwingEventBus;
35
 import com.dmdirc.addons.ui_swing.events.SwingEventBus;
33
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
36
 import com.dmdirc.addons.ui_swing.events.SwingWindowAddedEvent;
36
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
39
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
37
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
40
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
38
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
41
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
39
-import com.dmdirc.addons.ui_swing.events.ClientMinimisedEvent;
40
-import com.dmdirc.addons.ui_swing.events.ClientUnminimisedEvent;
41
 import com.dmdirc.events.FrameTitleChangedEvent;
42
 import com.dmdirc.events.FrameTitleChangedEvent;
42
 import com.dmdirc.events.UnreadStatusChangedEvent;
43
 import com.dmdirc.events.UnreadStatusChangedEvent;
43
 import com.dmdirc.interfaces.LifecycleController;
44
 import com.dmdirc.interfaces.LifecycleController;
45
 import com.dmdirc.interfaces.config.ConfigChangeListener;
46
 import com.dmdirc.interfaces.config.ConfigChangeListener;
46
 import com.dmdirc.interfaces.ui.Window;
47
 import com.dmdirc.interfaces.ui.Window;
47
 import com.dmdirc.ui.CoreUIUtils;
48
 import com.dmdirc.ui.CoreUIUtils;
48
-import com.dmdirc.addons.ui_swing.components.IconManager;
49
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
49
 import com.dmdirc.util.collections.QueuedLinkedHashSet;
50
 
50
 
51
 import java.awt.Dialog;
51
 import java.awt.Dialog;
160
 
160
 
161
     @Override
161
     @Override
162
     public void setVisible(final boolean visible) {
162
     public void setVisible(final boolean visible) {
163
+        checkOnEDT();
163
         if (!initDone) {
164
         if (!initDone) {
164
             swingEventBus.subscribe(this);
165
             swingEventBus.subscribe(this);
165
             imageIcon = new ImageIcon(iconManager.getImage("icon"));
166
             imageIcon = new ImageIcon(iconManager.getImage("icon"));
203
 
204
 
204
     @Override
205
     @Override
205
     public void setTitle(final String title) {
206
     public void setTitle(final String title) {
206
-        UIUtilities.invokeLater(() -> {
207
-            if (title == null || !activeFrame.isPresent()) {
208
-                MainFrame.super.setTitle(getTitlePrefix());
209
-            } else {
210
-                MainFrame.super.setTitle(getTitlePrefix() + " - " + title);
211
-            }
212
-        });
207
+        checkOnEDT();
208
+        if (title == null || !activeFrame.isPresent()) {
209
+            MainFrame.super.setTitle(getTitlePrefix());
210
+        } else {
211
+            MainFrame.super.setTitle(getTitlePrefix() + " - " + title);
212
+        }
213
     }
213
     }
214
 
214
 
215
     /**
215
     /**
258
 
258
 
259
     /** Initialiases the frame managers. */
259
     /** Initialiases the frame managers. */
260
     private void initFrameManagers() {
260
     private void initFrameManagers() {
261
-        UIUtilities.invokeAndWait(() -> {
262
-            frameManagerPanel.removeAll();
263
-            if (mainFrameManager != null) {
264
-                swingEventBus.unsubscribe(mainFrameManager);
265
-            }
266
-            mainFrameManager = frameManagerProvider.get();
267
-            mainFrameManager.setParent(frameManagerPanel);
268
-            swingEventBus.subscribe(mainFrameManager);
269
-        });
261
+        checkOnEDT();
262
+        frameManagerPanel.removeAll();
263
+        if (mainFrameManager != null) {
264
+            swingEventBus.unsubscribe(mainFrameManager);
265
+        }
266
+        mainFrameManager = frameManagerProvider.get();
267
+        mainFrameManager.setParent(frameManagerPanel);
268
+        swingEventBus.subscribe(mainFrameManager);
270
     }
269
     }
271
 
270
 
272
     /**
271
     /**
273
      * Initialises the components for this frame.
272
      * Initialises the components for this frame.
274
      */
273
      */
275
     public void initComponents() {
274
     public void initComponents() {
276
-        UIUtilities.invokeAndWait(() -> {
277
-            frameManagerPanel = new JPanel();
278
-            activeFrame = Optional.empty();
279
-            framePanel = new JPanel(new MigLayout("fill, ins 0"));
280
-            initFrameManagers();
281
-            mainSplitPane = initSplitPane();
275
+        checkOnEDT();
276
+        frameManagerPanel = new JPanel();
277
+        activeFrame = Optional.empty();
278
+        framePanel = new JPanel(new MigLayout("fill, ins 0"));
279
+        initFrameManagers();
280
+        mainSplitPane = initSplitPane();
282
 
281
 
283
-            setPreferredSize(new Dimension(800, 600));
282
+        setPreferredSize(new Dimension(800, 600));
284
 
283
 
285
-            getContentPane().setLayout(new MigLayout(
286
-                    "fill, ins rel, wrap 1, hidemode 2"));
287
-            layoutComponents();
284
+        getContentPane().setLayout(new MigLayout(
285
+                "fill, ins rel, wrap 1, hidemode 2"));
286
+        layoutComponents();
288
 
287
 
289
-            setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
288
+        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
290
 
289
 
291
-            pack();
292
-        });
290
+        pack();
293
     }
291
     }
294
 
292
 
295
     /**
293
     /**
301
      * @param menuBar The menu bar to use.
299
      * @param menuBar The menu bar to use.
302
      */
300
      */
303
     public void setMenuBar(final MenuBar menuBar) {
301
     public void setMenuBar(final MenuBar menuBar) {
304
-        UIUtilities.invokeAndWait(() -> {
305
-            apple.setMenuBar(menuBar);
306
-            setJMenuBar(menuBar);
307
-        });
302
+        checkOnEDT();
303
+        apple.setMenuBar(menuBar);
304
+        setJMenuBar(menuBar);
308
     }
305
     }
309
 
306
 
310
     /**
307
     /**
466
 
463
 
467
     @Handler(invocation = EdtHandlerInvocation.class)
464
     @Handler(invocation = EdtHandlerInvocation.class)
468
     public void setActiveFrame(final SwingActiveWindowChangeRequestEvent event) {
465
     public void setActiveFrame(final SwingActiveWindowChangeRequestEvent event) {
466
+        checkOnEDT();
469
         focusOrder.offerAndMove(activeFrame);
467
         focusOrder.offerAndMove(activeFrame);
470
         framePanel.setVisible(false);
468
         framePanel.setVisible(false);
471
         framePanel.removeAll();
469
         framePanel.removeAll();
493
         swingEventBus.publish(new SwingWindowSelectedEvent(activeFrame));
491
         swingEventBus.publish(new SwingWindowSelectedEvent(activeFrame));
494
     }
492
     }
495
 
493
 
496
-    @Handler
494
+    @Handler(invocation = EdtHandlerInvocation.class)
497
     public void doWindowAdded(final SwingWindowAddedEvent event) {
495
     public void doWindowAdded(final SwingWindowAddedEvent event) {
496
+        checkOnEDT();
498
         if (!activeFrame.isPresent()) {
497
         if (!activeFrame.isPresent()) {
499
             setActiveFrame(new SwingActiveWindowChangeRequestEvent(
498
             setActiveFrame(new SwingActiveWindowChangeRequestEvent(
500
                     Optional.of(event.getChildWindow())));
499
                     Optional.of(event.getChildWindow())));
501
         }
500
         }
502
     }
501
     }
503
 
502
 
504
-    @Handler
503
+    @Handler(invocation = EdtHandlerInvocation.class)
505
     public void doWindowDeleted(final SwingWindowDeletedEvent event) {
504
     public void doWindowDeleted(final SwingWindowDeletedEvent event) {
505
+        checkOnEDT();
506
         final Optional<TextFrame> window = Optional.of(event.getChildWindow());
506
         final Optional<TextFrame> window = Optional.of(event.getChildWindow());
507
         focusOrder.remove(window);
507
         focusOrder.remove(window);
508
         if (activeFrame.equals(window)) {
508
         if (activeFrame.equals(window)) {
518
         }
518
         }
519
     }
519
     }
520
 
520
 
521
-    @Handler
521
+    @Handler(invocation = EdtHandlerInvocation.class)
522
     public void titleChanged(final FrameTitleChangedEvent event) {
522
     public void titleChanged(final FrameTitleChangedEvent event) {
523
+        checkOnEDT();
523
         activeFrame.map(Window::getContainer)
524
         activeFrame.map(Window::getContainer)
524
                 .filter(isEqual(event.getContainer()))
525
                 .filter(isEqual(event.getContainer()))
525
                 .ifPresent(c -> setTitle(event.getTitle()));
526
                 .ifPresent(c -> setTitle(event.getTitle()));
526
     }
527
     }
527
 
528
 
528
-    @Handler
529
+    @Handler(invocation = EdtHandlerInvocation.class)
529
     public void unreadStatusChanged(final UnreadStatusChangedEvent event) {
530
     public void unreadStatusChanged(final UnreadStatusChangedEvent event) {
531
+        checkOnEDT();
530
         activeFrame.map(Window::getContainer)
532
         activeFrame.map(Window::getContainer)
531
                 .filter(isEqual(event.getSource()))
533
                 .filter(isEqual(event.getSource()))
532
                 .ifPresent(c -> event.getManager().clearStatus());
534
                 .ifPresent(c -> event.getManager().clearStatus());

+ 31
- 27
ui_swing/src/com/dmdirc/addons/ui_swing/SwingManager.java View File

147
      * Handles loading of the UI.
147
      * Handles loading of the UI.
148
      */
148
      */
149
     public void load() {
149
     public void load() {
150
-        uiInitialiser.load();
151
-        this.mainFrame = mainFrameProvider.get();
152
-        mainFrame.setMenuBar(menuBar.get());
153
-        mainFrame.setWindowManager(ctrlTabManager);
154
-        mainFrame.setStatusBar(statusBar.get());
155
-        mainFrame.initComponents();
156
-        swingEventBus.subscribe(mainFrame);
157
-        swingEventBus.subscribe(ctrlTabManager);
158
-
159
-        windowManager.addListenerAndSync(windowFactory.get());
160
-        eventBus.subscribe(statusBar.get());
161
-        eventBus.subscribe(this);
162
-        eventBus.subscribe(mainFrame);
163
-        eventBus.subscribe(linkHandler);
164
-
165
-        mainFrame.setVisible(true);
150
+        UIUtilities.invokeLater(() -> {
151
+            uiInitialiser.load();
152
+            this.mainFrame = mainFrameProvider.get();
153
+            mainFrame.setMenuBar(menuBar.get());
154
+            mainFrame.setWindowManager(ctrlTabManager);
155
+            mainFrame.setStatusBar(statusBar.get());
156
+            mainFrame.initComponents();
157
+            swingEventBus.subscribe(mainFrame);
158
+            swingEventBus.subscribe(ctrlTabManager);
159
+
160
+            windowManager.addListenerAndSync(windowFactory.get());
161
+            eventBus.subscribe(statusBar.get());
162
+            eventBus.subscribe(this);
163
+            eventBus.subscribe(mainFrame);
164
+            eventBus.subscribe(linkHandler);
165
+
166
+            mainFrame.setVisible(true);
167
+        });
166
     }
168
     }
167
 
169
 
168
     /**
170
     /**
169
      * Handles unloading of the UI.
171
      * Handles unloading of the UI.
170
      */
172
      */
171
     public void unload() {
173
     public void unload() {
172
-        swingWindowManager.get().getTopLevelWindows().forEach(Window::dispose);
173
-        windowManager.removeListener(windowFactory.get());
174
-        windowFactory.get().dispose();
175
-        swingEventBus.unsubscribe(mainFrame);
176
-        swingEventBus.unsubscribe(ctrlTabManager);
177
-        mainFrame.dispose();
178
-        eventBus.unsubscribe(statusBar.get());
179
-        eventBus.unsubscribe(this);
180
-        eventBus.unsubscribe(mainFrame);
181
-        eventBus.unsubscribe(linkHandler);
182
-        uiInitialiser.unload();
174
+        UIUtilities.invokeLater(() -> {
175
+            swingWindowManager.get().getTopLevelWindows().forEach(Window::dispose);
176
+            windowManager.removeListener(windowFactory.get());
177
+            windowFactory.get().dispose();
178
+            swingEventBus.unsubscribe(mainFrame);
179
+            swingEventBus.unsubscribe(ctrlTabManager);
180
+            mainFrame.dispose();
181
+            eventBus.unsubscribe(statusBar.get());
182
+            eventBus.unsubscribe(this);
183
+            eventBus.unsubscribe(mainFrame);
184
+            eventBus.unsubscribe(linkHandler);
185
+            uiInitialiser.unload();
186
+        });
183
     }
187
     }
184
 
188
 
185
     /**
189
     /**

Loading…
Cancel
Save