1. /*
  2. * @(#)MetalComboBoxEditor.java 1.23 03/12/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.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.23 12/19/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. // The preferred and minimum sizes are overriden and padded by
  42. // 4 to keep the size as it previously was. Refer to bugs
  43. // 4775789 and 4517214 for details.
  44. public Dimension getPreferredSize() {
  45. Dimension pref = super.getPreferredSize();
  46. pref.height += 4;
  47. return pref;
  48. }
  49. public Dimension getMinimumSize() {
  50. Dimension min = super.getMinimumSize();
  51. min.height += 4;
  52. return min;
  53. }
  54. };
  55. editor.setBorder( new EditorBorder() );
  56. //editor.addFocusListener(this);
  57. }
  58. protected static Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
  59. class EditorBorder extends AbstractBorder {
  60. public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
  61. g.translate( x, y );
  62. if (MetalLookAndFeel.usingOcean()) {
  63. g.setColor(MetalLookAndFeel.getControlDarkShadow());
  64. g.drawRect(0, 0, w, h - 1);
  65. g.setColor(MetalLookAndFeel.getControlShadow());
  66. g.drawRect(1, 1, w - 2, h - 3);
  67. }
  68. else {
  69. g.setColor( MetalLookAndFeel.getControlDarkShadow() );
  70. g.drawLine( 0, 0, w-1, 0 );
  71. g.drawLine( 0, 0, 0, h-2 );
  72. g.drawLine( 0, h-2, w-1, h-2 );
  73. g.setColor( MetalLookAndFeel.getControlHighlight() );
  74. g.drawLine( 1, 1, w-1, 1 );
  75. g.drawLine( 1, 1, 1, h-1 );
  76. g.drawLine( 1, h-1, w-1, h-1 );
  77. g.setColor( MetalLookAndFeel.getControl() );
  78. g.drawLine( 1, h-2, 1, h-2 );
  79. }
  80. g.translate( -x, -y );
  81. }
  82. public Insets getBorderInsets( Component c ) {
  83. return editorBorderInsets;
  84. }
  85. }
  86. /**
  87. * A subclass of BasicComboBoxEditor that implements UIResource.
  88. * BasicComboBoxEditor doesn't implement UIResource
  89. * directly so that applications can safely override the
  90. * cellRenderer property with BasicListCellRenderer subclasses.
  91. * <p>
  92. * <strong>Warning:</strong>
  93. * Serialized objects of this class will not be compatible with
  94. * future Swing releases. The current serialization support is
  95. * appropriate for short term storage or RMI between applications running
  96. * the same version of Swing. As of 1.4, support for long term storage
  97. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  98. * has been added to the <code>java.beans</code> package.
  99. * Please see {@link java.beans.XMLEncoder}.
  100. */
  101. public static class UIResource extends MetalComboBoxEditor
  102. implements javax.swing.plaf.UIResource {
  103. }
  104. }