Showing the changes to java/pkg/javax/swing/plaf/basic/BasicPasswordFieldUI.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,108 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. | ||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| 4 | * | ||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||
| 7 | * published by the Free Software Foundation. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | package javax.swing.plaf.basic; | ||
| 26 | |||
| 27 | import java.awt.*; | ||
| 28 | import javax.swing.*; | ||
| 29 | import javax.swing.text.*; | ||
| 30 | import javax.swing.event.*; | ||
| 31 | import javax.swing.plaf.*; | ||
| 32 | |||
| 33 | |||
| 34 | /** | ||
| 35 | * Provides the Windows look and feel for a password field. | ||
| 36 | * The only difference from the standard text field is that | ||
| 37 | * the view of the text is simply a string of the echo | ||
| 38 | * character as specified in JPasswordField, rather than the | ||
| 39 | * real text contained in the field. | ||
| 40 | * | ||
| 41 | * @author Timothy Prinzing | ||
| 42 | */ | ||
| 43 | public class BasicPasswordFieldUI extends BasicTextFieldUI { | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Creates a UI for a JPasswordField. | ||
| 47 | * | ||
| 48 | * @param c the JPasswordField | ||
| 49 | * @return the UI | ||
| 50 | */ | ||
| 51 | public static ComponentUI createUI(JComponent c) { | ||
| 52 | return new BasicPasswordFieldUI(); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Fetches the name used as a key to look up properties through the | ||
| 57 | * UIManager. This is used as a prefix to all the standard | ||
| 58 | * text properties. | ||
| 59 | * | ||
| 60 | * @return the name ("PasswordField") | ||
| 61 | */ | ||
| 62 | protected String getPropertyPrefix() { | ||
| 63 | return "PasswordField"; | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | /** | ||
| 68 | * Installs the necessary properties on the JPasswordField. | ||
| 69 | * @since 1.6 | ||
| 70 | */ | ||
| 71 | protected void installDefaults() { | ||
| 72 | super.installDefaults(); | ||
| 73 | String prefix = getPropertyPrefix(); | ||
| 74 | Character echoChar = (Character)UIManager.getDefaults().get(prefix + ".echoChar"); | ||
| 75 | if(echoChar != null) { | ||
| 76 | LookAndFeel.installProperty(getComponent(), "echoChar", echoChar); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | /** | ||
| 81 | * Creates a view (PasswordView) for an element. | ||
| 82 | * | ||
| 83 | * @param elem the element | ||
| 84 | * @return the view | ||
| 85 | */ | ||
| 86 | public View create(Element elem) { | ||
| 87 | return new PasswordView(elem); | ||
| 88 | } | ||
| 89 | |||
| 90 | /** | ||
| 91 | * Create the action map for Password Field. This map provides | ||
| 92 | * same actions for double mouse click and | ||
| 93 | * and for triple mouse click (see bug 4231444). | ||
| 94 | */ | ||
| 95 | |||
| 96 | ActionMap createActionMap() { | ||
| 97 | ActionMap map = super.createActionMap(); | ||
| 98 | if (map.get(DefaultEditorKit.selectWordAction) != null) { | ||
| 99 | Action a = map.get(DefaultEditorKit.selectLineAction); | ||
| 100 | if (a != null) { | ||
| 101 | map.remove(DefaultEditorKit.selectWordAction); | ||
| 102 | map.put(DefaultEditorKit.selectWordAction, a); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | return map; | ||
| 106 | } | ||
| 107 | |||
| 108 | } | ||