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()));
}
});