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