public void actionPerformed(ActionEvent e) {
_userPreferences.setProxyEnabled(proxyCheckBox.isSelected());
}
});
final DCPanel proxyPanel = new DCPanel().setTitledBorder("Proxy settings");
final JTextField proxyHostField = WidgetFactory.createTextField("Proxy host");
proxyHostField.setText(_userPreferences.getProxyHostname());
proxyHostField.getDocument().addDocumentListener(new DCDocumentListener() {
@Override
protected void onChange(DocumentEvent e) {
_userPreferences.setProxyHostname(proxyHostField.getText());
}
});
WidgetUtils.addToGridBag(new JLabel("Proxy host"), proxyPanel, 0, 0);
WidgetUtils.addToGridBag(proxyHostField, proxyPanel, 1, 0);
final JTextField proxyPortField = WidgetFactory.createTextField("Proxy port");
proxyPortField.setDocument(new NumberDocument());
proxyPortField.getDocument().addDocumentListener(new DCDocumentListener() {
@Override
protected void onChange(DocumentEvent event) {
int port;
try {
port = Integer.parseInt(proxyPortField.getText());
} catch (Exception e) {
port = 8080;
}
_userPreferences.setProxyPort(port);
}
});
proxyPortField.setText("" + _userPreferences.getProxyPort());
WidgetUtils.addToGridBag(new JLabel("Proxy port"), proxyPanel, 0, 1);
WidgetUtils.addToGridBag(proxyPortField, proxyPanel, 1, 1);
final JCheckBox proxyAuthCheckBox = new JCheckBox("Enable authentication?",
_userPreferences.isProxyAuthenticationEnabled());
proxyAuthCheckBox.setOpaque(false);
proxyAuthCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
_userPreferences.setProxyAuthenticationEnabled(proxyAuthCheckBox.isSelected());
}
});
final DCPanel proxyAuthPanel = new DCPanel().setTitledBorder("Proxy authentication");
final JTextField proxyUsernameField = WidgetFactory.createTextField("Username");
proxyUsernameField.setText(_userPreferences.getProxyUsername());
proxyUsernameField.getDocument().addDocumentListener(new DCDocumentListener() {
@Override
protected void onChange(DocumentEvent event) {
_userPreferences.setProxyUsername(proxyUsernameField.getText());
}
});
WidgetUtils.addToGridBag(new JLabel("Username"), proxyAuthPanel, 0, 0);
WidgetUtils.addToGridBag(proxyUsernameField, proxyAuthPanel, 1, 0);
final JPasswordField proxyPasswordField = new JPasswordField(_userPreferences.getProxyPassword());
proxyPasswordField.getDocument().addDocumentListener(new DCDocumentListener() {
@Override
protected void onChange(DocumentEvent event) {
_userPreferences.setProxyPassword(String.valueOf(proxyPasswordField.getPassword()));
}
});
WidgetUtils.addToGridBag(new JLabel("Password"), proxyAuthPanel, 0, 1);
WidgetUtils.addToGridBag(proxyPasswordField, proxyAuthPanel, 1, 1);
WidgetUtils.addToGridBag(proxyAuthCheckBox, proxyPanel, 0, 2, 2, 1);
WidgetUtils.addToGridBag(proxyAuthPanel, proxyPanel, 0, 3, 2, 1);
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
proxyHostField.setEnabled(proxyCheckBox.isSelected());
proxyPortField.setEnabled(proxyCheckBox.isSelected());
proxyAuthCheckBox.setEnabled(proxyCheckBox.isSelected());
proxyUsernameField.setEnabled(proxyAuthCheckBox.isSelected() && proxyCheckBox.isSelected());
proxyPasswordField.setEnabled(proxyAuthCheckBox.isSelected() && proxyCheckBox.isSelected());
}
};
proxyCheckBox.addActionListener(actionListener);
proxyAuthCheckBox.addActionListener(actionListener);
// use ActionListener to initialize components
actionListener.actionPerformed(null);
final DCPanel networkTabPanel = new DCPanel(WidgetUtils.BG_COLOR_BRIGHT, WidgetUtils.BG_COLOR_BRIGHTEST);
networkTabPanel.setLayout(new BorderLayout());
networkTabPanel.add(proxyCheckBox, BorderLayout.NORTH);
networkTabPanel.add(proxyPanel, BorderLayout.CENTER);
return networkTabPanel;
}