1. /*
  2. * @(#)SynthPasswordFieldUI.java 1.7 04/03/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.plaf.synth;
  8. import java.awt.*;
  9. import javax.swing.*;
  10. import javax.swing.text.*;
  11. import javax.swing.plaf.*;
  12. /**
  13. * Provides the Synth look and feel for a password field.
  14. * The only difference from the standard text field is that
  15. * the view of the text is simply a string of the echo
  16. * character as specified in JPasswordField, rather than the
  17. * real text contained in the field.
  18. *
  19. * @author Shannon Hickey
  20. * @version 1.7 03/19/04
  21. */
  22. class SynthPasswordFieldUI extends SynthTextFieldUI {
  23. /**
  24. * Creates a UI for a JPasswordField.
  25. *
  26. * @param c the JPasswordField
  27. * @return the UI
  28. */
  29. public static ComponentUI createUI(JComponent c) {
  30. return new SynthPasswordFieldUI();
  31. }
  32. /**
  33. * Fetches the name used as a key to look up properties through the
  34. * UIManager. This is used as a prefix to all the standard
  35. * text properties.
  36. *
  37. * @return the name ("PasswordField")
  38. */
  39. protected String getPropertyPrefix() {
  40. return "PasswordField";
  41. }
  42. /**
  43. * Creates a view (PasswordView) for an element.
  44. *
  45. * @param elem the element
  46. * @return the view
  47. */
  48. public View create(Element elem) {
  49. return new PasswordView(elem);
  50. }
  51. void paintBackground(SynthContext context, Graphics g, JComponent c) {
  52. context.getPainter().paintPasswordFieldBackground(context, g, 0, 0,
  53. c.getWidth(), c.getHeight());
  54. }
  55. public void paintBorder(SynthContext context, Graphics g, int x,
  56. int y, int w, int h) {
  57. context.getPainter().paintPasswordFieldBorder(context, g, x, y, w, h);
  58. }
  59. protected void installKeyboardActions() {
  60. super.installKeyboardActions();
  61. ActionMap map = SwingUtilities.getUIActionMap(getComponent());
  62. if (map != null && map.get(DefaultEditorKit.selectWordAction) != null) {
  63. Action a = map.get(DefaultEditorKit.selectLineAction);
  64. if (a != null) {
  65. map.put(DefaultEditorKit.selectWordAction, a);
  66. }
  67. }
  68. }
  69. }