1. /*
  2. * @(#)MetalTextFieldUI.java 1.9 00/02/02
  3. *
  4. * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing.plaf.metal;
  11. import java.awt.*;
  12. import java.beans.*;
  13. import javax.swing.*;
  14. import javax.swing.text.*;
  15. import javax.swing.plaf.*;
  16. import javax.swing.plaf.basic.*;
  17. /**
  18. * Basis of a look and feel for a JTextField.
  19. * <p>
  20. * <strong>Warning:</strong>
  21. * Serialized objects of this class will not be compatible with
  22. * future Swing releases. The current serialization support is appropriate
  23. * for short term storage or RMI between applications running the same
  24. * version of Swing. A future release of Swing will provide support for
  25. * long term persistence.
  26. *
  27. * @author Steve Wilson
  28. * @version 1.9 02/02/00
  29. */
  30. public class MetalTextFieldUI extends BasicTextFieldUI {
  31. public static ComponentUI createUI(JComponent c) {
  32. return new MetalTextFieldUI();
  33. }
  34. public void installUI(JComponent c) {
  35. super.installUI(c);
  36. editableChanged(c, ((JTextComponent)c).isEditable());
  37. }
  38. public void propertyChange(PropertyChangeEvent e) {
  39. if (e.getPropertyName().equals("editable")) {
  40. JComponent source = (JComponent)e.getSource();
  41. Color background = source.getBackground();
  42. boolean editable = ((Boolean)e.getNewValue()).booleanValue();
  43. editableChanged( source, editable);
  44. }
  45. super.propertyChange(e);
  46. }
  47. private void editableChanged(JComponent c, boolean editable) {
  48. Color background = c.getBackground();
  49. if (editable == false) {
  50. if (background instanceof UIResource) {
  51. c.setBackground(UIManager.getColor("control"));
  52. }
  53. } else {
  54. if (background instanceof UIResource) {
  55. c.setBackground(UIManager.getColor("TextField.background"));
  56. }
  57. }
  58. }
  59. }