Просмотр исходного кода

backported Cycle not working


git-svn-id: http://svn.dmdirc.com/branches/0.5.5@3056 00569f92-eb28-0410-84fd-f71c24880f
remotes/0.5.5
Shane Mc Cormack 16 лет назад
Родитель
Сommit
475b44fbf5
1 измененных файлов: 128 добавлений и 129 удалений
  1. 128
    129
      src/com/dmdirc/Channel.java

+ 128
- 129
src/com/dmdirc/Channel.java Просмотреть файл

@@ -56,47 +56,47 @@ import java.util.Map;
56 56
  */
57 57
 public final class Channel extends MessageTarget
58 58
         implements ConfigChangeListener, Serializable {
59
-    
59
+
60 60
     /**
61 61
      * A version number for this class. It should be changed whenever the class
62 62
      * structure is changed (or anything else that would prevent serialized
63 63
      * objects being unserialized with the new class).
64 64
      */
65 65
     private static final long serialVersionUID = 1;
66
-    
66
+
67 67
     /** The parser's pChannel class. */
68 68
     private transient ChannelInfo channelInfo;
69
-    
69
+
70 70
     /** The server this channel is on. */
71 71
     private Server server;
72
-    
72
+
73 73
     /** The ChannelWindow used for this channel. */
74 74
     private ChannelWindow window;
75
-    
75
+
76 76
     /** The tabcompleter used for this channel. */
77 77
     private final TabCompleter tabCompleter;
78
-    
78
+
79 79
     /** The config manager for this channel. */
80 80
     private final ConfigManager configManager;
81
-    
81
+
82 82
     /** A list of previous topics we've seen. */
83 83
     private final RollingList<Topic> topics;
84
-    
84
+
85 85
     /** Our event handler. */
86 86
     private final ChannelEventHandler eventHandler;
87
-    
87
+
88 88
     /** Whether we're in this channel or not. */
89 89
     private boolean onChannel;
90
-    
90
+
91 91
     /** Whether we should send WHO requests for this channel. */
92 92
     private volatile boolean sendWho;
93
-    
93
+
94 94
     /** Whether we should show mode prefixes in text. */
95 95
     private volatile boolean showModePrefix;
96
-    
96
+
97 97
     /** Whether we should show colours in nicks. */
98 98
     private volatile boolean showColours;
99
-    
99
+
100 100
     /**
101 101
      * Creates a new instance of Channel.
102 102
      * @param newServer The server object that this channel belongs to
@@ -105,64 +105,64 @@ public final class Channel extends MessageTarget
105 105
      */
106 106
     public Channel(final Server newServer, final ChannelInfo newChannelInfo) {
107 107
         super();
108
-        
108
+
109 109
         channelInfo = newChannelInfo;
110 110
         server = newServer;
111
-        
111
+
112 112
         configManager = new ConfigManager(server.getIrcd(), server.getNetwork(),
113 113
                 server.getName(), channelInfo.getName());
114
-                
114
+
115 115
         configManager.addChangeListener("channel", this);
116 116
         configManager.addChangeListener("ui", "shownickcoloursintext", this);
117
-        
117
+
118 118
         topics = new RollingList<Topic>(configManager.getOptionInt("channel",
119 119
                 "topichistorysize", 10));
120
-        
120
+
121 121
         sendWho = configManager.getOptionBool("channel", "sendwho", false);
122 122
         showModePrefix = configManager.getOptionBool("channel", "showmodeprefix", false);
123 123
         showColours = configManager.getOptionBool("ui", "shownickcoloursintext", false);
124
-        
124
+
125 125
         icon = IconManager.getIconManager().getIcon("channel");
126
-        
126
+
127 127
         tabCompleter = new TabCompleter(server.getTabCompleter());
128 128
         tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHANNEL));
129 129
         tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHAT));
130
-        
130
+
131 131
         window = Main.getUI().getChannel(Channel.this);
132 132
         WindowManager.addWindow(server.getFrame(), window);
133 133
         window.setFrameIcon(icon);
134 134
         window.getInputHandler().setTabCompleter(tabCompleter);
135
-        
135
+
136 136
         eventHandler = new ChannelEventHandler(this);
137
-        
137
+
138 138
         registerCallbacks();
139
-        
139
+
140 140
         ActionManager.processEvent(CoreActionType.CHANNEL_OPENED, null, this);
141
-        
141
+
142 142
         updateTitle();
143 143
         selfJoin();
144 144
     }
145
-    
145
+
146 146
     /**
147 147
      * Registers callbacks with the parser for this channel.
148 148
      */
149 149
     private void registerCallbacks() {
150 150
         eventHandler.registerCallbacks();
151 151
     }
152
-    
152
+
153 153
     /**
154 154
      * Shows this channel's window.
155 155
      */
156 156
     public void show() {
157 157
         window.open();
158 158
     }
159
-    
159
+
160 160
     /** {@inheritDoc} */
161 161
     @Override
162 162
     public ConfigManager getConfigManager() {
163 163
         return configManager;
164 164
     }
165
-    
165
+
166 166
     /** {@inheritDoc} */
167 167
     @Override
168 168
     public void sendLine(final String line) {
@@ -173,36 +173,36 @@ public final class Channel extends MessageTarget
173 173
             for (String part : line.split("\n")) {
174 174
                 sendLine(part);
175 175
             }
176
-            
176
+
177 177
             return;
178 178
         }
179
-        
179
+
180 180
         final ClientInfo me = server.getParser().getMyself();
181 181
         final String modes = getModes(channelInfo.getUser(me));
182 182
         final String[] details = getDetails(channelInfo.getUser(me), showColours);
183
-        
183
+
184 184
         if (line.length() <= getMaxLineLength()) {
185 185
             final StringBuffer buff = new StringBuffer("channelSelfMessage");
186
-            
186
+
187 187
             ActionManager.processEvent(CoreActionType.CHANNEL_SELF_MESSAGE, buff,
188 188
                     this, channelInfo.getUser(me), line);
189
-            
189
+
190 190
             addLine(buff, modes, details[0], details[1], details[2],
191 191
                     window.getTranscoder().encode(line), channelInfo);
192
-            
192
+
193 193
             channelInfo.sendMessage(window.getTranscoder().encode(line));
194 194
         } else {
195 195
             sendLine(line.substring(0, getMaxLineLength()));
196 196
             sendLine(line.substring(getMaxLineLength()));
197 197
         }
198 198
     }
199
-    
199
+
200 200
     /** {@inheritDoc} */
201 201
     @Override
202 202
     public int getMaxLineLength() {
203 203
         return server.getParser().getMaxLength("PRIVMSG", getChannelInfo().getName());
204 204
     }
205
-    
205
+
206 206
     /** {@inheritDoc} */
207 207
     @Override
208 208
     public void sendAction(final String action) {
@@ -210,25 +210,25 @@ public final class Channel extends MessageTarget
210 210
             // We're not in the channel
211 211
             return;
212 212
         }
213
-        
213
+
214 214
         final ClientInfo me = server.getParser().getMyself();
215 215
         final String modes = channelInfo.getUser(me).getImportantModePrefix();
216
-        
216
+
217 217
         if (server.getParser().getMaxLength("PRIVMSG", getChannelInfo().getName()) <= action.length()) {
218 218
             addLine("actionTooLong", action.length());
219 219
         } else {
220 220
             final StringBuffer buff = new StringBuffer("channelSelfAction");
221
-            
221
+
222 222
             ActionManager.processEvent(CoreActionType.CHANNEL_SELF_ACTION, buff,
223 223
                     this, channelInfo.getUser(me), action);
224
-            
224
+
225 225
             addLine(buff, modes, me.getNickname(), me.getIdent(),
226 226
                     me.getHost(), window.getTranscoder().encode(action), channelInfo);
227
-            
227
+
228 228
             channelInfo.sendAction(window.getTranscoder().encode(action));
229 229
         }
230 230
     }
231
-    
231
+
232 232
     /**
233 233
      * Returns the server object that this channel belongs to.
234 234
      * @return The server object
@@ -237,7 +237,7 @@ public final class Channel extends MessageTarget
237 237
     public Server getServer() {
238 238
         return server;
239 239
     }
240
-    
240
+
241 241
     /**
242 242
      * Returns the parser's ChannelInfo object that this object is associated with.
243 243
      * @return The ChannelInfo object associated with this object
@@ -245,7 +245,7 @@ public final class Channel extends MessageTarget
245 245
     public ChannelInfo getChannelInfo() {
246 246
         return channelInfo;
247 247
     }
248
-    
248
+
249 249
     /**
250 250
      * Sets this object's ChannelInfo reference to the one supplied. This only needs
251 251
      * to be done if the channel window (and hence this channel object) has stayed
@@ -256,7 +256,7 @@ public final class Channel extends MessageTarget
256 256
         channelInfo = newChannelInfo;
257 257
         registerCallbacks();
258 258
     }
259
-    
259
+
260 260
     /**
261 261
      * Returns the internal window belonging to this object.
262 262
      * @return This object's internal window
@@ -265,7 +265,7 @@ public final class Channel extends MessageTarget
265 265
     public InputWindow getFrame() {
266 266
         return window;
267 267
     }
268
-    
268
+
269 269
     /**
270 270
      * Returns the tab completer for this channel.
271 271
      * @return This channel's tab completer
@@ -273,52 +273,51 @@ public final class Channel extends MessageTarget
273 273
     public TabCompleter getTabCompleter() {
274 274
         return tabCompleter;
275 275
     }
276
-    
276
+
277 277
     /**
278 278
      * Called when we join this channel. Just needs to output a message.
279 279
      */
280 280
     public void selfJoin() {
281 281
         onChannel = true;
282
-        
282
+
283 283
         final ClientInfo me = server.getParser().getMyself();
284 284
         addLine("channelSelfJoin", "", me.getNickname(), me.getIdent(),
285 285
                 me.getHost(), channelInfo.getName());
286
-        
286
+
287 287
         icon = IconManager.getIconManager().getIcon("channel");
288
-        iconUpdated(icon);        
288
+        iconUpdated(icon);
289 289
     }
290
-    
290
+
291 291
     /**
292 292
      * Updates the title of the channel window, and of the main window if appropriate.
293 293
      */
294 294
     private void updateTitle() {
295 295
         String temp = Styliser.stipControlCodes(channelInfo.getName());
296
-        
296
+
297 297
         if (!channelInfo.getTopic().isEmpty()) {
298 298
             temp = temp + " - " + Styliser.stipControlCodes(channelInfo.getTopic());
299 299
         }
300
-        
300
+
301 301
         window.setTitle(temp);
302
-        
302
+
303 303
         if (window.isMaximum() && window.equals(Main.getUI().getMainWindow().getActiveFrame())) {
304 304
             Main.getUI().getMainWindow().setTitle(
305 305
                     Main.getUI().getMainWindow().getTitlePrefix() + " - " + temp);
306 306
         }
307 307
     }
308
-    
308
+
309 309
     /**
310 310
      * Joins the specified channel. This only makes sense if used after a call to
311 311
      * part().
312 312
      */
313 313
     public void join() {
314
-        if (server.getParser().getChannelInfo(channelInfo.getName()) == null) {
315
-            server.getParser().joinChannel(channelInfo.getName());
316
-        }
317
-        
314
+        server.getParser().joinChannel(channelInfo.getName());
315
+        activateFrame();
316
+
318 317
         icon = IconManager.getIconManager().getIcon("channel");
319
-        iconUpdated(icon);        
318
+        iconUpdated(icon);
320 319
     }
321
-    
320
+
322 321
     /**
323 322
      * Parts this channel with the specified message. Parting does NOT close the
324 323
      * channel window.
@@ -328,19 +327,19 @@ public final class Channel extends MessageTarget
328 327
         server.getParser().partChannel(channelInfo.getName(), reason);
329 328
         resetWindow();
330 329
     }
331
-    
330
+
332 331
     /**
333 332
      * Resets the window state after the client has left a channel.
334 333
      */
335 334
     public void resetWindow() {
336 335
         onChannel = false;
337
-        
336
+
338 337
         icon = IconManager.getIconManager().getIcon("channel-inactive");
339 338
         iconUpdated(icon);
340
-        
339
+
341 340
         window.updateNames(new ArrayList<ChannelClientInfo>());
342 341
     }
343
-    
342
+
344 343
     /**
345 344
      * Parts the channel and then closes the window.
346 345
      */
@@ -349,14 +348,14 @@ public final class Channel extends MessageTarget
349 348
         part(configManager.getOption("general", "partmessage"));
350 349
         closeWindow();
351 350
     }
352
-    
351
+
353 352
     /**
354 353
      * Closes the window without parting the channel.
355 354
      */
356 355
     public void closeWindow() {
357 356
         closeWindow(true);
358 357
     }
359
-    
358
+
360 359
     /**
361 360
      * Closes the window without parting the channel.
362 361
      *
@@ -366,19 +365,19 @@ public final class Channel extends MessageTarget
366 365
         if (server.getParser() != null) {
367 366
             server.getParser().getCallbackManager().delAllCallback(eventHandler);
368 367
         }
369
-        
368
+
370 369
         ActionManager.processEvent(CoreActionType.CHANNEL_CLOSED, null, this);
371
-        
370
+
372 371
         if (shouldRemove) {
373 372
             server.delChannel(channelInfo.getName());
374 373
         }
375
-        
374
+
376 375
         window.setVisible(false);
377 376
         Main.getUI().getMainWindow().delChild(window);
378 377
         window = null;
379 378
         server = null;
380 379
     }
381
-    
380
+
382 381
     /**
383 382
      * Called every {general.whotime} seconds to check if the channel needs
384 383
      * to send a who request.
@@ -388,54 +387,54 @@ public final class Channel extends MessageTarget
388 387
             server.getParser().sendLine("WHO :" + channelInfo.getName());
389 388
         }
390 389
     }
391
-    
390
+
392 391
     public void addClient(final ChannelClientInfo client) {
393 392
         window.addName(client);
394
-        tabCompleter.addEntry(client.getNickname());   
393
+        tabCompleter.addEntry(client.getNickname());
395 394
     }
396
-    
395
+
397 396
     public void removeClient(final ChannelClientInfo client) {
398 397
         window.removeName(client);
399 398
         tabCompleter.removeEntry(client.getNickname());
400
-        
399
+
401 400
         if (client.getClient().equals(server.getParser().getMyself())) {
402 401
             resetWindow();
403 402
         }
404 403
     }
405
-    
404
+
406 405
     public void renameClient(final String oldName, final String newName) {
407 406
         tabCompleter.removeEntry(oldName);
408
-        tabCompleter.addEntry(newName);        
407
+        tabCompleter.addEntry(newName);
409 408
         refreshClients();
410 409
     }
411
-    
410
+
412 411
     public void refreshClients() {
413 412
         window.updateNames();
414 413
     }
415
-   
414
+
416 415
     public void onChannelGotNames() {
417
-        
416
+
418 417
         window.updateNames(channelInfo.getChannelClients());
419
-        
418
+
420 419
         final ArrayList<String> names = new ArrayList<String>();
421
-        
420
+
422 421
         for (ChannelClientInfo channelClient : channelInfo.getChannelClients()) {
423 422
             names.add(channelClient.getNickname());
424 423
         }
425
-        
424
+
426 425
         tabCompleter.replaceEntries(names);
427 426
         tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHANNEL));
428 427
         tabCompleter.addEntries(CommandManager.getCommandNames(CommandType.TYPE_CHAT));
429
-        
428
+
430 429
         ActionManager.processEvent(CoreActionType.CHANNEL_GOTNAMES, null, this);
431 430
     }
432
-    
431
+
433 432
     public void onChannelTopic(final boolean bIsJoinTopic) {
434 433
         if (bIsJoinTopic) {
435 434
             final StringBuffer buff = new StringBuffer("channelJoinTopic");
436
-            
435
+
437 436
             ActionManager.processEvent(CoreActionType.CHANNEL_GOTTOPIC, buff, this);
438
-            
437
+
439 438
             addLine(buff, channelInfo.getTopic(), channelInfo.getTopicUser(),
440 439
                     1000 * channelInfo.getTopicTime(), channelInfo);
441 440
         } else {
@@ -443,59 +442,59 @@ public final class Channel extends MessageTarget
443 442
             final String[] parts = ClientInfo.parseHostFull(channelInfo.getTopicUser());
444 443
             final String modes = getModes(user);
445 444
             final String topic = channelInfo.getTopic();
446
-            
445
+
447 446
             final StringBuffer buff = new StringBuffer("channelTopicChange");
448
-            
447
+
449 448
             ActionManager.processEvent(CoreActionType.CHANNEL_TOPICCHANGE, buff, this, user, topic);
450
-            
449
+
451 450
             addLine(buff, modes, parts[0], parts[1], parts[2], channelInfo, topic);
452 451
         }
453
-        
454
-        topics.add(new Topic(channelInfo.getTopic(), 
452
+
453
+        topics.add(new Topic(channelInfo.getTopic(),
455 454
                 channelInfo.getTopicUser(), channelInfo.getTopicTime()));
456
-        
455
+
457 456
         updateTitle();
458 457
     }
459
-    
458
+
460 459
     public void onChannelModeChanged(
461 460
             final ChannelClientInfo cChannelClient, final String sHost, final String sModes) {
462 461
         if (sHost.isEmpty()) {
463 462
             final StringBuffer buff = new StringBuffer(21);
464
-            
463
+
465 464
             if (sModes.length() <= 1) {
466 465
                 buff.append("channelNoModes");
467 466
             } else {
468 467
                 buff.append("channelModeDiscovered");
469 468
             }
470
-            
469
+
471 470
             ActionManager.processEvent(CoreActionType.CHANNEL_MODECHANGE, buff, this, cChannelClient, sModes);
472
-            
471
+
473 472
             addLine(buff, sModes, channelInfo.getName());
474 473
         } else {
475 474
             final String modes = getModes(cChannelClient);
476 475
             final String[] details = getDetails(cChannelClient, showColours);
477 476
             final String myNick = server.getParser().getMyself().getNickname();
478
-            
477
+
479 478
             String type = "channelModeChange";
480 479
             if (myNick.equals(cChannelClient.getNickname())) {
481 480
                 type = "channelSelfModeChange";
482 481
             }
483
-            
482
+
484 483
             final StringBuffer buff = new StringBuffer(type);
485
-            
484
+
486 485
             ActionManager.processEvent(CoreActionType.CHANNEL_MODECHANGE, buff, this, cChannelClient, sModes);
487
-            
486
+
488 487
             addLine(type,  modes, details[0], details[1],
489 488
                     details[2], channelInfo.getName(), sModes);
490 489
         }
491
-        
490
+
492 491
         window.updateNames();
493 492
     }
494
-    
493
+
495 494
     public void onChannelUserModeChanged(
496 495
             final ChannelClientInfo cChangedClient,
497 496
             final ChannelClientInfo cSetByClient, final String sMode) {
498
-        
497
+
499 498
         if (configManager.getOptionBool("channel", "splitusermodes", false)) {
500 499
             final String sourceModes = getModes(cSetByClient);
501 500
             final String[] sourceHost = getDetails(cSetByClient, showColours);
@@ -503,24 +502,24 @@ public final class Channel extends MessageTarget
503 502
             final String targetNick = cChangedClient.getClient().getNickname();
504 503
             final String targetIdent = cChangedClient.getClient().getIdent();
505 504
             final String targetHost = cChangedClient.getClient().getHost();
506
-            
505
+
507 506
             String format = "channelUserMode_" + sMode;
508 507
             if (!Formatter.hasFormat(format)) {
509 508
                 format = "channelUserMode_default";
510 509
             }
511
-            
510
+
512 511
             addLine(format, sourceModes, sourceHost[0], sourceHost[1],
513 512
                     sourceHost[2], targetModes, targetNick, targetIdent,
514 513
                     targetHost, channelInfo, sMode);
515 514
         }
516
-        
515
+
517 516
         ActionManager.processEvent(CoreActionType.CHANNEL_USERMODECHANGE, null,
518 517
                 this, cSetByClient, cChangedClient, sMode);
519 518
     }
520
-    
519
+
521 520
     public void onAwayStateOther(final ClientInfo client, final boolean state) {
522 521
         final ChannelClientInfo channelClient = channelInfo.getUser(client);
523
-        
522
+
524 523
         if (channelClient != null) {
525 524
             if (state) {
526 525
                 ActionManager.processEvent(CoreActionType.CHANNEL_USERAWAY,
@@ -531,10 +530,10 @@ public final class Channel extends MessageTarget
531 530
             }
532 531
         }
533 532
     }
534
-    
533
+
535 534
     /**
536 535
      * Returns a string containing the most important mode for the specified client.
537
-     * 
536
+     *
538 537
      * @param channelClient The channel client to check.
539 538
      * @return A string containing the most important mode, or an empty string
540 539
      * if there are no (known) modes.
@@ -546,20 +545,20 @@ public final class Channel extends MessageTarget
546 545
             return channelClient.getImportantModePrefix();
547 546
         }
548 547
     }
549
-       
548
+
550 549
     /**
551 550
      * Retrieve the topics that have been seen on this channel.
552
-     * 
551
+     *
553 552
      * @return A list of topics that have been seen on this channel, including
554 553
      * the current one.
555 554
      */
556 555
     public List<Topic> getTopics() {
557 556
         return topics.getList();
558 557
     }
559
-    
558
+
560 559
     /**
561 560
      * Returns this channel's name.
562
-     * 
561
+     *
563 562
      * @return A string representation of this channel (i.e., its name)
564 563
      */
565 564
     @Override
@@ -578,10 +577,10 @@ public final class Channel extends MessageTarget
578 577
             showColours = configManager.getOptionBool("ui", "shownickcoloursintext", false);
579 578
         }
580 579
     }
581
-    
580
+
582 581
     /**
583 582
      * Returns a string[] containing the nickname/ident/host of a channel client.
584
-     * 
583
+     *
585 584
      * @param client The channel client to check
586 585
      * @param showColours Whether or not to show colours
587 586
      * @return A string[] containing displayable components
@@ -592,17 +591,17 @@ public final class Channel extends MessageTarget
592 591
             throw new UnsupportedOperationException("getDetails called with" +
593 592
                     "null ChannelClientInfo");
594 593
         }
595
-        
594
+
596 595
         final String[] res = new String[3];
597 596
         res[0] = Styliser.CODE_NICKNAME + client.getNickname() + Styliser.CODE_NICKNAME;
598 597
         res[1] = client.getClient().getIdent();
599 598
         res[2] = client.getClient().getHost();
600
-        
599
+
601 600
         if (showColours) {
602 601
             final Map map = client.getMap();
603 602
             String prefix = null;
604 603
             Color colour;
605
-            
604
+
606 605
             if (map.containsKey(ChannelClientProperty.TEXT_FOREGROUND)) {
607 606
                 colour = (Color) map.get(ChannelClientProperty.TEXT_FOREGROUND);
608 607
                 prefix = Styliser.CODE_HEXCOLOUR + ColourManager.getHex(colour);
@@ -611,15 +610,15 @@ public final class Channel extends MessageTarget
611 610
                     prefix = "," + ColourManager.getHex(colour);
612 611
                 }
613 612
             }
614
-            
613
+
615 614
             if (prefix != null) {
616 615
                 res[0] = prefix + res[0] + Styliser.CODE_HEXCOLOUR;
617 616
             }
618 617
         }
619
-        
618
+
620 619
         return res;
621
-    }    
622
-    
620
+    }
621
+
623 622
     /** {@inheritDoc} */
624 623
     @Override
625 624
     protected boolean processNotificationArg(final Object arg, final List<Object> args) {
@@ -633,7 +632,7 @@ public final class Channel extends MessageTarget
633 632
             final ChannelClientInfo clientInfo = (ChannelClientInfo) arg;
634 633
             args.add(getModes(clientInfo));
635 634
             args.addAll(Arrays.asList(getDetails(clientInfo, showColours)));
636
-            return true;            
635
+            return true;
637 636
         } else {
638 637
             return super.processNotificationArg(arg, args);
639 638
         }
@@ -645,12 +644,12 @@ public final class Channel extends MessageTarget
645 644
             final List<Object> messageArgs) {
646 645
         messageArgs.add(channelInfo.getName());
647 646
     }
648
-    
647
+
649 648
     // ------------------------------------------ PARSER METHOD DELEGATION -----
650
-    
649
+
651 650
     /**
652 651
      * Attempts to set the topic of this channel.
653
-     * 
652
+     *
654 653
      * @param topic The new topic to be used. An empty string will clear the
655 654
      * current topic
656 655
      */

Загрузка…
Отмена
Сохранить