01 /*
02 * Copyright 2002-2004 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26 package javax.swing.plaf.synth;
27
28 import java.awt.*;
29 import javax.swing.*;
30 import javax.swing.text.*;
31 import javax.swing.plaf.*;
32
33 /**
34 * Provides the Synth look and feel for a password field.
35 * The only difference from the standard text field is that
36 * the view of the text is simply a string of the echo
37 * character as specified in JPasswordField, rather than the
38 * real text contained in the field.
39 *
40 * @author Shannon Hickey
41 * @version 1.14 05/05/07
42 */
43 class SynthPasswordFieldUI extends SynthTextFieldUI {
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 SynthPasswordFieldUI();
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 * Creates a view (PasswordView) for an element.
68 *
69 * @param elem the element
70 * @return the view
71 */
72 public View create(Element elem) {
73 return new PasswordView(elem);
74 }
75
76 void paintBackground(SynthContext context, Graphics g, JComponent c) {
77 context.getPainter().paintPasswordFieldBackground(context, g,
78 0, 0, c.getWidth(), c.getHeight());
79 }
80
81 public void paintBorder(SynthContext context, Graphics g, int x,
82 int y, int w, int h) {
83 context.getPainter().paintPasswordFieldBorder(context, g, x, y,
84 w, h);
85 }
86
87 protected void installKeyboardActions() {
88 super .installKeyboardActions();
89 ActionMap map = SwingUtilities.getUIActionMap(getComponent());
90 if (map != null
91 && map.get(DefaultEditorKit.selectWordAction) != null) {
92 Action a = map.get(DefaultEditorKit.selectLineAction);
93 if (a != null) {
94 map.put(DefaultEditorKit.selectWordAction, a);
95 }
96 }
97 }
98 }
|