瀏覽代碼

Use GroupChatUser some more.

pull/220/head
Greg Holmes 9 年之前
父節點
當前提交
43b938f43a

+ 2
- 2
contactlist/src/com/dmdirc/addons/contactlist/ContactListListener.java 查看文件

70
 
70
 
71
     @Handler
71
     @Handler
72
     public void handleClientsUpdated(final NickListClientsChangedEvent event) {
72
     public void handleClientsUpdated(final NickListClientsChangedEvent event) {
73
-        event.getUsers().forEach(this::clientAdded);
73
+        //event.getUsers().forEach(this::clientAdded);
74
     }
74
     }
75
 
75
 
76
     @Handler
76
     @Handler
77
     public void handleClientAdded(final NickListClientAddedEvent event) {
77
     public void handleClientAdded(final NickListClientAddedEvent event) {
78
-        clientAdded(event.getUser());
78
+        //clientAdded(event.getUser());
79
     }
79
     }
80
 
80
 
81
     @Handler
81
     @Handler

+ 1
- 3
nickcolours/plugin.config 查看文件

35
 defaults:
35
 defaults:
36
   useowncolour=false
36
   useowncolour=false
37
   owncolour=ff0000
37
   owncolour=ff0000
38
-  userandomcolour=false
39
-  settext=false
40
-  setnicklist=false
38
+  userandomcolour=false

+ 8
- 7
ui_swing/src/com/dmdirc/addons/ui_swing/components/NickList.java 查看文件

35
 import com.dmdirc.events.NickListClientRemovedEvent;
35
 import com.dmdirc.events.NickListClientRemovedEvent;
36
 import com.dmdirc.events.NickListClientsChangedEvent;
36
 import com.dmdirc.events.NickListClientsChangedEvent;
37
 import com.dmdirc.events.NickListUpdatedEvent;
37
 import com.dmdirc.events.NickListUpdatedEvent;
38
+import com.dmdirc.interfaces.GroupChatUser;
38
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
39
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
39
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
40
 import com.dmdirc.ui.messages.ColourManager;
40
 import com.dmdirc.ui.messages.ColourManager;
41
 import com.dmdirc.ui.messages.ColourManagerFactory;
41
 import com.dmdirc.ui.messages.ColourManagerFactory;
42
 
42
 
61
     /** A version number for this class. */
61
     /** A version number for this class. */
62
     private static final long serialVersionUID = 10;
62
     private static final long serialVersionUID = 10;
63
     /** Nick list. */
63
     /** Nick list. */
64
-    private final JList<ChannelClientInfo> nickList;
64
+    private final JList<GroupChatUser> nickList;
65
     /** Parent frame. */
65
     /** Parent frame. */
66
     private final ChannelFrame frame;
66
     private final ChannelFrame frame;
67
     /** The colour manager to use for this nicklist. */
67
     /** The colour manager to use for this nicklist. */
81
         this.colourManager = colourManagerFactory.getColourManager(config);
81
         this.colourManager = colourManagerFactory.getColourManager(config);
82
 
82
 
83
         nickList = new JList<>();
83
         nickList = new JList<>();
84
-        nickList.setCellRenderer(new NicklistRenderer(config, nickList, colourManager));
84
+        nickList.setCellRenderer(new NicklistRenderer(nickList.getCellRenderer(), config,
85
+                nickList, colourManager));
85
         nickList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
86
         nickList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
86
 
87
 
87
         nickList.addMouseListener(this);
88
         nickList.addMouseListener(this);
95
         setPreferredSize(new Dimension(splitPanePosition, 0));
96
         setPreferredSize(new Dimension(splitPanePosition, 0));
96
         setMinimumSize(new Dimension(75, 0));
97
         setMinimumSize(new Dimension(75, 0));
97
 
98
 
98
-        nicklistModel.replace(((Channel) frame.getContainer()).getChannelInfo().getChannelClients());
99
+        nicklistModel.replace(((Channel) frame.getContainer()).getUsers());
99
         frame.getContainer().getEventBus().subscribe(this);
100
         frame.getContainer().getEventBus().subscribe(this);
100
         config.getBinder().bind(this, NickList.class);
101
         config.getBinder().bind(this, NickList.class);
101
     }
102
     }
133
             return;
134
             return;
134
         }
135
         }
135
         if (checkCursorInSelectedCell() || selectNickUnderCursor()) {
136
         if (checkCursorInSelectedCell() || selectNickUnderCursor()) {
136
-            final List<ChannelClientInfo> values = nickList.getSelectedValuesList();
137
+            final List<GroupChatUser> values = nickList.getSelectedValuesList();
137
             final StringBuilder builder = new StringBuilder();
138
             final StringBuilder builder = new StringBuilder();
138
 
139
 
139
-            for (ChannelClientInfo value : values) {
140
+            for (GroupChatUser value : values) {
140
                 if (builder.length() > 0) {
141
                 if (builder.length() > 0) {
141
                     builder.append('\n');
142
                     builder.append('\n');
142
                 }
143
                 }
143
 
144
 
144
-                builder.append(value.getClient().getNickname());
145
+                builder.append(value.getNickname());
145
             }
146
             }
146
 
147
 
147
             frame.showPopupMenu(new ClickTypeValue(ClickType.NICKNAME,
148
             frame.showPopupMenu(new ClickTypeValue(ClickType.NICKNAME,

+ 13
- 25
ui_swing/src/com/dmdirc/addons/ui_swing/components/NicklistComparator.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.components;
23
 package com.dmdirc.addons.ui_swing.components;
24
 
24
 
25
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
25
+import com.dmdirc.interfaces.GroupChatUser;
26
+
27
+import com.google.common.collect.ComparisonChain;
26
 
28
 
27
 import java.io.Serializable;
29
 import java.io.Serializable;
28
 import java.util.Comparator;
30
 import java.util.Comparator;
30
 /**
32
 /**
31
  * Compares nicklist entries to each other, for sorting purposes.
33
  * Compares nicklist entries to each other, for sorting purposes.
32
  */
34
  */
33
-public final class NicklistComparator implements Comparator<ChannelClientInfo>,
34
-        Serializable {
35
+public final class NicklistComparator implements Comparator<GroupChatUser>, Serializable {
35
 
36
 
36
     /** A version number for this class. */
37
     /** A version number for this class. */
37
     private static final long serialVersionUID = 1;
38
     private static final long serialVersionUID = 1;
52
         this.sortByCase = newSortByCase;
53
         this.sortByCase = newSortByCase;
53
     }
54
     }
54
 
55
 
55
-    /**
56
-     * Compares two ChannelClient objects based on the settings the comparator was initialised with.
57
-     *
58
-     * @param client1 the first client to be compared
59
-     * @param client2 the second client to be compared
60
-     *
61
-     * @return a negative integer, zero, or a positive integer as the first argument is less than,
62
-     *         equal to, or greater than the second.
63
-     */
64
     @Override
56
     @Override
65
-    public int compare(final ChannelClientInfo client1,
66
-            final ChannelClientInfo client2) {
57
+    public int compare(final GroupChatUser client1, final GroupChatUser client2) {
58
+        ComparisonChain comparisonChain = ComparisonChain.start();
67
         if (sortByMode) {
59
         if (sortByMode) {
68
-            final int modeCom = client2.compareTo(client1);
69
-
70
-            if (modeCom != 0) {
71
-                return modeCom;
72
-            }
60
+            comparisonChain = comparisonChain
61
+                    .compare(client1.getImportantMode(), client2.getImportantMode());
73
         }
62
         }
74
-
75
-        final String nickname1 = client1.getClient().getNickname();
76
-        final String nickname2 = client2.getClient().getNickname();
77
-
78
         if (sortByCase) {
63
         if (sortByCase) {
79
-            return nickname1.compareTo(nickname2);
64
+            comparisonChain = comparisonChain.compare(client1.getNickname(), client2.getNickname());
80
         } else {
65
         } else {
81
-            return nickname1.compareToIgnoreCase(nickname2);
66
+            comparisonChain = comparisonChain
67
+                    .compare(client1.getNickname().toLowerCase(),
68
+                            client2.getNickname().toLowerCase());
82
         }
69
         }
70
+        return comparisonChain.result();
83
     }
71
     }
84
 
72
 
85
 }
73
 }

+ 13
- 17
ui_swing/src/com/dmdirc/addons/ui_swing/components/NicklistListModel.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.components;
23
 package com.dmdirc.addons.ui_swing.components;
24
 
24
 
25
+import com.dmdirc.interfaces.GroupChatUser;
25
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
26
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
26
 import com.dmdirc.interfaces.config.ConfigChangeListener;
27
 import com.dmdirc.interfaces.config.ConfigChangeListener;
27
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
28
 
28
 
29
 import java.util.ArrayList;
29
 import java.util.ArrayList;
30
 import java.util.Collection;
30
 import java.util.Collection;
34
 import javax.swing.AbstractListModel;
34
 import javax.swing.AbstractListModel;
35
 
35
 
36
 /** Stores and provides means to modify nicklist data for a channel. */
36
 /** Stores and provides means to modify nicklist data for a channel. */
37
-public final class NicklistListModel extends AbstractListModel<ChannelClientInfo> implements
37
+public final class NicklistListModel extends AbstractListModel<GroupChatUser> implements
38
         ConfigChangeListener {
38
         ConfigChangeListener {
39
 
39
 
40
     /** A version number for this class. */
40
     /** A version number for this class. */
41
     private static final long serialVersionUID = 1;
41
     private static final long serialVersionUID = 1;
42
     /** stores the nicknames to be shown in this list. */
42
     /** stores the nicknames to be shown in this list. */
43
-    private final List<ChannelClientInfo> nicknames;
43
+    private final List<GroupChatUser> nicknames;
44
     /** Config manager. */
44
     /** Config manager. */
45
     private final AggregateConfigProvider config;
45
     private final AggregateConfigProvider config;
46
     /** Sort by mode? */
46
     /** Sort by mode? */
54
      * @param config Config manager
54
      * @param config Config manager
55
      */
55
      */
56
     public NicklistListModel(final AggregateConfigProvider config) {
56
     public NicklistListModel(final AggregateConfigProvider config) {
57
-        this(config, Collections.synchronizedList(
58
-                new ArrayList<>()));
57
+        this(config, Collections.synchronizedList(new ArrayList<>()));
59
     }
58
     }
60
 
59
 
61
     /**
60
     /**
65
      * @param newNicknames list of nicknames used for initialisation
64
      * @param newNicknames list of nicknames used for initialisation
66
      */
65
      */
67
     public NicklistListModel(final AggregateConfigProvider config,
66
     public NicklistListModel(final AggregateConfigProvider config,
68
-            final List<ChannelClientInfo> newNicknames) {
67
+            final List<GroupChatUser> newNicknames) {
69
 
68
 
70
         this.config = config;
69
         this.config = config;
71
 
70
 
96
      * @return nicklist entry requested
95
      * @return nicklist entry requested
97
      */
96
      */
98
     @Override
97
     @Override
99
-    public ChannelClientInfo getElementAt(final int index) {
98
+    public GroupChatUser getElementAt(final int index) {
100
         return nicknames.get(index);
99
         return nicknames.get(index);
101
     }
100
     }
102
 
101
 
105
      */
104
      */
106
     public void sort() {
105
     public void sort() {
107
         synchronized (nicknames) {
106
         synchronized (nicknames) {
108
-            Collections.sort(nicknames,
109
-                    new NicklistComparator(sortByMode, sortByCase));
107
+            Collections.sort(nicknames, new NicklistComparator(sortByMode, sortByCase));
110
         }
108
         }
111
         rerender();
109
         rerender();
112
     }
110
     }
118
      *
116
      *
119
      * @return boolean success
117
      * @return boolean success
120
      */
118
      */
121
-    public boolean replace(final Collection<ChannelClientInfo> clients) {
119
+    public boolean replace(final Collection<GroupChatUser> clients) {
122
         nicknames.clear();
120
         nicknames.clear();
123
         nicknames.addAll(clients);
121
         nicknames.addAll(clients);
124
         sort();
122
         sort();
133
      *
131
      *
134
      * @return boolean success
132
      * @return boolean success
135
      */
133
      */
136
-    public boolean add(final ChannelClientInfo client) {
134
+    public boolean add(final GroupChatUser client) {
137
         nicknames.add(client);
135
         nicknames.add(client);
138
         sort();
136
         sort();
139
 
137
 
147
      *
145
      *
148
      * @return boolean success
146
      * @return boolean success
149
      */
147
      */
150
-    public boolean remove(final ChannelClientInfo client) {
151
-        final boolean returnValue;
148
+    public boolean remove(final GroupChatUser client) {
152
 
149
 
153
-        returnValue = nicknames.remove(client);
150
+        final boolean returnValue = nicknames.remove(client);
154
         rerender();
151
         rerender();
155
 
152
 
156
         return returnValue;
153
         return returnValue;
163
      *
160
      *
164
      * @return ChannelClientInfo client removed
161
      * @return ChannelClientInfo client removed
165
      */
162
      */
166
-    public ChannelClientInfo remove(final int index) {
167
-        final ChannelClientInfo returnValue;
163
+    public GroupChatUser remove(final int index) {
168
 
164
 
169
-        returnValue = nicknames.remove(index);
165
+        final GroupChatUser returnValue = nicknames.remove(index);
170
         rerender();
166
         rerender();
171
 
167
 
172
         return returnValue;
168
         return returnValue;

+ 18
- 36
ui_swing/src/com/dmdirc/addons/ui_swing/components/renderers/NicklistRenderer.java 查看文件

22
 
22
 
23
 package com.dmdirc.addons.ui_swing.components.renderers;
23
 package com.dmdirc.addons.ui_swing.components.renderers;
24
 
24
 
25
-import com.dmdirc.ChannelClientProperty;
26
 import com.dmdirc.addons.ui_swing.EDTInvocation;
25
 import com.dmdirc.addons.ui_swing.EDTInvocation;
27
 import com.dmdirc.addons.ui_swing.UIUtilities;
26
 import com.dmdirc.addons.ui_swing.UIUtilities;
28
 import com.dmdirc.config.ConfigBinding;
27
 import com.dmdirc.config.ConfigBinding;
28
+import com.dmdirc.events.DisplayProperty;
29
+import com.dmdirc.interfaces.GroupChatUser;
29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30
-import com.dmdirc.parser.interfaces.ChannelClientInfo;
31
 import com.dmdirc.ui.messages.ColourManager;
31
 import com.dmdirc.ui.messages.ColourManager;
32
-import com.dmdirc.util.colours.Colour;
33
 
32
 
34
 import java.awt.Color;
33
 import java.awt.Color;
35
-import java.awt.Component;
36
-import java.util.Map;
37
 
34
 
38
-import javax.swing.DefaultListCellRenderer;
35
+import javax.swing.JLabel;
39
 import javax.swing.JList;
36
 import javax.swing.JList;
37
+import javax.swing.ListCellRenderer;
40
 
38
 
41
 /** Renders the nicklist. */
39
 /** Renders the nicklist. */
42
-public final class NicklistRenderer extends DefaultListCellRenderer {
40
+public final class NicklistRenderer extends DMDircListCellRenderer<GroupChatUser> {
43
 
41
 
44
-    /** A version number for this class. */
45
-    private static final long serialVersionUID = 5;
46
     /** Config manager. */
42
     /** Config manager. */
47
     private final AggregateConfigProvider config;
43
     private final AggregateConfigProvider config;
48
     /** Nicklist alternate background colour. */
44
     /** Nicklist alternate background colour. */
50
     /** Show nick colours. */
46
     /** Show nick colours. */
51
     private boolean showColours;
47
     private boolean showColours;
52
     /** The list that we're using for the nicklist. */
48
     /** The list that we're using for the nicklist. */
53
-    private final JList<ChannelClientInfo> nicklist;
49
+    private final JList<GroupChatUser> nicklist;
54
     /** Colour manager to use to resolve colours. */
50
     /** Colour manager to use to resolve colours. */
55
     private final ColourManager colourManager;
51
     private final ColourManager colourManager;
56
 
52
 
61
      * @param nicklist      The nicklist that we're rendering for.
57
      * @param nicklist      The nicklist that we're rendering for.
62
      * @param colourManager Colour manager to use to resolve colours.
58
      * @param colourManager Colour manager to use to resolve colours.
63
      */
59
      */
64
-    public NicklistRenderer(
60
+    public NicklistRenderer(final ListCellRenderer<? super GroupChatUser> renderer,
65
             final AggregateConfigProvider config,
61
             final AggregateConfigProvider config,
66
-            final JList<ChannelClientInfo> nicklist,
62
+            final JList<GroupChatUser> nicklist,
67
             final ColourManager colourManager) {
63
             final ColourManager colourManager) {
64
+        super(renderer);
68
         this.config = config;
65
         this.config = config;
69
         this.nicklist = nicklist;
66
         this.nicklist = nicklist;
70
         this.colourManager = colourManager;
67
         this.colourManager = colourManager;
72
     }
69
     }
73
 
70
 
74
     @Override
71
     @Override
75
-    public Component getListCellRendererComponent(final JList<?> list,
76
-            final Object value, final int index, final boolean isSelected,
77
-            final boolean cellHasFocus) {
78
-
79
-        super.getListCellRendererComponent(list, value, index, isSelected,
80
-                cellHasFocus);
81
-
72
+    protected void renderValue(final JLabel label, final GroupChatUser value, final int index,
73
+            final boolean isSelected, final boolean hasFocus) {
82
         if (!isSelected && (index & 1) == 1) {
74
         if (!isSelected && (index & 1) == 1) {
83
-            setBackground(altBackgroundColour);
75
+            label.setBackground(altBackgroundColour);
84
         }
76
         }
85
-
86
-        final Map<?, ?> map = ((ChannelClientInfo) value).getMap();
87
-
88
-        if (showColours && map != null) {
89
-            if (map.containsKey(ChannelClientProperty.NICKLIST_FOREGROUND)) {
90
-                setForeground(UIUtilities.convertColour((Colour) map.get(
91
-                        ChannelClientProperty.NICKLIST_FOREGROUND)));
92
-            }
93
-
94
-            if (map.containsKey(ChannelClientProperty.NICKLIST_BACKGROUND)) {
95
-                setBackground(UIUtilities.convertColour((Colour) map.get(
96
-                        ChannelClientProperty.NICKLIST_BACKGROUND)));
97
-            }
77
+        if (showColours) {
78
+            value.getDisplayProperty(DisplayProperty.FOREGROUND_COLOUR).ifPresent(
79
+                    c -> label.setForeground(UIUtilities.convertColour(c)));
80
+            value.getDisplayProperty(DisplayProperty.BACKGROUND_COLOUR).ifPresent(
81
+                    c -> label.setForeground(UIUtilities.convertColour(c)));
98
         }
82
         }
99
-
100
-        return this;
83
+        label.setText(value.getImportantMode() + value.getNickname());
101
     }
84
     }
102
 
85
 
103
     @ConfigBinding(domain = "ui", key = "shownickcoloursinnicklist",
86
     @ConfigBinding(domain = "ui", key = "shownickcoloursinnicklist",
115
                 colourManager.getColourFromString(value, null));
98
                 colourManager.getColourFromString(value, null));
116
         nicklist.repaint();
99
         nicklist.repaint();
117
     }
100
     }
118
-
119
 }
101
 }

Loading…
取消
儲存