41 |
import java.awt.Container; |
import java.awt.Container; |
42 |
import java.awt.Dimension; |
import java.awt.Dimension; |
43 |
import java.awt.Graphics; |
import java.awt.Graphics; |
44 |
|
import java.awt.Insets; |
45 |
import java.awt.LayoutManager; |
import java.awt.LayoutManager; |
46 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
47 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
50 |
|
|
51 |
import javax.swing.CellRendererPane; |
import javax.swing.CellRendererPane; |
52 |
import javax.swing.ComboBoxEditor; |
import javax.swing.ComboBoxEditor; |
53 |
|
import javax.swing.Icon; |
54 |
import javax.swing.JButton; |
import javax.swing.JButton; |
55 |
import javax.swing.JComboBox; |
import javax.swing.JComboBox; |
56 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
63 |
/** |
/** |
64 |
* A UI delegate for the {@link JComboBox} component. |
* A UI delegate for the {@link JComboBox} component. |
65 |
*/ |
*/ |
66 |
public class MetalComboBoxUI |
public class MetalComboBoxUI extends BasicComboBoxUI |
|
extends BasicComboBoxUI |
|
67 |
{ |
{ |
68 |
/** |
/** |
69 |
* A layout manager that arranges the editor component (if active) and the |
* A layout manager that arranges the editor component (if active) and the |
76 |
* Creates a new instance of the layout manager. |
* Creates a new instance of the layout manager. |
77 |
*/ |
*/ |
78 |
public MetalComboBoxLayoutManager() |
public MetalComboBoxLayoutManager() |
79 |
{ |
{ |
80 |
|
// Nothing to do here. |
81 |
} |
} |
82 |
|
|
83 |
/** |
/** |
123 |
*/ |
*/ |
124 |
public MetalPropertyChangeListener() |
public MetalPropertyChangeListener() |
125 |
{ |
{ |
126 |
|
// Nothing to do here. |
127 |
} |
} |
128 |
|
|
129 |
/** |
/** |
212 |
*/ |
*/ |
213 |
protected JButton createArrowButton() |
protected JButton createArrowButton() |
214 |
{ |
{ |
215 |
return new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(), |
JButton button = new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(), |
216 |
new CellRendererPane(), listBox); |
new CellRendererPane(), listBox); |
217 |
|
button.setMargin(new Insets(0, 1, 1, 3)); |
218 |
|
return button; |
219 |
} |
} |
220 |
|
|
221 |
/** |
/** |
256 |
} |
} |
257 |
else |
else |
258 |
{ |
{ |
259 |
arrowButton.setText(comboBox.getSelectedItem().toString()); |
String text = ""; |
260 |
|
Object selected = comboBox.getSelectedItem(); |
261 |
|
if (selected != null) |
262 |
|
text = selected.toString(); |
263 |
|
arrowButton.setText(text); |
264 |
if (editor != null) |
if (editor != null) |
265 |
editor.setVisible(true); |
editor.setVisible(true); |
266 |
} |
} |
295 |
*/ |
*/ |
296 |
public Dimension getMinimumSize(JComponent c) |
public Dimension getMinimumSize(JComponent c) |
297 |
{ |
{ |
298 |
// FIXME: this needs work |
MetalComboBoxButton b = (MetalComboBoxButton) arrowButton; |
299 |
Dimension result = super.getMinimumSize(c); |
Icon icon = b.getComboIcon(); |
300 |
result.height = result.height + 9; |
Insets insets = b.getInsets(); |
301 |
return result; |
Dimension d = getDisplaySize(); |
302 |
|
int insetsH = insets.top + insets.bottom; |
303 |
|
int insetsW = insets.left + insets.right; |
304 |
|
int iconWidth = icon.getIconWidth() + 6; |
305 |
|
return new Dimension(d.width + insetsW + iconWidth, |
306 |
|
d.height + insetsH); |
307 |
} |
} |
308 |
|
|
309 |
} |
} |