[RFC][Icedtea-Web]: Ensure all ports entered are numeric values

Andrew Su asu at redhat.com
Mon Feb 28 08:18:57 PST 2011



----- Original Message -----
> From: "Deepak Bhole" <dbhole at redhat.com>
> To: "Andrew Su" <asu at redhat.com>
> Cc: "Deepak Bhole" <dbhole at redhat.com>, "IcedTea" <distro-pkg-dev at openjdk.java.net>
> Sent: Monday, February 28, 2011 11:12:54 AM
> Subject: Re: [RFC][Icedtea-Web]: Ensure all ports entered are numeric values
> * Andrew Su <asu at redhat.com> [2011-02-28 11:04]:
> >
> >
> > ----- Original Message -----
> > > From: "Deepak Bhole" <dbhole at redhat.com>
> > > To: "Deepak Bhole" <dbhole at redhat.com>
> > > Cc: "Andrew Su" <asu at redhat.com>, "IcedTea"
> > > <distro-pkg-dev at openjdk.java.net>
> > > Sent: Monday, February 28, 2011 10:19:29 AM
> > > Subject: Re: [RFC][Icedtea-Web]: Ensure all ports entered are
> > > numeric values
> > > * Deepak Bhole <dbhole at redhat.com> [2011-02-28 10:18]:
> > > > * Andrew Su <asu at redhat.com> [2011-02-27 23:28]:
> > > > > Hello,
> > > > >
> > > > >   This patch ensures that the port fields in itw-settings only
> > > > >   accept numeric values.
> > > > >
> > > > >   In this patch:
> > > > >     - New Class: NumberDocument.
> > > > >     - All port fields now use NumberDocument.
> > > > >
> > > > >   Questions? Comments? Concerns?
> > > > >
> > > >
> > > > Rather than defining a separate class, it might be better to use
> > > > JFormatterTextField to force the field to accept numbers only.
> > > >
> > >
> > > s/JFormatterTextField/JFormattedTextField
> >
> > Hi Deepak,
> >
> >   I didn't think JFormatterTextField fits what I'm trying to do
> >   here, since the value gets cleared when text field loses focus. I
> >   wanted it to make sure that no "bad" inputs are given the moment
> >   it is typed.
> >
> 
> What do you mean the value gets cleared when it loses focus?

I meant that if the value entered is invalid it gets cleared. Of course this behaviour can be changed, but iirc it only does the check after the focus to the JFormattedTextField.

Regards,
  Andrew

> 
> Deepak
> 
> > Cheers,
> >   Andrew
> >
> > >
> > > > Cheers,
> > > > Deepak
> > > >
> > > > > Cheers,
> > > > >   Andrew
> > > >
> > > > > diff -r 4860276e9bf2
> > > > > netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
> > > > > ---
> > > > > a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
> > > > > Sun Feb 27 21:48:17 2011 -0500
> > > > > +++
> > > > > b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
> > > > > Sun Feb 27 23:26:36 2011 -0500
> > > > > @@ -115,6 +115,7 @@
> > > > >          JLabel http = new JLabel(Translator.R("APSLabelHTTP")
> > > > >          +
> > > > >          ":");
> > > > >          final JTextField httpAddressField = new
> > > > >          JTextField(fields[0]);
> > > > >          final JTextField httpPortField = new
> > > > >          JTextField(fields[1]);
> > > > > + httpPortField.setDocument(new NumberDocument());
> > > > >          httpAddressField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 0));
> > > > >          httpPortField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 1));
> > > > >
> > > > > @@ -122,6 +123,7 @@
> > > > >          JLabel secure = new
> > > > >          JLabel(Translator.R("APSLabelSecure")
> > > > >          + ":");
> > > > >          final JTextField secureAddressField = new
> > > > >          JTextField(fields[2]);
> > > > >          final JTextField securePortField = new
> > > > >          JTextField(fields[3]);
> > > > > + securePortField.setDocument(new NumberDocument());
> > > > >          secureAddressField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 2));
> > > > >          securePortField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 3));
> > > > >
> > > > > @@ -129,6 +131,7 @@
> > > > >          JLabel ftp = new JLabel(Translator.R("APSLabelFTP") +
> > > > >          ":");
> > > > >          final JTextField ftpAddressField = new
> > > > >          JTextField(fields[4]);
> > > > >          final JTextField ftpPortField = new
> > > > >          JTextField(fields[5]);
> > > > > + ftpPortField.setDocument(new NumberDocument());
> > > > >          ftpAddressField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 4));
> > > > >          ftpPortField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 5));
> > > > >
> > > > > @@ -136,6 +139,7 @@
> > > > >          JLabel socks = new
> > > > >          JLabel(Translator.R("APSLabelSocks") +
> > > > >          ":");
> > > > >          final JTextField socksAddressField = new
> > > > >          JTextField(fields[6]);
> > > > >          final JTextField socksPortField = new
> > > > >          JTextField(fields[7]);
> > > > > + socksPortField.setDocument(new NumberDocument());
> > > > >          socksAddressField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 6));
> > > > >          socksPortField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(fields, 7));
> > > > >
> > > > > diff -r 4860276e9bf2
> > > > > netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
> > > > > ---
> > > > > a/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
> > > > > Sun Feb 27 21:48:17 2011 -0500
> > > > > +++
> > > > > b/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
> > > > > Sun Feb 27 23:26:36 2011 -0500
> > > > > @@ -114,6 +114,7 @@
> > > > >          addressField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(config, properties[1]));
> > > > >
> > > > >          final JTextField portField = new
> > > > >          JTextField(config.getProperty(properties[2]), 3);
> > > > > + portField.setDocument(new NumberDocument());
> > > > >          portField.getDocument().addDocumentListener(new
> > > > >          DocumentAdapter(config, properties[2]));
> > > > >
> > > > >          // Create the button which allows setting of other
> > > > >          types
> > > > >          of proxy.
> > > > > diff -r 4860276e9bf2
> > > > > netx/net/sourceforge/jnlp/controlpanel/NumberDocument.java
> > > > > --- /dev/null Thu Jan 01 00:00:00 1970 +0000
> > > > > +++
> > > > > b/netx/net/sourceforge/jnlp/controlpanel/NumberDocument.java
> > > > > Sun Feb 27 23:26:36 2011 -0500
> > > > > @@ -0,0 +1,53 @@
> > > > > +/* NumberDocument.java -- Allow only numeric entries on this
> > > > > document.
> > > > > +Copyright (C) 2011 Red Hat
> > > > > +
> > > > > +This program is free software; you can redistribute it and/or
> > > > > modify
> > > > > +it under the terms of the GNU General Public License as
> > > > > published
> > > > > by
> > > > > +the Free Software Foundation; either version 2 of the
> > > > > License, or
> > > > > +(at your option) any later version.
> > > > > +
> > > > > +This program is distributed in the hope that it will be
> > > > > useful,
> > > > > but
> > > > > +WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > > > > GNU
> > > > > +General Public License for more details.
> > > > > +
> > > > > +You should have received a copy of the GNU General Public
> > > > > License
> > > > > +along with this program; if not, write to the Free Software
> > > > > +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> > > > > 02111-1307 USA
> > > > > + */
> > > > > +
> > > > > +package net.sourceforge.jnlp.controlpanel;
> > > > > +
> > > > > +import javax.swing.text.AttributeSet;
> > > > > +import javax.swing.text.BadLocationException;
> > > > > +import javax.swing.text.PlainDocument;
> > > > > +
> > > > > +/**
> > > > > + * This class will ensure that strings entered into this
> > > > > document
> > > > > will be
> > > > > + * numbers only.
> > > > > + *
> > > > > + * @author Andrew Su (asu at redhat.com, andrew.su at utoronto.ca)
> > > > > + *
> > > > > + */
> > > > > +public class NumberDocument extends PlainDocument {
> > > > > +
> > > > > + /**
> > > > > + * Constructs an instance of NumberDocument.
> > > > > + */
> > > > > + public NumberDocument() {
> > > > > + super();
> > > > > + }
> > > > > +
> > > > > + @Override
> > > > > + public void insertString(int offs, String str, AttributeSet
> > > > > a)
> > > > > throws BadLocationException {
> > > > > + if (str != null) {
> > > > > + try {
> > > > > + Integer.valueOf(str);
> > > > > + super.insertString(offs, str, a);
> > > > > + } catch (Exception e) {
> > > > > + // Nothing to do
> > > > > + }
> > > > > + }
> > > > > + return;
> > > > > + }
> > > > > +}
> > > > > \ No newline at end of file
> > > >



More information about the distro-pkg-dev mailing list