aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net
diff options
context:
space:
mode:
authorAndrew Su <[email protected]>2011-04-06 10:02:46 -0400
committerAndrew Su <[email protected]>2011-04-06 10:02:46 -0400
commit8052764963c42498f360806702086ba6a0a43c9b (patch)
tree08d8af0cef8d8f432aabea7b59e22b2ac620e303 /netx/net
parent7a7bd2ef05d809809f34ee2b11925966da922383 (diff)
Restrict port fields in itw-settings to accept only valid port numbers.
Diffstat (limited to 'netx/net')
-rw-r--r--netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java16
-rw-r--r--netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java33
-rw-r--r--netx/net/sourceforge/jnlp/resources/Messages.properties2
3 files changed, 46 insertions, 5 deletions
diff --git a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
index 6f41671..62b327f 100644
--- a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
+++ b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
@@ -114,30 +114,38 @@ public class AdvancedProxySettingsPane extends JPanel {
// This addresses the HTTP proxy settings.
JLabel http = new JLabel(Translator.R("APSLabelHTTP") + ":");
final JTextField httpAddressField = new JTextField(fields[0]);
- final JTextField httpPortField = new JTextField(fields[1]);
+ final JTextField httpPortField = new JTextField();
+ httpPortField.setDocument(NetworkSettingsPanel.getPortNumberDocument());
httpAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 0));
httpPortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 1));
+ httpPortField.setText(fields[1]);
// This addresses the HTTPS proxy settings.
JLabel secure = new JLabel(Translator.R("APSLabelSecure") + ":");
final JTextField secureAddressField = new JTextField(fields[2]);
- final JTextField securePortField = new JTextField(fields[3]);
+ final JTextField securePortField = new JTextField();
+ securePortField.setDocument(NetworkSettingsPanel.getPortNumberDocument());
secureAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 2));
securePortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 3));
+ securePortField.setText(fields[3]);
// This addresses the FTP proxy settings.
JLabel ftp = new JLabel(Translator.R("APSLabelFTP") + ":");
final JTextField ftpAddressField = new JTextField(fields[4]);
- final JTextField ftpPortField = new JTextField(fields[5]);
+ final JTextField ftpPortField = new JTextField();
+ ftpPortField.setDocument(NetworkSettingsPanel.getPortNumberDocument());
ftpAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 4));
ftpPortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 5));
+ ftpPortField.setText(fields[5]);
// This addresses the Socks proxy settings.
JLabel socks = new JLabel(Translator.R("APSLabelSocks") + ":");
final JTextField socksAddressField = new JTextField(fields[6]);
- final JTextField socksPortField = new JTextField(fields[7]);
+ final JTextField socksPortField = new JTextField();
+ socksPortField.setDocument(NetworkSettingsPanel.getPortNumberDocument());
socksAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 6));
socksPortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 7));
+ socksPortField.setText(fields[7]);
JCheckBox sameProxyForAll = new JCheckBox(Translator.R("APSSameProxyForAllProtocols"), Boolean.parseBoolean(fields[8]));
sameProxyForAll.addItemListener(new ItemListener() {
diff --git a/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java b/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
index 90dfe5d..a599c16 100644
--- a/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
+++ b/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
@@ -36,9 +36,13 @@ import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.PlainDocument;
import net.sourceforge.jnlp.config.DeploymentConfiguration;
import net.sourceforge.jnlp.runtime.Translator;
@@ -113,8 +117,10 @@ public class NetworkSettingsPanel extends JPanel implements ActionListener {
final JTextField addressField = new JTextField(config.getProperty(properties[1]), 10);
addressField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[1]));
- final JTextField portField = new JTextField(config.getProperty(properties[2]), 3);
+ final JTextField portField = new JTextField(5);
+ portField.setDocument(NetworkSettingsPanel.getPortNumberDocument());
portField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[2]));
+ portField.setText(config.getProperty(properties[2]));
// Create the button which allows setting of other types of proxy.
JButton advancedProxyButton = new JButton(Translator.R("NSAdvanced") + "...");
@@ -254,4 +260,29 @@ public class NetworkSettingsPanel extends JPanel implements ActionListener {
enablePanel(panel, false);
}
}
+
+ /**
+ * Creates a PlainDocument that only take numbers if it will create a valid port number.
+ * @return PlainDocument which will ensure numeric values only and is a valid port number.
+ */
+ public static PlainDocument getPortNumberDocument(){
+ return new PlainDocument(){
+ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+ if (str != null) {
+ try {
+ Integer.valueOf(str);
+ int val = Integer.valueOf(this.getText(0, this.getLength()) + str);
+ if (val < 1 || val > 65535) { // Invalid port number if true
+ throw new NumberFormatException("Invalid port number");
+ }
+ super.insertString(offs, str, a);
+ } catch (Exception e) {
+ JOptionPane.showMessageDialog(null, Translator.R("CPInvalidPort"), Translator.R("CPInvalidPortTitle")
+ , JOptionPane.WARNING_MESSAGE);
+ }
+ }
+ return;
+ }
+ };
+ }
}
diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties
index 29593d0..41c9310 100644
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties
+++ b/netx/net/sourceforge/jnlp/resources/Messages.properties
@@ -407,6 +407,8 @@ CVCPColName=Name
# Control Panel - Misc.
CPJRESupport=IcedTea-Web currently does not support the use of multiple JREs.
+CPInvalidPort=Invalid port number given.\n[Valid port numbers are 1-65535]
+CPInvalidPortTitle=Error on input.
# command line control panel
CLNoInfo=No information avaiable (is this a valid option?).