|
@@ -23,14 +23,19 @@
|
23
|
23
|
package com.dmdirc.addons.ui_swing.components;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.Channel;
|
|
26
|
+import com.dmdirc.addons.ui_swing.EDTInvocation;
|
|
27
|
+import com.dmdirc.addons.ui_swing.EdtHandlerInvocation;
|
26
|
28
|
import com.dmdirc.addons.ui_swing.UIUtilities;
|
27
|
29
|
import com.dmdirc.addons.ui_swing.components.frames.ChannelFrame;
|
28
|
30
|
import com.dmdirc.addons.ui_swing.components.renderers.NicklistRenderer;
|
29
|
31
|
import com.dmdirc.addons.ui_swing.textpane.ClickType;
|
30
|
32
|
import com.dmdirc.addons.ui_swing.textpane.ClickTypeValue;
|
31
|
|
-import com.dmdirc.interfaces.NicklistListener;
|
|
33
|
+import com.dmdirc.config.ConfigBinding;
|
|
34
|
+import com.dmdirc.events.NickListClientAddedEvent;
|
|
35
|
+import com.dmdirc.events.NickListClientRemovedEvent;
|
|
36
|
+import com.dmdirc.events.NickListClientsChangedEvent;
|
|
37
|
+import com.dmdirc.events.NickListUpdatedEvent;
|
32
|
38
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
33
|
|
-import com.dmdirc.interfaces.config.ConfigChangeListener;
|
34
|
39
|
import com.dmdirc.parser.interfaces.ChannelClientInfo;
|
35
|
40
|
import com.dmdirc.ui.messages.ColourManager;
|
36
|
41
|
import com.dmdirc.ui.messages.ColourManagerFactory;
|
|
@@ -40,19 +45,18 @@ import java.awt.Font;
|
40
|
45
|
import java.awt.Point;
|
41
|
46
|
import java.awt.event.MouseEvent;
|
42
|
47
|
import java.awt.event.MouseListener;
|
43
|
|
-import java.util.Collection;
|
44
|
48
|
import java.util.List;
|
45
|
49
|
|
46
|
50
|
import javax.swing.JList;
|
47
|
51
|
import javax.swing.JScrollPane;
|
48
|
52
|
import javax.swing.ListSelectionModel;
|
49
|
|
-import javax.swing.SwingUtilities;
|
|
53
|
+
|
|
54
|
+import net.engio.mbassy.listener.Handler;
|
50
|
55
|
|
51
|
56
|
/**
|
52
|
57
|
* Nicklist class.
|
53
|
58
|
*/
|
54
|
|
-public class NickList extends JScrollPane implements ConfigChangeListener,
|
55
|
|
- MouseListener, NicklistListener {
|
|
59
|
+public class NickList extends JScrollPane implements MouseListener {
|
56
|
60
|
|
57
|
61
|
/** A version number for this class. */
|
58
|
62
|
private static final long serialVersionUID = 10;
|
|
@@ -60,8 +64,6 @@ public class NickList extends JScrollPane implements ConfigChangeListener,
|
60
|
64
|
private final JList<ChannelClientInfo> nickList;
|
61
|
65
|
/** Parent frame. */
|
62
|
66
|
private final ChannelFrame frame;
|
63
|
|
- /** Config. */
|
64
|
|
- private final AggregateConfigProvider config;
|
65
|
67
|
/** The colour manager to use for this nicklist. */
|
66
|
68
|
private final ColourManager colourManager;
|
67
|
69
|
/** Nick list model. */
|
|
@@ -76,33 +78,11 @@ public class NickList extends JScrollPane implements ConfigChangeListener,
|
76
|
78
|
public NickList(final ChannelFrame frame, final AggregateConfigProvider config,
|
77
|
79
|
final ColourManagerFactory colourManagerFactory) {
|
78
|
80
|
this.frame = frame;
|
79
|
|
- this.config = config;
|
80
|
81
|
this.colourManager = colourManagerFactory.getColourManager(config);
|
81
|
82
|
|
82
|
83
|
nickList = new JList<>();
|
83
|
|
-
|
84
|
|
- nickList.setBackground(UIUtilities.convertColour(
|
85
|
|
- colourManager.getColourFromString(
|
86
|
|
- config.getOptionString(
|
87
|
|
- "ui", "nicklistbackgroundcolour",
|
88
|
|
- "ui", "backgroundcolour"), null)));
|
89
|
|
- nickList.setForeground(UIUtilities.convertColour(
|
90
|
|
- colourManager.getColourFromString(
|
91
|
|
- config.getOptionString(
|
92
|
|
- "ui", "nicklistforegroundcolour",
|
93
|
|
- "ui", "foregroundcolour"), null)));
|
94
|
|
- nickList.setFont(new Font(config.getOption("ui", "textPaneFontName"),
|
95
|
|
- Font.PLAIN, getFont().getSize()));
|
96
|
|
- config.addChangeListener("ui", "nicklistforegroundcolour", this);
|
97
|
|
- config.addChangeListener("ui", "foregroundcolour", this);
|
98
|
|
- config.addChangeListener("ui", "nicklistbackgroundcolour", this);
|
99
|
|
- config.addChangeListener("ui", "backgroundcolour", this);
|
100
|
|
- config.addChangeListener("ui", "nickListAltBackgroundColour", this);
|
101
|
|
- config.addChangeListener("ui", "textPaneFontName", this);
|
102
|
|
-
|
103
|
84
|
nickList.setCellRenderer(new NicklistRenderer(config, nickList, colourManager));
|
104
|
|
- nickList.setSelectionMode(
|
105
|
|
- ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
85
|
+ nickList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
106
|
86
|
|
107
|
87
|
nickList.addMouseListener(this);
|
108
|
88
|
|
|
@@ -111,14 +91,13 @@ public class NickList extends JScrollPane implements ConfigChangeListener,
|
111
|
91
|
nickList.setModel(nicklistModel);
|
112
|
92
|
setViewportView(nickList);
|
113
|
93
|
|
114
|
|
- final int splitPanePosition = config.getOptionInt("ui",
|
115
|
|
- "channelSplitPanePosition");
|
|
94
|
+ final int splitPanePosition = config.getOptionInt("ui", "channelSplitPanePosition");
|
116
|
95
|
setPreferredSize(new Dimension(splitPanePosition, 0));
|
117
|
96
|
setMinimumSize(new Dimension(75, 0));
|
118
|
97
|
|
119
|
|
- ((Channel) frame.getContainer()).addNicklistListener(this);
|
120
|
|
- clientListUpdated(((Channel) frame.getContainer()).getChannelInfo()
|
121
|
|
- .getChannelClients());
|
|
98
|
+ nicklistModel.replace(((Channel) frame.getContainer()).getChannelInfo().getChannelClients());
|
|
99
|
+ frame.getContainer().getEventBus().subscribe(this);
|
|
100
|
+ config.getBinder().bind(this, NickList.class);
|
122
|
101
|
}
|
123
|
102
|
|
124
|
103
|
@Override
|
|
@@ -146,11 +125,6 @@ public class NickList extends JScrollPane implements ConfigChangeListener,
|
146
|
125
|
//Ignore
|
147
|
126
|
}
|
148
|
127
|
|
149
|
|
- /**
|
150
|
|
- * Processes every mouse button event to check for a popup trigger.
|
151
|
|
- *
|
152
|
|
- * @param e mouse event
|
153
|
|
- */
|
154
|
128
|
@Override
|
155
|
129
|
public void processMouseEvent(final MouseEvent e) {
|
156
|
130
|
if (!e.isPopupTrigger()
|
|
@@ -225,53 +199,47 @@ public class NickList extends JScrollPane implements ConfigChangeListener,
|
225
|
199
|
return suceeded;
|
226
|
200
|
}
|
227
|
201
|
|
228
|
|
- @Override
|
229
|
|
- public void configChanged(final String domain, final String key) {
|
230
|
|
- if ("nickListAltBackgroundColour".equals(key)
|
231
|
|
- || "nicklistbackgroundcolour".equals(key)
|
232
|
|
- || "backgroundcolour".equals(key)
|
233
|
|
- || "nicklistforegroundcolour".equals(key)
|
234
|
|
- || "foregroundcolour".equals(key)
|
235
|
|
- || "textPaneFontName".equals(key)) {
|
236
|
|
- nickList.setBackground(UIUtilities.convertColour(
|
237
|
|
- colourManager.getColourFromString(
|
238
|
|
- config.getOptionString(
|
239
|
|
- "ui", "nicklistbackgroundcolour",
|
240
|
|
- "ui", "backgroundcolour"), null)));
|
241
|
|
- nickList.setForeground(UIUtilities.convertColour(
|
242
|
|
- colourManager.getColourFromString(
|
243
|
|
- config.getOptionString(
|
244
|
|
- "ui", "nicklistforegroundcolour",
|
245
|
|
- "ui", "foregroundcolour"), null)));
|
246
|
|
- nickList.setFont(new Font(config.getOption("ui", "textPaneFontName"),
|
247
|
|
- Font.PLAIN, getFont().getSize()));
|
248
|
|
- nickList.repaint();
|
249
|
|
- }
|
250
|
|
- nickList.setSelectionMode(
|
251
|
|
- ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
202
|
+ @ConfigBinding(domain = "ui", key = "textPaneFontName", invocation = EDTInvocation.class)
|
|
203
|
+ public void handleFontName(final String value) {
|
|
204
|
+ nickList.setFont(new Font(value, Font.PLAIN, getFont().getSize()));
|
|
205
|
+ nickList.repaint();
|
252
|
206
|
}
|
253
|
207
|
|
254
|
|
- @Override
|
255
|
|
- public void clientListUpdated(final Collection<ChannelClientInfo> clients) {
|
256
|
|
- SwingUtilities.invokeLater(() -> nicklistModel.replace(clients));
|
|
208
|
+ @ConfigBinding(domain = "ui", key = "nicklistbackgroundcolour",
|
|
209
|
+ fallbacks = {"ui", "backgroundcolour"}, invocation = EDTInvocation.class)
|
|
210
|
+ public void handleBackgroundColour(final String value) {
|
|
211
|
+ nickList.setBackground(UIUtilities.convertColour(
|
|
212
|
+ colourManager.getColourFromString(value, null)));
|
|
213
|
+ nickList.repaint();
|
257
|
214
|
}
|
258
|
215
|
|
259
|
|
- @Override
|
260
|
|
- public void clientListUpdated() {
|
261
|
|
- SwingUtilities.invokeLater(() -> {
|
262
|
|
- nicklistModel.sort();
|
263
|
|
- repaint();
|
264
|
|
- });
|
|
216
|
+ @ConfigBinding(domain = "ui", key = "nicklistforegroundcolour",
|
|
217
|
+ fallbacks = {"ui", "foregroundcolour"}, invocation = EDTInvocation.class)
|
|
218
|
+ public void handleForegroundColour(final String value) {
|
|
219
|
+ nickList.setForeground(UIUtilities.convertColour(
|
|
220
|
+ colourManager.getColourFromString(value, null)));
|
|
221
|
+ nickList.repaint();
|
265
|
222
|
}
|
266
|
223
|
|
267
|
|
- @Override
|
268
|
|
- public void clientAdded(final ChannelClientInfo client) {
|
269
|
|
- SwingUtilities.invokeLater(() -> nicklistModel.add(client));
|
|
224
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
225
|
+ public void handleClientsChanged(final NickListClientsChangedEvent event) {
|
|
226
|
+ nicklistModel.replace(event.getUsers());
|
270
|
227
|
}
|
271
|
228
|
|
272
|
|
- @Override
|
273
|
|
- public void clientRemoved(final ChannelClientInfo client) {
|
274
|
|
- SwingUtilities.invokeLater(() -> nicklistModel.remove(client));
|
|
229
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
230
|
+ public void handleNickListUpdated(final NickListUpdatedEvent event) {
|
|
231
|
+ nicklistModel.sort();
|
|
232
|
+ repaint();
|
|
233
|
+ }
|
|
234
|
+
|
|
235
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
236
|
+ public void handleClientAdded(final NickListClientAddedEvent event) {
|
|
237
|
+ nicklistModel.add(event.getUser());
|
|
238
|
+ }
|
|
239
|
+
|
|
240
|
+ @Handler(invocation = EdtHandlerInvocation.class)
|
|
241
|
+ public void handleClientRemoved(final NickListClientRemovedEvent event) {
|
|
242
|
+ nicklistModel.remove(event.getUser());
|
275
|
243
|
}
|
276
|
244
|
|
277
|
245
|
}
|