1 7 8 package javax.swing.plaf.metal; 9 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import java.io.Serializable ; 13 import java.awt.*; 14 import java.awt.event.*; 15 16 import javax.swing.plaf.basic.BasicComboBoxEditor ; 17 18 33 public class MetalComboBoxEditor extends BasicComboBoxEditor { 34 35 public MetalComboBoxEditor() { 36 super(); 37 editor = new JTextField("",9) { 39 public void setText(String s) { 41 if (getText().equals(s)) { 42 return; 43 } 44 super.setText(s); 45 } 46 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 } 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 119 public static class UIResource extends MetalComboBoxEditor 120 implements javax.swing.plaf.UIResource { 121 } 122 } 123 124 | Popular Tags |