/*
* ProxyDialog.java
*
* Created on 3. Mai 2005, 13:33
*/
package gui;
import lib.*;
import tttool.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import tttool.Setup;
/**
*
*/
public class ProxyDialog extends JDialog {
private Language language;
private Setup setup;
private String loginUser;
private String loginPassword;
private JTextField jTextFieldProxyUrl;
private JTextField jTextFieldProxyPort;
private JTextField jTextFieldUser;
private JPasswordField jPasswordFieldPass;
private JLabel jLabelProxyUrl;
private JLabel jLabelProxyPort;
private JLabel jLabelUser;
private JLabel jLabelPass;
private JLabel jLabelProxyAuth;
private JCheckBox jCheckBoxProxyAuth;
private JCheckBox jCheckBoxProxyUse;
private JButton jButtonAbort;
private JButton jButtonOkay;
boolean useProxyAuth = false;
boolean useProxyUse = false;
/** Creates a new instance of ProxyDialog */
public ProxyDialog(Setup setup, Language language, Frame owner, boolean modal) {
super(owner, null, modal);
this.setup = setup;
this.language = language;
initComponets();
}
private void initComponets() {
setResizable(false);
setLayout();
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new java.awt.GridLayout(6, 2));
initVariables();
addActionListeners();
setTitles();
addComponents();
}
private void setDialogToCenter() {
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Dimension dialogSize = getSize();
setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
}
private void initVariables() {
jTextFieldProxyUrl = new JTextField();
jTextFieldProxyPort = new JTextField();
jTextFieldUser = new JTextField();
jPasswordFieldPass = new JPasswordField ();
jLabelProxyPort = new JLabel();
jLabelProxyUrl = new JLabel();
jLabelUser = new JLabel();
jLabelPass = new JLabel();
jLabelProxyAuth = new JLabel();
jCheckBoxProxyAuth = new JCheckBox();
jCheckBoxProxyUse = new JCheckBox();
jButtonAbort = new JButton();
jButtonOkay = new JButton();
}
private void setTitles() {
setTitle(language.get("gui_proxydialog_title"));
jLabelProxyUrl.setText(language.get("gui_proxydialog_label_proxy_url"));
jLabelProxyPort.setText(language.get("gui_proxydialog_label_proxy_port"));
jLabelUser.setText(language.get("gui_proxydialog_label_proxy_user"));
jLabelPass.setText(language.get("gui_proxydialog_label_proxy_pass"));
jButtonAbort.setText(language.get("gui_proxydialog_button_abort"));
jButtonOkay.setText(language.get("gui_proxydialog_button_okay"));
jCheckBoxProxyUse.setText(language.get("gui_proxydialog_checkbox_proxy_use"));
jCheckBoxProxyAuth.setText(language.get("gui_proxydialog_checkbox_proxy_auth"));
}
private void addComponents() {
getContentPane().add(jLabelProxyUrl);
getContentPane().add(jTextFieldProxyUrl);
getContentPane().add(jLabelProxyPort);
getContentPane().add(jTextFieldProxyPort);
getContentPane().add(jLabelUser);
getContentPane().add(jTextFieldUser);
getContentPane().add(jLabelPass);
getContentPane().add(jPasswordFieldPass);
getContentPane().add(jCheckBoxProxyUse);
getContentPane().add(jCheckBoxProxyAuth);
// getContentPane().add(jLabelProxyAuth);
getContentPane().add(jButtonAbort);
getContentPane().add(jButtonOkay);
pack();
}
private void addActionListeners() {
jButtonAbort.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent evt) {
toogleOff();
}
});
jButtonOkay.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent evt) {
saveProperties();
toogleOff();
}
});
jCheckBoxProxyUse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jCheckBoxProxyUseAction();
}
});
jCheckBoxProxyAuth.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jCheckBoxProxyAuthAction();
}
});
}
private void jCheckBoxProxyUseAction() {
if(useProxyUse) {
useProxyUse = false;
} else {
useProxyUse = true;
}
toggleProxyUse();
}
private void jCheckBoxProxyAuthAction() {
if(useProxyAuth) {
useProxyAuth = false;
} else {
useProxyAuth = true;
}
toggleProxyAuth();
}
private void toogleOff() {
setVisible(false);
}
public void showTheDialog() {
refreshProperties();
setDialogToCenter();
setVisible(true);
}
private void saveProperties() {
setup.setMainProperty("proxy", jTextFieldProxyUrl.getText());
setup.setMainProperty("proxy_port", jTextFieldProxyPort.getText());
setup.setMainProperty("proxy_user", jTextFieldUser.getText());
setup.setMainProperty("proxy_pass", jPasswordFieldPass.getText());
if(useProxyAuth) {
setup.setMainProperty("proxy_auth", "1");
} else {
setup.setMainProperty("proxy_auth", "0");
}
if(useProxyUse) {
setup.setMainProperty("proxy_use", "1");
} else {
setup.setMainProperty("proxy_use", "0");
}
setup.saveMainSetup();
}
private void refreshProperties() {
jTextFieldProxyUrl.setText(setup.getMainPropertyAsString("proxy"));
jTextFieldProxyPort.setText(setup.getMainPropertyAsString("proxy_port"));
jTextFieldUser.setText(setup.getMainPropertyAsString("proxy_user"));
jPasswordFieldPass.setText(setup.getMainPropertyAsString("proxy_pass"));
setProxyUseCheckBox();
setProxyAuthCheckBox();
}
private void toggleProxyUse() {
if(useProxyUse) {
enableProxyUseView();
} else {
disableProxyUseView();
}
}
private void toggleProxyAuth() {
if(useProxyAuth) {
enableProxyAuthView();
} else {
disableProxyAuthView();
}
}
private void enableProxyUseView() {
jLabelProxyPort.setEnabled(true);
jLabelProxyUrl.setEnabled(true);
jTextFieldProxyPort.setEnabled(true);
jTextFieldProxyUrl.setEnabled(true);
jCheckBoxProxyAuth.setEnabled(true);
}
private void disableProxyUseView() {
jLabelProxyPort.setEnabled(false);
jLabelProxyUrl.setEnabled(false);
jTextFieldProxyPort.setEnabled(false);
jTextFieldProxyUrl.setEnabled(false);
jCheckBoxProxyAuth.setEnabled(false);
}
private void enableProxyAuthView() {
jLabelUser.setEnabled(true);
jLabelPass.setEnabled(true);
jTextFieldUser.setEnabled(true);
jPasswordFieldPass.setEnabled(true);
}
private void disableProxyAuthView() {
jLabelUser.setEnabled(false);
jLabelPass.setEnabled(false);
jTextFieldUser.setEnabled(false);
jPasswordFieldPass.setEnabled(false);
}
private void setProxyUseCheckBox() {
if(setup.getMainPropertyAsInteger("proxy_use") == 1) {
// System.out.println("Proxyuse yes");
useProxyUse = true;
jCheckBoxProxyUse.setSelected(true);
enableProxyUseView();
jCheckBoxProxyAuth.setEnabled(true);
} else {
// System.out.println("Proxyuse no");
useProxyUse = false;
disableProxyUseView();
jCheckBoxProxyUse.setSelected(false);
jCheckBoxProxyAuth.setEnabled(false);
}
}
private void setProxyAuthCheckBox() {
if(setup.getMainPropertyAsInteger("proxy_auth") == 1) {
// System.out.println("Proxyauth yes");
useProxyAuth = true;
jCheckBoxProxyAuth.setSelected(true);
enableProxyAuthView();
} else {
// System.out.println("Proxyauth no");
useProxyAuth = false;
disableProxyAuthView();
jCheckBoxProxyAuth.setSelected(false);
}
}
public void setLayout() {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Error: LF");
}
}
}