1. /*
  2. * @(#)MetalComboBoxEditor.java 1.19 03/01/23
  3. *
  4. * Copyright 2003 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 javax.swing.*;
  9. import javax.swing.border.*;
  10. import java.io.Serializable;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.plaf.basic.BasicComboBoxEditor;
  14. /**
  15. * The default editor for Metal editable combo boxes
  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
  20. * appropriate for short term storage or RMI between applications running
  21. * the same version of Swing. As of 1.4, support for long term storage
  22. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  23. * has been added to the <code>java.beans</code> package.
  24. * Please see {@link java.beans.XMLEncoder}.
  25. *
  26. * @version 1.19 01/23/03
  27. * @author Steve Wilson
  28. */
  29. public class MetalComboBoxEditor extends BasicComboBoxEditor {
  30. public MetalComboBoxEditor() {
  31. super();
  32. //editor.removeFocusListener(this);
  33. editor = new JTextField("",9) {
  34. // workaround for 4530952
  35. public void setText(String s) {
  36. if (getText().equals(s)) {
  37. return;
  38. }
  39. super.setText(s);
  40. }
  41. };
  42. editor.setBorder( new EditorBorder() );
  43. //editor.addFocusListener(this);
  44. }
  45. protected static Insets editorBorderInsets = new Insets( 4, 2, 4, 0 );
  46. class EditorBorder extends AbstractBorder {
  47. public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  48. g.translate( x, y );
  49. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  50. g.drawLine( 0, 0, w-1, 0 );
  51. g.drawLine( 0, 0, 0, h-2 );
  52. g.drawLine( 0, h-2, w-1, h-2 );
  53. g.setColor( MetalLookAndFeel.getControlHighlight() );
  54. g.drawLine( 1, 1, w-1, 1 );
  55. g.drawLine( 1, 1, 1, h-1 );
  56. g.drawLine( 1, h-1, w-1, h-1 );
  57. g.setColor( MetalLookAndFeel.getControl() );
  58. g.drawLine( 1, h-2, 1, h-2 );
  59. g.translate( -x, -y );
  60. }
  61. public Insets getBorderInsets( Component c ) {
  62. return editorBorderInsets;
  63. }
  64. }
  65. /**
  66. * A subclass of BasicComboBoxEditor that implements UIResource.
  67. * BasicComboBoxEditor doesn't implement UIResource
  68. * directly so that applications can safely override the
  69. * cellRenderer property with BasicListCellRenderer subclasses.
  70. * <p>
  71. * <strong>Warning:</strong>
  72. * Serialized objects of this class will not be compatible with
  73. * future Swing releases. The current serialization support is
  74. * appropriate for short term storage or RMI between applications running
  75. * the same version of Swing. As of 1.4, support for long term storage
  76. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  77. * has been added to the <code>java.beans</code> package.
  78. * Please see {@link java.beans.XMLEncoder}.
  79. */
  80. public static class UIResource extends MetalComboBoxEditor
  81. implements javax.swing.plaf.UIResource {
  82. }
  83. }