001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Evgeniya G. Maenkova
019: * @version $Revision$
020: */package javax.swing;
021:
022: import javax.accessibility.AccessibleContext;
023: import javax.accessibility.AccessibleRole;
024: import javax.swing.text.Document;
025:
026: import org.apache.harmony.awt.ComponentInternals;
027: import org.apache.harmony.x.swing.StringConstants;
028:
029: public class JPasswordField extends JTextField {
030: protected class AccessibleJPasswordField extends
031: AccessibleJTextField {
032: public AccessibleRole getAccessibleRole() {
033: return AccessibleRole.PASSWORD_TEXT;
034: }
035: }
036:
037: final class PasswordTextKit extends TextFieldKitImpl {
038: public boolean echoCharIsSet() {
039: return JPasswordField.this .echoCharIsSet();
040: }
041:
042: public char getEchoChar() {
043: return JPasswordField.this .getEchoChar();
044: }
045: }
046:
047: private static final String uiClassID = "PasswordFieldUI";
048: private static final char zeroEcho = '\0';
049: private char echoChar = '*';
050:
051: public JPasswordField() {
052: this (null, null, 0);
053: }
054:
055: public JPasswordField(final String text, final int columns) {
056: this (null, text, columns);
057: }
058:
059: public JPasswordField(final String text) {
060: this (null, text, 0);
061: }
062:
063: public JPasswordField(final int columns) {
064: this (null, null, columns);
065: }
066:
067: public JPasswordField(final Document document, final String text,
068: final int columns) {
069: super (document, text, columns);
070: installTextKit();
071: }
072:
073: void installTextKit() {
074: ComponentInternals.getComponentInternals().setTextFieldKit(
075: this , new PasswordTextKit());
076: }
077:
078: public void copy() {
079: UIManager.getLookAndFeel().provideErrorFeedback(this );
080: }
081:
082: public void cut() {
083: UIManager.getLookAndFeel().provideErrorFeedback(this );
084: }
085:
086: public boolean echoCharIsSet() {
087: return echoChar != zeroEcho;
088: }
089:
090: public AccessibleContext getAccessibleContext() {
091: if (accessibleContext == null) {
092: accessibleContext = new AccessibleJPasswordField();
093: }
094: return accessibleContext;
095: }
096:
097: public char getEchoChar() {
098: return echoChar;
099: }
100:
101: public String getUIClassID() {
102: return uiClassID;
103: }
104:
105: public char[] getPassword() {
106: return getText().toCharArray();
107: }
108:
109: public void setEchoChar(final char echoChar) {
110: char oldValue = this.echoChar;
111: this.echoChar = echoChar;
112: firePropertyChange(
113: StringConstants.PASSWORD_FIELD_ECHO_CHAR_PROPERTY,
114: oldValue, echoChar);
115: }
116: }
|