|
@@ -37,11 +37,10 @@ import com.dmdirc.addons.ui_swing.components.text.WrapEditorKit;
|
37
|
37
|
import com.dmdirc.interfaces.TopicChangeListener;
|
38
|
38
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
39
|
39
|
import com.dmdirc.interfaces.config.ConfigChangeListener;
|
40
|
|
-import com.dmdirc.parser.common.ChannelJoinRequest;
|
|
40
|
+import com.dmdirc.interfaces.ui.Window;
|
41
|
41
|
import com.dmdirc.plugins.PluginDomain;
|
42
|
42
|
import com.dmdirc.plugins.PluginManager;
|
43
|
43
|
import com.dmdirc.ui.IconManager;
|
44
|
|
-import com.dmdirc.ui.core.util.URLHandler;
|
45
|
44
|
import com.dmdirc.ui.messages.ColourManager;
|
46
|
45
|
import com.dmdirc.ui.messages.Styliser;
|
47
|
46
|
import com.dmdirc.util.annotations.factory.Factory;
|
|
@@ -62,8 +61,6 @@ import javax.swing.KeyStroke;
|
62
|
61
|
import javax.swing.SwingUtilities;
|
63
|
62
|
import javax.swing.event.DocumentEvent;
|
64
|
63
|
import javax.swing.event.DocumentListener;
|
65
|
|
-import javax.swing.event.HyperlinkEvent;
|
66
|
|
-import javax.swing.event.HyperlinkListener;
|
67
|
64
|
import javax.swing.text.DefaultStyledDocument;
|
68
|
65
|
import javax.swing.text.SimpleAttributeSet;
|
69
|
66
|
import javax.swing.text.StyleConstants;
|
|
@@ -75,9 +72,8 @@ import net.miginfocom.swing.MigLayout;
|
75
|
72
|
* Component to show and edit topics for a channel.
|
76
|
73
|
*/
|
77
|
74
|
@Factory(inject = true, singleton = true)
|
78
|
|
-public class TopicBar extends JComponent implements ActionListener,
|
79
|
|
- ConfigChangeListener, HyperlinkListener, MouseListener,
|
80
|
|
- DocumentListener, TopicChangeListener {
|
|
75
|
+public class TopicBar extends JComponent implements ActionListener, ConfigChangeListener,
|
|
76
|
+ MouseListener, DocumentListener, TopicChangeListener {
|
81
|
77
|
|
82
|
78
|
/** Serial version UID. */
|
83
|
79
|
private static final long serialVersionUID = 1;
|
|
@@ -91,10 +87,8 @@ public class TopicBar extends JComponent implements ActionListener,
|
91
|
87
|
private final SwingWindowFactory windowFactory;
|
92
|
88
|
/** Manager to use to resolve colours. */
|
93
|
89
|
private final ColourManager colourManager;
|
94
|
|
- /** The URL handler to use to launch URLs. */
|
95
|
|
- private final URLHandler urlHandler;
|
96
|
|
- /** The controller to use to manage window focus. */
|
97
|
|
- private final SwingController swingController;
|
|
90
|
+ /** The window this topic bar is for. */
|
|
91
|
+ private final Window window;
|
98
|
92
|
/** Associated channel. */
|
99
|
93
|
private final Channel channel;
|
100
|
94
|
/** the maximum length allowed for a topic. */
|
|
@@ -128,6 +122,7 @@ public class TopicBar extends JComponent implements ActionListener,
|
128
|
122
|
* @param urlHandler The URL handler to use to open URLs.
|
129
|
123
|
* @param swingController The controller to use to manage window focus.
|
130
|
124
|
* @param channel The channel that this topic bar is for.
|
|
125
|
+ * @param window The window this topic bar is for.
|
131
|
126
|
* @param iconManager The icon manager to use for this bar's icons.
|
132
|
127
|
*/
|
133
|
128
|
public TopicBar(
|
|
@@ -137,23 +132,19 @@ public class TopicBar extends JComponent implements ActionListener,
|
137
|
132
|
final ColourManager colourManager,
|
138
|
133
|
final PluginManager pluginManager,
|
139
|
134
|
final SwingWindowFactory windowFactory,
|
140
|
|
- final URLHandler urlHandler,
|
141
|
|
- final SwingController swingController,
|
142
|
135
|
@Unbound final Channel channel,
|
|
136
|
+ @Unbound final Window window,
|
143
|
137
|
@Unbound final IconManager iconManager) {
|
144
|
|
- super();
|
145
|
|
-
|
146
|
138
|
this.channel = channel;
|
147
|
139
|
this.domain = domain;
|
148
|
140
|
this.windowFactory = windowFactory;
|
149
|
|
- this.urlHandler = urlHandler;
|
150
|
141
|
this.colourManager = colourManager;
|
151
|
|
- this.swingController = swingController;
|
|
142
|
+ this.window = window;
|
152
|
143
|
topicText = new TextPaneInputField(parentWindow, globalConfig, colourManager, iconManager);
|
153
|
144
|
topicLengthMax = channel.getMaxTopicLength();
|
154
|
145
|
updateOptions();
|
155
|
146
|
errorIcon = new JLabel(iconManager.getIcon("input-error"));
|
156
|
|
- topicText.setEditorKit(new WrapEditorKit(showFull));
|
|
147
|
+ topicText.setEditorKit(new WrapEditorKit(showFull, channel.getEventBus(), window));
|
157
|
148
|
((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
|
158
|
149
|
new NewlinesDocumentFilter());
|
159
|
150
|
|
|
@@ -189,34 +180,26 @@ public class TopicBar extends JComponent implements ActionListener,
|
189
|
180
|
topicText.addActionListener(this);
|
190
|
181
|
topicEdit.addActionListener(this);
|
191
|
182
|
topicCancel.addActionListener(this);
|
192
|
|
- topicText.getInputMap().put(KeyStroke.getKeyStroke("ENTER"),
|
193
|
|
- "enterButton");
|
194
|
|
- topicText.getActionMap().put("enterButton", new AbstractAction(
|
195
|
|
- "enterButton") {
|
196
|
|
- /**
|
197
|
|
- * A version number for this class. It should be changed whenever the class
|
198
|
|
- * structure is changed (or anything else that would prevent serialized objects
|
199
|
|
- * being unserialized with the new class).
|
200
|
|
- */
|
201
|
|
- private static final long serialVersionUID = 1;
|
202
|
|
-
|
203
|
|
- @Override
|
204
|
|
- public void actionPerformed(final ActionEvent e) {
|
205
|
|
- commitTopicEdit();
|
206
|
|
- }
|
207
|
|
- });
|
208
|
|
- topicText.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"),
|
209
|
|
- "escapeButton");
|
210
|
|
- topicText.getActionMap().put("escapeButton", new AbstractAction(
|
211
|
|
- "escapeButton") {
|
212
|
|
- private static final long serialVersionUID = 1;
|
213
|
|
-
|
214
|
|
- @Override
|
215
|
|
- public void actionPerformed(final ActionEvent e) {
|
216
|
|
- cancelTopicEdit();
|
217
|
|
- }
|
218
|
|
- });
|
219
|
|
- topicText.addHyperlinkListener(this);
|
|
183
|
+ topicText.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "enterButton");
|
|
184
|
+ topicText.getActionMap().put("enterButton", new AbstractAction("enterButton") {
|
|
185
|
+ /** A version number for this class. */
|
|
186
|
+ private static final long serialVersionUID = 1;
|
|
187
|
+
|
|
188
|
+ @Override
|
|
189
|
+ public void actionPerformed(final ActionEvent e) {
|
|
190
|
+ commitTopicEdit();
|
|
191
|
+ }
|
|
192
|
+ });
|
|
193
|
+ topicText.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"), "escapeButton");
|
|
194
|
+ topicText.getActionMap().put("escapeButton", new AbstractAction("escapeButton") {
|
|
195
|
+ /** A version number for this class. */
|
|
196
|
+ private static final long serialVersionUID = 1;
|
|
197
|
+
|
|
198
|
+ @Override
|
|
199
|
+ public void actionPerformed(final ActionEvent e) {
|
|
200
|
+ cancelTopicEdit();
|
|
201
|
+ }
|
|
202
|
+ });
|
220
|
203
|
topicText.addMouseListener(this);
|
221
|
204
|
topicText.getDocument().addDocumentListener(this);
|
222
|
205
|
|
|
@@ -351,24 +334,6 @@ public class TopicBar extends JComponent implements ActionListener,
|
351
|
334
|
topicChanged(channel, null);
|
352
|
335
|
}
|
353
|
336
|
|
354
|
|
- @Override
|
355
|
|
- public void hyperlinkUpdate(final HyperlinkEvent e) {
|
356
|
|
- if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
357
|
|
- final String url = e.getDescription();
|
358
|
|
- if (url == null) {
|
359
|
|
- return;
|
360
|
|
- }
|
361
|
|
- if (url.charAt(0) == '#') {
|
362
|
|
- channel.getConnection().join(new ChannelJoinRequest(url));
|
363
|
|
- } else if (url.contains("://")) {
|
364
|
|
- urlHandler.launchApp(e.getDescription());
|
365
|
|
- } else {
|
366
|
|
- swingController.requestWindowFocus(
|
367
|
|
- windowFactory.getSwingWindow(channel.getConnection().getQuery(url)));
|
368
|
|
- }
|
369
|
|
- }
|
370
|
|
- }
|
371
|
|
-
|
372
|
337
|
/**
|
373
|
338
|
* Load and set colours.
|
374
|
339
|
*/
|
|
@@ -496,7 +461,7 @@ public class TopicBar extends JComponent implements ActionListener,
|
496
|
461
|
setVisible(showBar);
|
497
|
462
|
cancelTopicEdit();
|
498
|
463
|
if ("showfulltopic".equals(key)) {
|
499
|
|
- topicText.setEditorKit(new WrapEditorKit(showFull));
|
|
464
|
+ topicText.setEditorKit(new WrapEditorKit(showFull, channel.getEventBus(), window));
|
500
|
465
|
((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
|
501
|
466
|
new NewlinesDocumentFilter());
|
502
|
467
|
topicChanged(channel, null);
|