Package

Source Code of Main

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import Communication.ChatProvider;
import Communication.Interfaces.Connection;
import Communication.Mocks.ICQSimulation;
import Communication.Mocks.MSNSimulation;
import Control.Record;
import Control.SatedaHandler;
import Control.Settings;
import GUI.MainWindow;

/**
* Generates the client based on the saved {@link Settings} and {@link Record}s and
* then transfers the control to the {@link SatedaHandler}.
*
* @author Sebastian
*
*/
public class Main {

  /**
   * The root location of all information the client saves
   */
  public final static String CLIENT_DATA_URL = "C:/Sateda/";

  /**
   * @param args
   */
  public static void main(String[] args) {
   
    try {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (ClassNotFoundException e1) {
      e1.printStackTrace();
    } catch (InstantiationException e1) {
      e1.printStackTrace();
    } catch (IllegalAccessException e1) {
      e1.printStackTrace();
    } catch (UnsupportedLookAndFeelException e1) {
      e1.printStackTrace();
    }
   
    Settings settings = null;
    Record record = null;
   
    try {
      FileInputStream fileinput = new FileInputStream(CLIENT_DATA_URL + "settings.dat");
      ObjectInputStream input = new ObjectInputStream(fileinput);
      settings = (Settings) input.readObject();
      input.close();
    } catch (FileNotFoundException e) {
     
      settings = new Settings();
     
    } catch (IOException e) {
    } catch (ClassNotFoundException e) {
    }

    try {
      ObjectInputStream objectinput = new ObjectInputStream(new FileInputStream(CLIENT_DATA_URL + "records.dat"));
      record = (Record) objectinput.readObject();
      objectinput.close();
    } catch (FileNotFoundException e) {
     
      record = new Record();
     
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
 
    MainWindow mainWindow = new MainWindow(settings.mainWindowBounds, settings.loginAtClientStart,
        settings.connectionName.size());
    SatedaHandler satedaHandler = new SatedaHandler(settings, mainWindow, record);
   
    mainWindow.setEventHandler(satedaHandler);
     
    int index = -1;
    for(ChatProvider type : settings.connectionType){
      index++;
      Connection connection = null;
     
      if(type.equals(ChatProvider.ICQ)){
        connection = new ICQSimulation(settings.loginName.get(index),
            settings.loginPassword.get(index), satedaHandler, ChatProvider.ICQ);
      }else if(type.equals(ChatProvider.MSN)){
        connection = new MSNSimulation(settings.loginName.get(index),
            settings.loginPassword.get(index), satedaHandler, ChatProvider.MSN);     
      }
      satedaHandler.addConnection(connection);
    }
   
    satedaHandler.startClient();

  }
}
TOP

Related Classes of Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.