import java.awt.event.*;
import javax.swing.event.* ;
import java.io.* ;
import javax.swing.* ;

public class KawaGet implements ActionListener, WindowListener, CaretListener, ChangeListener {
    private Gui theGui = null ;
    private LigneDeCommande ldc = null ;
    private WgetProcess wgetproc = null ;

    // Des variables utiles pour "l'ecoute" des JTextField
    private String url = "" ;
    private String read = "" ;
    private String depth = "" ;
    private String log = "" ;
    private String ret = "" ;
    private String tout = "" ;
    private String wait = "" ;
    private String quota = "" ;
    private String prefix = "" ;
    private String cutdir = "" ;
    private String httpuser = "" ;
    private String httppwd = "" ;
    private String proxyuser = "" ;
    private String proxypwd = "" ;
    private String agent = "" ;
    private String accdom = "" ;
    private String accept = "" ;
    private String excdirs = "" ;
    private String incdirs = "" ;
    private String rejdom = "" ;
    private String reject = "" ;


    public KawaGet() {
	super();
	theGui = new Gui() ;
	ldc = new LigneDeCommande() ;
	theGui.setVisible(true) ;
	
	// Enregistrement de tous les Action/Window Listeners
	theGui.addWindowListener(this) ;
	// Tab Basic
	theGui.gettab_basic().getread_cb().addActionListener(this) ;
	theGui.gettab_basic().getrecursive_cb().addActionListener(this) ;
	theGui.gettab_basic().getdepth_cb().addActionListener(this) ;
	theGui.gettab_basic().getlog_cb().addActionListener(this) ;
	theGui.gettab_basic().getoverw_b().addActionListener(this) ;
	theGui.gettab_basic().getquiet_rb().addActionListener(this) ;
	theGui.gettab_basic().getverb_rb().addActionListener(this) ;
	theGui.gettab_basic().getvverb_rb().addActionListener(this) ;
	theGui.gettab_basic().getrel_cb().addActionListener(this) ;
	theGui.gettab_basic().getconv_cb().addActionListener(this) ;
	theGui.gettab_basic().getmirror_cb().addActionListener(this) ;
	theGui.gettab_basic().getback_cb().addActionListener(this) ;
	theGui.gettab_basic().getgo_b().addActionListener(this) ;
	// Tab Download
	theGui.gettab_download().getret_cb().addActionListener(this) ;
	theGui.gettab_download().gettout_cb().addActionListener(this) ;
	theGui.gettab_download().getcont_cb().addActionListener(this) ;
	theGui.gettab_download().getnoclob_cb().addActionListener(this) ;
	theGui.gettab_download().gettimestamp_cb().addActionListener(this) ;
	theGui.gettab_download().getproxy_co().addActionListener(this) ;
	theGui.gettab_download().getwait_cb().addActionListener(this) ;
	theGui.gettab_download().getquota_cb().addActionListener(this) ;
	theGui.gettab_download().getdel_cb().addActionListener(this) ;
	theGui.gettab_download().getlisting_cb().addActionListener(this) ;
	theGui.gettab_download().getfolftp_cb().addActionListener(this) ;
	theGui.gettab_download().getspan_cb().addActionListener(this) ;
	theGui.gettab_download().getprefix_cb().addActionListener(this) ;
	theGui.gettab_download().getnopar_cb().addActionListener(this) ;
	theGui.gettab_download().getnolookup_cb().addActionListener(this) ;
	theGui.gettab_download().getnodirs_cb().addActionListener(this) ;
	theGui.gettab_download().getforcedir_cb().addActionListener(this) ;
	theGui.gettab_download().getnohostdir_cb().addActionListener(this) ;
	theGui.gettab_download().getcutdir_cb().addActionListener(this) ;
	// Tab Http
	theGui.gettab_http().gethttpuser_cb().addActionListener(this) ;
	theGui.gettab_http().gethttppwd_cb().addActionListener(this) ;
	theGui.gettab_http().getproxyuser_cb().addActionListener(this) ;
	theGui.gettab_http().getproxypwd_cb().addActionListener(this) ;
	theGui.gettab_http().getcache_co().addActionListener(this) ;
	theGui.gettab_http().getsavehdrs_cb().addActionListener(this) ;
	theGui.gettab_http().getignorelen_cb().addActionListener(this) ;
	theGui.gettab_http().getagent_cb().addActionListener(this) ;
	theGui.gettab_http().getglob_co().addActionListener(this) ;
	theGui.gettab_http().getretsymlnks_cb().addActionListener(this) ;
	theGui.gettab_http().getpassiveftp_cb().addActionListener(this) ;
	// Tab Exclusions
	theGui.gettab_exclusions().getaccdom_cb().addActionListener(this) ;
	theGui.gettab_exclusions().getaccept_cb().addActionListener(this) ;
	theGui.gettab_exclusions().getexcdirs_cb().addActionListener(this) ;
	theGui.gettab_exclusions().getincdirs_cb().addActionListener(this) ;
	theGui.gettab_exclusions().getrejdom_cb().addActionListener(this) ;
	theGui.gettab_exclusions().getreject_cb().addActionListener(this) ;
	// Et les CaretListeners
	theGui.gettab_basic().geturl_tf().addCaretListener(this) ;
	theGui.gettab_basic().getread_tf().addCaretListener(this) ;
	theGui.gettab_basic().getdepth_tf().addCaretListener(this) ;
	theGui.gettab_basic().getlog_tf().addCaretListener(this) ;
	theGui.gettab_download().getret_tf().addCaretListener(this) ;
	theGui.gettab_download().gettout_tf().addCaretListener(this) ;
	theGui.gettab_download().getwait_tf().addCaretListener(this) ;
	theGui.gettab_download().getquota_tf().addCaretListener(this) ;
	theGui.gettab_download().getprefix_tf().addCaretListener(this) ;
	theGui.gettab_download().getcutdir_tf().addCaretListener(this) ;
	theGui.gettab_http().gethttpuser_tf().addCaretListener(this) ;
	theGui.gettab_http().gethttppwd_tf().addCaretListener(this) ;
	theGui.gettab_http().getproxyuser_tf().addCaretListener(this) ;
	theGui.gettab_http().getproxypwd_tf().addCaretListener(this) ;
	theGui.gettab_http().getagent_tf().addCaretListener(this) ;
	theGui.gettab_exclusions().getaccdom_tf().addCaretListener(this) ;
	theGui.gettab_exclusions().getaccept_tf().addCaretListener(this) ;
	theGui.gettab_exclusions().getexcdirs_tf().addCaretListener(this) ;
	theGui.gettab_exclusions().getincdirs_tf().addCaretListener(this) ;
	theGui.gettab_exclusions().getrejdom_tf().addCaretListener(this) ;
	theGui.gettab_exclusions().getreject_tf().addCaretListener(this) ;
	// Les 2 boutons du panel Basic , pour les file choosers
	theGui.gettab_basic().getlog_b().addActionListener(this) ;
	theGui.gettab_basic().getread_b().addActionListener(this) ;

	// Le ChangeListener du JSlider
	theGui.gettab_basic().getdepth_sl().addChangeListener(this) ;
	
	// Le menu
	theGui.getitem_exit().addActionListener(this) ;
    }

    public void stateChanged(ChangeEvent e) {
	JSlider source = (JSlider)e.getSource();
	if(source == theGui.gettab_basic().getdepth_sl()) {
	    //	    if (!source.getValueIsAdjusting()) {
	    int d = (int)((JSlider)e.getSource()).getValue();
	    theGui.gettab_basic().getdepth_tf().setText((new Integer(d)).toString()) ;
	    // }
	}
    }

    public void caretUpdate(CaretEvent e) {
	Object src = e.getSource() ;
	String text ;
	if(src == theGui.gettab_basic().geturl_tf()) {
	    text = theGui.gettab_basic().geturl_tf().getText() ;
	    if(!url.equals(text)) {
		url = text ;
		ldc.setUrl(url) ;
	    }
	}
	else
	if(src == theGui.gettab_basic().getread_tf()) {
	    text = theGui.gettab_basic().getread_tf().getText() ;
	    if(!read.equals(text)) {
		read = text ;
		ldc.updateOpt("-i " , "-i " , read) ;
	    }
	}
	else
	if(src == theGui.gettab_basic().getdepth_tf()) {
	    text = theGui.gettab_basic().getdepth_tf().getText() ;
	    if(!depth.equals(text)) {
		depth = text ;
		ldc.updateOpt("-l " , "-l " , depth) ;
	    }
	}
	else
	if(src == theGui.gettab_basic().getlog_tf()) {
	    text = theGui.gettab_basic().getlog_tf().getText() ;
	    if(!log.equals(text)) {
		log = text ;
		if(theGui.gettab_basic().getoverw_b().isSelected()) // append
		    ldc.updateOpt("-o " , "-o " , log) ;
		else
		    ldc.updateOpt("-a " , "-a " , log) ;
	    }
	}
	else
	if(src == theGui.gettab_download().getret_tf()) {
	    text = theGui.gettab_download().getret_tf().getText() ;
	    if(!ret.equals(text)) {
		ret = text ;
		ldc.updateOpt("-t ", "-t ", ret) ;
	    }
	}
	else
	if(src == theGui.gettab_download().gettout_tf()) {
	    text = theGui.gettab_download().gettout_tf().getText() ;
	    if(!tout.equals(text)) {
		tout = text ;
		ldc.updateOpt("-T " , "-T " , tout) ;
	    }
	}
	else
	if(src == theGui.gettab_download().getwait_tf()) {
	    text = theGui.gettab_download().getwait_tf().getText() ;
	    if(!wait.equals(text)) {
		 wait= text ;
		ldc.updateOpt("-w " , "-w " , wait) ;
	    }
	}
	else
	if(src == theGui.gettab_download().getquota_tf()) {
	    text = theGui.gettab_download().getquota_tf().getText() ;
	    if(!quota.equals(text)) {
		 quota = text ;
		ldc.updateOpt("-Q " , "-Q " , quota) ;
	    }
	}
	else
	if(src == theGui.gettab_download().getprefix_tf()) {
	    text = theGui.gettab_download().getprefix_tf().getText() ;
	    if(!prefix.equals(text)) {
		prefix = text ;
		ldc.updateOpt("-P " , "-P " , prefix) ;
	    }
	}
	else
	if(src == theGui.gettab_download().getcutdir_tf()) {
	    text = theGui.gettab_download().getcutdir_tf().getText() ;
	    if(!cutdir.equals(text)) {
		cutdir = text ;
		ldc.updateOpt("--cut-dirs=" , "--cut-dirs=" , cutdir) ;
	    }
	}
	else
	if(src == theGui.gettab_http().gethttpuser_tf()) {
	    text = theGui.gettab_http().gethttpuser_tf().getText() ;
	    if(!httpuser.equals(text)) {
		httpuser = text ;
		ldc.updateOpt("--http-user=" , "--http-user=" , httpuser) ;
	    }
	}
	else
	if(src == theGui.gettab_http().gethttppwd_tf()) {
	    text = theGui.gettab_http().gethttppwd_tf().getText() ;
	    if(!httppwd.equals(text)) {
		httppwd = text ;
		ldc.updateOpt("--http-passwd=" , "--http-passwd=" , httppwd) ;
	    }
	}
	else
	if(src == theGui.gettab_http().getproxyuser_tf()) {
	    text = theGui.gettab_http().getproxyuser_tf().getText() ; 
	    if(!proxyuser.equals(text)) {
		proxyuser = text ;
		ldc.updateOpt("--proxy-user=", "--proxy-user=", proxyuser) ;
	    }
	}
	else
	if(src == theGui.gettab_http().getproxypwd_tf()) {
	    text = theGui.gettab_http().getproxypwd_tf().getText() ;
	    if(!proxypwd.equals(text)) {
		proxypwd = text ;
		ldc.updateOpt("--proxy-passwd=", "--proxy-passwd=", proxypwd) ;
	    }
	}
	else
	if(src == theGui.gettab_http().getagent_tf()) {
	    text = theGui.gettab_http().getagent_tf().getText() ;
	    if(!agent.equals(text)) {
		agent = text ;
		ldc.updateOpt("-U ", "-U ", agent) ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getincdirs_tf()) {
	    text = theGui.gettab_exclusions().getincdirs_tf().getText() ;
	    if(!incdirs.equals(text)) {
		incdirs = text ;
		ldc.updateOpt("-I ", "-I ",incdirs) ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getaccdom_tf()) {
	    text = theGui.gettab_exclusions().getaccdom_tf().getText() ;
	    if(!accdom.equals(text)) {
		accdom = text ;
		ldc.updateOpt("-D ", "-D ", accdom) ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getaccept_tf()) {
	    text = theGui.gettab_exclusions().getaccept_tf().getText() ;
	    if(!accept.equals(text)) {
		accept = text ;
		ldc.updateOpt("-A ", "-A ",accept) ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getexcdirs_tf()) {
	    text = theGui.gettab_exclusions().getexcdirs_tf().getText() ;
	    if(!excdirs.equals(text)) {
		excdirs = text ;
		ldc.updateOpt("-X ", "-X ",excdirs) ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getrejdom_tf()) {
	    text = theGui.gettab_exclusions().getrejdom_tf().getText() ;
	    if(!rejdom.equals(text)) {
		rejdom = text ;
		ldc.updateOpt("--exclude-domains=", "--exclude-domains=",rejdom) ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getreject_tf()) {
	    text = theGui.gettab_exclusions().getreject_tf().getText() ;
	    if(!reject.equals(text)) {
		reject = text ;
		ldc.updateOpt("-R ", "-R ",reject) ;
	    }
	}
    }

    public void actionPerformed(ActionEvent e) {
	Object src = e.getSource() ;

	// Exit ?
	if(src == theGui.getitem_exit()){
	    theGui.dispose() ;
	    System.exit(0) ;
	}
	else
	// L'ONGLET BASIC

	// Ligne 2 : input file stuff
	if(src == theGui.gettab_basic().getread_cb()) {
	    if(theGui.gettab_basic().getread_cb().isSelected()) {
		theGui.gettab_basic().getread_tf().setEnabled(true) ;
		theGui.gettab_basic().getread_b().setEnabled(true) ;
		ldc.setOptInputFile(theGui.gettab_basic().getread_tf().getText()) ;
	    }
	    else {
		theGui.gettab_basic().getread_tf().setEnabled(false) ;
		theGui.gettab_basic().getread_b().setEnabled(false) ;
		ldc.unsetOptInputFile() ;
	    }
	    
	}
	else
	// Ligne 3 : recursive , depth, etc ...
	if(src == theGui.gettab_basic().getrecursive_cb()) {
	    if(theGui.gettab_basic().getrecursive_cb().isSelected()) {
		theGui.gettab_basic().getdepth_cb().setEnabled(true) ;
		if(theGui.gettab_basic().getdepth_cb().isSelected()) {
		    theGui.gettab_basic().getdepth_tf().setEnabled(true) ;
		    theGui.gettab_basic().getdepth_sl().setEnabled(true) ;
		}
		ldc.setOptRecursive() ;
	    }
	    else {
		theGui.gettab_basic().getdepth_cb().setEnabled(false) ;
		if(theGui.gettab_basic().getdepth_cb().isSelected()) {
		    theGui.gettab_basic().getdepth_tf().setEnabled(false) ;
		    theGui.gettab_basic().getdepth_sl().setEnabled(false) ;
		}
		ldc.unsetOptRecursive() ;
	    }
	}
	else
	if(src == theGui.gettab_basic().getdepth_cb()) {
	    if(theGui.gettab_basic().getdepth_cb().isSelected()) {
		theGui.gettab_basic().getdepth_tf().setEnabled(true) ;
		theGui.gettab_basic().getdepth_sl().setEnabled(true) ;
		ldc.setOptLevel(theGui.gettab_basic().getdepth_tf().getText()) ;
	    }
	    else {
		theGui.gettab_basic().getdepth_tf().setEnabled(false) ;
		theGui.gettab_basic().getdepth_sl().setEnabled(false) ;
		ldc.unsetOptLevel() ;
	    }
	}
	else
	// Ligne 4 : log
	if(src == theGui.gettab_basic().getlog_cb()) {
	    if(theGui.gettab_basic().getlog_cb().isSelected()) {
		theGui.gettab_basic().getlog_tf().setEnabled(true) ;
		theGui.gettab_basic().getlog_b().setEnabled(true) ;
		theGui.gettab_basic().getoverw_b().setEnabled(true) ;
		if(!theGui.gettab_basic().getoverw_b().isSelected())
		    ldc.setOptAppendLog(theGui.gettab_basic().getlog_tf().getText()) ;
		else
		    ldc.setOptOutputLog(theGui.gettab_basic().getlog_tf().getText()) ;
	    }
	    else {
		theGui.gettab_basic().getlog_tf().setEnabled(false) ;
		theGui.gettab_basic().getlog_b().setEnabled(false) ;
		theGui.gettab_basic().getoverw_b().setEnabled(false) ;
		if(!theGui.gettab_basic().getoverw_b().isSelected())
		    ldc.unsetOptAppendLog() ;
		else
		    ldc.unsetOptOutputLog() ;
	    }
	}
	else
	if(src == theGui.gettab_basic().getoverw_b()) {
	    if(!theGui.gettab_basic().getoverw_b().isSelected())
		ldc.updateOpt("-o " , "-a " , theGui.gettab_basic().getlog_tf().getText()) ;
	    else
		ldc.updateOpt("-a " , "-o " , theGui.gettab_basic().getlog_tf().getText()) ;
	}
	else
	if(src == theGui.gettab_basic().getread_b()) {
	    JFileChooser fc = new JFileChooser() ;
	    int returnval = fc.showOpenDialog(theGui) ;
	    if(returnval == JFileChooser.APPROVE_OPTION) {
		File file = fc.getSelectedFile() ;
		theGui.gettab_basic().getread_tf().setText(file.getAbsolutePath()) ;
	    }
	}
	else
	if(src == theGui.gettab_basic().getlog_b()) {
	    JFileChooser fc = new JFileChooser() ;
	    int returnval = fc.showOpenDialog(theGui) ;
	    if(returnval == JFileChooser.APPROVE_OPTION) {
		File file = fc.getSelectedFile() ;
		theGui.gettab_basic().getlog_tf().setText(file.getAbsolutePath()) ;
	    }
	}
	else
	// Ligne 5 : verbose mode
	if(src == theGui.gettab_basic().getquiet_rb()) {
	    ldc.unsetOptNonVerbose() ;
	    ldc.unsetOptVerbose() ;
	    ldc.unsetOptQuiet() ;
	    ldc.setOptQuiet() ;
	}
	else
	if(src == theGui.gettab_basic().getverb_rb()) {
	    ldc.unsetOptNonVerbose() ;
	    ldc.unsetOptVerbose() ;
	    ldc.unsetOptQuiet() ;
	    ldc.setOptNonVerbose() ;
	}
	else
	if(src == theGui.gettab_basic().getvverb_rb()) {
	    ldc.unsetOptNonVerbose() ;
	    ldc.unsetOptVerbose() ;
	    ldc.unsetOptQuiet() ;
	    ldc.setOptVerbose() ;
	}
	else
	// Ligne 6 : general options
	if(src == theGui.gettab_basic().getrel_cb()) {
	    if(theGui.gettab_basic().getrel_cb().isSelected()) 
		ldc.setOptRelative() ;
	    else
		ldc.unsetOptRelative() ;
	}
	else
	if(src == theGui.gettab_basic().getconv_cb()) {
	    if(theGui.gettab_basic().getconv_cb().isSelected()) 
		ldc.setOptConvertLinks() ;
	    else
		ldc.unsetOptConvertLinks() ;
	}
	else
	if(src == theGui.gettab_basic().getmirror_cb()) {
	    if(theGui.gettab_basic().getmirror_cb().isSelected()) 
		ldc.setOptMirror() ;
	    else
		ldc.unsetOptMirror() ;
	}
	else
	if(src == theGui.gettab_basic().getback_cb()) {
	    if(theGui.gettab_basic().getback_cb().isSelected()) 
		ldc.setOptBackground() ;
	    else
		ldc.unsetOptBackground() ;
	}
	else
	// Ligne 7 : Go !
	if(src == theGui.gettab_basic().getgo_b()) {
	    try {
		WgetProcess proc = new WgetProcess(ldc.makeCommandLine()) ;
		if(!theGui.gettab_basic().getback_cb().isSelected()) {
		    LogWin log = new LogWin(proc.getProcess().getErrorStream()) ;
		    log.start() ;
		}
	    }catch(IOException excep) {
		System.out.println("*** ERROR ***") ;
		System.out.println("Can't locate the main executable ! Please check the path.") ;
	    }
	    // System.out.println(ldc.makeCommandLine());
	    
	}
	else
	// L'ONGLET DOWNLOAD

	// Ligne 1 : Retries & Timeout
	if(src == theGui.gettab_download().getret_cb()) {
	    if(theGui.gettab_download().getret_cb().isSelected()) {
		theGui.gettab_download().getret_tf().setEnabled(true) ;
		ldc.setOptTries(theGui.gettab_download().getret_tf().getText()) ;
	    }
	    else {
		theGui.gettab_download().getret_tf().setEnabled(false) ;
		ldc.unsetOptTries() ;
	    }
	}
	else
	if(src == theGui.gettab_download().gettout_cb()) {
	    if(theGui.gettab_download().gettout_cb().isSelected()) {
		theGui.gettab_download().gettout_tf().setEnabled(true) ;
		ldc.setOptTimeout(theGui.gettab_download().gettout_tf().getText()) ;
	    }
	    else {
		theGui.gettab_download().gettout_tf().setEnabled(false) ;
		ldc.unsetOptTimeout() ;
	    }
	}
	else
	// Ligne 2 : continue , no clobbing , timestamping & proxy
	if(src == theGui.gettab_download().getcont_cb()) {
	    if(theGui.gettab_download().getcont_cb().isSelected()) {
		ldc.setOptContinue() ;
	    }
	    else {
		ldc.unsetOptContinue() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getnoclob_cb()) {
	    if(theGui.gettab_download().getnoclob_cb().isSelected()) {
		ldc.setOptNoClober() ;
	    }
	    else {
		ldc.unsetOptNoClober() ;
	    }
	}
	else
	if(src == theGui.gettab_download().gettimestamp_cb()) {
	    if(theGui.gettab_download().gettimestamp_cb().isSelected()) {
		ldc.setOptTimestamping() ;
	    }
	    else {
		ldc.unsetOptTimestamping() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getproxy_co()) {
	    ldc.unsetOptProxy() ;
	    int i = theGui.gettab_download().getproxy_co().getSelectedIndex() ;
	    if(i == 1)
		ldc.setOptProxy("on") ;
	    else if(i == 2)
		ldc.setOptProxy("off") ;
	    // Sinon rien !
	}
	else
	// Ligne 3 : wait & quota
	if(src == theGui.gettab_download().getwait_cb()) {
	    if(theGui.gettab_download().getwait_cb().isSelected()) {
		theGui.gettab_download().getwait_tf().setEnabled(true) ;
		ldc.setOptWait(theGui.gettab_download().getwait_tf().getText()) ;
	    }
	    else {
		theGui.gettab_download().getwait_tf().setEnabled(false) ;
		ldc.unsetOptWait() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getquota_cb()) {
	    if(theGui.gettab_download().getquota_cb().isSelected()) {
		theGui.gettab_download().getquota_tf().setEnabled(true) ;
		ldc.setOptQuota(theGui.gettab_download().getquota_tf().getText()) ;
	    }
	    else {
		theGui.gettab_download().getquota_tf().setEnabled(false) ;
		ldc.unsetOptQuota() ;
	    }
	}
	else
	// Ligne 4 : del , listing , ...
	if(src == theGui.gettab_download().getdel_cb()) {
	    if(theGui.gettab_download().getdel_cb().isSelected()) {
		ldc.setOptDeleteAfter() ;
	    }
	    else {
		ldc.unsetOptDeleteAfter() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getlisting_cb()) {
	    if(theGui.gettab_download().getlisting_cb().isSelected()) {
		ldc.setOptDontRemoveListing() ;
	    }
	    else {
		ldc.unsetOptDontRemoveListing() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getfolftp_cb()) {
	    if(theGui.gettab_download().getfolftp_cb().isSelected()) {
		ldc.setOptFollowFTP() ;
	    }
	    else {
		ldc.unsetOptFollowFTP() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getspan_cb()) {
	    if(theGui.gettab_download().getspan_cb().isSelected()) {
		ldc.setOptSpanHosts() ;
	    }
	    else {
		ldc.unsetOptSpanHosts() ;
	    }
	}
	else
	// Ligne 5 : prefix
	if(src == theGui.gettab_download().getprefix_cb()) {
	    if(theGui.gettab_download().getprefix_cb().isSelected()) {
		theGui.gettab_download().getprefix_tf().setEnabled(true) ;
		ldc.setOptDirectoryPrefix(theGui.gettab_download().getprefix_tf().getText()) ;
	    }
	    else {
		theGui.gettab_download().getprefix_tf().setEnabled(false) ;
		ldc.unsetOptDirectoryPrefix() ;
	    }
	}
	else
	// Ligne 6 : no parent , no lookup , no dirs
	if(src == theGui.gettab_download().getnopar_cb()) {
	    if(theGui.gettab_download().getnopar_cb().isSelected()) {
		ldc.setOptNoParent() ;
	    }
	    else {
		ldc.unsetOptNoParent() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getnolookup_cb()) {
	    if(theGui.gettab_download().getnolookup_cb().isSelected()) {
		ldc.setOptNoHostLookup() ;
	    }
	    else {
		ldc.unsetOptNoHostLookup() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getnodirs_cb()) {
	    if(theGui.gettab_download().getnodirs_cb().isSelected()) {
		ldc.setOptNoDirectories() ;
		if(theGui.gettab_download().getforcedir_cb().isSelected()) {
		    theGui.gettab_download().getforcedir_cb().setSelected(false) ;
		    ldc.unsetOptForceDirectories() ;
		}
	    }
	    else {
		ldc.unsetOptNoDirectories() ;
	    }
	}
	else
	// Ligne 7 : forecedir , nohostdir , ...
	if(src == theGui.gettab_download().getforcedir_cb()) {
	    if(theGui.gettab_download().getforcedir_cb().isSelected()) {
		ldc.setOptForceDirectories() ;
		if(theGui.gettab_download().getnodirs_cb().isSelected()) {
		    theGui.gettab_download().getnodirs_cb().setSelected(false) ;
		    ldc.unsetOptNoDirectories() ;
		}
	    }
	    else {
		ldc.unsetOptForceDirectories() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getnohostdir_cb()) {
	    if(theGui.gettab_download().getnohostdir_cb().isSelected()) {
		ldc.setOptNoHostDirectories() ;
	    }
	    else {
		ldc.unsetOptNoHostDirectories() ;
	    }
	}
	else
	if(src == theGui.gettab_download().getcutdir_cb()) {
	    if(theGui.gettab_download().getcutdir_cb().isSelected()) {
		theGui.gettab_download().getcutdir_tf().setEnabled(true) ;
		ldc.setOptCutDirs(theGui.gettab_download().getcutdir_tf().getText()) ;
	    }
	    else {
		theGui.gettab_download().getcutdir_tf().setEnabled(false) ;
		ldc.unsetOptCutDirs() ;
	    }
	}
	else
	// L'ONGLET HTTP
	if(src == theGui.gettab_http().gethttpuser_cb()) {
	    if(theGui.gettab_http().gethttpuser_cb().isSelected()) {
		theGui.gettab_http().gethttpuser_tf().setEnabled(true) ;
		ldc.setOptHTTPUser(theGui.gettab_http().gethttpuser_tf().getText()) ;
	    }
	    else {
		theGui.gettab_http().gethttpuser_tf().setEnabled(false) ;
		ldc.unsetOptHTTPUser() ;
	    }
	}
	else
	if(src == theGui.gettab_http().gethttppwd_cb()) {
	    if(theGui.gettab_http().gethttppwd_cb().isSelected()) {
		theGui.gettab_http().gethttppwd_tf().setEnabled(true) ;
		ldc.setOptHTTPPassword(theGui.gettab_http().gethttppwd_tf().getText()) ;
	    }
	    else {
		theGui.gettab_http().gethttppwd_tf().setEnabled(false) ;
		ldc.unsetOptHTTPPassword() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getproxyuser_cb()) {
	    if(theGui.gettab_http().getproxyuser_cb().isSelected()) {
		theGui.gettab_http().getproxyuser_tf().setEnabled(true) ;
		ldc.setOptProxyUser(theGui.gettab_http().getproxyuser_tf().getText()) ;
	    }
	    else {
		theGui.gettab_http().getproxyuser_tf().setEnabled(false) ;
		ldc.unsetOptProxyUser() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getproxypwd_cb()) {
	    if(theGui.gettab_http().getproxypwd_cb().isSelected()) {
		theGui.gettab_http().getproxypwd_tf().setEnabled(true) ;
		ldc.setOptProxyPassword(theGui.gettab_http().getproxypwd_tf().getText()) ;
	    }
	    else {
		theGui.gettab_http().getproxypwd_tf().setEnabled(false) ;
		ldc.unsetOptProxyPassword() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getcache_co()) {
	    ldc.unsetOptCache() ;
	    int i = theGui.gettab_http().getcache_co().getSelectedIndex() ;
	    if(i == 1)
		ldc.setOptCache("on") ;
	    else if(i == 2)
		ldc.setOptCache("off") ;
	    // sinon rien
	}
	else
	if(src == theGui.gettab_http().getsavehdrs_cb()) {
	    if(theGui.gettab_http().getsavehdrs_cb().isSelected()) {
		ldc.setOptSaveHeaders() ;
	    }
	    else {
		ldc.unsetOptSaveHeaders() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getignorelen_cb()) {
	    if(theGui.gettab_http().getignorelen_cb().isSelected()) {
		ldc.setOptIgnoreLength() ;
	    }
	    else {
		ldc.unsetOptIgnoreLength() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getagent_cb()) {
	    if(theGui.gettab_http().getagent_cb().isSelected()) {
		theGui.gettab_http().getagent_tf().setEnabled(true) ;
		ldc.setOptUserAgent(theGui.gettab_http().getagent_tf().getText()) ;
	    }
	    else {
		theGui.gettab_http().getagent_tf().setEnabled(false) ;
		ldc.unsetOptUserAgent() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getglob_co()) {
	    ldc.unsetOptGlob() ;
	    int i = theGui.gettab_http().getglob_co().getSelectedIndex() ;
	    if(i == 1)
		ldc.setOptGlob("on") ;
	    else if(i == 2)
		ldc.setOptGlob("off") ;
	    // sinon rien
	}
	else
	if(src == theGui.gettab_http().getretsymlnks_cb()) {
	    if(theGui.gettab_http().getretsymlnks_cb().isSelected()) {
		ldc.setOptRetrieveSymlinks() ;
	    }
	    else {
		ldc.unsetOptRetrieveSymlinks() ;
	    }
	}
	else
	if(src == theGui.gettab_http().getpassiveftp_cb()) {
	    if(theGui.gettab_http().getpassiveftp_cb().isSelected()) {
		ldc.setOptPassiveFTP() ;
	    }
	    else {
		ldc.unsetOptPassiveFTP() ;
	    }
	}
	else
	// ONGLET EXCLUSIONS
	if(src == theGui.gettab_exclusions().getaccdom_cb()) {
	    if(theGui.gettab_exclusions().getaccdom_cb().isSelected()) {
		theGui.gettab_exclusions().getaccdom_tf().setEnabled(true) ;
		ldc.setOptDomains(theGui.gettab_exclusions().getaccdom_tf().getText()) ;
	    }
	    else {
		theGui.gettab_exclusions().getaccdom_tf().setEnabled(false) ;
		ldc.unsetOptDomains() ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getaccept_cb()) {
	    if(theGui.gettab_exclusions().getaccept_cb().isSelected()) {
		theGui.gettab_exclusions().getaccept_tf().setEnabled(true) ;
		ldc.setOptAccept(theGui.gettab_exclusions().getaccept_tf().getText()) ;
	    }
	    else {
		theGui.gettab_exclusions().getaccept_tf().setEnabled(false) ;
		ldc.unsetOptAccept() ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getexcdirs_cb()) {
	    if(theGui.gettab_exclusions().getexcdirs_cb().isSelected()) {
		theGui.gettab_exclusions().getexcdirs_tf().setEnabled(true) ;
		ldc.setOptExcludeDirectory(theGui.gettab_exclusions().getexcdirs_tf().getText()) ;
	    }
	    else {
		theGui.gettab_exclusions().getexcdirs_tf().setEnabled(false) ;
		ldc.unsetOptExcludeDirectory() ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getincdirs_cb()) {
	    if(theGui.gettab_exclusions().getincdirs_cb().isSelected()) {
		theGui.gettab_exclusions().getincdirs_tf().setEnabled(true) ;
		ldc.setOptIncludeDirectory(theGui.gettab_exclusions().getincdirs_tf().getText()) ;
	    }
	    else {
		theGui.gettab_exclusions().getincdirs_tf().setEnabled(false) ;
		ldc.unsetOptIncludeDirectory() ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getrejdom_cb()) {
	    if(theGui.gettab_exclusions().getrejdom_cb().isSelected()) {
		theGui.gettab_exclusions().getrejdom_tf().setEnabled(true) ;
		ldc.setOptExcludeDomains(theGui.gettab_exclusions().getrejdom_tf().getText()) ;
	    }
	    else {
		theGui.gettab_exclusions().getrejdom_tf().setEnabled(false) ;
		ldc.unsetOptExcludeDomains() ;
	    }
	}
	else
	if(src == theGui.gettab_exclusions().getreject_cb()) {
	    if(theGui.gettab_exclusions().getreject_cb().isSelected()) {
		theGui.gettab_exclusions().getreject_tf().setEnabled(true) ;
		ldc.setOptReject(theGui.gettab_exclusions().getreject_tf().getText()) ;
	    }
	    else {
		theGui.gettab_exclusions().getreject_tf().setEnabled(false) ;
		ldc.unsetOptReject() ;
	    }
	}

	

	
    }

    public static void main(String[] args) {
	KawaGet kawaget = new KawaGet() ;
    }

    public void windowActivated(WindowEvent e) {
    }

    public void windowClosed(WindowEvent e) {
	theGui.dispose() ;
	System.exit(0) ;
    }

    public void windowClosing(WindowEvent e) {
    }

    public void windowDeactivated(WindowEvent e) {
    }

    public void windowDeiconified(WindowEvent e) {
    }

    public void windowIconified(WindowEvent e) {
    }

    public void windowOpened(WindowEvent e) {
    }
}

