Pārlūkot izejas kodu

Remove WritableFrameContainer.

Move the functionality down into just FrameContainer. Callers can use
isWritable() to determine if the FrameContainer is writable, instead
of horrible instanceof/casting logic.

Change-Id: Iab58f1d2b9275ee3fc60d79e433e158bae784911
Depends-On: I52a09d5f5ad69c2bebafa58582a173f706515fa6
Reviewed-on: http://gerrit.dmdirc.com/3426
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 gadus atpakaļ
vecāks
revīzija
6dee6ca79e
36 mainītis faili ar 366 papildinājumiem un 388 dzēšanām
  1. 274
    0
      src/com/dmdirc/FrameContainer.java
  2. 2
    3
      src/com/dmdirc/GlobalWindow.java
  3. 2
    2
      src/com/dmdirc/MessageTarget.java
  4. 2
    4
      src/com/dmdirc/Raw.java
  5. 2
    2
      src/com/dmdirc/Server.java
  6. 0
    278
      src/com/dmdirc/WritableFrameContainer.java
  7. 5
    5
      src/com/dmdirc/actions/ActionModel.java
  8. 4
    7
      src/com/dmdirc/actions/wrappers/AliasWrapper.java
  9. 10
    9
      src/com/dmdirc/commandparser/commands/IntelligentCommand.java
  10. 2
    3
      src/com/dmdirc/commandparser/commands/ValidatingCommand.java
  11. 2
    2
      src/com/dmdirc/commandparser/commands/WrappableCommand.java
  12. 1
    2
      src/com/dmdirc/commandparser/commands/chat/Me.java
  13. 2
    3
      src/com/dmdirc/commandparser/commands/global/Help.java
  14. 2
    4
      src/com/dmdirc/commandparser/commands/global/Ifplugin.java
  15. 1
    3
      src/com/dmdirc/commandparser/commands/server/Message.java
  16. 1
    3
      src/com/dmdirc/commandparser/commands/server/OpenQuery.java
  17. 0
    9
      src/com/dmdirc/interfaces/ui/InputWindow.java
  18. 2
    2
      src/com/dmdirc/messages/AllMessageSink.java
  19. 2
    2
      src/com/dmdirc/messages/ChannelMessageSink.java
  20. 2
    2
      src/com/dmdirc/messages/CommonChanelsMessageSink.java
  21. 1
    2
      src/com/dmdirc/messages/CustomWindowMessageSink.java
  22. 2
    2
      src/com/dmdirc/messages/ForkMessageSink.java
  23. 2
    2
      src/com/dmdirc/messages/FormatMessageSink.java
  24. 2
    2
      src/com/dmdirc/messages/GroupMessageSink.java
  25. 5
    7
      src/com/dmdirc/messages/LastCommandMessageSink.java
  26. 2
    2
      src/com/dmdirc/messages/MessageSink.java
  27. 4
    4
      src/com/dmdirc/messages/MessageSinkManager.java
  28. 2
    2
      src/com/dmdirc/messages/NullMessageSink.java
  29. 2
    2
      src/com/dmdirc/messages/SelfMessageSink.java
  30. 2
    2
      src/com/dmdirc/messages/ServerMessageSink.java
  31. 2
    2
      src/com/dmdirc/messages/StatusBarMessageSink.java
  32. 3
    3
      src/com/dmdirc/ui/input/InputHandler.java
  33. 3
    3
      src/com/dmdirc/ui/input/TabCompleter.java
  34. 7
    0
      test/com/dmdirc/ServerTest.java
  35. 5
    4
      test/com/dmdirc/WritableFrameContainerTest.java
  36. 4
    4
      test/com/dmdirc/harness/TestWritableFrameContainer.java

+ 274
- 0
src/com/dmdirc/FrameContainer.java Parādīt failu

@@ -24,6 +24,7 @@ package com.dmdirc;
24 24
 
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27
+import com.dmdirc.commandparser.parsers.CommandParser;
27 28
 import com.dmdirc.interfaces.Connection;
28 29
 import com.dmdirc.interfaces.FrameCloseListener;
29 30
 import com.dmdirc.interfaces.FrameComponentChangeListener;
@@ -31,14 +32,20 @@ import com.dmdirc.interfaces.FrameInfoListener;
31 32
 import com.dmdirc.interfaces.NotificationListener;
32 33
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
33 34
 import com.dmdirc.interfaces.config.ConfigChangeListener;
35
+import com.dmdirc.messages.MessageSinkManager;
36
+import com.dmdirc.parser.common.CompositionState;
34 37
 import com.dmdirc.ui.Colour;
35 38
 import com.dmdirc.ui.IconManager;
39
+import com.dmdirc.ui.input.TabCompleter;
36 40
 import com.dmdirc.ui.messages.Formatter;
37 41
 import com.dmdirc.ui.messages.IRCDocument;
38 42
 import com.dmdirc.ui.messages.Styliser;
39 43
 import com.dmdirc.util.URLBuilder;
40 44
 import com.dmdirc.util.collections.ListenerList;
41 45
 
46
+import com.google.common.base.Optional;
47
+
48
+import java.util.ArrayList;
42 49
 import java.util.Collection;
43 50
 import java.util.Collections;
44 51
 import java.util.Date;
@@ -48,6 +55,8 @@ import java.util.List;
48 55
 import java.util.Set;
49 56
 import java.util.concurrent.CopyOnWriteArrayList;
50 57
 
58
+import static com.google.common.base.Preconditions.checkState;
59
+
51 60
 /**
52 61
  * The frame container implements basic methods that should be present in all objects that handle a
53 62
  * frame.
@@ -84,6 +93,26 @@ public abstract class FrameContainer {
84 93
     private final Object documentSync = new Object();
85 94
     /** The icon manager to use for this container. */
86 95
     private final IconManager iconManager;
96
+    /** Whether or not this container is writable. */
97
+    private final boolean writable;
98
+    /**
99
+     * The command parser used for commands in this container.
100
+     * <p>
101
+     * Only defined if this container is {@link #writable}.
102
+     */
103
+    private final Optional<CommandParser> commandParser;
104
+    /**
105
+     * The manager to use to despatch messages to sinks.
106
+     * <p>
107
+     * Only defined if this container is {@link #writable}.
108
+     */
109
+    private final Optional<MessageSinkManager> messageSinkManager;
110
+    /**
111
+     * The tab completer to use.
112
+     * <p>
113
+     * Only defined if this container is {@link #writable}.
114
+     */
115
+    private final Optional<TabCompleter> tabCompleter;
87 116
 
88 117
     /**
89 118
      * Instantiate new frame container.
@@ -109,6 +138,49 @@ public abstract class FrameContainer {
109 138
         this.title = title;
110 139
         this.components = new HashSet<>(components);
111 140
         this.iconManager = new IconManager(configManager, urlBuilder);
141
+        this.writable = false;
142
+        this.commandParser = Optional.absent();
143
+        this.tabCompleter = Optional.absent();
144
+        this.messageSinkManager = Optional.absent();
145
+
146
+        setIcon(icon);
147
+    }
148
+
149
+    /**
150
+     * Instantiate new frame container that accepts user input.
151
+     *
152
+     * @param icon               The icon to use for this container
153
+     * @param name               The name of this container
154
+     * @param title              The title of this container
155
+     * @param config             The config manager for this container
156
+     * @param urlBuilder         The URL builder to use when finding icons.
157
+     * @param commandParser      The command parser to use for input.
158
+     * @param tabCompleter       The tab completer to use.
159
+     * @param messageSinkManager The manager to use to despatch notifications.
160
+     * @param components         The UI components that this frame requires
161
+     *
162
+     * @since 0.6.4
163
+     */
164
+    protected FrameContainer(
165
+            final String icon,
166
+            final String name,
167
+            final String title,
168
+            final AggregateConfigProvider config,
169
+            final URLBuilder urlBuilder,
170
+            final CommandParser commandParser,
171
+            final TabCompleter tabCompleter,
172
+            final MessageSinkManager messageSinkManager,
173
+            final Collection<String> components) {
174
+        this.configManager = config;
175
+        this.name = name;
176
+        this.title = title;
177
+        this.components = new HashSet<>(components);
178
+        this.iconManager = new IconManager(configManager, urlBuilder);
179
+        this.writable = true;
180
+        this.commandParser = Optional.of(commandParser);
181
+        this.tabCompleter = Optional.of(tabCompleter);
182
+        this.messageSinkManager = Optional.of(messageSinkManager);
183
+        commandParser.setOwner(this);
112 184
 
113 185
         setIcon(icon);
114 186
     }
@@ -137,6 +209,10 @@ public abstract class FrameContainer {
137 209
         return configManager;
138 210
     }
139 211
 
212
+    public boolean isWritable() {
213
+        return writable;
214
+    }
215
+
140 216
     /**
141 217
      * Returns a collection of direct children of this frame.
142 218
      *
@@ -522,6 +598,204 @@ public abstract class FrameContainer {
522 598
         listeners.remove(FrameInfoListener.class, listener);
523 599
     }
524 600
 
601
+    /**
602
+     * Sends a line of text to this container's source.
603
+     *
604
+     * @param line The line to be sent
605
+     */
606
+    public void sendLine(final String line) {
607
+        throw new UnsupportedOperationException("Container doesn't override sendLine");
608
+    }
609
+
610
+    /**
611
+     * Retrieves the command parser to be used for this container.
612
+     *
613
+     * @return This container's command parser
614
+     */
615
+    public CommandParser getCommandParser() {
616
+        checkState(writable);
617
+        return commandParser.get();
618
+    }
619
+
620
+    /**
621
+     * Retrieves the tab completer which should be used for this cotnainer.
622
+     *
623
+     * @return This container's tab completer
624
+     */
625
+    public TabCompleter getTabCompleter() {
626
+        checkState(writable);
627
+        return tabCompleter.get();
628
+    }
629
+
630
+    /**
631
+     * Returns the maximum length that a line passed to sendLine() should be, in order to prevent it
632
+     * being truncated or causing protocol violations.
633
+     *
634
+     * @return The maximum line length for this container
635
+     */
636
+    public int getMaxLineLength() {
637
+        throw new UnsupportedOperationException("Container doesn't override getMaxLineLength");
638
+    }
639
+
640
+    /**
641
+     * Splits the specified line into chunks that contain a number of bytes less than or equal to
642
+     * the value returned by {@link #getMaxLineLength()}.
643
+     *
644
+     * @param line The line to be split
645
+     *
646
+     * @return An ordered list of chunks of the desired length
647
+     */
648
+    protected List<String> splitLine(final String line) {
649
+        final List<String> result = new ArrayList<>();
650
+
651
+        if (line.indexOf('\n') > -1) {
652
+            for (String part : line.split("\n")) {
653
+                result.addAll(splitLine(part));
654
+            }
655
+        } else {
656
+            final StringBuilder remaining = new StringBuilder(line);
657
+
658
+            while (getMaxLineLength() > -1 && remaining.toString().getBytes().length
659
+                    > getMaxLineLength()) {
660
+                int number = Math.min(remaining.length(), getMaxLineLength());
661
+
662
+                while (remaining.substring(0, number).getBytes().length > getMaxLineLength()) {
663
+                    number--;
664
+                }
665
+
666
+                result.add(remaining.substring(0, number));
667
+                remaining.delete(0, number);
668
+            }
669
+
670
+            result.add(remaining.toString());
671
+        }
672
+
673
+        return result;
674
+    }
675
+
676
+    /**
677
+     * Returns the number of lines that the specified string would be sent as.
678
+     *
679
+     * @param line The string to be split and sent
680
+     *
681
+     * @return The number of lines required to send the specified string
682
+     */
683
+    public final int getNumLines(final String line) {
684
+        final String[] splitLines = line.split("(\n|\r\n|\r)", Integer.MAX_VALUE);
685
+        int lines = 0;
686
+
687
+        for (String splitLine : splitLines) {
688
+            if (getMaxLineLength() <= 0) {
689
+                lines++;
690
+            } else {
691
+                lines += (int) Math.ceil(splitLine.getBytes().length
692
+                        / (double) getMaxLineLength());
693
+            }
694
+        }
695
+
696
+        return lines;
697
+    }
698
+
699
+    /**
700
+     * Processes and displays a notification.
701
+     *
702
+     * @param messageType The name of the formatter to be used for the message
703
+     * @param args        The arguments for the message
704
+     *
705
+     * @return True if any further behaviour should be executed, false otherwise
706
+     */
707
+    public boolean doNotification(final String messageType, final Object... args) {
708
+        return doNotification(new Date(), messageType, args);
709
+    }
710
+
711
+    /**
712
+     * Processes and displays a notification.
713
+     *
714
+     * @param date        The date/time at which the event occured
715
+     * @param messageType The name of the formatter to be used for the message
716
+     * @param args        The arguments for the message
717
+     *
718
+     * @return True if any further behaviour should be executed, false otherwise
719
+     */
720
+    public boolean doNotification(final Date date, final String messageType, final Object... args) {
721
+        final List<Object> messageArgs = new ArrayList<>();
722
+        final List<Object> actionArgs = new ArrayList<>();
723
+        final StringBuffer buffer = new StringBuffer(messageType);
724
+
725
+        actionArgs.add(this);
726
+
727
+        for (Object arg : args) {
728
+            actionArgs.add(arg);
729
+
730
+            if (!processNotificationArg(arg, messageArgs)) {
731
+                messageArgs.add(arg);
732
+            }
733
+        }
734
+
735
+        modifyNotificationArgs(actionArgs, messageArgs);
736
+
737
+        handleNotification(date, buffer.toString(), messageArgs.toArray());
738
+
739
+        return true;
740
+    }
741
+
742
+    /**
743
+     * Allows subclasses to modify the lists of arguments for notifications.
744
+     *
745
+     * @param actionArgs  The list of arguments to be passed to the actions system
746
+     * @param messageArgs The list of arguments to be passed to the formatter
747
+     */
748
+    protected void modifyNotificationArgs(final List<Object> actionArgs,
749
+            final List<Object> messageArgs) {
750
+        // Do nothing
751
+    }
752
+
753
+    /**
754
+     * Allows subclasses to process specific types of notification arguments.
755
+     *
756
+     * @param arg  The argument to be processed
757
+     * @param args The list of arguments that any data should be appended to
758
+     *
759
+     * @return True if the arg has been processed, false otherwise
760
+     */
761
+    protected boolean processNotificationArg(final Object arg, final List<Object> args) {
762
+        return false;
763
+    }
764
+
765
+    /**
766
+     * Handles general server notifications (i.e., ones not tied to a specific window). The user can
767
+     * select where the notifications should go in their config.
768
+     *
769
+     * @param messageType The type of message that is being sent
770
+     * @param args        The arguments for the message
771
+     */
772
+    public void handleNotification(final String messageType, final Object... args) {
773
+        handleNotification(new Date(), messageType, args);
774
+    }
775
+
776
+    /**
777
+     * Handles general server notifications (i.e., ones not tied to a specific window). The user can
778
+     * select where the notifications should go in their config.
779
+     *
780
+     * @param date        The date/time at which the event occured
781
+     * @param messageType The type of message that is being sent
782
+     * @param args        The arguments for the message
783
+     */
784
+    public void handleNotification(final Date date, final String messageType, final Object... args) {
785
+        checkState(writable);
786
+        messageSinkManager.get().despatchMessage(this, date, messageType, args);
787
+    }
788
+
789
+    /**
790
+     * Sets the composition state for the local user for this chat.
791
+     *
792
+     * @param state The new composition state
793
+     */
794
+    public void setCompositionState(final CompositionState state) {
795
+        // Default implementation does nothing. Subclasses that support
796
+        // composition should override this.
797
+    }
798
+
525 799
     /**
526 800
      * Updates the icon of this frame if its config setting is changed.
527 801
      */

+ 2
- 3
src/com/dmdirc/GlobalWindow.java Parādīt failu

@@ -45,7 +45,7 @@ import javax.inject.Singleton;
45 45
 /**
46 46
  * A window which can be used to execute global commands.
47 47
  */
48
-public class GlobalWindow extends WritableFrameContainer {
48
+public class GlobalWindow extends FrameContainer {
49 49
 
50 50
     /**
51 51
      * Creates a new instance of GlobalWindow.
@@ -62,10 +62,9 @@ public class GlobalWindow extends WritableFrameContainer {
62 62
             final TabCompleterFactory tabCompleterFactory,
63 63
             final MessageSinkManager messageSinkManager,
64 64
             final URLBuilder urlBuilder) {
65
-        super("icon", "Global", "(Global)", config, parser,
65
+        super("icon", "Global", "(Global)", config, urlBuilder, parser,
66 66
                 tabCompleterFactory.getTabCompleter(config, CommandType.TYPE_GLOBAL),
67 67
                 messageSinkManager,
68
-                urlBuilder,
69 68
                 Arrays.asList(
70 69
                         WindowComponent.TEXTAREA.getIdentifier(),
71 70
                         WindowComponent.INPUTFIELD.getIdentifier()));

+ 2
- 2
src/com/dmdirc/MessageTarget.java Parādīt failu

@@ -33,7 +33,7 @@ import java.util.Collection;
33 33
 /**
34 34
  * Defines common methods for objects that you can send messages to (such as channels and queries).
35 35
  */
36
-public abstract class MessageTarget extends WritableFrameContainer {
36
+public abstract class MessageTarget extends FrameContainer {
37 37
 
38 38
     /**
39 39
      * Creates a new MessageTarget.
@@ -60,7 +60,7 @@ public abstract class MessageTarget extends WritableFrameContainer {
60 60
             final MessageSinkManager messageSinkManager,
61 61
             final URLBuilder urlBuilder,
62 62
             final Collection<String> components) {
63
-        super(icon, name, title, config, parser, tabCompleter, messageSinkManager, urlBuilder,
63
+        super(icon, name, title, config, urlBuilder, parser, tabCompleter, messageSinkManager,
64 64
                 components);
65 65
     }
66 66
 

+ 2
- 4
src/com/dmdirc/Raw.java Parādīt failu

@@ -45,8 +45,7 @@ import java.util.Date;
45 45
  * server).
46 46
  */
47 47
 @Factory(inject = true, providers = true, singleton = true)
48
-public class Raw extends WritableFrameContainer
49
-        implements DataInListener, DataOutListener {
48
+public class Raw extends FrameContainer implements DataInListener, DataOutListener {
50 49
 
51 50
     /** The server object that's being monitored. */
52 51
     private final Server server;
@@ -64,11 +63,10 @@ public class Raw extends WritableFrameContainer
64 63
             final CommandController commandController,
65 64
             final MessageSinkManager messageSinkManager,
66 65
             final URLBuilder urlBuilder) {
67
-        super("raw", "Raw", "(Raw log)", newServer.getConfigManager(),
66
+        super("raw", "Raw", "(Raw log)", newServer.getConfigManager(), urlBuilder,
68 67
                 new ServerCommandParser(newServer.getConfigManager(), commandController),
69 68
                 newServer.getTabCompleter(),
70 69
                 messageSinkManager,
71
-                urlBuilder,
72 70
                 Arrays.asList(
73 71
                         WindowComponent.TEXTAREA.getIdentifier(),
74 72
                         WindowComponent.INPUTFIELD.getIdentifier()));

+ 2
- 2
src/com/dmdirc/Server.java Parādīt failu

@@ -99,7 +99,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
99 99
  * queries, etc, and handles parser callbacks pertaining to the server.
100 100
  */
101 101
 @Factory(inject = true, singleton = true, providers = true, name = "ServerFactoryImpl")
102
-public class Server extends WritableFrameContainer implements ConfigChangeListener,
102
+public class Server extends FrameContainer implements ConfigChangeListener,
103 103
         CertificateProblemListener, Connection {
104 104
 
105 105
     private static final org.slf4j.Logger log = LoggerFactory.getLogger(Server.class);
@@ -228,11 +228,11 @@ public class Server extends WritableFrameContainer implements ConfigChangeListen
228 228
                 getHost(uri),
229 229
                 getHost(uri),
230 230
                 configMigrator.getConfigProvider(),
231
+                urlBuilder,
231 232
                 commandParser,
232 233
                 tabCompleterFactory.getTabCompleter(configMigrator.getConfigProvider(),
233 234
                         CommandType.TYPE_SERVER, CommandType.TYPE_GLOBAL),
234 235
                 messageSinkManager,
235
-                urlBuilder,
236 236
                 Arrays.asList(
237 237
                         WindowComponent.TEXTAREA.getIdentifier(),
238 238
                         WindowComponent.INPUTFIELD.getIdentifier(),

+ 0
- 278
src/com/dmdirc/WritableFrameContainer.java Parādīt failu

@@ -1,278 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 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;
24
-
25
-import com.dmdirc.commandparser.parsers.CommandParser;
26
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
27
-import com.dmdirc.messages.MessageSinkManager;
28
-import com.dmdirc.parser.common.CompositionState;
29
-import com.dmdirc.ui.input.TabCompleter;
30
-import com.dmdirc.util.URLBuilder;
31
-
32
-import java.util.ArrayList;
33
-import java.util.Collection;
34
-import java.util.Date;
35
-import java.util.List;
36
-
37
-/**
38
- * The writable frame container adds additional methods to the frame container class that allow the
39
- * sending of lines back to whatever the container's data source is (e.g. an IRC channel or server).
40
- */
41
-public abstract class WritableFrameContainer extends FrameContainer {
42
-
43
-    /** The name of the server notification target. */
44
-    protected static final String NOTIFICATION_SERVER = "server";
45
-    /** The name of the channel notification target. */
46
-    protected static final String NOTIFICATION_CHANNEL = "channel";
47
-    /** The command parser used for commands in this container. */
48
-    private final CommandParser commandParser;
49
-    /** The manager to use to despatch messages to sinks. */
50
-    private final MessageSinkManager messageSinkManager;
51
-    /** The tab completer to use. */
52
-    private final TabCompleter tabCompleter;
53
-
54
-    /**
55
-     * Creates a new WritableFrameContainer.
56
-     *
57
-     * @param icon               The icon to use for this container
58
-     * @param name               The name of this container
59
-     * @param title              The title of this container
60
-     * @param config             The config manager for this container
61
-     * @param parser             The command parser for this container
62
-     * @param tabCompleter       The tab completer to use.
63
-     * @param messageSinkManager The sink manager to use to despatch messages
64
-     * @param urlBuilder         The URL builder to use when finding icons.
65
-     * @param components         The UI components that this frame requires
66
-     *
67
-     * @since 0.6.4
68
-     */
69
-    public WritableFrameContainer(
70
-            final String icon,
71
-            final String name,
72
-            final String title,
73
-            final AggregateConfigProvider config,
74
-            final CommandParser parser,
75
-            final TabCompleter tabCompleter,
76
-            final MessageSinkManager messageSinkManager,
77
-            final URLBuilder urlBuilder,
78
-            final Collection<String> components) {
79
-        super(icon, name, title, config, urlBuilder, components);
80
-
81
-        this.commandParser = parser;
82
-        this.tabCompleter = tabCompleter;
83
-        this.messageSinkManager = messageSinkManager;
84
-        parser.setOwner(this);
85
-    }
86
-
87
-    /**
88
-     * Sends a line of text to this container's source.
89
-     *
90
-     * @param line The line to be sent
91
-     */
92
-    public abstract void sendLine(String line);
93
-
94
-    /**
95
-     * Retrieves the command parser to be used for this container.
96
-     *
97
-     * @return This container's command parser
98
-     */
99
-    public CommandParser getCommandParser() {
100
-        return commandParser;
101
-    }
102
-
103
-    /**
104
-     * Retrieves the tab completer which should be used for this cotnainer.
105
-     *
106
-     * @return This container's tab completer
107
-     */
108
-    public TabCompleter getTabCompleter() {
109
-        return tabCompleter;
110
-    }
111
-
112
-    /**
113
-     * Returns the maximum length that a line passed to sendLine() should be, in order to prevent it
114
-     * being truncated or causing protocol violations.
115
-     *
116
-     * @return The maximum line length for this container
117
-     */
118
-    public abstract int getMaxLineLength();
119
-
120
-    /**
121
-     * Splits the specified line into chunks that contain a number of bytes less than or equal to
122
-     * the value returned by {@link #getMaxLineLength()}.
123
-     *
124
-     * @param line The line to be split
125
-     *
126
-     * @return An ordered list of chunks of the desired length
127
-     */
128
-    protected List<String> splitLine(final String line) {
129
-        final List<String> result = new ArrayList<>();
130
-
131
-        if (line.indexOf('\n') > -1) {
132
-            for (String part : line.split("\n")) {
133
-                result.addAll(splitLine(part));
134
-            }
135
-        } else {
136
-            final StringBuilder remaining = new StringBuilder(line);
137
-
138
-            while (getMaxLineLength() > -1 && remaining.toString().getBytes().length
139
-                    > getMaxLineLength()) {
140
-                int number = Math.min(remaining.length(), getMaxLineLength());
141
-
142
-                while (remaining.substring(0, number).getBytes().length > getMaxLineLength()) {
143
-                    number--;
144
-                }
145
-
146
-                result.add(remaining.substring(0, number));
147
-                remaining.delete(0, number);
148
-            }
149
-
150
-            result.add(remaining.toString());
151
-        }
152
-
153
-        return result;
154
-    }
155
-
156
-    /**
157
-     * Returns the number of lines that the specified string would be sent as.
158
-     *
159
-     * @param line The string to be split and sent
160
-     *
161
-     * @return The number of lines required to send the specified string
162
-     */
163
-    public final int getNumLines(final String line) {
164
-        final String[] splitLines = line.split("(\n|\r\n|\r)", Integer.MAX_VALUE);
165
-        int lines = 0;
166
-
167
-        for (String splitLine : splitLines) {
168
-            if (getMaxLineLength() <= 0) {
169
-                lines++;
170
-            } else {
171
-                lines += (int) Math.ceil(splitLine.getBytes().length
172
-                        / (double) getMaxLineLength());
173
-            }
174
-        }
175
-
176
-        return lines;
177
-    }
178
-
179
-    /**
180
-     * Processes and displays a notification.
181
-     *
182
-     * @param messageType The name of the formatter to be used for the message
183
-     * @param args        The arguments for the message
184
-     *
185
-     * @return True if any further behaviour should be executed, false otherwise
186
-     */
187
-    public boolean doNotification(final String messageType, final Object... args) {
188
-        return doNotification(new Date(), messageType, args);
189
-    }
190
-
191
-    /**
192
-     * Processes and displays a notification.
193
-     *
194
-     * @param date        The date/time at which the event occured
195
-     * @param messageType The name of the formatter to be used for the message
196
-     * @param args        The arguments for the message
197
-     *
198
-     * @return True if any further behaviour should be executed, false otherwise
199
-     */
200
-    public boolean doNotification(final Date date, final String messageType, final Object... args) {
201
-        final List<Object> messageArgs = new ArrayList<>();
202
-        final List<Object> actionArgs = new ArrayList<>();
203
-        final StringBuffer buffer = new StringBuffer(messageType);
204
-
205
-        actionArgs.add(this);
206
-
207
-        for (Object arg : args) {
208
-            actionArgs.add(arg);
209
-
210
-            if (!processNotificationArg(arg, messageArgs)) {
211
-                messageArgs.add(arg);
212
-            }
213
-        }
214
-
215
-        modifyNotificationArgs(actionArgs, messageArgs);
216
-
217
-        handleNotification(date, buffer.toString(), messageArgs.toArray());
218
-
219
-        return true;
220
-    }
221
-
222
-    /**
223
-     * Allows subclasses to modify the lists of arguments for notifications.
224
-     *
225
-     * @param actionArgs  The list of arguments to be passed to the actions system
226
-     * @param messageArgs The list of arguments to be passed to the formatter
227
-     */
228
-    protected void modifyNotificationArgs(final List<Object> actionArgs,
229
-            final List<Object> messageArgs) {
230
-        // Do nothing
231
-    }
232
-
233
-    /**
234
-     * Allows subclasses to process specific types of notification arguments.
235
-     *
236
-     * @param arg  The argument to be processed
237
-     * @param args The list of arguments that any data should be appended to
238
-     *
239
-     * @return True if the arg has been processed, false otherwise
240
-     */
241
-    protected boolean processNotificationArg(final Object arg, final List<Object> args) {
242
-        return false;
243
-    }
244
-
245
-    /**
246
-     * Handles general server notifications (i.e., ones not tied to a specific window). The user can
247
-     * select where the notifications should go in their config.
248
-     *
249
-     * @param messageType The type of message that is being sent
250
-     * @param args        The arguments for the message
251
-     */
252
-    public void handleNotification(final String messageType, final Object... args) {
253
-        handleNotification(new Date(), messageType, args);
254
-    }
255
-
256
-    /**
257
-     * Handles general server notifications (i.e., ones not tied to a specific window). The user can
258
-     * select where the notifications should go in their config.
259
-     *
260
-     * @param date        The date/time at which the event occured
261
-     * @param messageType The type of message that is being sent
262
-     * @param args        The arguments for the message
263
-     */
264
-    public void handleNotification(final Date date, final String messageType, final Object... args) {
265
-        messageSinkManager.despatchMessage(this, date, messageType, args);
266
-    }
267
-
268
-    /**
269
-     * Sets the composition state for the local user for this chat.
270
-     *
271
-     * @param state The new composition state
272
-     */
273
-    public void setCompositionState(final CompositionState state) {
274
-        // Default implementation does nothing. Subclasses that support
275
-        // composition should override this.
276
-    }
277
-
278
-}

+ 5
- 5
src/com/dmdirc/actions/ActionModel.java Parādīt failu

@@ -22,9 +22,9 @@
22 22
 
23 23
 package com.dmdirc.actions;
24 24
 
25
+import com.dmdirc.FrameContainer;
25 26
 import com.dmdirc.Precondition;
26 27
 import com.dmdirc.ServerManager;
27
-import com.dmdirc.WritableFrameContainer;
28 28
 import com.dmdirc.commandparser.parsers.CommandParser;
29 29
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
30 30
 import com.dmdirc.interfaces.actions.ActionType;
@@ -149,12 +149,12 @@ public class ActionModel {
149 149
             return false;
150 150
         }
151 151
 
152
-        WritableFrameContainer container = null;
152
+        FrameContainer container = null;
153 153
         CommandParser cp;
154 154
 
155
-        if (arguments.length > 0
156
-                && arguments[0] instanceof WritableFrameContainer) {
157
-            container = (WritableFrameContainer) arguments[0];
155
+        if (arguments.length > 0 && arguments[0] instanceof FrameContainer
156
+                && ((FrameContainer) arguments[0]).isWritable()) {
157
+            container = (FrameContainer) arguments[0];
158 158
         } else if (serverManager.numServers() > 0) {
159 159
             container = serverManager.getServers().get(0);
160 160
         }

+ 4
- 7
src/com/dmdirc/actions/wrappers/AliasWrapper.java Parādīt failu

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.actions.wrappers;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.WritableFrameContainer;
27 26
 import com.dmdirc.actions.Action;
28 27
 import com.dmdirc.actions.ActionCondition;
29 28
 import com.dmdirc.actions.ActionGroup;
@@ -91,9 +90,8 @@ public class AliasWrapper extends ActionGroup {
91 90
                 aliases.add(commandName);
92 91
 
93 92
                 for (FrameContainer root : windowManager.getRootWindows()) {
94
-                    if (root instanceof WritableFrameContainer) {
95
-                        ((WritableFrameContainer) root).getTabCompleter()
96
-                                .addEntry(TabCompletionType.COMMAND, commandName);
93
+                    if (root.isWritable()) {
94
+                        root.getTabCompleter().addEntry(TabCompletionType.COMMAND, commandName);
97 95
                     }
98 96
                 }
99 97
             } else {
@@ -116,9 +114,8 @@ public class AliasWrapper extends ActionGroup {
116 114
             aliases.remove(commandName);
117 115
 
118 116
             for (FrameContainer root : windowManager.getRootWindows()) {
119
-                if (root instanceof WritableFrameContainer) {
120
-                    ((WritableFrameContainer) root).getTabCompleter()
121
-                            .removeEntry(TabCompletionType.COMMAND, commandName);
117
+                if (root.isWritable()) {
118
+                    root.getTabCompleter().removeEntry(TabCompletionType.COMMAND, commandName);
122 119
                 }
123 120
             }
124 121
         }

+ 10
- 9
src/com/dmdirc/commandparser/commands/IntelligentCommand.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.ui.input.AdditionalTabTargets;
27 27
 
28 28
 import java.util.List;
@@ -53,14 +53,21 @@ public interface IntelligentCommand {
53 53
     @SuppressWarnings("PMD.UnusedPrivateField")
54 54
     class IntelligentCommandContext {
55 55
 
56
-        public IntelligentCommandContext(final WritableFrameContainer window,
56
+        /** The window the command is being entered in. */
57
+        private final FrameContainer window;
58
+        /** The previously supplied arguments, if any. */
59
+        private final List<String> previousArgs;
60
+        /** The partially typed word, if any. */
61
+        private final String partial;
62
+
63
+        public IntelligentCommandContext(final FrameContainer window,
57 64
                 final List<String> previousArgs, final String partial) {
58 65
             this.window = window;
59 66
             this.previousArgs = previousArgs;
60 67
             this.partial = partial;
61 68
         }
62 69
 
63
-        public WritableFrameContainer getWindow() {
70
+        public FrameContainer getWindow() {
64 71
             return window;
65 72
         }
66 73
 
@@ -71,12 +78,6 @@ public interface IntelligentCommand {
71 78
         public String getPartial() {
72 79
             return partial;
73 80
         }
74
-        /** The window the command is being entered in. */
75
-        private final WritableFrameContainer window;
76
-        /** The previously supplied arguments, if any. */
77
-        private final List<String> previousArgs;
78
-        /** The partially typed word, if any. */
79
-        private final String partial;
80 81
 
81 82
     }
82 83
 

+ 2
- 3
src/com/dmdirc/commandparser/commands/ValidatingCommand.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.util.validators.ValidationResponse;
28 28
 
@@ -42,7 +42,6 @@ public interface ValidatingCommand {
42 42
      *
43 43
      * @since 0.6.3m1
44 44
      */
45
-    ValidationResponse validateArguments(WritableFrameContainer origin,
46
-            CommandArguments arguments);
45
+    ValidationResponse validateArguments(FrameContainer origin, CommandArguments arguments);
47 46
 
48 47
 }

+ 2
- 2
src/com/dmdirc/commandparser/commands/WrappableCommand.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 
28 28
 /**
@@ -40,6 +40,6 @@ public interface WrappableCommand {
40 40
      *
41 41
      * @since 0.6.3m1
42 42
      */
43
-    int getLineCount(WritableFrameContainer origin, CommandArguments arguments);
43
+    int getLineCount(FrameContainer origin, CommandArguments arguments);
44 44
 
45 45
 }

+ 1
- 2
src/com/dmdirc/commandparser/commands/chat/Me.java Parādīt failu

@@ -24,7 +24,6 @@ package com.dmdirc.commandparser.commands.chat;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.MessageTarget;
27
-import com.dmdirc.WritableFrameContainer;
28 27
 import com.dmdirc.commandparser.BaseCommandInfo;
29 28
 import com.dmdirc.commandparser.CommandArguments;
30 29
 import com.dmdirc.commandparser.CommandInfo;
@@ -72,7 +71,7 @@ public class Me extends Command implements ValidatingCommand {
72 71
 
73 72
     @Override
74 73
     public ValidationResponse validateArguments(
75
-            final WritableFrameContainer origin,
74
+            final FrameContainer origin,
76 75
             final CommandArguments arguments) {
77 76
         if (origin.getConnection() == null
78 77
                 || origin.getConnection().getParser() == null) {

+ 2
- 3
src/com/dmdirc/commandparser/commands/global/Help.java Parādīt failu

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.commandparser.commands.global;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.WritableFrameContainer;
27 26
 import com.dmdirc.commandparser.BaseCommandInfo;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.CommandInfo;
@@ -82,8 +81,8 @@ public class Help extends Command implements IntelligentCommand {
82 81
      * @param isSilent Whether this command has been silenced or not
83 82
      */
84 83
     private void showAllCommands(final FrameContainer origin, final boolean isSilent) {
85
-        final List<String> commands = new ArrayList<>(((WritableFrameContainer) origin)
86
-                .getCommandParser().getCommands().keySet());
84
+        final List<String> commands = new ArrayList<>(origin.getCommandParser()
85
+                .getCommands().keySet());
87 86
 
88 87
         Collections.sort(commands);
89 88
 

+ 2
- 4
src/com/dmdirc/commandparser/commands/global/Ifplugin.java Parādīt failu

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.commandparser.commands.global;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26
-import com.dmdirc.WritableFrameContainer;
27 26
 import com.dmdirc.commandparser.BaseCommandInfo;
28 27
 import com.dmdirc.commandparser.CommandArguments;
29 28
 import com.dmdirc.commandparser.CommandInfo;
@@ -95,12 +94,11 @@ public class Ifplugin extends Command implements IntelligentCommand {
95 94
         }
96 95
 
97 96
         if (result != negative) {
98
-            if (origin == null) {
97
+            if (origin == null || !origin.isWritable()) {
99 98
                 globalCommandParserProvider.get()
100 99
                         .parseCommand(null, args.getArgumentsAsString(1));
101 100
             } else {
102
-                ((WritableFrameContainer) origin).getCommandParser()
103
-                        .parseCommand(origin, args.getArgumentsAsString(1));
101
+                origin.getCommandParser().parseCommand(origin, args.getArgumentsAsString(1));
104 102
             }
105 103
         }
106 104
     }

+ 1
- 3
src/com/dmdirc/commandparser/commands/server/Message.java Parādīt failu

@@ -24,7 +24,6 @@ package com.dmdirc.commandparser.commands.server;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Server;
27
-import com.dmdirc.WritableFrameContainer;
28 27
 import com.dmdirc.commandparser.BaseCommandInfo;
29 28
 import com.dmdirc.commandparser.CommandArguments;
30 29
 import com.dmdirc.commandparser.CommandInfo;
@@ -113,8 +112,7 @@ public class Message extends Command implements IntelligentCommand,
113 112
     }
114 113
 
115 114
     @Override
116
-    public int getLineCount(final WritableFrameContainer origin,
117
-            final CommandArguments arguments) {
115
+    public int getLineCount(final FrameContainer origin, final CommandArguments arguments) {
118 116
         if (arguments.getArguments().length >= 2) {
119 117
             final String target = arguments.getArguments()[0];
120 118
             return ((Server) origin.getConnection()).getNumLines("PRIVMSG "

+ 1
- 3
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Parādīt failu

@@ -25,7 +25,6 @@ package com.dmdirc.commandparser.commands.server;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Query;
27 27
 import com.dmdirc.Server;
28
-import com.dmdirc.WritableFrameContainer;
29 28
 import com.dmdirc.commandparser.BaseCommandInfo;
30 29
 import com.dmdirc.commandparser.CommandArguments;
31 30
 import com.dmdirc.commandparser.CommandInfo;
@@ -110,8 +109,7 @@ public class OpenQuery extends Command implements IntelligentCommand,
110 109
     }
111 110
 
112 111
     @Override
113
-    public int getLineCount(final WritableFrameContainer origin,
114
-            final CommandArguments arguments) {
112
+    public int getLineCount(final FrameContainer origin, final CommandArguments arguments) {
115 113
         if (arguments.getArguments().length >= 2) {
116 114
             final String target = arguments.getArguments()[0];
117 115
             return ((Server) origin.getConnection()).getNumLines("PRIVMSG "

+ 0
- 9
src/com/dmdirc/interfaces/ui/InputWindow.java Parādīt failu

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.interfaces.ui;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
26 25
 import com.dmdirc.ui.input.InputHandler;
27 26
 
28 27
 /**
@@ -38,12 +37,4 @@ public interface InputWindow extends Window {
38 37
      */
39 38
     InputHandler getInputHandler();
40 39
 
41
-    /**
42
-     * Retrieves the container that owns this command window.
43
-     *
44
-     * @return The container that owns this command window.
45
-     */
46
-    @Override
47
-    WritableFrameContainer getContainer();
48
-
49 40
 }

+ 2
- 2
src/com/dmdirc/messages/AllMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -42,7 +42,7 @@ public class AllMessageSink implements MessageSink {
42 42
 
43 43
     @Override
44 44
     public void handleMessage(final MessageSinkManager despatcher,
45
-            final WritableFrameContainer source,
45
+            final FrameContainer source,
46 46
             final String[] patternMatches, final Date date,
47 47
             final String messageType, final Object... args) {
48 48
         source.getConnection().addLineToAll(messageType, date, args);

+ 2
- 2
src/com/dmdirc/messages/ChannelMessageSink.java Parādīt failu

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.messages;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.WritableFrameContainer;
26
+import com.dmdirc.FrameContainer;
27 27
 
28 28
 import java.util.Date;
29 29
 import java.util.regex.Pattern;
@@ -45,7 +45,7 @@ public class ChannelMessageSink implements MessageSink {
45 45
 
46 46
     @Override
47 47
     public void handleMessage(final MessageSinkManager despatcher,
48
-            final WritableFrameContainer source,
48
+            final FrameContainer source,
49 49
             final String[] patternMatches, final Date date,
50 50
             final String messageType, final Object... args) {
51 51
         final String user = String.format(patternMatches[0], args);

+ 2
- 2
src/com/dmdirc/messages/CommonChanelsMessageSink.java Parādīt failu

@@ -23,7 +23,7 @@
23 23
 package com.dmdirc.messages;
24 24
 
25 25
 import com.dmdirc.Channel;
26
-import com.dmdirc.WritableFrameContainer;
26
+import com.dmdirc.FrameContainer;
27 27
 
28 28
 import java.util.Date;
29 29
 import java.util.regex.Pattern;
@@ -46,7 +46,7 @@ public class CommonChanelsMessageSink implements MessageSink {
46 46
 
47 47
     @Override
48 48
     public void handleMessage(final MessageSinkManager despatcher,
49
-            final WritableFrameContainer source,
49
+            final FrameContainer source,
50 50
             final String[] patternMatches, final Date date,
51 51
             final String messageType, final Object... args) {
52 52
         final String user = String.format(patternMatches[0], args);

+ 1
- 2
src/com/dmdirc/messages/CustomWindowMessageSink.java Parādīt failu

@@ -25,7 +25,6 @@ package com.dmdirc.messages;
25 25
 import com.dmdirc.CustomWindow;
26 26
 import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.Server;
28
-import com.dmdirc.WritableFrameContainer;
29 28
 import com.dmdirc.ui.WindowManager;
30 29
 import com.dmdirc.util.URLBuilder;
31 30
 
@@ -64,7 +63,7 @@ public class CustomWindowMessageSink implements MessageSink {
64 63
 
65 64
     @Override
66 65
     public void handleMessage(final MessageSinkManager despatcher,
67
-            final WritableFrameContainer source,
66
+            final FrameContainer source,
68 67
             final String[] patternMatches, final Date date,
69 68
             final String messageType, final Object... args) {
70 69
         FrameContainer targetWindow = windowManager

+ 2
- 2
src/com/dmdirc/messages/ForkMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -42,7 +42,7 @@ public class ForkMessageSink implements MessageSink {
42 42
 
43 43
     @Override
44 44
     public void handleMessage(final MessageSinkManager despatcher,
45
-            final WritableFrameContainer source,
45
+            final FrameContainer source,
46 46
             final String[] patternMatches, final Date date,
47 47
             final String messageType, final Object... args) {
48 48
         for (String target : patternMatches[0].split("\\|")) {

+ 2
- 2
src/com/dmdirc/messages/FormatMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -42,7 +42,7 @@ public class FormatMessageSink implements MessageSink {
42 42
 
43 43
     @Override
44 44
     public void handleMessage(final MessageSinkManager despatcher,
45
-            final WritableFrameContainer source,
45
+            final FrameContainer source,
46 46
             final String[] patternMatches, final Date date,
47 47
             final String messageType, final Object... args) {
48 48
         despatcher.despatchMessage(source, date, patternMatches[0], patternMatches[1], args);

+ 2
- 2
src/com/dmdirc/messages/GroupMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -45,7 +45,7 @@ public class GroupMessageSink implements MessageSink {
45 45
     /** {@inheritDoc} */
46 46
     @Override
47 47
     public void handleMessage(final MessageSinkManager despatcher,
48
-            final WritableFrameContainer source,
48
+            final FrameContainer source,
49 49
             final String[] patternMatches, final Date date,
50 50
             final String messageType, final Object... args) {
51 51
         final String target;

+ 5
- 7
src/com/dmdirc/messages/LastCommandMessageSink.java Parādīt failu

@@ -24,7 +24,6 @@ package com.dmdirc.messages;
24 24
 
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.Server;
27
-import com.dmdirc.WritableFrameContainer;
28 27
 
29 28
 import java.util.ArrayList;
30 29
 import java.util.Date;
@@ -49,7 +48,7 @@ public class LastCommandMessageSink implements MessageSink {
49 48
     /** {@inheritDoc} */
50 49
     @Override
51 50
     public void handleMessage(final MessageSinkManager despatcher,
52
-            final WritableFrameContainer source,
51
+            final FrameContainer source,
53 52
             final String[] patternMatches, final Date date,
54 53
             final String messageType, final Object... args) {
55 54
         final Object[] escapedargs = new Object[args.length];
@@ -60,7 +59,7 @@ public class LastCommandMessageSink implements MessageSink {
60 59
 
61 60
         final String command = String.format(patternMatches[0], escapedargs);
62 61
 
63
-        WritableFrameContainer best = source;
62
+        FrameContainer best = source;
64 63
         long besttime = 0;
65 64
 
66 65
         final List<FrameContainer> containers = new ArrayList<>();
@@ -69,15 +68,14 @@ public class LastCommandMessageSink implements MessageSink {
69 68
         containers.addAll(((Server) source.getConnection()).getChildren());
70 69
 
71 70
         for (FrameContainer container : containers) {
72
-            if (!(container instanceof WritableFrameContainer)) {
71
+            if (!container.isWritable()) {
73 72
                 continue;
74 73
             }
75 74
 
76
-            final long time = ((WritableFrameContainer) container)
77
-                    .getCommandParser().getCommandTime(command);
75
+            final long time = container.getCommandParser().getCommandTime(command);
78 76
             if (time > besttime) {
79 77
                 besttime = time;
80
-                best = (WritableFrameContainer) container;
78
+                best = container;
81 79
             }
82 80
         }
83 81
 

+ 2
- 2
src/com/dmdirc/messages/MessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -52,7 +52,7 @@ public interface MessageSink {
52 52
      * @param args           The message arguments
53 53
      */
54 54
     void handleMessage(final MessageSinkManager despatcher,
55
-            final WritableFrameContainer source,
55
+            final FrameContainer source,
56 56
             final String[] patternMatches, final Date date,
57 57
             final String messageType, final Object... args);
58 58
 

+ 4
- 4
src/com/dmdirc/messages/MessageSinkManager.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.logger.ErrorLevel;
27 27
 import com.dmdirc.logger.Logger;
28 28
 import com.dmdirc.ui.WindowManager;
@@ -73,8 +73,8 @@ public class MessageSinkManager {
73 73
      * @param messageType The type (or 'format') of the message
74 74
      * @param args        The message arguments
75 75
      */
76
-    public void despatchMessage(final WritableFrameContainer source,
77
-            final Date date, final String messageType, final Object... args) {
76
+    public void despatchMessage(final FrameContainer source, final Date date,
77
+            final String messageType, final Object... args) {
78 78
         final String target;
79 79
         if (source.getConfigManager().hasOptionString(CONFIG_DOMAIN, messageType)) {
80 80
             target = source.getConfigManager().getOption(CONFIG_DOMAIN, messageType);
@@ -94,7 +94,7 @@ public class MessageSinkManager {
94 94
      * @param targetSink  The textual representation of the destination sink
95 95
      * @param args        The message arguments
96 96
      */
97
-    public void despatchMessage(final WritableFrameContainer source,
97
+    public void despatchMessage(final FrameContainer source,
98 98
             final Date date, final String messageType, final String targetSink,
99 99
             final Object... args) {
100 100
         for (MessageSink sink : sinks) {

+ 2
- 2
src/com/dmdirc/messages/NullMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -44,7 +44,7 @@ public class NullMessageSink implements MessageSink {
44 44
     /** {@inheritDoc} */
45 45
     @Override
46 46
     public void handleMessage(final MessageSinkManager despatcher,
47
-            final WritableFrameContainer source,
47
+            final FrameContainer source,
48 48
             final String[] patternMatches, final Date date,
49 49
             final String messageType, final Object... args) {
50 50
         // Do nothing

+ 2
- 2
src/com/dmdirc/messages/SelfMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 
27 27
 import java.util.Date;
28 28
 import java.util.regex.Pattern;
@@ -44,7 +44,7 @@ public class SelfMessageSink implements MessageSink {
44 44
     /** {@inheritDoc} */
45 45
     @Override
46 46
     public void handleMessage(final MessageSinkManager despatcher,
47
-            final WritableFrameContainer source,
47
+            final FrameContainer source,
48 48
             final String[] patternMatches, final Date date,
49 49
             final String messageType, final Object... args) {
50 50
         source.addLine(messageType, date, args);

+ 2
- 2
src/com/dmdirc/messages/ServerMessageSink.java Parādīt failu

@@ -22,8 +22,8 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
+import com.dmdirc.FrameContainer;
25 26
 import com.dmdirc.Server;
26
-import com.dmdirc.WritableFrameContainer;
27 27
 
28 28
 import java.util.Date;
29 29
 import java.util.regex.Pattern;
@@ -45,7 +45,7 @@ public class ServerMessageSink implements MessageSink {
45 45
     /** {@inheritDoc} */
46 46
     @Override
47 47
     public void handleMessage(final MessageSinkManager despatcher,
48
-            final WritableFrameContainer source,
48
+            final FrameContainer source,
49 49
             final String[] patternMatches, final Date date,
50 50
             final String messageType, final Object... args) {
51 51
         ((Server) source.getConnection()).addLine(messageType, date, args);

+ 2
- 2
src/com/dmdirc/messages/StatusBarMessageSink.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.messages;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.ui.StatusMessage;
27 27
 import com.dmdirc.ui.core.components.StatusBarManager;
28 28
 import com.dmdirc.ui.messages.Formatter;
@@ -58,7 +58,7 @@ public class StatusBarMessageSink implements MessageSink {
58 58
     /** {@inheritDoc} */
59 59
     @Override
60 60
     public void handleMessage(final MessageSinkManager despatcher,
61
-            final WritableFrameContainer source,
61
+            final FrameContainer source,
62 62
             final String[] patternMatches, final Date date,
63 63
             final String messageType, final Object... args) {
64 64
         final String message = Formatter.formatMessage(source.getConfigManager(),

+ 3
- 3
src/com/dmdirc/ui/input/InputHandler.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.input;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28 28
 import com.dmdirc.commandparser.commands.Command;
@@ -97,7 +97,7 @@ public abstract class InputHandler implements ConfigChangeListener {
97 97
     /** The CommandParser to use for our input. */
98 98
     protected final CommandParser commandParser;
99 99
     /** The frame that we belong to. */
100
-    protected final WritableFrameContainer parentWindow;
100
+    protected final FrameContainer parentWindow;
101 101
     /** The tab completion style. */
102 102
     protected TabCompletionStyle style;
103 103
     /** Our listener list. */
@@ -128,7 +128,7 @@ public abstract class InputHandler implements ConfigChangeListener {
128 128
             final InputField target,
129 129
             final CommandController commandController,
130 130
             final CommandParser commandParser,
131
-            final WritableFrameContainer parentWindow,
131
+            final FrameContainer parentWindow,
132 132
             final EventBus eventBus) {
133 133
         buffer = new RollingList<>(parentWindow.getConfigManager()
134 134
                 .getOptionInt("ui", "inputbuffersize"), "");

+ 3
- 3
src/com/dmdirc/ui/input/TabCompleter.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.ui.input;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28 28
 import com.dmdirc.commandparser.CommandType;
@@ -251,7 +251,7 @@ public class TabCompleter {
251 251
      * @since 0.6.4
252 252
      */
253 253
     private static AdditionalTabTargets getIntelligentResults(
254
-            final WritableFrameContainer window,
254
+            final FrameContainer window,
255 255
             final CommandArguments args, final String partial) {
256 256
         if (!args.isCommand()) {
257 257
             return null;
@@ -294,7 +294,7 @@ public class TabCompleter {
294 294
      * @since 0.6.4
295 295
      */
296 296
     public static AdditionalTabTargets getIntelligentResults(
297
-            final WritableFrameContainer window, final String text,
297
+            final FrameContainer window, final String text,
298 298
             final String partial) {
299 299
         return getIntelligentResults(window,
300 300
                 new CommandArguments(window.getCommandParser().getCommandManager(), text), partial);

+ 7
- 0
test/com/dmdirc/ServerTest.java Parādīt failu

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc;
24 24
 
25
+import com.dmdirc.commandparser.CommandType;
25 26
 import com.dmdirc.commandparser.parsers.CommandParser;
26 27
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 28
 import com.dmdirc.interfaces.config.ConfigProvider;
@@ -30,6 +31,7 @@ import com.dmdirc.interfaces.config.IdentityFactory;
30 31
 import com.dmdirc.messages.MessageSinkManager;
31 32
 import com.dmdirc.ui.WindowManager;
32 33
 import com.dmdirc.ui.core.components.StatusBarManager;
34
+import com.dmdirc.ui.input.TabCompleter;
33 35
 import com.dmdirc.ui.input.TabCompleterFactory;
34 36
 import com.dmdirc.util.URLBuilder;
35 37
 
@@ -40,11 +42,13 @@ import java.util.concurrent.ScheduledExecutorService;
40 42
 
41 43
 import org.junit.Before;
42 44
 import org.junit.Test;
45
+import org.mockito.Matchers;
43 46
 import org.mockito.Mock;
44 47
 import org.mockito.MockitoAnnotations;
45 48
 
46 49
 import static org.junit.Assert.assertEquals;
47 50
 import static org.mockito.Matchers.anyString;
51
+import static org.mockito.Matchers.eq;
48 52
 import static org.mockito.Mockito.when;
49 53
 
50 54
 public class ServerTest {
@@ -58,6 +62,7 @@ public class ServerTest {
58 62
     @Mock private ParserFactory parserFactory;
59 63
     @Mock private IdentityFactory identityFactory;
60 64
     @Mock private TabCompleterFactory tabCompleterFactory;
65
+    @Mock private TabCompleter tabCompleter;
61 66
     @Mock private MessageSinkManager messageSinkManager;
62 67
     @Mock private WindowManager windowManager;
63 68
     @Mock private ChannelFactory channelFactory;
@@ -75,6 +80,8 @@ public class ServerTest {
75 80
         MockitoAnnotations.initMocks(this);
76 81
         when(configManager.getOptionInt(anyString(), anyString())).thenReturn(Integer.MAX_VALUE);
77 82
         when(configMigrator.getConfigProvider()).thenReturn(configManager);
83
+        when(tabCompleterFactory.getTabCompleter(eq(configManager),
84
+                Matchers.<CommandType>anyVararg())).thenReturn(tabCompleter);
78 85
 
79 86
         server = new Server(
80 87
                 serverManager,

+ 5
- 4
test/com/dmdirc/WritableFrameContainerTest.java Parādīt failu

@@ -36,8 +36,9 @@ import org.junit.Test;
36 36
 import org.mockito.Mock;
37 37
 import org.mockito.MockitoAnnotations;
38 38
 
39
-import static org.junit.Assert.*;
40
-import static org.mockito.Mockito.*;
39
+import static org.junit.Assert.assertEquals;
40
+import static org.junit.Assert.assertTrue;
41
+import static org.mockito.Mockito.when;
41 42
 
42 43
 public class WritableFrameContainerTest {
43 44
 
@@ -60,7 +61,7 @@ public class WritableFrameContainerTest {
60 61
 
61 62
     @Test
62 63
     public void testGetNumLines() {
63
-        final WritableFrameContainer container10
64
+        final FrameContainer container10
64 65
                 = new TestWritableFrameContainer(10, acp, commands, messageSinkManager, urlBuilder);
65 66
 
66 67
         final int res0a = container10.getNumLines("");
@@ -90,7 +91,7 @@ public class WritableFrameContainerTest {
90 91
 
91 92
     @Test
92 93
     public void testSplitLine() {
93
-        final WritableFrameContainer container10
94
+        final FrameContainer container10
94 95
                 = new TestWritableFrameContainer(10, acp, commands, messageSinkManager, urlBuilder);
95 96
         final String[][][] tests = new String[][][]{
96 97
             {{""}, {""}},

+ 4
- 4
test/com/dmdirc/harness/TestWritableFrameContainer.java Parādīt failu

@@ -22,7 +22,7 @@
22 22
 
23 23
 package com.dmdirc.harness;
24 24
 
25
-import com.dmdirc.WritableFrameContainer;
25
+import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandManager;
27 27
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
28 28
 import com.dmdirc.interfaces.CommandController;
@@ -36,17 +36,17 @@ import java.util.Collections;
36 36
 
37 37
 import static org.mockito.Mockito.mock;
38 38
 
39
-public class TestWritableFrameContainer extends WritableFrameContainer {
39
+public class TestWritableFrameContainer extends FrameContainer {
40 40
 
41 41
     private final int lineLength;
42 42
 
43 43
     public TestWritableFrameContainer(final int lineLength,
44 44
             final AggregateConfigProvider cm, final CommandManager commandManager,
45 45
             final MessageSinkManager messageSinkManager, final URLBuilder urlBuilder) {
46
-        super("raw", "Raw", "(Raw)", cm,
46
+        super("raw", "Raw", "(Raw)", cm, urlBuilder,
47 47
                 new GlobalCommandParser(cm, commandManager),
48 48
                 new TabCompleter(mock(CommandController.class), cm),
49
-                messageSinkManager, urlBuilder,
49
+                messageSinkManager,
50 50
                 Collections.<String>emptySet());
51 51
 
52 52
         this.lineLength = lineLength;

Notiek ielāde…
Atcelt
Saglabāt