blob: f0e8e648b59df11eccc0b5bbe03a08f041af2f07 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package javax.swing.plaf.metal;
27
28import javax.swing.*;
29import javax.swing.border.*;
30import java.io.Serializable;
31import java.awt.*;
32import java.awt.event.*;
33
34import 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<sup><font size="-2">TM</font></sup>
45 * has been added to the <code>java.beans</code> package.
46 * Please see {@link java.beans.XMLEncoder}.
47 *
48 * @author Steve Wilson
49 */
50public class MetalComboBoxEditor extends BasicComboBoxEditor {
51
52 public MetalComboBoxEditor() {
53 super();
54 //editor.removeFocusListener(this);
55 editor = new JTextField("",9) {
56 // workaround for 4530952
57 public void setText(String s) {
58 if (getText().equals(s)) {
59 return;
60 }
61 super.setText(s);
62 }
63 // The preferred and minimum sizes are overriden and padded by
64 // 4 to keep the size as it previously was. Refer to bugs
65 // 4775789 and 4517214 for details.
66 public Dimension getPreferredSize() {
67 Dimension pref = super.getPreferredSize();
68 pref.height += 4;
69 return pref;
70 }
71 public Dimension getMinimumSize() {
72 Dimension min = super.getMinimumSize();
73 min.height += 4;
74 return min;
75 }
76 };
77
78 editor.setBorder( new EditorBorder() );
79 //editor.addFocusListener(this);
80 }
81
82 /**
83 * The default editor border <code>Insets</code>. This field
84 * might not be used.
85 */
86 protected static Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
87
88 class EditorBorder extends AbstractBorder {
89 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
90 g.translate( x, y );
91
92 if (MetalLookAndFeel.usingOcean()) {
93 g.setColor(MetalLookAndFeel.getControlDarkShadow());
94 g.drawRect(0, 0, w, h - 1);
95 g.setColor(MetalLookAndFeel.getControlShadow());
96 g.drawRect(1, 1, w - 2, h - 3);
97 }
98 else {
99 g.setColor( MetalLookAndFeel.getControlDarkShadow() );
100 g.drawLine( 0, 0, w-1, 0 );
101 g.drawLine( 0, 0, 0, h-2 );
102 g.drawLine( 0, h-2, w-1, h-2 );
103 g.setColor( MetalLookAndFeel.getControlHighlight() );
104 g.drawLine( 1, 1, w-1, 1 );
105 g.drawLine( 1, 1, 1, h-1 );
106 g.drawLine( 1, h-1, w-1, h-1 );
107 g.setColor( MetalLookAndFeel.getControl() );
108 g.drawLine( 1, h-2, 1, h-2 );
109 }
110
111 g.translate( -x, -y );
112 }
113
114 public Insets getBorderInsets(Component c, Insets insets) {
115 insets.set(2, 2, 2, 0);
116 return insets;
117 }
118 }
119
120
121 /**
122 * A subclass of BasicComboBoxEditor that implements UIResource.
123 * BasicComboBoxEditor doesn't implement UIResource
124 * directly so that applications can safely override the
125 * cellRenderer property with BasicListCellRenderer subclasses.
126 * <p>
127 * <strong>Warning:</strong>
128 * Serialized objects of this class will not be compatible with
129 * future Swing releases. The current serialization support is
130 * appropriate for short term storage or RMI between applications running
131 * the same version of Swing. As of 1.4, support for long term storage
132 * of all JavaBeans<sup><font size="-2">TM</font></sup>
133 * has been added to the <code>java.beans</code> package.
134 * Please see {@link java.beans.XMLEncoder}.
135 */
136 public static class UIResource extends MetalComboBoxEditor
137 implements javax.swing.plaf.UIResource {
138 }
139}