Browse Source

Add an interface for FrameContainers.

pull/470/head
Chris Smith 9 years ago
parent
commit
7287ba0d4f
2 changed files with 275 additions and 144 deletions
  1. 31
    144
      src/com/dmdirc/FrameContainer.java
  2. 244
    0
      src/com/dmdirc/interfaces/WindowModel.java

+ 31
- 144
src/com/dmdirc/FrameContainer.java View File

@@ -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
     }

+ 244
- 0
src/com/dmdirc/interfaces/WindowModel.java View File

@@ -0,0 +1,244 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.interfaces;
24
+
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.FrameContainer;
27
+import com.dmdirc.commandparser.parsers.CommandParser;
28
+import com.dmdirc.events.FrameIconChangedEvent;
29
+import com.dmdirc.events.FrameTitleChangedEvent;
30
+import com.dmdirc.interfaces.config.AggregateConfigProvider;
31
+import com.dmdirc.ui.input.TabCompleter;
32
+import com.dmdirc.ui.messages.BackBuffer;
33
+import com.dmdirc.ui.messages.UnreadStatusManager;
34
+
35
+import java.util.Collection;
36
+import java.util.Date;
37
+import java.util.Optional;
38
+import java.util.Set;
39
+
40
+/**
41
+ * Models the state of a window.
42
+ */
43
+public interface WindowModel {
44
+
45
+    Optional<FrameContainer> getParent();
46
+
47
+    String getIcon();
48
+
49
+    String getName();
50
+
51
+    String getTitle();
52
+
53
+    AggregateConfigProvider getConfigManager();
54
+
55
+    DMDircMBassador getEventBus();
56
+
57
+    boolean isWritable();
58
+
59
+    /**
60
+     * Returns a collection of direct children of this frame.
61
+     *
62
+     * @return This frame's children
63
+     *
64
+     * @since 0.6.4
65
+     */
66
+    Collection<FrameContainer> getChildren();
67
+
68
+    /**
69
+     * Adds a new child window to this frame.
70
+     *
71
+     * @param child The window to be added
72
+     *
73
+     * @since 0.6.4
74
+     */
75
+    void addChild(FrameContainer child);
76
+
77
+    /**
78
+     * Removes a child window from this frame.
79
+     *
80
+     * @param child The window to be removed
81
+     *
82
+     * @since 0.6.4
83
+     */
84
+    void removeChild(FrameContainer child);
85
+
86
+    /**
87
+     * Changes the title of this container, and fires a {@link FrameTitleChangedEvent}.
88
+     *
89
+     * @param title The new title for this frame.
90
+     */
91
+    void setTitle(String title);
92
+
93
+    /**
94
+     * Returns the collection of UI component identifiers that this frame container requires for its
95
+     * display.
96
+     *
97
+     * @since 0.6.6
98
+     * @return Collection of UI component identifiers
99
+     */
100
+    Set<String> getComponents();
101
+
102
+    /**
103
+     * Adds a new component to this container.
104
+     *
105
+     * @since 0.6.6
106
+     * @param component The component to be added
107
+     */
108
+    void addComponent(String component);
109
+
110
+    /**
111
+     * Removes a component from this container.
112
+     *
113
+     * @since 0.6.6
114
+     * @param component The component to be removed
115
+     */
116
+    void removeComponent(String component);
117
+
118
+    /**
119
+     * Closes this container (and its associated frame).
120
+     */
121
+    void close();
122
+
123
+    /**
124
+     * Returns the connection that this container is associated with.
125
+     *
126
+     * @return the associated connection.
127
+     */
128
+    Optional<Connection> getConnection();
129
+
130
+    /**
131
+     * Sets the icon to be used by this frame container and fires a {@link FrameIconChangedEvent}.
132
+     *
133
+     * @param icon The new icon to be used
134
+     */
135
+    void setIcon(String icon);
136
+
137
+    /**
138
+     * Gets the back buffer for this container.
139
+     *
140
+     * @return This container's back buffer.
141
+     */
142
+    BackBuffer getBackBuffer();
143
+
144
+    /**
145
+     * Adds a line to this container's window. If the window is null for some reason, the line is
146
+     * silently discarded.
147
+     *
148
+     * @param type      The message type to use
149
+     * @param timestamp The timestamp to use for this line
150
+     * @param args      The message's arguments
151
+     *
152
+     * @since 0.6.4
153
+     */
154
+    void addLine(String type, Date timestamp, Object... args);
155
+
156
+    /**
157
+     * Adds a line to this container's window. If the window is null for some reason, the line is
158
+     * silently discarded.
159
+     *
160
+     * @param type The message type to use
161
+     * @param args The message's arguments
162
+     */
163
+    void addLine(String type, Object... args);
164
+
165
+    /**
166
+     * Adds a line to this container's window. If the window is null for some reason, the line is
167
+     * silently discarded.
168
+     *
169
+     * @param type      The message type to use
170
+     * @param timestamp The timestamp to use for this line
171
+     * @param args      The message's arguments
172
+     *
173
+     * @since 0.6.4
174
+     */
175
+    void addLine(StringBuffer type, Date timestamp, Object... args);
176
+
177
+    /**
178
+     * Adds a line to this container's window. If the window is null for some reason, the line is
179
+     * silently discarded.
180
+     *
181
+     * @param type The message type to use
182
+     * @param args The message's arguments
183
+     */
184
+    void addLine(StringBuffer type, Object... args);
185
+
186
+    /**
187
+     * Adds the specified raw line to the window, without using a formatter.
188
+     *
189
+     * @param line      The line to be added
190
+     * @param timestamp Whether or not to display the timestamp for this line
191
+     */
192
+    void addLine(String line, boolean timestamp);
193
+
194
+    /**
195
+     * Adds the specified raw line to the window, without using a formatter, and using the specified
196
+     * timestamp. If the timestamp is <code>null</code>, no timestamp is added.
197
+     *
198
+     * @param line      The line to be added
199
+     * @param timestamp The timestamp to use for the line
200
+     *
201
+     * @since 0.6.4
202
+     */
203
+    void addLine(String line, Date timestamp);
204
+
205
+    /**
206
+     * Sends a line of text to this container's source.
207
+     *
208
+     * @param line The line to be sent
209
+     */
210
+    void sendLine(String line);
211
+
212
+    /**
213
+     * Retrieves the command parser to be used for this container.
214
+     *
215
+     * @return This container's command parser
216
+     */
217
+    CommandParser getCommandParser();
218
+
219
+    /**
220
+     * Retrieves the tab completer which should be used for this container.
221
+     *
222
+     * @return This container's tab completer
223
+     */
224
+    TabCompleter getTabCompleter();
225
+
226
+    /**
227
+     * Returns the maximum length that a line passed to sendLine() should be, in order to prevent it
228
+     * being truncated or causing protocol violations.
229
+     *
230
+     * @return The maximum line length for this container
231
+     */
232
+    int getMaxLineLength();
233
+
234
+    /**
235
+     * Returns the number of lines that the specified string would be sent as.
236
+     *
237
+     * @param line The string to be split and sent
238
+     *
239
+     * @return The number of lines required to send the specified string
240
+     */
241
+    int getNumLines(String line);
242
+
243
+    UnreadStatusManager getUnreadStatusManager();
244
+}

Loading…
Cancel
Save