|
@@ -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
|
}
|