blob: 52c7a4d74355be32022190d30320f1561bea5ab1 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002-2004 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * 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
26package javax.swing.plaf.synth;
27
28import java.awt.*;
29import javax.swing.*;
30import javax.swing.text.*;
31import 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 */
42class SynthPasswordFieldUI extends SynthTextFieldUI {
43
44 /**
45 * Creates a UI for a JPasswordField.
46 *
47 * @param c the JPasswordField
48 * @return the UI
49 */
50 public static ComponentUI createUI(JComponent c) {
51 return new SynthPasswordFieldUI();
52 }
53
54 /**
55 * Fetches the name used as a key to look up properties through the
56 * UIManager. This is used as a prefix to all the standard
57 * text properties.
58 *
59 * @return the name ("PasswordField")
60 */
61 protected String getPropertyPrefix() {
62 return "PasswordField";
63 }
64
65 /**
66 * Creates a view (PasswordView) for an element.
67 *
68 * @param elem the element
69 * @return the view
70 */
71 public View create(Element elem) {
72 return new PasswordView(elem);
73 }
74
75 void paintBackground(SynthContext context, Graphics g, JComponent c) {
76 context.getPainter().paintPasswordFieldBackground(context, g, 0, 0,
77 c.getWidth(), c.getHeight());
78 }
79
80 public void paintBorder(SynthContext context, Graphics g, int x,
81 int y, int w, int h) {
82 context.getPainter().paintPasswordFieldBorder(context, g, x, y, w, h);
83 }
84
85 protected void installKeyboardActions() {
86 super.installKeyboardActions();
87 ActionMap map = SwingUtilities.getUIActionMap(getComponent());
88 if (map != null && map.get(DefaultEditorKit.selectWordAction) != null) {
89 Action a = map.get(DefaultEditorKit.selectLineAction);
90 if (a != null) {
91 map.put(DefaultEditorKit.selectWordAction, a);
92 }
93 }
94 }
95}