client/ftpd/src/se/lu/thep/coreftpd/webserver/JTextFieldInt.java

Code
Comments
Other
Rev Date Author Line
741 10 Oct 06 olle 1 /*
1652 22 May 07 gregory 2  $Id$
741 10 Oct 06 olle 3
1916 31 Aug 07 jari 4  Copyright (C) 2006 Olle Mansson
1916 31 Aug 07 jari 5  Copyright (C) 2007 Gregory Vincic
741 10 Oct 06 olle 6
1652 22 May 07 gregory 7  This file is part of Proteios.
1652 22 May 07 gregory 8  Available at http://www.proteios.org/
741 10 Oct 06 olle 9
1652 22 May 07 gregory 10  Proteios is free software; you can redistribute it and/or modify it
1652 22 May 07 gregory 11  under the terms of the GNU General Public License as published by
1652 22 May 07 gregory 12  the Free Software Foundation; either version 2 of the License, or
1652 22 May 07 gregory 13  (at your option) any later version.
741 10 Oct 06 olle 14
1652 22 May 07 gregory 15  Proteios is distributed in the hope that it will be useful, but
1652 22 May 07 gregory 16  WITHOUT ANY WARRANTY; without even the implied warranty of
1652 22 May 07 gregory 17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1652 22 May 07 gregory 18  General Public License for more details.
741 10 Oct 06 olle 19
1652 22 May 07 gregory 20  You should have received a copy of the GNU General Public License
1652 22 May 07 gregory 21  along with this program; if not, write to the Free Software
1652 22 May 07 gregory 22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1652 22 May 07 gregory 23  02111-1307, USA.
1652 22 May 07 gregory 24  */
741 10 Oct 06 olle 25
741 10 Oct 06 olle 26 //  Xerver Free Web Server
741 10 Oct 06 olle 27 //  Copyright (C) 2002-2005 Omid Rouhani
741 10 Oct 06 olle 28 //
741 10 Oct 06 olle 29 //
741 10 Oct 06 olle 30 //  This program is free software; you can redistribute it and/or
741 10 Oct 06 olle 31 //  modify it under the terms of the GNU General Public License
741 10 Oct 06 olle 32 //  as published by the Free Software Foundation; either version 2
741 10 Oct 06 olle 33 //  of the License, or (at your option) any later version.
741 10 Oct 06 olle 34 //
741 10 Oct 06 olle 35 //  This program is distributed in the hope that it will be useful,
741 10 Oct 06 olle 36 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
741 10 Oct 06 olle 37 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
741 10 Oct 06 olle 38 //  GNU General Public License for more details.
741 10 Oct 06 olle 39 //
741 10 Oct 06 olle 40 //  You should have received a copy of the GNU General Public License
741 10 Oct 06 olle 41 //  along with this program; if not, write to the Free Software
741 10 Oct 06 olle 42 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
741 10 Oct 06 olle 43 //
741 10 Oct 06 olle 44 //
741 10 Oct 06 olle 45 //  #############################################################
741 10 Oct 06 olle 46 //  ##  YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT:          ##
741 10 Oct 06 olle 47 //  ##  HTTP://WWW.JAVASCRIPT.NU/XERVER/                       ##
741 10 Oct 06 olle 48 //  ##                                                         ##
741 10 Oct 06 olle 49 //  ##  IF YOUR SOFTWARE IS NOT RELEASED UNDER THE             ##
741 10 Oct 06 olle 50 //  ##  GNU GENERAL PUBLIC LICENSE (GPL),                      ##
741 10 Oct 06 olle 51 //  ##  PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!!   ##
741 10 Oct 06 olle 52 //  ##                                                         ##
741 10 Oct 06 olle 53 //  ##  FOR FULL LICENSE, PLEASE READ "XERVER LICENSE".        ##
741 10 Oct 06 olle 54 //  #############################################################
741 10 Oct 06 olle 55
1652 22 May 07 gregory 56 package se.lu.thep.coreftpd.webserver;
741 10 Oct 06 olle 57
741 10 Oct 06 olle 58 import java.awt.event.KeyEvent;
741 10 Oct 06 olle 59 import java.awt.event.KeyListener;
741 10 Oct 06 olle 60 import javax.swing.JTextField;
741 10 Oct 06 olle 61
741 10 Oct 06 olle 62 /**
1652 22 May 07 gregory 63  * 
1652 22 May 07 gregory 64  * <B>About this class:</B> <BR>
1652 22 May 07 gregory 65  * A <CODE>JTextField</CODE> that only supports integers >= 0 (the "-" might
1652 22 May 07 gregory 66  * not appear in the field). <BR>
1652 22 May 07 gregory 67  * The field can be empty. <BR>
741 10 Oct 06 olle 68  * Nothing but numbers 0-9 can be in this field.
1652 22 May 07 gregory 69  * 
741 10 Oct 06 olle 70  * @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a>
741 10 Oct 06 olle 71  * @version 1.0
741 10 Oct 06 olle 72  */
741 10 Oct 06 olle 73
1223 18 Feb 07 gregory 74 @SuppressWarnings("serial")
1652 22 May 07 gregory 75 public class JTextFieldInt extends JTextField implements KeyListener {
1652 22 May 07 gregory 76   public JTextFieldInt() {
741 10 Oct 06 olle 77     super();
741 10 Oct 06 olle 78     addKeyListener(this);
741 10 Oct 06 olle 79   }
741 10 Oct 06 olle 80
1652 22 May 07 gregory 81   public JTextFieldInt(int nrCols) {
741 10 Oct 06 olle 82     super(nrCols);
741 10 Oct 06 olle 83     addKeyListener(this);
741 10 Oct 06 olle 84   }
741 10 Oct 06 olle 85
1652 22 May 07 gregory 86   public JTextFieldInt(int value, int nrCols) {
741 10 Oct 06 olle 87     super(Integer.toString(value), nrCols);
741 10 Oct 06 olle 88     addKeyListener(this);
741 10 Oct 06 olle 89   }
741 10 Oct 06 olle 90
1652 22 May 07 gregory 91   public JTextFieldInt(String value, int nrCols) {
741 10 Oct 06 olle 92     super(value, nrCols);
741 10 Oct 06 olle 93     addKeyListener(this);
741 10 Oct 06 olle 94   }
741 10 Oct 06 olle 95
1652 22 May 07 gregory 96   // implementation of KeyListener
1652 22 May 07 gregory 97   public void keyPressed(KeyEvent e) {
1652 22 May 07 gregory 98   }
741 10 Oct 06 olle 99
1652 22 May 07 gregory 100   public void keyReleased(KeyEvent e) {
1652 22 May 07 gregory 101   }
741 10 Oct 06 olle 102
1652 22 May 07 gregory 103   public void keyTyped(KeyEvent e) {
1652 22 May 07 gregory 104     char c = e.getKeyChar();
741 10 Oct 06 olle 105
1652 22 May 07 gregory 106     if (Character.isDigit(c) || c == KeyEvent.VK_BACK_SPACE
1652 22 May 07 gregory 107         || c == KeyEvent.VK_DELETE || c == KeyEvent.VK_ENTER
1652 22 May 07 gregory 108         || c == KeyEvent.VK_TAB) {
1652 22 May 07 gregory 109       // everythig is fine
1652 22 May 07 gregory 110     } else {
1652 22 May 07 gregory 111       // consume the event => NumericField will not get an invalid char
1652 22 May 07 gregory 112       e.consume();
1652 22 May 07 gregory 113     }// end if
1652 22 May 07 gregory 114   }
741 10 Oct 06 olle 115
741 10 Oct 06 olle 116 }