瀏覽代碼

Split ActiveFrameManager out of MainFrame

pull/95/head
Greg Holmes 9 年之前
父節點
當前提交
57f4af88a6

+ 1
- 8
ui_swing/src/com/dmdirc/addons/ui_swing/MainFrame.java 查看文件

@@ -37,7 +37,6 @@ import com.dmdirc.addons.ui_swing.events.SwingWindowSelectedEvent;
37 37
 import com.dmdirc.addons.ui_swing.framemanager.FrameManager;
38 38
 import com.dmdirc.addons.ui_swing.framemanager.FramemanagerPosition;
39 39
 import com.dmdirc.addons.ui_swing.framemanager.ctrltab.CtrlTabWindowManager;
40
-import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
41 40
 import com.dmdirc.events.ClientFocusGainedEvent;
42 41
 import com.dmdirc.events.ClientFocusLostEvent;
43 42
 import com.dmdirc.events.ClientMinimisedEvent;
@@ -75,8 +74,7 @@ import static com.dmdirc.addons.ui_swing.SwingPreconditions.checkOnEDT;
75 74
 /**
76 75
  * The main application frame.
77 76
  */
78
-public class MainFrame extends JFrame implements WindowListener, ConfigChangeListener,
79
-        ActiveFrameManager {
77
+public class MainFrame extends JFrame implements WindowListener, ConfigChangeListener {
80 78
 
81 79
     /** A version number for this class. */
82 80
     private static final long serialVersionUID = 9;
@@ -485,11 +483,6 @@ public class MainFrame extends JFrame implements WindowListener, ConfigChangeLis
485 483
         }
486 484
     }
487 485
 
488
-    @Override
489
-    public TextFrame getActiveFrame() {
490
-        return activeFrame;
491
-    }
492
-
493 486
     @Handler(invocation = EdtHandlerInvocation.class)
494 487
     public void setActiveFrame(final SwingActiveWindowChangeRequestEvent event) {
495 488
         focusOrder.offerAndMove(activeFrame);

+ 57
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/SimpleActiveFrameManager.java 查看文件

@@ -0,0 +1,57 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing;
24
+
25
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
26
+import com.dmdirc.addons.ui_swing.events.SwingActiveWindowChangeRequestEvent;
27
+import com.dmdirc.addons.ui_swing.interfaces.ActiveFrameManager;
28
+import com.dmdirc.interfaces.ui.Window;
29
+
30
+import java.util.Optional;
31
+
32
+import javax.inject.Inject;
33
+
34
+import net.engio.mbassy.listener.Handler;
35
+
36
+/**
37
+ * Simple active frame manager used only to keep track of the active frame.
38
+ */
39
+public class SimpleActiveFrameManager implements ActiveFrameManager {
40
+
41
+    private Optional<Window> window;
42
+
43
+    @Inject
44
+    public SimpleActiveFrameManager() {
45
+        window = Optional.empty();
46
+    }
47
+
48
+    @Handler(invocation = EdtHandlerInvocation.class)
49
+    public void setActiveFrame(final SwingActiveWindowChangeRequestEvent event) {
50
+        this.window = event.getWindow();
51
+    }
52
+
53
+    @Override
54
+    public TextFrame getActiveFrame() {
55
+        return (TextFrame) window.orElse(null);
56
+    }
57
+}

+ 5
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/injection/SwingModule.java 查看文件

@@ -31,6 +31,7 @@ import com.dmdirc.addons.ui_swing.Apple;
31 31
 import com.dmdirc.addons.ui_swing.MainFrame;
32 32
 import com.dmdirc.addons.ui_swing.NoopClipboard;
33 33
 import com.dmdirc.addons.ui_swing.QuitWorker;
34
+import com.dmdirc.addons.ui_swing.SimpleActiveFrameManager;
34 35
 import com.dmdirc.addons.ui_swing.SwingController;
35 36
 import com.dmdirc.addons.ui_swing.SwingManager;
36 37
 import com.dmdirc.addons.ui_swing.UIUtilities;
@@ -160,8 +161,10 @@ public class SwingModule {
160 161
 
161 162
     @Provides
162 163
     @Singleton
163
-    public ActiveFrameManager getActiveFrameManager(final MainFrame mainFrame) {
164
-        return mainFrame;
164
+    public ActiveFrameManager getActiveFrameManager(final SimpleActiveFrameManager frameManager,
165
+            final SwingEventBus eventBus) {
166
+        eventBus.subscribe(frameManager);
167
+        return frameManager;
165 168
     }
166 169
 
167 170
     @Provides

Loading…
取消
儲存