Przeglądaj źródła

Begin tidying up of WindowStatus Plugin.

Change-Id: Idfd426ddcc9441020c837dca79b97af4d78894f0
Reviewed-on: http://gerrit.dmdirc.com/3989
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/89/3989/2
Greg Holmes 9 lat temu
rodzic
commit
4fe44ffe14

+ 72
- 58
windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusManager.java Wyświetl plik

@@ -141,78 +141,92 @@ public class WindowStatusManager implements ConfigChangeListener, SelectionListe
141 141
         if (current == null) {
142 142
             return;
143 143
         }
144
-        final StringBuilder textString = new StringBuilder();
144
+        final String textString;
145 145
 
146 146
         if (current instanceof Connection) {
147
-            textString.append(((Connection) current).getAddress());
147
+            textString = updateStatusConnection((Connection) current);
148 148
         } else if (current instanceof Channel) {
149
-            final ChannelInfo chan = ((Channel) current).getChannelInfo();
150
-            final Map<Integer, String> names = new HashMap<>();
151
-            final Map<Integer, Integer> types = new HashMap<>();
152
-
153
-            textString.append(chan.getName());
154
-            textString.append(" - Nicks: ");
155
-            textString.append(chan.getChannelClientCount());
156
-            textString.append(" (");
157
-
158
-            for (ChannelClientInfo client : chan.getChannelClients()) {
159
-                String mode = client.getImportantModePrefix();
160
-                final Integer im = client.getClient().getParser()
161
-                        .getChannelUserModes().indexOf(mode);
162
-
163
-                if (!names.containsKey(im)) {
164
-                    if (mode.isEmpty()) {
165
-                        if (shownone) {
166
-                            mode = nonePrefix;
167
-                        } else {
168
-                            continue;
169
-                        }
170
-                    }
171
-                    names.put(im, mode);
172
-                }
149
+            textString = updateStatusChannel((Channel) current);
150
+        } else if (current instanceof Query) {
151
+            textString = updateStatusQuery((Query) current);
152
+        } else {
153
+            textString = "???";
154
+        }
155
+        if (panel != null) {
156
+            panel.setText(textString);
157
+        }
158
+    }
173 159
 
174
-                Integer count = types.get(im);
160
+    private String updateStatusConnection(final Connection connection) {
161
+        return connection.getAddress();
162
+    }
175 163
 
176
-                if (count == null) {
177
-                    count = 1;
178
-                } else {
179
-                    count++;
164
+    private String updateStatusChannel(final Channel frame) {
165
+        final StringBuilder textString = new StringBuilder();
166
+        final ChannelInfo chan = frame.getChannelInfo();
167
+        final Map<Integer, String> names = new HashMap<>();
168
+        final Map<Integer, Integer> types = new HashMap<>();
169
+
170
+        textString.append(chan.getName());
171
+        textString.append(" - Nicks: ");
172
+        textString.append(chan.getChannelClientCount());
173
+        textString.append(" (");
174
+
175
+        for (ChannelClientInfo client : chan.getChannelClients()) {
176
+            String mode = client.getImportantModePrefix();
177
+            final Integer im = client.getClient().getParser()
178
+                    .getChannelUserModes().indexOf(mode);
179
+
180
+            if (!names.containsKey(im)) {
181
+                if (mode.isEmpty()) {
182
+                    if (shownone) {
183
+                        mode = nonePrefix;
184
+                    } else {
185
+                        continue;
186
+                    }
180 187
                 }
181
-                types.put(im, count);
188
+                names.put(im, mode);
182 189
             }
183 190
 
184
-            boolean isFirst = true;
191
+            Integer count = types.get(im);
185 192
 
186
-            for (Map.Entry<Integer, Integer> entry : types.entrySet()) {
187
-                if (isFirst) {
188
-                    isFirst = false;
189
-                } else {
190
-                    textString.append(' ');
191
-                }
192
-                textString.append(names.get(entry.getKey()));
193
-                textString.append(entry.getValue());
193
+            if (count == null) {
194
+                count = 1;
195
+            } else {
196
+                count++;
194 197
             }
198
+            types.put(im, count);
199
+        }
195 200
 
196
-            textString.append(')');
197
-        } else if (current instanceof Query) {
198
-            final Query frame = (Query) current;
199
-
200
-            textString.append(frame.getHost());
201
-            if (showname && frame.getConnection().getParser() != null) {
202
-                final ClientInfo client = frame.getConnection().getParser()
203
-                        .getClient(frame.getHost());
204
-                final String realname = client.getRealname();
205
-                if (realname != null && !realname.isEmpty()) {
206
-                    textString.append(" - ");
207
-                    textString.append(client.getRealname());
208
-                }
201
+        boolean isFirst = true;
202
+
203
+        for (Map.Entry<Integer, Integer> entry : types.entrySet()) {
204
+            if (isFirst) {
205
+                isFirst = false;
206
+            } else {
207
+                textString.append(' ');
209 208
             }
210
-        } else {
211
-            textString.append("???");
209
+            textString.append(names.get(entry.getKey()));
210
+            textString.append(entry.getValue());
212 211
         }
213
-        if (panel != null) {
214
-            panel.setText(textString.toString());
212
+
213
+        textString.append(')');
214
+        return textString.toString();
215
+    }
216
+
217
+    private String updateStatusQuery(final Query frame) {
218
+        final StringBuilder textString = new StringBuilder();
219
+        textString.append(frame.getHost());
220
+        if (showname && frame.getConnection().getParser() != null) {
221
+            final ClientInfo client = frame.getConnection().getParser()
222
+                    .getClient(frame.getHost());
223
+            final String realname = client.getRealname();
224
+            if (realname != null && !realname.isEmpty()) {
225
+                textString.append(" - ");
226
+                textString.append(client.getRealname());
227
+            }
215 228
         }
229
+        return textString.toString();
216 230
     }
217 231
 
218 232
     @Override

+ 1
- 1
windowstatus/src/com/dmdirc/addons/windowstatus/WindowStatusModule.java Wyświetl plik

@@ -32,7 +32,7 @@ import dagger.Provides;
32 32
 /**
33 33
  * DI module for this plugin.
34 34
  */
35
-@Module(injects = {WindowStatusManager.class}, addsTo = SwingModule.class)
35
+@Module(injects = WindowStatusManager.class, addsTo = SwingModule.class)
36 36
 public class WindowStatusModule {
37 37
 
38 38
     /** The plugin's plugin info. */

Ładowanie…
Anuluj
Zapisz