Pārlūkot izejas kodu

Pass WindowModel into Server.

pull/650/head
Chris Smith 8 gadus atpakaļ
vecāks
revīzija
1141fd113f

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

@@ -140,12 +140,8 @@ public class FrameContainer implements WindowModel {
140 140
         return eventBus;
141 141
     }
142 142
 
143
-    /**
144
-     * Changes the name of this container, and fires a {@link FrameNameChangedEvent}.
145
-     *
146
-     * @param name The new name for this frame.
147
-     */
148
-    protected void setName(final String name) {
143
+    @Override
144
+    public void setName(final String name) {
149 145
         this.name = name;
150 146
 
151 147
         eventBus.publishAsync(new FrameNameChangedEvent(this, name));

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

@@ -50,9 +50,7 @@ import com.dmdirc.parser.interfaces.ProtocolDescription;
50 50
 import com.dmdirc.parser.interfaces.SecureParser;
51 51
 import com.dmdirc.parser.interfaces.StringConverter;
52 52
 import com.dmdirc.tls.CertificateManager;
53
-import com.dmdirc.ui.core.components.WindowComponent;
54 53
 import com.dmdirc.ui.input.TabCompletionType;
55
-import com.dmdirc.ui.messages.BackBufferFactory;
56 54
 import com.dmdirc.ui.messages.ColourManager;
57 55
 import com.dmdirc.ui.messages.Formatter;
58 56
 import com.dmdirc.ui.messages.HighlightManager;
@@ -64,7 +62,6 @@ import java.net.URI;
64 62
 import java.net.URISyntaxException;
65 63
 import java.net.UnknownHostException;
66 64
 import java.util.ArrayList;
67
-import java.util.Arrays;
68 65
 import java.util.Collection;
69 66
 import java.util.Collections;
70 67
 import java.util.Map;
@@ -166,7 +163,7 @@ public class Server implements Connection {
166 163
     private final HighlightManager highlightManager;
167 164
     /** Listener to use for config changes. */
168 165
     private final ConfigChangeListener configListener = (domain, key) -> updateTitle();
169
-    private final FrameContainer windowModel;
166
+    private final WindowModel windowModel;
170 167
     /** The future used when a reconnect timer is scheduled. */
171 168
     private ScheduledFuture<?> reconnectTimerFuture;
172 169
 
@@ -174,28 +171,19 @@ public class Server implements Connection {
174 171
      * Creates a new server which will connect to the specified URL with the specified profile.
175 172
      */
176 173
     public Server(
174
+            final WindowModel windowModel,
177 175
             final ConfigProviderMigrator configMigrator,
178 176
             final ParserFactory parserFactory,
179 177
             final IdentityFactory identityFactory,
180 178
             final QueryFactory queryFactory,
181
-            final DMDircMBassador eventBus,
182 179
             final MessageEncoderFactory messageEncoderFactory,
183 180
             final ConfigProvider userSettings,
184 181
             final GroupChatManagerImplFactory groupChatManagerFactory,
185 182
             final ScheduledExecutorService executorService,
186 183
             @Nonnull final URI uri,
187 184
             @Nonnull final Profile profile,
188
-            final BackBufferFactory backBufferFactory,
189 185
             final UserManager userManager) {
190
-        // TODO: Pass this in
191
-        windowModel =
192
-                new FrameContainer("server-disconnected", getHost(uri), getHost(uri),
193
-                        configMigrator.getConfigProvider(), backBufferFactory, eventBus,
194
-                        Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
195
-                                WindowComponent.INPUTFIELD.getIdentifier(),
196
-                                WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));
197
-        windowModel.setConnection(this);
198
-
186
+        this.windowModel = windowModel;
199 187
         this.parserFactory = parserFactory;
200 188
         this.identityFactory = identityFactory;
201 189
         this.configMigrator = configMigrator;
@@ -219,7 +207,6 @@ public class Server implements Connection {
219 207
         windowModel.getConfigManager().addChangeListener("formatter", "serverName", configListener);
220 208
         windowModel.getConfigManager().addChangeListener("formatter", "serverTitle", configListener);
221 209
 
222
-        windowModel.initBackBuffer();
223 210
         this.highlightManager = new HighlightManager(windowModel.getConfigManager(),
224 211
                 new ColourManager(windowModel.getConfigManager()));
225 212
         highlightManager.init();
@@ -527,26 +514,6 @@ public class Server implements Connection {
527 514
         new ArrayList<>(queries.values()).forEach(Query::close);
528 515
     }
529 516
 
530
-    /**
531
-     * Retrieves the host component of the specified URI, or throws a relevant exception if this is
532
-     * not possible.
533
-     *
534
-     * @param uri The URI to be processed
535
-     *
536
-     * @return The URI's host component, as returned by {@link URI#getHost()}.
537
-     *
538
-     * @throws NullPointerException     If <code>uri</code> is null
539
-     * @throws IllegalArgumentException If the specified URI has no host
540
-     * @since 0.6.4
541
-     */
542
-    private static String getHost(final URI uri) {
543
-        if (uri.getHost() == null) {
544
-            throw new IllegalArgumentException("URIs must have hosts");
545
-        }
546
-
547
-        return uri.getHost();
548
-    }
549
-
550 517
     /**
551 518
      * Builds an appropriately configured {@link Parser} for this server.
552 519
      *

+ 36
- 6
src/com/dmdirc/ServerFactoryImpl.java Parādīt failu

@@ -29,10 +29,12 @@ import com.dmdirc.interfaces.CommandController;
29 29
 import com.dmdirc.interfaces.config.ConfigProvider;
30 30
 import com.dmdirc.interfaces.config.ConfigProviderMigrator;
31 31
 import com.dmdirc.interfaces.config.IdentityFactory;
32
+import com.dmdirc.ui.core.components.WindowComponent;
32 33
 import com.dmdirc.ui.input.TabCompleterFactory;
33 34
 import com.dmdirc.ui.messages.BackBufferFactory;
34 35
 
35 36
 import java.net.URI;
37
+import java.util.Arrays;
36 38
 import java.util.concurrent.ScheduledExecutorService;
37 39
 
38 40
 import javax.inject.Inject;
@@ -40,7 +42,7 @@ import javax.inject.Provider;
40 42
 import javax.inject.Singleton;
41 43
 
42 44
 /**
43
- * Factory for {@link Server}s
45
+ * Factory for {@link Server}s.
44 46
  */
45 47
 @Singleton
46 48
 public class ServerFactoryImpl {
@@ -88,12 +90,19 @@ public class ServerFactoryImpl {
88 90
             final ScheduledExecutorService executorService,
89 91
             final URI uri,
90 92
             final Profile profile) {
91
-        final Server server = new Server(configMigrator, parserFactory,
92
-                identityFactory, queryFactory.get(), eventBus,
93
+        final FrameContainer windowModel =
94
+                new FrameContainer("server-disconnected", getHost(uri), getHost(uri),
95
+                        configMigrator.getConfigProvider(), backBufferFactory, eventBus,
96
+                        Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
97
+                                WindowComponent.INPUTFIELD.getIdentifier(),
98
+                                WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));
99
+        final Server server = new Server(windowModel, configMigrator, parserFactory,
100
+                identityFactory, queryFactory.get(),
93 101
                 messageEncoderFactory, userSettings, groupChatManagerFactory, executorService,
94
-                uri, profile, backBufferFactory, userManager);
95
-        // TODO: Yuck!
96
-        ((FrameContainer) server.getWindowModel()).setInputModel(new DefaultInputModel(
102
+                uri, profile, userManager);
103
+        windowModel.setConnection(server);
104
+        windowModel.initBackBuffer();
105
+        windowModel.setInputModel(new DefaultInputModel(
97 106
                 server::sendLine,
98 107
                 new ServerCommandParser(
99 108
                         server.getWindowModel().getConfigManager(),
@@ -107,4 +116,25 @@ public class ServerFactoryImpl {
107 116
                 server::getMaxLineLength));
108 117
         return server;
109 118
     }
119
+
120
+    /**
121
+     * Retrieves the host component of the specified URI, or throws a relevant exception if this is
122
+     * not possible.
123
+     *
124
+     * @param uri The URI to be processed
125
+     *
126
+     * @return The URI's host component, as returned by {@link URI#getHost()}.
127
+     *
128
+     * @throws NullPointerException     If <code>uri</code> is null
129
+     * @throws IllegalArgumentException If the specified URI has no host
130
+     * @since 0.6.4
131
+     */
132
+    private static String getHost(final URI uri) {
133
+        if (uri.getHost() == null) {
134
+            throw new IllegalArgumentException("URIs must have hosts");
135
+        }
136
+
137
+        return uri.getHost();
138
+    }
139
+
110 140
 }

+ 8
- 0
src/com/dmdirc/interfaces/WindowModel.java Parādīt failu

@@ -24,6 +24,7 @@ package com.dmdirc.interfaces;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.events.FrameIconChangedEvent;
27
+import com.dmdirc.events.FrameNameChangedEvent;
27 28
 import com.dmdirc.events.FrameTitleChangedEvent;
28 29
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
29 30
 import com.dmdirc.ui.messages.BackBuffer;
@@ -47,6 +48,13 @@ public interface WindowModel {
47 48
 
48 49
     DMDircMBassador getEventBus();
49 50
 
51
+    /**
52
+     * Changes the name of this container, and fires a {@link FrameNameChangedEvent}.
53
+     *
54
+     * @param name The new name for this frame.
55
+     */
56
+    void setName(String name);
57
+
50 58
     /**
51 59
      * Changes the title of this container, and fires a {@link FrameTitleChangedEvent}.
52 60
      *

Notiek ielāde…
Atcelt
Saglabāt