171 |
{ |
{ |
172 |
this.comboBox = comboBox; |
this.comboBox = comboBox; |
173 |
installComboBoxListeners(); |
installComboBoxListeners(); |
174 |
|
configurePopup(); |
|
// initialize list that will be used to display elements of the combo box |
|
|
this.list = createList(); |
|
|
((JLabel) list.getCellRenderer()).setHorizontalAlignment(SwingConstants.LEFT); |
|
|
configureList(); |
|
|
|
|
|
// initialize scroller. Add list to the scroller. |
|
|
scroller = createScroller(); |
|
|
configureScroller(); |
|
|
|
|
|
// add scroller with list inside of it to JPopupMenu |
|
|
super.add(scroller); |
|
|
|
|
175 |
setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled()); |
setLightWeightPopupEnabled(comboBox.isLightWeightPopupEnabled()); |
176 |
} |
} |
177 |
|
|
187 |
int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount()) |
int popupHeight = getPopupHeightForRowCount(comboBox.getMaximumRowCount()) |
188 |
+ 4; |
+ 4; |
189 |
|
|
190 |
|
// FIXME: Uncomment this out once preferred size of JList will be working |
191 |
|
// list.setPreferredSize(new Dimension(cbBounds.width, popupHeight)); |
192 |
super.setPopupSize(cbBounds.width, popupHeight); |
super.setPopupSize(cbBounds.width, popupHeight); |
193 |
|
|
194 |
// location specified is relative to comboBox |
// location specified is relative to comboBox |
283 |
*/ |
*/ |
284 |
protected void firePopupMenuWillBecomeVisible() |
protected void firePopupMenuWillBecomeVisible() |
285 |
{ |
{ |
286 |
// FIXME: Need to implement |
PopupMenuListener[] ll = comboBox.getPopupMenuListeners(); |
287 |
|
|
288 |
|
for (int i = 0; i < ll.length; i++) |
289 |
|
ll[i].popupMenuWillBecomeVisible(new PopupMenuEvent(comboBox)); |
290 |
} |
} |
291 |
|
|
292 |
/** |
/** |
295 |
*/ |
*/ |
296 |
protected void firePopupMenuWillBecomeInvisible() |
protected void firePopupMenuWillBecomeInvisible() |
297 |
{ |
{ |
298 |
// FIXME: Need to implement |
PopupMenuListener[] ll = comboBox.getPopupMenuListeners(); |
299 |
|
|
300 |
|
for (int i = 0; i < ll.length; i++) |
301 |
|
ll[i].popupMenuWillBecomeInvisible(new PopupMenuEvent(comboBox)); |
302 |
} |
} |
303 |
|
|
304 |
/** |
/** |
307 |
*/ |
*/ |
308 |
protected void firePopupMenuCanceled() |
protected void firePopupMenuCanceled() |
309 |
{ |
{ |
310 |
// FIXME: Need to implement |
PopupMenuListener[] ll = comboBox.getPopupMenuListeners(); |
311 |
|
|
312 |
|
for (int i = 0; i < ll.length; i++) |
313 |
|
ll[i].popupMenuCanceled(new PopupMenuEvent(comboBox)); |
314 |
} |
} |
315 |
|
|
316 |
/** |
/** |
439 |
protected void configureList() |
protected void configureList() |
440 |
{ |
{ |
441 |
list.setModel(comboBox.getModel()); |
list.setModel(comboBox.getModel()); |
442 |
|
list.setVisibleRowCount(comboBox.getMaximumRowCount()); |
|
if (comboBox.getItemCount() < comboBox.getMaximumRowCount()) |
|
|
list.setVisibleRowCount(comboBox.getItemCount()); |
|
|
else |
|
|
list.setVisibleRowCount(comboBox.getMaximumRowCount()); |
|
443 |
installListListeners(); |
installListListeners(); |
444 |
} |
} |
445 |
|
|
488 |
*/ |
*/ |
489 |
protected void configurePopup() |
protected void configurePopup() |
490 |
{ |
{ |
491 |
// FIXME: Need to implement |
// initialize list that will be used to display combo box's items |
492 |
|
this.list = createList(); |
493 |
|
((JLabel) list.getCellRenderer()).setHorizontalAlignment(SwingConstants.LEFT); |
494 |
|
configureList(); |
495 |
|
|
496 |
|
// initialize scroller. Add list to the scroller. |
497 |
|
scroller = createScroller(); |
498 |
|
configureScroller(); |
499 |
|
|
500 |
|
// add scroller with list inside of it to JPopupMenu |
501 |
|
super.add(scroller); |
502 |
} |
} |
503 |
|
|
504 |
/* |
/* |
648 |
for (int i = 0; i < maxRowCount; i++) |
for (int i = 0; i < maxRowCount; i++) |
649 |
{ |
{ |
650 |
Component comp = rend.getListCellRendererComponent(list, |
Component comp = rend.getListCellRendererComponent(list, |
651 |
list.getModel() |
comboBox.getModel() |
652 |
.getElementAt(i), |
.getElementAt(i), |
653 |
-1, false, false); |
-1, false, false); |
654 |
Dimension dim = comp.getPreferredSize(); |
Dimension dim = comp.getPreferredSize(); |
655 |
totalHeight += dim.height; |
totalHeight += dim.height; |
808 |
|
|
809 |
public void mouseMoved(MouseEvent anEvent) |
public void mouseMoved(MouseEvent anEvent) |
810 |
{ |
{ |
811 |
// FIXME: Need to implement |
// Highlight list cells over which the mouse is located. |
812 |
// NOTE: the change isn't reflected in data model of the combo box. |
// This changes list model, but has no effect on combo box's data model |
813 |
// The items are only highlited, but not selected |
int index = list.locationToIndex(anEvent.getPoint()); |
814 |
|
list.setSelectedIndex(index); |
815 |
|
list.repaint(); |
816 |
} |
} |
817 |
} |
} |
818 |
|
|
835 |
revalidate(); |
revalidate(); |
836 |
repaint(); |
repaint(); |
837 |
} |
} |
838 |
|
if (e.getPropertyName().equals(JComboBox.MODEL_CHANGED_PROPERTY)) |
839 |
|
{ |
840 |
|
list.setModel((ComboBoxModel) e.getNewValue()); |
841 |
|
revalidate(); |
842 |
|
repaint(); |
843 |
|
} |
844 |
} |
} |
845 |
} |
} |
846 |
|
|