2015-05-05 Yvan Roux <yvan.roux@linaro.org>
[official-gcc.git] / libjava / classpath / javax / swing / JPasswordField.java
blobe73993f626a76fc9129926bbdf7553e150ea6c02
1 /* JPasswordField.java --
2 Copyright (C) 2002, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
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.
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. */
39 package javax.swing;
41 import java.io.IOException;
42 import java.io.ObjectOutputStream;
44 import javax.accessibility.AccessibleContext;
45 import javax.accessibility.AccessibleRole;
46 import javax.swing.text.BadLocationException;
47 import javax.swing.text.Document;
49 /**
50 * class JPasswordField
52 * @author Andrew Selkirk
53 * @author Lillian Angel
54 * @version 1.0
56 public class JPasswordField extends JTextField
58 /**
59 * AccessibleJPasswordField
61 protected class AccessibleJPasswordField extends AccessibleJTextField
63 private static final long serialVersionUID = -8477039424200681086L;
65 /**
66 * Constructor AccessibleJPasswordField
68 protected AccessibleJPasswordField()
70 // Nothing to do here.
73 /**
74 * getAccessibleRole
76 * @return AccessibleRole
78 public AccessibleRole getAccessibleRole()
80 return AccessibleRole.PASSWORD_TEXT;
84 /**
85 * echoChar. Default is 0.
87 private char echoChar = 0;
89 /**
90 * Creates a <code>JPasswordField</code> object.
92 public JPasswordField()
94 this(null, null, 0);
97 /**
98 * Creates a <code>JPasswordField</code> object.
100 * @param text the initial text
102 public JPasswordField(String text)
104 this(null, text, 0);
108 * Creates a <code>JPasswordField</code> object.
110 * @param columns the number of columns
112 public JPasswordField(int columns)
114 this(null, null, columns);
118 * Creates a <code>JPasswordField</code> object.
120 * @param text the initial text
121 * @param columns the number of columns
123 public JPasswordField(String text, int columns)
125 this(null, text, columns);
129 * Creates a <code>JPasswordField</code> object.
131 * @param document the document to use
132 * @param text the initial text
133 * @param columns the number of columns
135 public JPasswordField(Document document, String text, int columns)
137 super(document, text, columns);
141 * writeObject
143 * @param stream the stream to write to
145 * @exception IOException if an error occurs
147 private void writeObject(ObjectOutputStream stream) throws IOException
149 // TODO: Implement me.
153 * Returns the <code>UIClassID</code>
155 * @return the string "PasswordFieldUI"
157 public String getUIClassID()
159 return "PasswordFieldUI";
163 * getEchoChar
165 * @return the echo char
167 public char getEchoChar()
169 return echoChar;
173 * setEchoChar
175 * @param echo the echo char
177 public void setEchoChar(char echo)
179 this.echoChar = echo;
183 * Returns true if this JPasswordField has a character set for echoing.
184 * A character is considered to be set if the echo character is not 0.
186 * @return <code>true</code> if the echo char is set,
187 * <code>false</code> otherwise.
189 public boolean echoCharIsSet()
191 return echoChar != 0;
195 * Copies the selected text into the clipboard. This operation is not
196 * allowed in a password input field.
198 public void copy()
200 UIManager.getLookAndFeel().provideErrorFeedback(this);
204 * Cuts the selected text and puts it into the clipboard. This operation
205 * is not allowed in a password input field.
207 public void cut()
209 UIManager.getLookAndFeel().provideErrorFeedback(this);
213 * Returns the text contained in this TextComponent. If the
214 * underlying document is null, will give a NullPointerException.
216 * @return String
218 * @deprecated
220 public String getText()
224 return getDocument().getText(0, getDocument().getLength());
226 catch (BadLocationException ble)
228 // This should never happen.
229 throw new AssertionError(ble);
234 * Fetches a portion of the text represented by the component.
235 * Returns an empty string if length is 0. If the
236 * underlying document is null, will give a NullPointerException.
238 * @param offset TODO
239 * @param length TODO
241 * @return String
243 * @exception BadLocationException TODO
245 * @deprecated
247 public String getText(int offset, int length) throws BadLocationException
249 return getDocument().getText(offset, length);
253 * Returns the text contained in this TextComponent. If the underlying
254 * document is null, will give a NullPointerException.
255 * For stronger security, it is recommended that the returned character
256 * array be cleared after use by setting each character to zero.
258 * @return char[]
260 public char[] getPassword()
262 return getText().toCharArray();
266 * Returns a string representation of this JPasswordField. This method is
267 * intended to be used only for debugging purposes,
268 * and the content and format of the returned string may vary between
269 * implementations. The returned string may be empty but may not be null.
271 * @return String
273 protected String paramString()
277 return getText();
279 catch (NullPointerException npe)
281 return "";
286 * getAccessibleContext
288 * @return the <code>AccessibleContext</code> object
290 public AccessibleContext getAccessibleContext()
292 if (accessibleContext == null)
293 accessibleContext = new AccessibleJPasswordField();
295 return accessibleContext;