KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > plaf > metal > MetalComboBoxEditor


1 /*
2  * @(#)MetalComboBoxEditor.java 1.25 05/10/31
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.plaf.metal;
9
10 import javax.swing.*;
11 import javax.swing.border.*;
12 import java.io.Serializable JavaDoc;
13 import java.awt.*;
14 import java.awt.event.*;
15
16 import javax.swing.plaf.basic.BasicComboBoxEditor JavaDoc;
17
18 /**
19  * The default editor for Metal editable combo boxes
20  * <p>
21  * <strong>Warning:</strong>
22  * Serialized objects of this class will not be compatible with
23  * future Swing releases. The current serialization support is
24  * appropriate for short term storage or RMI between applications running
25  * the same version of Swing. As of 1.4, support for long term storage
26  * of all JavaBeans<sup><font size="-2">TM</font></sup>
27  * has been added to the <code>java.beans</code> package.
28  * Please see {@link java.beans.XMLEncoder}.
29  *
30  * @version 1.25 10/31/05
31  * @author Steve Wilson
32  */

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

119     public static class UIResource extends MetalComboBoxEditor JavaDoc
120     implements javax.swing.plaf.UIResource JavaDoc {
121     }
122 }
123
124
Popular Tags