Пример #1
0
  /**
   * Constructor. Initializes the controller, but does not log on to the network.
   *
   * @param ui The active user interface object.
   * @param settings The settings to use.
   */
  public Controller(final UserInterface ui, final Settings settings) {
    Validate.notNull(ui, "User interface can not be null");
    Validate.notNull(settings, "Settings can not be null");

    this.ui = ui;
    this.settings = settings;

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread("ControllerShutdownHook") {
              @Override
              public void run() {
                logOff(false);
                shutdown();
              }
            });

    me = settings.getMe();
    userListController = new UserListController(settings);
    chatState = new ChatState();
    tList = new TransferList();
    wList = new WaitingList();
    idleThread = new IdleThread(this, ui, settings);
    networkService = new NetworkService(settings);
    final MessageResponder msgResponder = new DefaultMessageResponder(this, ui, settings);
    final PrivateMessageResponder privmsgResponder =
        new DefaultPrivateMessageResponder(this, ui, settings);
    final MessageParser msgParser = new MessageParser(msgResponder, settings);
    networkService.registerMessageReceiverListener(msgParser);
    final PrivateMessageParser privmsgParser = new PrivateMessageParser(privmsgResponder, settings);
    networkService.registerUDPReceiverListener(privmsgParser);
    messages = new Messages(networkService, settings);
    networkService.registerNetworkConnectionListener(this);
    msgController = ui.getMessageController();

    new DayTimer(ui);
    idleThread.start();

    msgController.showSystemMessage(
        "Welcome to " + Constants.APP_NAME + " v" + Constants.APP_VERSION + "!");
    final String date = Tools.dateToString(null, "EEEE, d MMMM yyyy");
    msgController.showSystemMessage("Today is " + date);
  }
Пример #2
0
 /**
  * Logs this client off the network. <br>
  * <br>
  * <strong>Note:</strong> removeUsers should not be true when called from a ShutdownHook, as that
  * will lead to a deadlock. See http://bugs.sun.com/bugdatabase/view_bug.do;?bug_id=6261550 for
  * details.
  *
  * @param removeUsers Set to true to remove users from the user list.
  */
 public void logOff(final boolean removeUsers) {
   messages.sendLogoffMessage();
   chatState.setLoggedOn(false);
   chatState.setLogonCompleted(false);
   networkService.disconnect();
   getTopic().resetTopic();
   if (removeUsers) {
     removeAllUsers();
   }
   me.reset();
 }
Пример #3
0
 public void registerNetworkConnectionListener(final NetworkConnectionListener listener) {
   networkService.registerNetworkConnectionListener(listener);
 }
Пример #4
0
 /**
  * Creates an instance of a JMX bean loader, and returns it.
  *
  * @return A JMX bean loader.
  */
 public JMXBeanLoader createJMXBeanLoader() {
   return new JMXBeanLoader(this, networkService.getConnectionWorker(), settings);
 }
Пример #5
0
 /** Checks the state of the network, and tries to keep the best possible network connection up. */
 public void checkNetwork() {
   networkService.checkNetwork();
 }
Пример #6
0
 /**
  * Returns if the client is logged on to the chat and connected to the network.
  *
  * @return True if the client is connected.
  */
 public boolean isConnected() {
   return networkService.isNetworkUp() && isLoggedOn();
 }
Пример #7
0
 /** Logs this client onto the network. */
 public void logOn() {
   if (!networkService.isConnectionWorkerAlive()) {
     networkService.connect();
   }
 }