|
@@ -31,7 +31,7 @@ import com.dmdirc.events.FrameComponentRemovedEvent;
|
31
|
31
|
import com.dmdirc.events.FrameIconChangedEvent;
|
32
|
32
|
import com.dmdirc.events.FrameNameChangedEvent;
|
33
|
33
|
import com.dmdirc.events.FrameTitleChangedEvent;
|
34
|
|
-import com.dmdirc.interfaces.Connection;
|
|
34
|
+import com.dmdirc.interfaces.WindowModel;
|
35
|
35
|
import com.dmdirc.interfaces.config.AggregateConfigProvider;
|
36
|
36
|
import com.dmdirc.interfaces.config.ConfigChangeListener;
|
37
|
37
|
import com.dmdirc.parser.common.CompositionState;
|
|
@@ -62,7 +62,7 @@ import static com.google.common.base.Preconditions.checkState;
|
62
|
62
|
* The frame container implements basic methods that should be present in all objects that handle a
|
63
|
63
|
* frame.
|
64
|
64
|
*/
|
65
|
|
-public abstract class FrameContainer {
|
|
65
|
+public abstract class FrameContainer implements WindowModel {
|
66
|
66
|
|
67
|
67
|
/** Listeners not yet using ListenerSupport. */
|
68
|
68
|
protected final ListenerList listeners = new ListenerList();
|
|
@@ -189,63 +189,52 @@ public abstract class FrameContainer {
|
189
|
189
|
backBuffer.startAddingEvents();
|
190
|
190
|
}
|
191
|
191
|
|
|
192
|
+ @Override
|
192
|
193
|
public Optional<FrameContainer> getParent() {
|
193
|
194
|
return parent;
|
194
|
195
|
}
|
195
|
196
|
|
|
197
|
+ @Override
|
196
|
198
|
public String getIcon() {
|
197
|
199
|
return icon;
|
198
|
200
|
}
|
199
|
201
|
|
|
202
|
+ @Override
|
200
|
203
|
public String getName() {
|
201
|
204
|
return name;
|
202
|
205
|
}
|
203
|
206
|
|
|
207
|
+ @Override
|
204
|
208
|
public String getTitle() {
|
205
|
209
|
return title;
|
206
|
210
|
}
|
207
|
211
|
|
|
212
|
+ @Override
|
208
|
213
|
public AggregateConfigProvider getConfigManager() {
|
209
|
214
|
return configManager;
|
210
|
215
|
}
|
211
|
216
|
|
|
217
|
+ @Override
|
212
|
218
|
public DMDircMBassador getEventBus() {
|
213
|
219
|
return eventBus;
|
214
|
220
|
}
|
215
|
221
|
|
|
222
|
+ @Override
|
216
|
223
|
public boolean isWritable() {
|
217
|
224
|
return writable;
|
218
|
225
|
}
|
219
|
226
|
|
220
|
|
- /**
|
221
|
|
- * Returns a collection of direct children of this frame.
|
222
|
|
- *
|
223
|
|
- * @return This frame's children
|
224
|
|
- *
|
225
|
|
- * @since 0.6.4
|
226
|
|
- */
|
|
227
|
+ @Override
|
227
|
228
|
public Collection<FrameContainer> getChildren() {
|
228
|
229
|
return Collections.unmodifiableCollection(children);
|
229
|
230
|
}
|
230
|
231
|
|
231
|
|
- /**
|
232
|
|
- * Adds a new child window to this frame.
|
233
|
|
- *
|
234
|
|
- * @param child The window to be added
|
235
|
|
- *
|
236
|
|
- * @since 0.6.4
|
237
|
|
- */
|
|
232
|
+ @Override
|
238
|
233
|
public void addChild(final FrameContainer child) {
|
239
|
234
|
children.add(child);
|
240
|
235
|
}
|
241
|
236
|
|
242
|
|
- /**
|
243
|
|
- * Removes a child window from this frame.
|
244
|
|
- *
|
245
|
|
- * @param child The window to be removed
|
246
|
|
- *
|
247
|
|
- * @since 0.6.4
|
248
|
|
- */
|
|
237
|
+ @Override
|
249
|
238
|
public void removeChild(final FrameContainer child) {
|
250
|
239
|
children.remove(child);
|
251
|
240
|
}
|
|
@@ -261,54 +250,32 @@ public abstract class FrameContainer {
|
261
|
250
|
eventBus.publishAsync(new FrameNameChangedEvent(this, name));
|
262
|
251
|
}
|
263
|
252
|
|
264
|
|
- /**
|
265
|
|
- * Changes the title of this container, and fires a {@link FrameTitleChangedEvent}.
|
266
|
|
- *
|
267
|
|
- * @param title The new title for this frame.
|
268
|
|
- */
|
|
253
|
+ @Override
|
269
|
254
|
public void setTitle(final String title) {
|
270
|
255
|
this.title = title;
|
271
|
256
|
|
272
|
257
|
eventBus.publishAsync(new FrameTitleChangedEvent(this, title));
|
273
|
258
|
}
|
274
|
259
|
|
275
|
|
- /**
|
276
|
|
- * Returns the collection of UI component identifiers that this frame container requires for its
|
277
|
|
- * display.
|
278
|
|
- *
|
279
|
|
- * @since 0.6.6
|
280
|
|
- * @return Collection of UI component identifiers
|
281
|
|
- */
|
|
260
|
+ @Override
|
282
|
261
|
public Set<String> getComponents() {
|
283
|
262
|
return Collections.unmodifiableSet(components);
|
284
|
263
|
}
|
285
|
264
|
|
286
|
|
- /**
|
287
|
|
- * Adds a new component to this container.
|
288
|
|
- *
|
289
|
|
- * @since 0.6.6
|
290
|
|
- * @param component The component to be added
|
291
|
|
- */
|
|
265
|
+ @Override
|
292
|
266
|
public void addComponent(final String component) {
|
293
|
267
|
components.add(component);
|
294
|
268
|
eventBus.publishAsync(new FrameComponentAddedEvent(this, component));
|
295
|
269
|
}
|
296
|
270
|
|
297
|
|
- /**
|
298
|
|
- * Removes a component from this container.
|
299
|
|
- *
|
300
|
|
- * @since 0.6.6
|
301
|
|
- * @param component The component to be removed
|
302
|
|
- */
|
|
271
|
+ @Override
|
303
|
272
|
public void removeComponent(final String component) {
|
304
|
273
|
components.remove(component);
|
305
|
274
|
|
306
|
275
|
eventBus.publishAsync(new FrameComponentRemovedEvent(this, component));
|
307
|
276
|
}
|
308
|
277
|
|
309
|
|
- /**
|
310
|
|
- * Closes this container (and its associated frame).
|
311
|
|
- */
|
|
278
|
+ @Override
|
312
|
279
|
public void close() {
|
313
|
280
|
eventBus.unsubscribe(unreadStatusManager);
|
314
|
281
|
configManager.getBinder().unbind(unreadStatusManager);
|
|
@@ -317,18 +284,7 @@ public abstract class FrameContainer {
|
317
|
284
|
getBackBuffer().stopAddingEvents();
|
318
|
285
|
}
|
319
|
286
|
|
320
|
|
- /**
|
321
|
|
- * Returns the connection that this container is associated with.
|
322
|
|
- *
|
323
|
|
- * @return the associated connection.
|
324
|
|
- */
|
325
|
|
- public abstract Optional<Connection> getConnection();
|
326
|
|
-
|
327
|
|
- /**
|
328
|
|
- * Sets the icon to be used by this frame container and fires a {@link FrameIconChangedEvent}.
|
329
|
|
- *
|
330
|
|
- * @param icon The new icon to be used
|
331
|
|
- */
|
|
287
|
+ @Override
|
332
|
288
|
public final void setIcon(final String icon) {
|
333
|
289
|
this.icon = icon;
|
334
|
290
|
|
|
@@ -345,88 +301,41 @@ public abstract class FrameContainer {
|
345
|
301
|
eventBus.publish(new FrameIconChangedEvent(this, icon));
|
346
|
302
|
}
|
347
|
303
|
|
348
|
|
- /**
|
349
|
|
- * Gets the back buffer for this container.
|
350
|
|
- *
|
351
|
|
- * @return This container's back buffer.
|
352
|
|
- */
|
|
304
|
+ @Override
|
353
|
305
|
public BackBuffer getBackBuffer() {
|
354
|
306
|
return backBuffer;
|
355
|
307
|
}
|
356
|
308
|
|
357
|
|
- /**
|
358
|
|
- * Adds a line to this container's window. If the window is null for some reason, the line is
|
359
|
|
- * silently discarded.
|
360
|
|
- *
|
361
|
|
- * @param type The message type to use
|
362
|
|
- * @param timestamp The timestamp to use for this line
|
363
|
|
- * @param args The message's arguments
|
364
|
|
- *
|
365
|
|
- * @since 0.6.4
|
366
|
|
- */
|
|
309
|
+ @Override
|
367
|
310
|
public void addLine(final String type, final Date timestamp, final Object... args) {
|
368
|
311
|
if (type != null && !type.isEmpty()) {
|
369
|
312
|
addLine(Formatter.formatMessage(getConfigManager(), type, args), timestamp);
|
370
|
313
|
}
|
371
|
314
|
}
|
372
|
315
|
|
373
|
|
- /**
|
374
|
|
- * Adds a line to this container's window. If the window is null for some reason, the line is
|
375
|
|
- * silently discarded.
|
376
|
|
- *
|
377
|
|
- * @param type The message type to use
|
378
|
|
- * @param args The message's arguments
|
379
|
|
- */
|
|
316
|
+ @Override
|
380
|
317
|
public void addLine(final String type, final Object... args) {
|
381
|
318
|
addLine(type, new Date(), args);
|
382
|
319
|
}
|
383
|
320
|
|
384
|
|
- /**
|
385
|
|
- * Adds a line to this container's window. If the window is null for some reason, the line is
|
386
|
|
- * silently discarded.
|
387
|
|
- *
|
388
|
|
- * @param type The message type to use
|
389
|
|
- * @param timestamp The timestamp to use for this line
|
390
|
|
- * @param args The message's arguments
|
391
|
|
- *
|
392
|
|
- * @since 0.6.4
|
393
|
|
- */
|
|
321
|
+ @Override
|
394
|
322
|
public void addLine(final StringBuffer type, final Date timestamp, final Object... args) {
|
395
|
323
|
if (type != null) {
|
396
|
324
|
addLine(type.toString(), timestamp, args);
|
397
|
325
|
}
|
398
|
326
|
}
|
399
|
327
|
|
400
|
|
- /**
|
401
|
|
- * Adds a line to this container's window. If the window is null for some reason, the line is
|
402
|
|
- * silently discarded.
|
403
|
|
- *
|
404
|
|
- * @param type The message type to use
|
405
|
|
- * @param args The message's arguments
|
406
|
|
- */
|
|
328
|
+ @Override
|
407
|
329
|
public void addLine(final StringBuffer type, final Object... args) {
|
408
|
330
|
addLine(type, new Date(), args);
|
409
|
331
|
}
|
410
|
332
|
|
411
|
|
- /**
|
412
|
|
- * Adds the specified raw line to the window, without using a formatter.
|
413
|
|
- *
|
414
|
|
- * @param line The line to be added
|
415
|
|
- * @param timestamp Whether or not to display the timestamp for this line
|
416
|
|
- */
|
|
333
|
+ @Override
|
417
|
334
|
public void addLine(final String line, final boolean timestamp) {
|
418
|
335
|
addLine(line, timestamp ? new Date() : null);
|
419
|
336
|
}
|
420
|
337
|
|
421
|
|
- /**
|
422
|
|
- * Adds the specified raw line to the window, without using a formatter, and using the specified
|
423
|
|
- * timestamp. If the timestamp is <code>null</code>, no timestamp is added.
|
424
|
|
- *
|
425
|
|
- * @param line The line to be added
|
426
|
|
- * @param timestamp The timestamp to use for the line
|
427
|
|
- *
|
428
|
|
- * @since 0.6.4
|
429
|
|
- */
|
|
338
|
+ @Override
|
430
|
339
|
public void addLine(final String line, final Date timestamp) {
|
431
|
340
|
for (final String myLine : line.split("\n")) {
|
432
|
341
|
getBackBuffer().getDocument().addText(
|
|
@@ -435,41 +344,24 @@ public abstract class FrameContainer {
|
435
|
344
|
}
|
436
|
345
|
}
|
437
|
346
|
|
438
|
|
- /**
|
439
|
|
- * Sends a line of text to this container's source.
|
440
|
|
- *
|
441
|
|
- * @param line The line to be sent
|
442
|
|
- */
|
|
347
|
+ @Override
|
443
|
348
|
public void sendLine(final String line) {
|
444
|
349
|
throw new UnsupportedOperationException("Container doesn't override sendLine");
|
445
|
350
|
}
|
446
|
351
|
|
447
|
|
- /**
|
448
|
|
- * Retrieves the command parser to be used for this container.
|
449
|
|
- *
|
450
|
|
- * @return This container's command parser
|
451
|
|
- */
|
|
352
|
+ @Override
|
452
|
353
|
public CommandParser getCommandParser() {
|
453
|
354
|
checkState(writable);
|
454
|
355
|
return commandParser.get();
|
455
|
356
|
}
|
456
|
357
|
|
457
|
|
- /**
|
458
|
|
- * Retrieves the tab completer which should be used for this container.
|
459
|
|
- *
|
460
|
|
- * @return This container's tab completer
|
461
|
|
- */
|
|
358
|
+ @Override
|
462
|
359
|
public TabCompleter getTabCompleter() {
|
463
|
360
|
checkState(writable);
|
464
|
361
|
return tabCompleter.get();
|
465
|
362
|
}
|
466
|
363
|
|
467
|
|
- /**
|
468
|
|
- * Returns the maximum length that a line passed to sendLine() should be, in order to prevent it
|
469
|
|
- * being truncated or causing protocol violations.
|
470
|
|
- *
|
471
|
|
- * @return The maximum line length for this container
|
472
|
|
- */
|
|
364
|
+ @Override
|
473
|
365
|
public int getMaxLineLength() {
|
474
|
366
|
throw new UnsupportedOperationException("Container doesn't override getMaxLineLength");
|
475
|
367
|
}
|
|
@@ -510,13 +402,7 @@ public abstract class FrameContainer {
|
510
|
402
|
return result;
|
511
|
403
|
}
|
512
|
404
|
|
513
|
|
- /**
|
514
|
|
- * Returns the number of lines that the specified string would be sent as.
|
515
|
|
- *
|
516
|
|
- * @param line The string to be split and sent
|
517
|
|
- *
|
518
|
|
- * @return The number of lines required to send the specified string
|
519
|
|
- */
|
|
405
|
+ @Override
|
520
|
406
|
public final int getNumLines(final String line) {
|
521
|
407
|
final String[] splitLines = line.split("(\n|\r\n|\r)", Integer.MAX_VALUE);
|
522
|
408
|
int lines = 0;
|
|
@@ -632,6 +518,7 @@ public abstract class FrameContainer {
|
632
|
518
|
// composition should override this.
|
633
|
519
|
}
|
634
|
520
|
|
|
521
|
+ @Override
|
635
|
522
|
public UnreadStatusManager getUnreadStatusManager() {
|
636
|
523
|
return unreadStatusManager;
|
637
|
524
|
}
|