Package gui.action

Source Code of gui.action.MakeConnection

/*
* Hamsam - Instant Messaging API
* Copyright (C) 2003 Raghu K
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package gui.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import gui.tools.Traces;
import gui.tools.PropertiesManager;
import gui.ConnectionPanel;
import gui.MainFrame;

import hamsam.exception.HamsamException;
import hamsam.exception.IllegalArgumentException;
import hamsam.net.ProxyInfo;

/**
* <p>Titre : Hamsam Project</p>
* <p>Description : Instant Messenger</p>
* <p>Copyright : Copyright (c) 2003</p>
* <p>Soci�t� : </p>
* @author Fr�d�ric DIB
* @version 0.1
*/

public class MakeConnection implements ActionListener
{
  private ConnectionPanel connectionPanel = null;
  private PropertiesManager propertiesMgr = null;

  public MakeConnection(ConnectionPanel cP, PropertiesManager p)
  {
    this.connectionPanel = cP;
    this.propertiesMgr = p;
  }
  public void actionPerformed(ActionEvent evt)
  {
    Traces.printTraces("Starting connection ...");
    Traces.printTraces(
      "Login          : " + this.connectionPanel.getLogin());
    Traces.printTraces(
      "Password       : " + this.connectionPanel.getPassword());
    Traces.printTraces(
      "Protocol Index : " + this.connectionPanel.getSelectedProtocol());

    ConnectionInfos.currentProtocol =
      ConnectionInfos
        .protocols[this
        .connectionPanel
        .getSelectedProtocol()];
    Traces.printTraces(
      "Protocol Name  : "
        + ConnectionInfos.currentProtocol.getProtocolName());
    ConnectionInfos.currentProtocol.setListener(
      ConnectionInfos.MyIMListener);
    ConnectionInfos.MyIMListener.setPropertiesMgr(this.propertiesMgr);
    try
    {
      ProxyInfo info = getProxyInfo();
      ConnectionInfos.currentProtocol.connect(
        this.connectionPanel.getLogin(),
        this.connectionPanel.getPassword(),
        info);
    }
    catch (HamsamException e)
    {
      e.printStackTrace();
    }
  }

  private ProxyInfo getProxyInfo() throws IllegalArgumentException
  {
    PropertiesManager prop = MainFrame.myRef.getGeneralPropertiesManager();
    int proxyType = Integer.parseInt(prop.getValue("proxyType"));
    String proxyHost = prop.getValue("proxyHost");
    int proxyPort = Integer.parseInt(prop.getValue("proxyPort"));

    switch(proxyType)
    {
      case 1:
        return new ProxyInfo(ProxyInfo.HTTP, proxyHost, proxyPort);
      case 2:
        return new ProxyInfo(ProxyInfo.SOCKS4, proxyHost, proxyPort);
      case 3:
        return new ProxyInfo(ProxyInfo.SOCKS5, proxyHost, proxyPort);
    }
   
    return new ProxyInfo();
  }
}
TOP

Related Classes of gui.action.MakeConnection

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.