1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.*; 34 35 import javax.swing.*; 36 import javax.swing.plaf.ComponentUI ; 37 import javax.swing.plaf.basic.BasicComboBoxUI ; 38 39 import com.jgoodies.looks.LookUtils; 40 41 52 53 public final class WindowsComboBoxUI extends com.sun.java.swing.plaf.windows.WindowsComboBoxUI { 54 55 59 private static final JTextField phantom = new JTextField("Phantom"); 60 61 62 public static ComponentUI createUI(JComponent b) { 63 return new WindowsComboBoxUI(); 64 } 65 66 69 public Dimension getMinimumSize(JComponent c) { 70 Dimension size = super.getMinimumSize(c); 71 Dimension textFieldSize = phantom.getMinimumSize(); 72 return new Dimension(size.width, Math.max(textFieldSize.height, size.height)); 73 } 74 75 76 81 protected ComboBoxEditor createEditor() { 82 return new com.jgoodies.looks.windows.WindowsComboBoxEditor.UIResource(); 83 } 84 85 86 94 protected LayoutManager createLayoutManager() { 95 return new WindowsComboBoxLayoutManager(); 96 } 97 98 99 104 protected JButton createArrowButton() { 105 return LookUtils.IS_LAF_WINDOWS_XP_ENABLED 106 ? super.createArrowButton() 107 : new WindowsArrowButton(SwingConstants.SOUTH); 108 } 109 110 111 114 protected Rectangle rectangleForCurrentValue() { 115 if (comboBox.isEditable() || !comboBox.isEnabled()) 116 return super.rectangleForCurrentValue(); 117 118 int width = comboBox.getWidth(); 119 int height = comboBox.getHeight(); 120 Insets insets = getInsets(); 121 Insets rendererMargin = UIManager.getInsets("ComboBox.rendererMargin"); 122 int buttonSize = height - (insets.top + insets.bottom); 123 if (arrowButton != null) { 125 buttonSize = arrowButton.getWidth(); 126 } 127 if (comboBox.getComponentOrientation().isLeftToRight()) { 128 return new Rectangle( 129 insets.left + rendererMargin.left, 130 insets.top + rendererMargin.top, 131 width - (insets.left + rendererMargin.left + insets.right 132 + rendererMargin.right + buttonSize), 133 height - (insets.top + rendererMargin.top + insets.bottom 134 + rendererMargin.bottom)); 135 } else { 136 return new Rectangle( 137 insets.left + rendererMargin.left + buttonSize, 138 insets.top + rendererMargin.top, 139 width - (insets.left + rendererMargin.left + insets.right 140 + rendererMargin.right + buttonSize), 141 height - (insets.top + rendererMargin.top + insets.bottom 142 + rendererMargin.bottom)); 143 } 144 } 145 146 147 148 155 private class WindowsComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager { 156 157 public void layoutContainer(Container parent) { 158 JComboBox cb = (JComboBox) parent; 159 int width = cb.getWidth(); 160 int height = cb.getHeight(); 161 162 Insets insets = getInsets(); 163 int buttonWidth = UIManager.getInt("ScrollBar.width"); 164 int buttonHeight = height - (insets.top + insets.bottom); 165 167 if (arrowButton != null) { 168 if (cb.getComponentOrientation().isLeftToRight()) { 169 arrowButton.setBounds(width - (insets.right + buttonWidth), 170 insets.top, buttonWidth, buttonHeight); 171 } else { 172 arrowButton.setBounds(insets.left, insets.top, buttonWidth, buttonHeight); 173 } 174 } 175 if (editor != null) { 176 editor.setBounds(rectangleForCurrentValue()); 177 } 178 } 179 180 } 181 182 183 } | Popular Tags |