001 /*
002 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.swing.plaf.basic;
026
027 import java.awt.*;
028 import javax.swing.*;
029 import javax.swing.text.*;
030 import javax.swing.event.*;
031 import javax.swing.plaf.*;
032
033 /**
034 * Provides the Windows look and feel for a password field.
035 * The only difference from the standard text field is that
036 * the view of the text is simply a string of the echo
037 * character as specified in JPasswordField, rather than the
038 * real text contained in the field.
039 *
040 * @author Timothy Prinzing
041 * @version 1.39 05/05/07
042 */
043 public class BasicPasswordFieldUI extends BasicTextFieldUI {
044
045 /**
046 * Creates a UI for a JPasswordField.
047 *
048 * @param c the JPasswordField
049 * @return the UI
050 */
051 public static ComponentUI createUI(JComponent c) {
052 return new BasicPasswordFieldUI();
053 }
054
055 /**
056 * Fetches the name used as a key to look up properties through the
057 * UIManager. This is used as a prefix to all the standard
058 * text properties.
059 *
060 * @return the name ("PasswordField")
061 */
062 protected String getPropertyPrefix() {
063 return "PasswordField";
064 }
065
066 /**
067 * Installs the necessary properties on the JPasswordField.
068 * @since 1.6
069 */
070 protected void installDefaults() {
071 super .installDefaults();
072 String prefix = getPropertyPrefix();
073 Character echoChar = (Character) UIManager.getDefaults().get(
074 prefix + ".echoChar");
075 if (echoChar != null) {
076 LookAndFeel.installProperty(getComponent(), "echoChar",
077 echoChar);
078 }
079 }
080
081 /**
082 * Creates a view (PasswordView) for an element.
083 *
084 * @param elem the element
085 * @return the view
086 */
087 public View create(Element elem) {
088 return new PasswordView(elem);
089 }
090
091 /**
092 * Create the action map for Password Field. This map provides
093 * same actions for double mouse click and
094 * and for triple mouse click (see bug 4231444).
095 */
096
097 ActionMap createActionMap() {
098 ActionMap map = super .createActionMap();
099 if (map.get(DefaultEditorKit.selectWordAction) != null) {
100 Action a = map.get(DefaultEditorKit.selectLineAction);
101 if (a != null) {
102 map.remove(DefaultEditorKit.selectWordAction);
103 map.put(DefaultEditorKit.selectWordAction, a);
104 }
105 }
106 return map;
107 }
108
109 }
|