|
@@ -25,21 +25,23 @@ package com.dmdirc.addons.ui_swing.components;
|
25
|
25
|
import com.dmdirc.Channel;
|
26
|
26
|
import com.dmdirc.DMDircMBassador;
|
27
|
27
|
import com.dmdirc.Topic;
|
|
28
|
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
|
28
|
29
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
29
|
30
|
import com.dmdirc.addons.ui_swing.actions.ReplacePasteAction;
|
30
|
31
|
import com.dmdirc.addons.ui_swing.components.frames.ChannelFrame;
|
31
|
32
|
import com.dmdirc.addons.ui_swing.components.inputfields.SwingInputHandler;
|
32
|
33
|
import com.dmdirc.addons.ui_swing.components.inputfields.TextPaneInputField;
|
33
|
34
|
import com.dmdirc.addons.ui_swing.components.text.WrapEditorKit;
|
|
35
|
+import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
|
|
36
|
+import com.dmdirc.events.ChannelTopicChangeEvent;
|
|
37
|
+import com.dmdirc.events.ChannelTopicUnsetEvent;
|
34
|
38
|
import com.dmdirc.interfaces.CommandController;
|
35
|
|
-import com.dmdirc.interfaces.TopicChangeListener;
|
36
|
39
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
37
|
40
|
import com.dmdirc.interfaces.config.ConfigChangeListener;
|
38
|
41
|
import com.dmdirc.plugins.PluginManager;
|
39
|
42
|
import com.dmdirc.ui.IconManager;
|
40
|
43
|
import com.dmdirc.ui.input.TabCompleterUtils;
|
41
|
44
|
import com.dmdirc.ui.messages.ColourManager;
|
42
|
|
-import com.dmdirc.addons.ui_swing.textpane.StyledDocumentMaker;
|
43
|
45
|
import com.dmdirc.ui.messages.Styliser;
|
44
|
46
|
|
45
|
47
|
import java.awt.Color;
|
|
@@ -68,11 +70,13 @@ import javax.swing.text.StyledDocument;
|
68
|
70
|
|
69
|
71
|
import net.miginfocom.swing.MigLayout;
|
70
|
72
|
|
|
73
|
+import net.engio.mbassy.listener.Handler;
|
|
74
|
+
|
71
|
75
|
/**
|
72
|
76
|
* Component to show and edit topics for a channel.
|
73
|
77
|
*/
|
74
|
78
|
public class TopicBar extends JComponent implements ActionListener, ConfigChangeListener,
|
75
|
|
- MouseListener, DocumentListener, TopicChangeListener {
|
|
79
|
+ MouseListener, DocumentListener {
|
76
|
80
|
|
77
|
81
|
/** Serial version UID. */
|
78
|
82
|
private static final long serialVersionUID = 1;
|
|
@@ -176,7 +180,7 @@ public class TopicBar extends JComponent implements ActionListener, ConfigChange
|
176
|
180
|
validate();
|
177
|
181
|
invalidate();
|
178
|
182
|
|
179
|
|
- channel.addTopicChangeListener(this);
|
|
183
|
+ channel.getEventBus().subscribe(this);
|
180
|
184
|
topicText.addActionListener(this);
|
181
|
185
|
topicEdit.addActionListener(this);
|
182
|
186
|
topicCancel.addActionListener(this);
|
|
@@ -224,25 +228,32 @@ public class TopicBar extends JComponent implements ActionListener, ConfigChange
|
224
|
228
|
}
|
225
|
229
|
}
|
226
|
230
|
|
227
|
|
- @Override
|
228
|
|
- public final void topicChanged(final Channel channel, final Topic topic) {
|
229
|
|
- UIUtilities.invokeLater(() -> {
|
230
|
|
- if (topicText.isEditable()) {
|
231
|
|
- return;
|
232
|
|
- }
|
233
|
|
- topicText.setText("");
|
234
|
|
- if (topic != null) {
|
|
231
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
232
|
+ public void handleTopicChanged(final ChannelTopicChangeEvent event) {
|
|
233
|
+ topicChanged(event.getChannel(), event.getTopic());
|
|
234
|
+ }
|
|
235
|
+
|
|
236
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
237
|
+ public void handleTopicUnset(final ChannelTopicUnsetEvent event) {
|
|
238
|
+ topicChanged(event.getChannel(), null);
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ private void topicChanged(final Channel channel, final Topic topic) {
|
|
242
|
+ if (topicText.isEditable()) {
|
|
243
|
+ return;
|
|
244
|
+ }
|
|
245
|
+ topicText.setText("");
|
|
246
|
+ if (topic != null) {
|
235
|
247
|
channel.getBackBuffer().getStyliser().addStyledString(
|
236
|
248
|
new StyledDocumentMaker((StyledDocument) topicText.getDocument(), as),
|
237
|
249
|
Styliser.CODE_HEXCOLOUR
|
238
|
250
|
+ UIUtilities.getHex(foregroundColour)
|
239
|
251
|
+ topic.getTopic());
|
240
|
|
- }
|
241
|
|
- topicText.setCaretPosition(0);
|
242
|
|
- validateTopic();
|
243
|
|
- setVisible(false);
|
244
|
|
- setVisible(true);
|
245
|
|
- });
|
|
252
|
+ }
|
|
253
|
+ topicText.setCaretPosition(0);
|
|
254
|
+ validateTopic();
|
|
255
|
+ setVisible(false);
|
|
256
|
+ setVisible(true);
|
246
|
257
|
}
|
247
|
258
|
|
248
|
259
|
@Override
|
|
@@ -431,7 +442,7 @@ public class TopicBar extends JComponent implements ActionListener, ConfigChange
|
431
|
442
|
* Closes this topic bar.
|
432
|
443
|
*/
|
433
|
444
|
public void close() {
|
434
|
|
- channel.removeTopicChangeListener(this);
|
|
445
|
+ channel.getEventBus().unsubscribe(this);
|
435
|
446
|
}
|
436
|
447
|
|
437
|
448
|
/**
|