Browse Source

Add a factory for swing search bars.

pull/276/head
Chris Smith 9 years ago
parent
commit
19a406d8d6

+ 54
- 0
ui_swing/src/com/dmdirc/addons/ui_swing/components/SwingSearchBarFactory.java View File

@@ -0,0 +1,54 @@
1
+/*
2
+ * Copyright (c) 2006-2015 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.components;
24
+
25
+import com.dmdirc.ClientModule.GlobalConfig;
26
+import com.dmdirc.addons.ui_swing.components.frames.TextFrame;
27
+import com.dmdirc.ui.IconManager;
28
+import com.dmdirc.ui.messages.ColourManager;
29
+
30
+import javax.inject.Inject;
31
+import javax.inject.Singleton;
32
+
33
+/**
34
+ * Factory for creating {@link SwingSearchBar}s.
35
+ */
36
+@Singleton
37
+public class SwingSearchBarFactory {
38
+
39
+    private final IconManager iconManager;
40
+    private final ColourManager colourManager;
41
+
42
+    @Inject
43
+    public SwingSearchBarFactory(
44
+            final IconManager iconManager,
45
+            @GlobalConfig final ColourManager colourManager) {
46
+        this.iconManager = iconManager;
47
+        this.colourManager = colourManager;
48
+    }
49
+
50
+    public SwingSearchBar create(final TextFrame owner) {
51
+        return new SwingSearchBar(owner, iconManager, colourManager);
52
+    }
53
+
54
+}

+ 8
- 7
ui_swing/src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java View File

@@ -31,6 +31,7 @@ import com.dmdirc.addons.ui_swing.UIUtilities;
31 31
 import com.dmdirc.addons.ui_swing.actions.InputFieldCopyAction;
32 32
 import com.dmdirc.addons.ui_swing.actions.SearchAction;
33 33
 import com.dmdirc.addons.ui_swing.components.SwingSearchBar;
34
+import com.dmdirc.addons.ui_swing.components.SwingSearchBarFactory;
34 35
 import com.dmdirc.addons.ui_swing.dialogs.paste.PasteDialogFactory;
35 36
 import com.dmdirc.addons.ui_swing.events.SwingActiveWindowChangeRequestEvent;
36 37
 import com.dmdirc.addons.ui_swing.events.SwingEventBus;
@@ -120,8 +121,6 @@ public abstract class TextFrame extends JPanel implements Window, TextPaneListen
120 121
     private DesktopWindowFrame popoutFrame;
121 122
     /** Desktop place holder object used if this frame is popped out. */
122 123
     private DesktopPlaceHolderFrame popoutPlaceholder;
123
-    /** Icon manager to retrieve icons from. */
124
-    private final IconManager iconManager;
125 124
 
126 125
     /**
127 126
      * Creates a new instance of Frame.
@@ -137,13 +136,12 @@ public abstract class TextFrame extends JPanel implements Window, TextPaneListen
137 136
         this.swingEventBus = deps.swingEventBus;
138 137
         this.popupManager = deps.popupManager;
139 138
         this.frameParent = owner;
140
-        this.iconManager = deps.iconManager;
141 139
         this.eventBus = deps.eventBus;
142 140
         this.commandParser = commandParser;
143 141
         this.clipboard = deps.clipboard;
144 142
         this.colourManager = deps.colourManagerFactory.getColourManager(owner.getConfigManager());
145 143
 
146
-        initComponents(deps.textPaneFactory, colourManager);
144
+        initComponents(deps.textPaneFactory, deps.searchBarFactory);
147 145
         setFocusable(true);
148 146
         setLayout(new MigLayout("fill"));
149 147
     }
@@ -224,10 +222,10 @@ public abstract class TextFrame extends JPanel implements Window, TextPaneListen
224 222
      * Initialises the components for this frame.
225 223
      */
226 224
     private void initComponents(final TextPaneFactory textPaneFactory,
227
-            final ColourManager colourManager) {
225
+            final SwingSearchBarFactory searchBarFactory) {
228 226
         setTextPane(textPaneFactory.getTextPane(this));
229 227
 
230
-        searchBar = new SwingSearchBar(this, iconManager, colourManager);
228
+        searchBar = searchBarFactory.create(this);
231 229
         searchBar.setVisible(false);
232 230
 
233 231
         getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
@@ -535,6 +533,7 @@ public abstract class TextFrame extends JPanel implements Window, TextPaneListen
535 533
         final ColourManagerFactory colourManagerFactory;
536 534
         final SwingEventBus swingEventBus;
537 535
         final TabCompleterUtils tabCompleterUtils;
536
+        final SwingSearchBarFactory searchBarFactory;
538 537
 
539 538
         @Inject
540 539
         public TextFrameDependencies(
@@ -552,7 +551,8 @@ public abstract class TextFrame extends JPanel implements Window, TextPaneListen
552 551
                 final CommandController commandController,
553 552
                 final ColourManagerFactory colourManagerFactory,
554 553
                 final SwingEventBus swingEventBus,
555
-                final TabCompleterUtils tabCompleterUtils) {
554
+                final TabCompleterUtils tabCompleterUtils,
555
+                final SwingSearchBarFactory searchBarFactory) {
556 556
             this.textPaneFactory = textPaneFactory;
557 557
             this.controller = controller;
558 558
             this.mainWindow = mainWindow;
@@ -568,6 +568,7 @@ public abstract class TextFrame extends JPanel implements Window, TextPaneListen
568 568
             this.colourManagerFactory = colourManagerFactory;
569 569
             this.swingEventBus = swingEventBus;
570 570
             this.tabCompleterUtils = tabCompleterUtils;
571
+            this.searchBarFactory = searchBarFactory;
571 572
         }
572 573
 
573 574
     }

Loading…
Cancel
Save