| 1 | /* TextField.java -- A one line text entry field
|
|---|
| 2 | Copyright (C) 1999 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt;
|
|---|
| 40 |
|
|---|
| 41 | import java.awt.event.ActionEvent;
|
|---|
| 42 | import java.awt.event.ActionListener;
|
|---|
| 43 | import java.awt.peer.TextFieldPeer;
|
|---|
| 44 | import java.awt.peer.TextComponentPeer;
|
|---|
| 45 | import java.awt.peer.ComponentPeer;
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * This class implements a single line text entry field widget
|
|---|
| 49 | *
|
|---|
| 50 | * @author Aaron M. Renn ([email protected])
|
|---|
| 51 | */
|
|---|
| 52 | public class TextField extends TextComponent implements java.io.Serializable
|
|---|
| 53 | {
|
|---|
| 54 |
|
|---|
| 55 | /*
|
|---|
| 56 | * Static Variables
|
|---|
| 57 | */
|
|---|
| 58 |
|
|---|
| 59 | // Serialization constant
|
|---|
| 60 | private static final long serialVersionUID = -2966288784432217853L;
|
|---|
| 61 |
|
|---|
| 62 | /*************************************************************************/
|
|---|
| 63 |
|
|---|
| 64 | /*
|
|---|
| 65 | * Instance Variables
|
|---|
| 66 | */
|
|---|
| 67 |
|
|---|
| 68 | /**
|
|---|
| 69 | * @serial The number of columns in the text entry field.
|
|---|
| 70 | */
|
|---|
| 71 | private int columns;
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | * @serial The character that is echoed when doing protected input
|
|---|
| 75 | */
|
|---|
| 76 | private char echoChar;
|
|---|
| 77 |
|
|---|
| 78 | // List of registered ActionListener's for this object.
|
|---|
| 79 | private ActionListener action_listeners;
|
|---|
| 80 |
|
|---|
| 81 | /*************************************************************************/
|
|---|
| 82 |
|
|---|
| 83 | /*
|
|---|
| 84 | * Constructors
|
|---|
| 85 | */
|
|---|
| 86 |
|
|---|
| 87 | /*
|
|---|
| 88 | * Initializes a new instance of <code>TextField</code> that is empty
|
|---|
| 89 | * and has one column.
|
|---|
| 90 | */
|
|---|
| 91 | public
|
|---|
| 92 | TextField()
|
|---|
| 93 | {
|
|---|
| 94 | this("", 1);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /*************************************************************************/
|
|---|
| 98 |
|
|---|
| 99 | /**
|
|---|
| 100 | * Initializes a new instance of <code>TextField</code> containing
|
|---|
| 101 | * the specified text. The number of columns will be equal to the
|
|---|
| 102 | * length of the text string.
|
|---|
| 103 | *
|
|---|
| 104 | * @param text The text to display in the field.
|
|---|
| 105 | */
|
|---|
| 106 | public
|
|---|
| 107 | TextField(String text)
|
|---|
| 108 | {
|
|---|
| 109 | this(text, text.length());
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /*************************************************************************/
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * Initializes a new instance of <code>TextField</code> that is empty
|
|---|
| 116 | * and has the specified number of columns.
|
|---|
| 117 | *
|
|---|
| 118 | * @param columns The number of columns in the text field.
|
|---|
| 119 | */
|
|---|
| 120 | public
|
|---|
| 121 | TextField(int columns)
|
|---|
| 122 | {
|
|---|
| 123 | this("", columns);
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | /*************************************************************************/
|
|---|
| 127 |
|
|---|
| 128 | /**
|
|---|
| 129 | * Initializes a new instance of <code>TextField</code> with the
|
|---|
| 130 | * specified text and number of columns.
|
|---|
| 131 | *
|
|---|
| 132 | * @param text The text to display in the field.
|
|---|
| 133 | * @param columns The number of columns in the field.
|
|---|
| 134 | */
|
|---|
| 135 | public
|
|---|
| 136 | TextField(String text, int columns)
|
|---|
| 137 | {
|
|---|
| 138 | super(text);
|
|---|
| 139 | this.columns = columns;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | /*************************************************************************/
|
|---|
| 143 |
|
|---|
| 144 | /*
|
|---|
| 145 | * Instance Methods
|
|---|
| 146 | */
|
|---|
| 147 |
|
|---|
| 148 | /**
|
|---|
| 149 | * Returns the number of columns in the field.
|
|---|
| 150 | *
|
|---|
| 151 | * @return The number of columns in the field.
|
|---|
| 152 | */
|
|---|
| 153 | public int
|
|---|
| 154 | getColumns()
|
|---|
| 155 | {
|
|---|
| 156 | return(columns);
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | /*************************************************************************/
|
|---|
| 160 |
|
|---|
| 161 | /**
|
|---|
| 162 | * Sets the number of columns in this field to the specified value.
|
|---|
| 163 | *
|
|---|
| 164 | * @param columns The new number of columns in the field.
|
|---|
| 165 | *
|
|---|
| 166 | * @exception IllegalArgumentException If columns is less than zero.
|
|---|
| 167 | */
|
|---|
| 168 | public synchronized void
|
|---|
| 169 | setColumns(int columns)
|
|---|
| 170 | {
|
|---|
| 171 | if (columns < 0)
|
|---|
| 172 | throw new IllegalArgumentException("Value is less than zero: " +
|
|---|
| 173 | columns);
|
|---|
|
|---|