瀏覽代碼

Start injecting TextPane dependencies.

Bundle them up in a static class to avoid having to pass a million deps
around in each and every subclass.

Change-Id: I581e39f9da6f7a4b79ab69d043de4c81111e9b52
Reviewed-on: http://gerrit.dmdirc.com/3064
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8
Chris Smith 10 年之前
父節點
當前提交
e5c04b4a97

+ 4
- 4
src/com/dmdirc/addons/ui_swing/components/frames/ChannelFrame.java 查看文件

@@ -78,12 +78,12 @@ public final class ChannelFrame extends InputTextFrame implements ActionListener
78 78
      * Creates a new instance of ChannelFrame. Sets up callbacks and handlers,
79 79
      * and default options for the form.
80 80
      *
81
+     * @param deps The dependencies required by text frames.
81 82
      * @param owner The Channel object that owns this frame
82
-     * @param controller Swing controller
83 83
      */
84
-    public ChannelFrame(final SwingController controller, @Unbound final Channel owner) {
85
-        super(controller, owner);
86
-        this.controller = controller;
84
+    public ChannelFrame(final TextFrameDependencies deps, @Unbound final Channel owner) {
85
+        super(deps, owner);
86
+        this.controller = getController();
87 87
 
88 88
         initComponents();
89 89
 

+ 4
- 4
src/com/dmdirc/addons/ui_swing/components/frames/ComponentFrame.java 查看文件

@@ -52,14 +52,14 @@ public class ComponentFrame extends TextFrame {
52 52
     /**
53 53
      * Creates a new instance of CustomFrame.
54 54
      *
55
+     * @param deps The dependencies required by text frames.
55 56
      * @param owner The frame container that owns this frame
56
-     * @param controller Swing controller
57 57
      */
58 58
     public ComponentFrame(
59
-            final SwingController controller,
59
+            final TextFrameDependencies deps,
60 60
             @Unbound final FrameContainer owner) {
61
-        super(owner, controller);
62
-        this.controller = controller;
61
+        super(owner, deps);
62
+        this.controller = getController();
63 63
         this.owner = owner;
64 64
         initComponents();
65 65
     }

+ 4
- 4
src/com/dmdirc/addons/ui_swing/components/frames/ComponentInputFrame.java 查看文件

@@ -52,13 +52,13 @@ public class ComponentInputFrame extends InputTextFrame {
52 52
     /**
53 53
      * Creates a new instance of CustomInputFrame.
54 54
      *
55
+     * @param deps The dependencies required by text frames.
55 56
      * @param owner The frame container that owns this frame
56
-     * @param controller Swing controller
57 57
      */
58
-    public ComponentInputFrame(final SwingController controller,
58
+    public ComponentInputFrame(final TextFrameDependencies deps,
59 59
             final WritableFrameContainer owner) {
60
-        super(controller, owner);
61
-        this.controller = controller;
60
+        super(deps, owner);
61
+        this.controller = getController();
62 62
         this.owner = owner;
63 63
         initComponents();
64 64
     }

+ 3
- 4
src/com/dmdirc/addons/ui_swing/components/frames/CustomFrame.java 查看文件

@@ -22,7 +22,6 @@
22 22
 package com.dmdirc.addons.ui_swing.components.frames;
23 23
 
24 24
 import com.dmdirc.FrameContainer;
25
-import com.dmdirc.addons.ui_swing.SwingController;
26 25
 import com.dmdirc.commandparser.PopupType;
27 26
 import com.dmdirc.util.annotations.factory.Factory;
28 27
 import com.dmdirc.util.annotations.factory.Unbound;
@@ -47,13 +46,13 @@ public class CustomFrame extends TextFrame {
47 46
     /**
48 47
      * Creates a new instance of CustomFrame.
49 48
      *
49
+     * @param deps The dependencies required by text frames.
50 50
      * @param owner The frame container that owns this frame
51
-     * @param controller Swing controller
52 51
      */
53 52
     public CustomFrame(
54
-            final SwingController controller,
53
+            final TextFrameDependencies deps,
55 54
             @Unbound final FrameContainer owner) {
56
-        super(owner, controller);
55
+        super(owner, deps);
57 56
 
58 57
         initComponents();
59 58
     }

+ 3
- 4
src/com/dmdirc/addons/ui_swing/components/frames/CustomInputFrame.java 查看文件

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.ui_swing.components.frames;
24 24
 
25 25
 import com.dmdirc.WritableFrameContainer;
26
-import com.dmdirc.addons.ui_swing.SwingController;
27 26
 import com.dmdirc.commandparser.PopupType;
28 27
 import com.dmdirc.util.annotations.factory.Factory;
29 28
 import com.dmdirc.util.annotations.factory.Unbound;
@@ -49,13 +48,13 @@ public class CustomInputFrame extends InputTextFrame {
49 48
     /**
50 49
      * Creates a new instance of CustomInputFrame.
51 50
      *
51
+     * @param deps The dependencies required by text frames.
52 52
      * @param owner The frame container that owns this frame
53
-     * @param controller Swing controller
54 53
      */
55 54
     public CustomInputFrame(
56
-            final SwingController controller,
55
+            final TextFrameDependencies deps,
57 56
             @Unbound final WritableFrameContainer owner) {
58
-        super(controller, owner);
57
+        super(deps, owner);
59 58
 
60 59
         initComponents();
61 60
     }

+ 5
- 4
src/com/dmdirc/addons/ui_swing/components/frames/InputTextFrame.java 查看文件

@@ -84,14 +84,15 @@ public abstract class InputTextFrame extends TextFrame implements InputWindow,
84 84
     /**
85 85
      * Creates a new instance of InputFrame.
86 86
      *
87
-     * @param controller Swing controller
87
+     * @param deps The dependencies required by text frames.
88 88
      * @param owner WritableFrameContainer owning this frame.
89 89
      */
90
-    public InputTextFrame(final SwingController controller,
90
+    public InputTextFrame(
91
+            final TextFrameDependencies deps,
91 92
             final WritableFrameContainer owner) {
92
-        super(owner, controller);
93
+        super(owner, deps);
93 94
 
94
-        this.controller = controller;
95
+        this.controller = getController();
95 96
         initComponents();
96 97
 
97 98
         final AggregateConfigProvider config = owner.getConfigManager();

+ 4
- 4
src/com/dmdirc/addons/ui_swing/components/frames/ServerFrame.java 查看文件

@@ -65,13 +65,13 @@ public final class ServerFrame extends InputTextFrame implements
65 65
     /**
66 66
      * Creates a new ServerFrame.
67 67
      *
68
+     * @param deps The dependencies required by text frames.
68 69
      * @param owner Parent Frame container
69
-     * @param controller Swing controller
70 70
      */
71
-    public ServerFrame(final SwingController controller, @Unbound final Server owner) {
72
-        super(controller, owner);
71
+    public ServerFrame(final TextFrameDependencies deps, @Unbound final Server owner) {
72
+        super(deps, owner);
73 73
 
74
-        this.controller = controller;
74
+        this.controller = getController();
75 75
         initComponents();
76 76
 
77 77
         owner.addCertificateProblemListener(this);

+ 78
- 21
src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java 查看文件

@@ -25,6 +25,7 @@ package com.dmdirc.addons.ui_swing.components.frames;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28
+import com.dmdirc.addons.ui_swing.MainFrame;
28 29
 import com.dmdirc.addons.ui_swing.SwingController;
29 30
 import com.dmdirc.addons.ui_swing.UIUtilities;
30 31
 import com.dmdirc.addons.ui_swing.actions.ChannelCopyAction;
@@ -40,6 +41,7 @@ import com.dmdirc.addons.ui_swing.textpane.TextPane;
40 41
 import com.dmdirc.addons.ui_swing.textpane.TextPaneControlCodeCopyAction;
41 42
 import com.dmdirc.addons.ui_swing.textpane.TextPaneCopyAction;
42 43
 import com.dmdirc.addons.ui_swing.textpane.TextPaneEndAction;
44
+import com.dmdirc.addons.ui_swing.textpane.TextPaneFactory;
43 45
 import com.dmdirc.addons.ui_swing.textpane.TextPaneHomeAction;
44 46
 import com.dmdirc.addons.ui_swing.textpane.TextPaneListener;
45 47
 import com.dmdirc.addons.ui_swing.textpane.TextPanePageDownAction;
@@ -50,6 +52,7 @@ import com.dmdirc.commandparser.PopupMenuItem;
50 52
 import com.dmdirc.commandparser.PopupType;
51 53
 import com.dmdirc.commandparser.parsers.CommandParser;
52 54
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
55
+import com.dmdirc.interfaces.CommandController;
53 56
 import com.dmdirc.interfaces.FrameCloseListener;
54 57
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
55 58
 import com.dmdirc.interfaces.config.ConfigChangeListener;
@@ -57,11 +60,15 @@ import com.dmdirc.interfaces.ui.InputWindow;
57 60
 import com.dmdirc.interfaces.ui.Window;
58 61
 import com.dmdirc.parser.common.ChannelJoinRequest;
59 62
 import com.dmdirc.ui.IconManager;
63
+import com.dmdirc.ui.core.util.URLHandler;
64
+import com.dmdirc.util.URLBuilder;
60 65
 
61 66
 import java.awt.Point;
62 67
 import java.awt.event.KeyEvent;
63 68
 import java.awt.event.MouseEvent;
64 69
 
70
+import javax.inject.Inject;
71
+import javax.inject.Provider;
65 72
 import javax.swing.JComponent;
66 73
 import javax.swing.JMenu;
67 74
 import javax.swing.JMenuItem;
@@ -95,6 +102,16 @@ public abstract class TextFrame extends JPanel implements Window,
95 102
     private final CommandParser commandParser;
96 103
     /** Swing controller. */
97 104
     private final SwingController controller;
105
+    /** Main frame to use to activate/deactivate windows. */
106
+    private final Provider<MainFrame> mainFrame;
107
+    /** Manager to use for building popups. */
108
+    private final PopupManager popupManager;
109
+    /** Handler to use to open URLs. */
110
+    private final URLHandler urlHandler;
111
+    /** Builder to use to construct URLs. */
112
+    private final URLBuilder urlBuilder;
113
+    /** Controller to use for commands. */
114
+    private final CommandController commandController;
98 115
     /** Boolean to determine if this frame should be popped out of main client. */
99 116
     private boolean popout;
100 117
     /**
@@ -109,13 +126,20 @@ public abstract class TextFrame extends JPanel implements Window,
109 126
      * Creates a new instance of Frame.
110 127
      *
111 128
      * @param owner FrameContainer owning this frame.
112
-     * @param controller Swing controller
129
+     * @param deps Collection of TextPane dependencies.
113 130
      */
114
-    public TextFrame(final FrameContainer owner,
115
-            final SwingController controller) {
131
+    public TextFrame(
132
+            final FrameContainer owner,
133
+            final TextFrameDependencies deps) {
116 134
         super();
117
-        this.controller = controller;
118
-        frameParent = owner;
135
+
136
+        this.controller = deps.controller;
137
+        this.mainFrame = deps.mainFrame;
138
+        this.popupManager = deps.popupManager;
139
+        this.urlBuilder = deps.urlBuilder;
140
+        this.urlHandler = deps.urlHandler;
141
+        this.commandController = deps.commandController;
142
+        this.frameParent = owner;
119 143
 
120 144
         final AggregateConfigProvider config = owner.getConfigManager();
121 145
 
@@ -124,7 +148,7 @@ public abstract class TextFrame extends JPanel implements Window,
124 148
 
125 149
         commandParser = findCommandParser();
126 150
 
127
-        initComponents();
151
+        initComponents(deps.textPaneFactory);
128 152
         setFocusable(true);
129 153
 
130 154
         getTextPane().addTextPaneListener(this);
@@ -157,7 +181,7 @@ public abstract class TextFrame extends JPanel implements Window,
157 181
 
158 182
         if (localParser == null) {
159 183
             localParser = new GlobalCommandParser(frameParent.getConfigManager(),
160
-                    controller.getCommandController());
184
+                    commandController);
161 185
         }
162 186
 
163 187
         return localParser;
@@ -177,18 +201,16 @@ public abstract class TextFrame extends JPanel implements Window,
177 201
         this.popout = popout;
178 202
         if (popout) {
179 203
             popoutPlaceholder = new DesktopPlaceHolderFrame();
180
-            popoutFrame = new DesktopWindowFrame(this)  ;
204
+            popoutFrame = new DesktopWindowFrame(this);
181 205
             popoutFrame.display();
182 206
         } else if (popoutFrame != null) {
183 207
             popoutPlaceholder = null;
184 208
             popoutFrame.dispose();
185 209
             popoutFrame = null;
186 210
         }
187
-        // Call setActiveFrame again so the contents of the frame manager
188
-        // are updated.
189
-        if (equals(controller.getMainFrame()
190
-                .getActiveFrame())) {
191
-            controller.getMainFrame().setActiveFrame(this);
211
+        // Call setActiveFrame again so the contents of the frame manager are updated.
212
+        if (equals(mainFrame.get().getActiveFrame())) {
213
+            mainFrame.get().setActiveFrame(this);
192 214
         }
193 215
     }
194 216
 
@@ -233,8 +255,8 @@ public abstract class TextFrame extends JPanel implements Window,
233 255
     /**
234 256
      * Initialises the components for this frame.
235 257
      */
236
-    private void initComponents() {
237
-        setTextPane(new TextPane(getController().getDomain(), getController().getUrlBuilder(), this));
258
+    private void initComponents(final TextPaneFactory textPaneFactory) {
259
+        setTextPane(textPaneFactory.getTextPane(this));
238 260
 
239 261
         searchBar = new SwingSearchBar(this);
240 262
         searchBar.setVisible(false);
@@ -347,7 +369,7 @@ public abstract class TextFrame extends JPanel implements Window,
347 369
                 if (ActionManager.getActionManager().triggerEvent(
348 370
                         CoreActionType.LINK_URL_CLICKED, null, this,
349 371
                         clickType.getValue())) {
350
-                    controller.getUrlHandler().launchApp(clickType.getValue());
372
+                    urlHandler.launchApp(clickType.getValue());
351 373
                 }
352 374
                 break;
353 375
             case NICKNAME:
@@ -482,8 +504,7 @@ public abstract class TextFrame extends JPanel implements Window,
482 504
 
483 505
         if (type != null) {
484 506
             popupMenu = (JPopupMenu) populatePopupMenu(popupMenu,
485
-                    new PopupManager(controller.getCommandController()).getMenu(type, getContainer()
486
-                    .getConfigManager()), arguments);
507
+                    popupManager.getMenu(type, getContainer().getConfigManager()), arguments);
487 508
         }
488 509
 
489 510
         return popupMenu;
@@ -528,8 +549,7 @@ public abstract class TextFrame extends JPanel implements Window,
528 549
     /** {@inheritDoc} */
529 550
     @Override
530 551
     public void configChanged(final String domain, final String key) {
531
-        if (getContainer().getConfigManager() == null
532
-                || getTextPane() == null) {
552
+        if (getContainer().getConfigManager() == null || getTextPane() == null) {
533 553
             return;
534 554
         }
535 555
 
@@ -548,6 +568,7 @@ public abstract class TextFrame extends JPanel implements Window,
548 568
 
549 569
     /** {@inheritDoc} */
550 570
     @Override
571
+    @Deprecated
551 572
     public SwingController getController() {
552 573
         return controller;
553 574
     }
@@ -558,7 +579,7 @@ public abstract class TextFrame extends JPanel implements Window,
558 579
      * @return This frame's IconManager
559 580
      */
560 581
     public IconManager getIconManager() {
561
-        return getContainer().getIconManager(controller.getUrlBuilder());
582
+        return getContainer().getIconManager(urlBuilder);
562 583
     }
563 584
 
564 585
     /**
@@ -578,4 +599,40 @@ public abstract class TextFrame extends JPanel implements Window,
578 599
         frameParent.getConfigManager().removeListener(this);
579 600
         frameParent.removeCloseListener(this);
580 601
     }
602
+
603
+    /**
604
+     * Bundle of dependencies required by {@link TextFrame}.
605
+     *
606
+     * <p>Because of the number of dependencies and the amount of subclassing, collect the
607
+     * dependencies together here so they can be easily modified without having to modify all
608
+     * subclasses.
609
+     */
610
+    public static class TextFrameDependencies {
611
+
612
+        private final TextPaneFactory textPaneFactory;
613
+        private final SwingController controller;
614
+        private final Provider<MainFrame> mainFrame;
615
+        private final PopupManager popupManager;
616
+        private final URLHandler urlHandler;
617
+        private final URLBuilder urlBuilder;
618
+        private final CommandController commandController;
619
+
620
+        @Inject
621
+        public TextFrameDependencies(
622
+                final TextPaneFactory textPaneFactory,
623
+                final SwingController controller,
624
+                final Provider<MainFrame> mainFrame,
625
+                final PopupManager popupManager,
626
+                final URLHandler urlHandler,
627
+                final URLBuilder urlBuilder,
628
+                final CommandController commandController) {
629
+            this.textPaneFactory = textPaneFactory;
630
+            this.controller = controller;
631
+            this.mainFrame = mainFrame;
632
+            this.popupManager = popupManager;
633
+            this.urlHandler = urlHandler;
634
+            this.urlBuilder = urlBuilder;
635
+            this.commandController = commandController;
636
+        }
637
+    }
581 638
 }

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

@@ -24,6 +24,7 @@ package com.dmdirc.addons.ui_swing.textpane;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.UIUtilities;
26 26
 import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27
+import com.dmdirc.addons.ui_swing.injection.SwingModule.SwingSettingsDomain;
27 28
 import com.dmdirc.interfaces.config.ConfigChangeListener;
28 29
 import com.dmdirc.interfaces.ui.Window;
29 30
 import com.dmdirc.ui.messages.IRCDocument;
@@ -31,6 +32,8 @@ import com.dmdirc.ui.messages.IRCDocumentListener;
31 32
 import com.dmdirc.ui.messages.LinePosition;
32 33
 import com.dmdirc.ui.messages.Styliser;
33 34
 import com.dmdirc.util.URLBuilder;
35
+import com.dmdirc.util.annotations.factory.Factory;
36
+import com.dmdirc.util.annotations.factory.Unbound;
34 37
 
35 38
 import java.awt.Color;
36 39
 import java.awt.Point;
@@ -57,6 +60,7 @@ import org.jdesktop.jxlayer.JXLayer;
57 60
 /**
58 61
  * Styled, scrollable text pane.
59 62
  */
63
+@Factory(inject = true, singleton = true)
60 64
 public final class TextPane extends JComponent implements MouseWheelListener,
61 65
         AdjustmentListener, IRCDocumentListener, ConfigChangeListener {
62 66
 
@@ -92,7 +96,10 @@ public final class TextPane extends JComponent implements MouseWheelListener,
92 96
      * @param urlBuilder The builder to use to construct URLs for resources.
93 97
      * @param frame Parent Frame
94 98
      */
95
-    public TextPane(final String configDomain, final URLBuilder urlBuilder, final TextFrame frame) {
99
+    public TextPane(
100
+            @SuppressWarnings("qualifiers") @SwingSettingsDomain final String configDomain,
101
+            final URLBuilder urlBuilder,
102
+            @Unbound final TextFrame frame) {
96 103
         super();
97 104
         this.frame = frame;
98 105
         this.configDomain = configDomain;

Loading…
取消
儲存