Skip to content

Commit

Permalink
Pass WindowModel into Server.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 19, 2016
1 parent 96933fd commit 1141fd1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
8 changes: 2 additions & 6 deletions src/com/dmdirc/FrameContainer.java
Expand Up @@ -140,12 +140,8 @@ public DMDircMBassador getEventBus() {
return eventBus;
}

/**
* Changes the name of this container, and fires a {@link FrameNameChangedEvent}.
*
* @param name The new name for this frame.
*/
protected void setName(final String name) {
@Override
public void setName(final String name) {
this.name = name;

eventBus.publishAsync(new FrameNameChangedEvent(this, name));
Expand Down
39 changes: 3 additions & 36 deletions src/com/dmdirc/Server.java
Expand Up @@ -50,9 +50,7 @@
import com.dmdirc.parser.interfaces.SecureParser;
import com.dmdirc.parser.interfaces.StringConverter;
import com.dmdirc.tls.CertificateManager;
import com.dmdirc.ui.core.components.WindowComponent;
import com.dmdirc.ui.input.TabCompletionType;
import com.dmdirc.ui.messages.BackBufferFactory;
import com.dmdirc.ui.messages.ColourManager;
import com.dmdirc.ui.messages.Formatter;
import com.dmdirc.ui.messages.HighlightManager;
Expand All @@ -64,7 +62,6 @@
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -166,36 +163,27 @@ public class Server implements Connection {
private final HighlightManager highlightManager;
/** Listener to use for config changes. */
private final ConfigChangeListener configListener = (domain, key) -> updateTitle();
private final FrameContainer windowModel;
private final WindowModel windowModel;
/** The future used when a reconnect timer is scheduled. */
private ScheduledFuture<?> reconnectTimerFuture;

/**
* Creates a new server which will connect to the specified URL with the specified profile.
*/
public Server(
final WindowModel windowModel,
final ConfigProviderMigrator configMigrator,
final ParserFactory parserFactory,
final IdentityFactory identityFactory,
final QueryFactory queryFactory,
final DMDircMBassador eventBus,
final MessageEncoderFactory messageEncoderFactory,
final ConfigProvider userSettings,
final GroupChatManagerImplFactory groupChatManagerFactory,
final ScheduledExecutorService executorService,
@Nonnull final URI uri,
@Nonnull final Profile profile,
final BackBufferFactory backBufferFactory,
final UserManager userManager) {
// TODO: Pass this in
windowModel =
new FrameContainer("server-disconnected", getHost(uri), getHost(uri),
configMigrator.getConfigProvider(), backBufferFactory, eventBus,
Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
WindowComponent.INPUTFIELD.getIdentifier(),
WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));
windowModel.setConnection(this);

this.windowModel = windowModel;
this.parserFactory = parserFactory;
this.identityFactory = identityFactory;
this.configMigrator = configMigrator;
Expand All @@ -219,7 +207,6 @@ public Server(
windowModel.getConfigManager().addChangeListener("formatter", "serverName", configListener);
windowModel.getConfigManager().addChangeListener("formatter", "serverTitle", configListener);

windowModel.initBackBuffer();
this.highlightManager = new HighlightManager(windowModel.getConfigManager(),
new ColourManager(windowModel.getConfigManager()));
highlightManager.init();
Expand Down Expand Up @@ -527,26 +514,6 @@ private void closeQueries() {
new ArrayList<>(queries.values()).forEach(Query::close);
}

/**
* Retrieves the host component of the specified URI, or throws a relevant exception if this is
* not possible.
*
* @param uri The URI to be processed
*
* @return The URI's host component, as returned by {@link URI#getHost()}.
*
* @throws NullPointerException If <code>uri</code> is null
* @throws IllegalArgumentException If the specified URI has no host
* @since 0.6.4
*/
private static String getHost(final URI uri) {
if (uri.getHost() == null) {
throw new IllegalArgumentException("URIs must have hosts");
}

return uri.getHost();
}

/**
* Builds an appropriately configured {@link Parser} for this server.
*
Expand Down
42 changes: 36 additions & 6 deletions src/com/dmdirc/ServerFactoryImpl.java
Expand Up @@ -29,18 +29,20 @@
import com.dmdirc.interfaces.config.ConfigProvider;
import com.dmdirc.interfaces.config.ConfigProviderMigrator;
import com.dmdirc.interfaces.config.IdentityFactory;
import com.dmdirc.ui.core.components.WindowComponent;
import com.dmdirc.ui.input.TabCompleterFactory;
import com.dmdirc.ui.messages.BackBufferFactory;

import java.net.URI;
import java.util.Arrays;
import java.util.concurrent.ScheduledExecutorService;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

/**
* Factory for {@link Server}s
* Factory for {@link Server}s.
*/
@Singleton
public class ServerFactoryImpl {
Expand Down Expand Up @@ -88,12 +90,19 @@ public Server getServer(
final ScheduledExecutorService executorService,
final URI uri,
final Profile profile) {
final Server server = new Server(configMigrator, parserFactory,
identityFactory, queryFactory.get(), eventBus,
final FrameContainer windowModel =
new FrameContainer("server-disconnected", getHost(uri), getHost(uri),
configMigrator.getConfigProvider(), backBufferFactory, eventBus,
Arrays.asList(WindowComponent.TEXTAREA.getIdentifier(),
WindowComponent.INPUTFIELD.getIdentifier(),
WindowComponent.CERTIFICATE_VIEWER.getIdentifier()));
final Server server = new Server(windowModel, configMigrator, parserFactory,
identityFactory, queryFactory.get(),
messageEncoderFactory, userSettings, groupChatManagerFactory, executorService,
uri, profile, backBufferFactory, userManager);
// TODO: Yuck!
((FrameContainer) server.getWindowModel()).setInputModel(new DefaultInputModel(
uri, profile, userManager);
windowModel.setConnection(server);
windowModel.initBackBuffer();
windowModel.setInputModel(new DefaultInputModel(
server::sendLine,
new ServerCommandParser(
server.getWindowModel().getConfigManager(),
Expand All @@ -107,4 +116,25 @@ public Server getServer(
server::getMaxLineLength));
return server;
}

/**
* Retrieves the host component of the specified URI, or throws a relevant exception if this is
* not possible.
*
* @param uri The URI to be processed
*
* @return The URI's host component, as returned by {@link URI#getHost()}.
*
* @throws NullPointerException If <code>uri</code> is null
* @throws IllegalArgumentException If the specified URI has no host
* @since 0.6.4
*/
private static String getHost(final URI uri) {
if (uri.getHost() == null) {
throw new IllegalArgumentException("URIs must have hosts");
}

return uri.getHost();
}

}
8 changes: 8 additions & 0 deletions src/com/dmdirc/interfaces/WindowModel.java
Expand Up @@ -24,6 +24,7 @@

import com.dmdirc.DMDircMBassador;
import com.dmdirc.events.FrameIconChangedEvent;
import com.dmdirc.events.FrameNameChangedEvent;
import com.dmdirc.events.FrameTitleChangedEvent;
import com.dmdirc.interfaces.config.AggregateConfigProvider;
import com.dmdirc.ui.messages.BackBuffer;
Expand All @@ -47,6 +48,13 @@ public interface WindowModel {

DMDircMBassador getEventBus();

/**
* Changes the name of this container, and fires a {@link FrameNameChangedEvent}.
*
* @param name The new name for this frame.
*/
void setName(String name);

/**
* Changes the title of this container, and fires a {@link FrameTitleChangedEvent}.
*
Expand Down

0 comments on commit 1141fd1

Please sign in to comment.