25
26 package javax.swing.plaf.metal;
27
28 import javax.swing.*;
29 import javax.swing.border.*;
30 import java.io.Serializable;
31 import java.awt.*;
32 import java.awt.event.*;
33
34 import javax.swing.plaf.basic.BasicComboBoxEditor;
35
36 /**
37 * The default editor for Metal editable combo boxes
38 * <p>
39 * <strong>Warning:</strong>
40 * Serialized objects of this class will not be compatible with
41 * future Swing releases. The current serialization support is
42 * appropriate for short term storage or RMI between applications running
43 * the same version of Swing. As of 1.4, support for long term storage
44 * of all JavaBeans™
45 * has been added to the <code>java.beans</code> package.
46 * Please see {@link java.beans.XMLEncoder}.
47 *
48 * @author Steve Wilson
49 */
50 @SuppressWarnings("serial") // Same-version serialization only
51 public class MetalComboBoxEditor extends BasicComboBoxEditor {
52
53 /**
54 * Constructs a new instance of {@code MetalComboBoxEditor}.
55 */
56 public MetalComboBoxEditor() {
57 super();
58 //editor.removeFocusListener(this);
59 editor = new JTextField("",9) {
60 // workaround for 4530952
61 public void setText(String s) {
62 if (getText().equals(s)) {
63 return;
64 }
65 super.setText(s);
67 // The preferred and minimum sizes are overriden and padded by
68 // 4 to keep the size as it previously was. Refer to bugs
69 // 4775789 and 4517214 for details.
70 public Dimension getPreferredSize() {
71 Dimension pref = super.getPreferredSize();
72 pref.height += 4;
73 return pref;
74 }
75 public Dimension getMinimumSize() {
76 Dimension min = super.getMinimumSize();
77 min.height += 4;
78 return min;
79 }
80 };
81
82 editor.setBorder( new EditorBorder() );
83 //editor.addFocusListener(this);
84 }
85
86 /**
87 * The default editor border <code>Insets</code>. This field
88 * might not be used.
89 */
90 protected static Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
91
92 class EditorBorder extends AbstractBorder {
93 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
94 g.translate( x, y );
95
96 if (MetalLookAndFeel.usingOcean()) {
97 g.setColor(MetalLookAndFeel.getControlDarkShadow());
98 g.drawRect(0, 0, w, h - 1);
99 g.setColor(MetalLookAndFeel.getControlShadow());
100 g.drawRect(1, 1, w - 2, h - 3);
101 }
102 else {
103 g.setColor( MetalLookAndFeel.getControlDarkShadow() );
104 g.drawLine( 0, 0, w-1, 0 );
105 g.drawLine( 0, 0, 0, h-2 );
106 g.drawLine( 0, h-2, w-1, h-2 );
107 g.setColor( MetalLookAndFeel.getControlHighlight() );
117
118 public Insets getBorderInsets(Component c, Insets insets) {
119 insets.set(2, 2, 2, 0);
120 return insets;
121 }
122 }
123
124
125 /**
126 * A subclass of BasicComboBoxEditor that implements UIResource.
127 * BasicComboBoxEditor doesn't implement UIResource
128 * directly so that applications can safely override the
129 * cellRenderer property with BasicListCellRenderer subclasses.
130 * <p>
131 * <strong>Warning:</strong>
132 * Serialized objects of this class will not be compatible with
133 * future Swing releases. The current serialization support is
134 * appropriate for short term storage or RMI between applications running
135 * the same version of Swing. As of 1.4, support for long term storage
136 * of all JavaBeans™
137 * has been added to the <code>java.beans</code> package.
138 * Please see {@link java.beans.XMLEncoder}.
139 */
140 @SuppressWarnings("serial") // Same-version serialization only
141 public static class UIResource extends MetalComboBoxEditor
142 implements javax.swing.plaf.UIResource {
143 }
144 }
|
25
26 package javax.swing.plaf.metal;
27
28 import javax.swing.*;
29 import javax.swing.border.*;
30 import java.io.Serializable;
31 import java.awt.*;
32 import java.awt.event.*;
33
34 import javax.swing.plaf.basic.BasicComboBoxEditor;
35
36 /**
37 * The default editor for Metal editable combo boxes
38 * <p>
39 * <strong>Warning:</strong>
40 * Serialized objects of this class will not be compatible with
41 * future Swing releases. The current serialization support is
42 * appropriate for short term storage or RMI between applications running
43 * the same version of Swing. As of 1.4, support for long term storage
44 * of all JavaBeans™
45 * has been added to the {@code java.beans} package.
46 * Please see {@link java.beans.XMLEncoder}.
47 *
48 * @author Steve Wilson
49 */
50 @SuppressWarnings("serial") // Same-version serialization only
51 public class MetalComboBoxEditor extends BasicComboBoxEditor {
52
53 /**
54 * Constructs a new instance of {@code MetalComboBoxEditor}.
55 */
56 public MetalComboBoxEditor() {
57 super();
58 //editor.removeFocusListener(this);
59 editor = new JTextField("",9) {
60 // workaround for 4530952
61 public void setText(String s) {
62 if (getText().equals(s)) {
63 return;
64 }
65 super.setText(s);
67 // The preferred and minimum sizes are overriden and padded by
68 // 4 to keep the size as it previously was. Refer to bugs
69 // 4775789 and 4517214 for details.
70 public Dimension getPreferredSize() {
71 Dimension pref = super.getPreferredSize();
72 pref.height += 4;
73 return pref;
74 }
75 public Dimension getMinimumSize() {
76 Dimension min = super.getMinimumSize();
77 min.height += 4;
78 return min;
79 }
80 };
81
82 editor.setBorder( new EditorBorder() );
83 //editor.addFocusListener(this);
84 }
85
86 /**
87 * The default editor border {@code Insets}. This field
88 * might not be used.
89 */
90 protected static Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
91
92 class EditorBorder extends AbstractBorder {
93 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
94 g.translate( x, y );
95
96 if (MetalLookAndFeel.usingOcean()) {
97 g.setColor(MetalLookAndFeel.getControlDarkShadow());
98 g.drawRect(0, 0, w, h - 1);
99 g.setColor(MetalLookAndFeel.getControlShadow());
100 g.drawRect(1, 1, w - 2, h - 3);
101 }
102 else {
103 g.setColor( MetalLookAndFeel.getControlDarkShadow() );
104 g.drawLine( 0, 0, w-1, 0 );
105 g.drawLine( 0, 0, 0, h-2 );
106 g.drawLine( 0, h-2, w-1, h-2 );
107 g.setColor( MetalLookAndFeel.getControlHighlight() );
117
118 public Insets getBorderInsets(Component c, Insets insets) {
119 insets.set(2, 2, 2, 0);
120 return insets;
121 }
122 }
123
124
125 /**
126 * A subclass of BasicComboBoxEditor that implements UIResource.
127 * BasicComboBoxEditor doesn't implement UIResource
128 * directly so that applications can safely override the
129 * cellRenderer property with BasicListCellRenderer subclasses.
130 * <p>
131 * <strong>Warning:</strong>
132 * Serialized objects of this class will not be compatible with
133 * future Swing releases. The current serialization support is
134 * appropriate for short term storage or RMI between applications running
135 * the same version of Swing. As of 1.4, support for long term storage
136 * of all JavaBeans™
137 * has been added to the {@code java.beans} package.
138 * Please see {@link java.beans.XMLEncoder}.
139 */
140 @SuppressWarnings("serial") // Same-version serialization only
141 public static class UIResource extends MetalComboBoxEditor
142 implements javax.swing.plaf.UIResource {
143 }
144 }
|