# HG changeset patch # User Carl Byington # Date 1406917587 25200 # Node ID 72de889ecfe78c7a033d0c7a76bb26fa02ab0f40 # Parent 205ee28733302ba6c7d1958361f9e7611b3e7e4f update jsocks to 2011-03-19 diff -r 205ee2873330 -r 72de889ecfe7 src/net/sourceforge/jsocks/SocksDialog.java --- a/src/net/sourceforge/jsocks/SocksDialog.java Fri Aug 01 11:23:10 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,615 +0,0 @@ -package net.sourceforge.jsocks; -import java.awt.*; -import java.awt.event.*; - -/** - Socks configuration dialog.
- Class which provides GUI means of getting CProxy configuration - from the user. - */ -public class SocksDialog extends Dialog - implements WindowListener, - ItemListener, - ActionListener, - Runnable{ - -//GUI components - TextField host_text, - port_text, - user_text, - password_text, - direct_text; - Button add_button, - remove_button, - cancel_button, - ok_button, - dismiss_button; - List direct_list; - Checkbox socks4radio, - socks5radio, - none_check, - up_check, - gssapi_check; - - Dialog warning_dialog; - Label warning_label; - - String host,user,password; - int port; - Thread net_thread = null; - - //CheckboxGroups - CheckboxGroup socks_group = new CheckboxGroup(); - - CProxy proxy; - InetRange ir; - - final static int COMMAND_MODE = 0; - final static int OK_MODE = 1; - - int mode; - - /**Wether to resolve addresses in separate thread. -

- Default value is true, however on some JVMs, namely one from - the Microsoft, it doesn't want to work properly, separate thread - can't close the dialog opened in GUI thread, and everuthing else - is then crashes. -

- When setting this variable to false, SocksDialog will block while - trying to look up proxy host, and if this takes considerable amount - of time it might be annoying to user. - - */ - public static boolean useThreads = true; - - -// Constructors -//////////////////////////////////// - /** - Creates SOCKS configuration dialog.
- Uses default initialisation:
- CProxy host: socks-proxy
- CProxy port: 1080
- Version: 5
- - */ - public SocksDialog(Frame parent){ - this(parent,null); - } - /** - Creates SOCKS configuration dialog and initialises it - to given proxy. - */ - public SocksDialog(Frame parent,CProxy init_proxy){ - super(parent,"Proxy Configuration",true); - warning_dialog = new Dialog(parent,"Warning",true); - - guiInit(); - setResizable(false); - addWindowListener(this); - Component[] comps = getComponents(); - for(int i=0;i - Returns initialised proxy object, or null if user cancels dialog - by either pressing Cancel or closing the dialog window. - */ - public CProxy getProxy(){ - mode = COMMAND_MODE; - pack(); - show(); - return proxy; - } - - /** - Initialises dialog to given proxy and displays SOCKS configuartion dialog. -

- Returns initialised proxy object, or null if user cancels dialog - by either pressing Cancel or closing the dialog window. - */ - public CProxy getProxy(CProxy p){ - if(p != null){ - doInit(p); - } - mode = COMMAND_MODE; - pack(); - show(); - return proxy; - } - -// WindowListener Interface -///////////////////////////////// - public void windowActivated(java.awt.event.WindowEvent e){ - } - public void windowDeactivated(java.awt.event.WindowEvent e){ - } - public void windowOpened(java.awt.event.WindowEvent e){ - } - public void windowClosing(java.awt.event.WindowEvent e){ - Window source = e.getWindow(); - if(source == this){ - onCancel(); - }else if(source == warning_dialog){ - onDismiss(); - } - } - public void windowClosed(java.awt.event.WindowEvent e){ - } - public void windowIconified(java.awt.event.WindowEvent e){ - } - public void windowDeiconified(java.awt.event.WindowEvent e){ - } - -//ActionListener interface -/////////////////////////// - public void actionPerformed(ActionEvent ae){ - - Object source = ae.getSource(); - - if(source == cancel_button ) - onCancel(); - else if(source == add_button || source == direct_text) - onAdd(); - else if(source == remove_button) - onRemove(); - else if(source == dismiss_button) - onDismiss(); - else if(source == ok_button || source instanceof TextField) - onOK(); - } -//ItemListener interface -//////////////////////// - public void itemStateChanged(ItemEvent ie){ - Object source = ie.getSource(); - //System.out.println("ItemEvent:"+source); - if(source == socks5radio || source == socks4radio) - onSocksChange(); - else if(source == up_check) - onUPChange(); - - } -//Runnable interface -//////////////////// - /** - Resolves proxy address in other thread, to avoid - annoying blocking in GUI thread. - */ - public void run(){ - - if(!initProxy()){ - //Check if we have been aborted - if(mode != OK_MODE) return; - if(net_thread != Thread.currentThread()) return; - - mode = COMMAND_MODE; - warning_label.setText("Look up failed."); - warning_label.invalidate(); - return; - } - - //System.out.println("Done!"); - while(!warning_dialog.isShowing()) - ; /* do nothing*/; - - warning_dialog.dispose(); - //dispose(); //End Dialog - } - -//Private Methods -/////////////////// - private void onOK(){ - host = host_text.getText().trim(); - user = user_text.getText(); - password = password_text.getText(); - - if(host.length() == 0){ - warn("Proxy host is not set!"); - return; - } - if(socks_group.getSelectedCheckbox() == socks4radio){ - if(user.length() == 0){ - warn("User name is not set"); - return; - } - - }else{ - if(up_check.getState()){ - if(user.length() == 0){ - warn("User name is not set."); - return; - } - if(password.length()==0){ - warn("Password is not set."); - return; - } - }else if(!none_check.getState()){ - warn("Please select at least one Authentication Method."); - return; - } - } - - try{ - port = Integer.parseInt(port_text.getText()); - }catch(NumberFormatException nfe){ - warn("Proxy port is invalid!"); - return; - } - - mode = OK_MODE; - - if(useThreads){ - net_thread = new Thread(this); - net_thread.start(); - - info("Looking up host: "+host); - //System.out.println("Info returned."); - }else if(!initProxy()){ - warn("Proxy host is invalid."); - mode = COMMAND_MODE; - } - - if(mode == OK_MODE) dispose(); - } - - private void onCancel(){ - //System.out.println("Cancel"); - proxy = null; - dispose(); - } - - private void onAdd(){ - String s = direct_text.getText(); - s.trim(); - if(s.length() == 0 ) return; - //Check for Duplicate - String[] direct_hosts = direct_list.getItems(); - for(int i=0;i