125 |
* Helper method to repaint the focused cell's |
* Helper method to repaint the focused cell's |
126 |
* lost or acquired focus state. |
* lost or acquired focus state. |
127 |
*/ |
*/ |
128 |
void repaintCellFocus() |
protected void repaintCellFocus() |
129 |
{ |
{ |
130 |
} |
} |
131 |
} |
} |
186 |
} |
} |
187 |
} |
} |
188 |
|
|
189 |
|
|
190 |
/** |
/** |
191 |
* A helper class which listens for {@link KeyEvents}s |
* A helper class which listens for {@link KeyEvents}s |
192 |
* from the {@link JList}. |
* from the {@link JList}. |
193 |
*/ |
*/ |
194 |
|
// FIXME: This should be handled somehow by the L&F key bindings. |
195 |
private class KeyHandler extends KeyAdapter |
private class KeyHandler extends KeyAdapter |
196 |
{ |
{ |
197 |
public KeyHandler() |
public KeyHandler() |
217 |
BasicListUI.this.list.setSelectedIndex(Math.min(lead+1,max)); |
BasicListUI.this.list.setSelectedIndex(Math.min(lead+1,max)); |
218 |
} |
} |
219 |
else if (evt.getModifiers() == InputEvent.SHIFT_MASK) |
else if (evt.getModifiers() == InputEvent.SHIFT_MASK) |
220 |
{ |
selectNextIndex(); |
|
BasicListUI.this.list.getSelectionModel(). |
|
|
setLeadSelectionIndex(Math.min(lead+1,max)); |
|
|
} |
|
221 |
} |
} |
222 |
else if ((evt.getKeyCode() == KeyEvent.VK_UP) |
else if ((evt.getKeyCode() == KeyEvent.VK_UP) |
223 |
|| (evt.getKeyCode() == KeyEvent.VK_KP_UP)) |
|| (evt.getKeyCode() == KeyEvent.VK_KP_UP)) |
228 |
BasicListUI.this.list.setSelectedIndex(Math.max(lead-1,0)); |
BasicListUI.this.list.setSelectedIndex(Math.max(lead-1,0)); |
229 |
} |
} |
230 |
else if (evt.getModifiers() == InputEvent.SHIFT_MASK) |
else if (evt.getModifiers() == InputEvent.SHIFT_MASK) |
231 |
{ |
selectPreviousIndex(); |
|
BasicListUI.this.list.getSelectionModel(). |
|
|
setLeadSelectionIndex(Math.max(lead-1,0)); |
|
|
} |
|
232 |
} |
} |
233 |
else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) |
else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) |
234 |
{ |
{ |
455 |
if (e.getNewValue() != null && e.getNewValue() instanceof ListModel) |
if (e.getNewValue() != null && e.getNewValue() instanceof ListModel) |
456 |
((ListModel) e.getNewValue()).addListDataListener(BasicListUI.this.listDataListener); |
((ListModel) e.getNewValue()).addListDataListener(BasicListUI.this.listDataListener); |
457 |
} |
} |
458 |
|
// Update the updateLayoutStateNeeded flag. |
459 |
|
if (e.getPropertyName().equals("model")) |
460 |
|
updateLayoutStateNeeded += modelChanged; |
461 |
|
else if (e.getPropertyName().equals("selectionModel")) |
462 |
|
updateLayoutStateNeeded += selectionModelChanged; |
463 |
|
else if (e.getPropertyName().equals("font")) |
464 |
|
updateLayoutStateNeeded += fontChanged; |
465 |
|
else if (e.getPropertyName().equals("fixedCellWidth")) |
466 |
|
updateLayoutStateNeeded += fixedCellWidthChanged; |
467 |
|
else if (e.getPropertyName().equals("fixedCellHeight")) |
468 |
|
updateLayoutStateNeeded += fixedCellHeightChanged; |
469 |
|
else if (e.getPropertyName().equals("prototypeCellValue")) |
470 |
|
updateLayoutStateNeeded += prototypeCellValueChanged; |
471 |
|
else if (e.getPropertyName().equals("cellRenderer")) |
472 |
|
updateLayoutStateNeeded += cellRendererChanged; |
473 |
|
|
474 |
BasicListUI.this.damageLayout(); |
BasicListUI.this.damageLayout(); |
475 |
} |
} |
476 |
} |
} |
477 |
|
|
478 |
/** |
/** |
479 |
|
* A constant to indicate that the model has changed. |
480 |
|
*/ |
481 |
|
protected static final int modelChanged = 1; |
482 |
|
|
483 |
|
/** |
484 |
|
* A constant to indicate that the selection model has changed. |
485 |
|
*/ |
486 |
|
protected static final int selectionModelChanged = 2; |
487 |
|
|
488 |
|
/** |
489 |
|
* A constant to indicate that the font has changed. |
490 |
|
*/ |
491 |
|
protected static final int fontChanged = 4; |
492 |
|
|
493 |
|
/** |
494 |
|
* A constant to indicate that the fixedCellWidth has changed. |
495 |
|
*/ |
496 |
|
protected static final int fixedCellWidthChanged = 8; |
497 |
|
|
498 |
|
/** |
499 |
|
* A constant to indicate that the fixedCellHeight has changed. |
500 |
|
*/ |
501 |
|
protected static final int fixedCellHeightChanged = 16; |
502 |
|
|
503 |
|
/** |
504 |
|
* A constant to indicate that the prototypeCellValue has changed. |
505 |
|
*/ |
506 |
|
protected static final int prototypeCellValueChanged = 32; |
507 |
|
|
508 |
|
/** |
509 |
|
* A constant to indicate that the cellRenderer has changed. |
510 |
|
*/ |
511 |
|
protected static final int cellRendererChanged = 64; |
512 |
|
|
513 |
|
/** |
514 |
* Creates a new BasicListUI for the component. |
* Creates a new BasicListUI for the component. |
515 |
* |
* |
516 |
* @param c The component to create a UI for |
* @param c The component to create a UI for |
561 |
protected int[] cellHeights; |
protected int[] cellHeights; |
562 |
|
|
563 |
/** |
/** |
564 |
* A simple counter. When nonzero, indicates that the UI class is out of |
* A bitmask that indicates which properties of the JList have changed. |
565 |
|
* When nonzero, indicates that the UI class is out of |
566 |
* date with respect to the underlying list, and must recalculate the |
* date with respect to the underlying list, and must recalculate the |
567 |
* list layout before painting or performing size calculations. |
* list layout before painting or performing size calculations. |
568 |
|
* |
569 |
|
* @see #modelChanged |
570 |
|
* @see #selectionModelChanged |
571 |
|
* @see #fontChanged |
572 |
|
* @see #fixedCellWidthChanged |
573 |
|
* @see #fixedCellHeightChanged |
574 |
|
* @see #prototypeCellValueChanged |
575 |
|
* @see #cellRendererChanged |
576 |
*/ |
*/ |
577 |
protected int updateLayoutStateNeeded; |
protected int updateLayoutStateNeeded; |
578 |
|
|
750 |
*/ |
*/ |
751 |
public BasicListUI() |
public BasicListUI() |
752 |
{ |
{ |
|
focusListener = new FocusHandler(); |
|
|
listDataListener = new ListDataHandler(); |
|
|
listSelectionListener = new ListSelectionHandler(); |
|
|
mouseInputListener = new MouseInputHandler(); |
|
|
keyListener = new KeyHandler(); |
|
|
propertyChangeListener = new PropertyChangeHandler(); |
|
|
componentListener = new ComponentHandler(); |
|
753 |
updateLayoutStateNeeded = 1; |
updateLayoutStateNeeded = 1; |
754 |
rendererPane = new CellRendererPane(); |
rendererPane = new CellRendererPane(); |
755 |
} |
} |
791 |
*/ |
*/ |
792 |
protected void installListeners() |
protected void installListeners() |
793 |
{ |
{ |
794 |
|
if (focusListener == null) |
795 |
|
focusListener = createFocusListener(); |
796 |
list.addFocusListener(focusListener); |
list.addFocusListener(focusListener); |
797 |
|
if (listDataListener == null) |
798 |
|
listDataListener = createListDataListener(); |
799 |
list.getModel().addListDataListener(listDataListener); |
list.getModel().addListDataListener(listDataListener); |
800 |
|
if (listSelectionListener == null) |
801 |
|
listSelectionListener = createListSelectionListener(); |
802 |
list.addListSelectionListener(listSelectionListener); |
list.addListSelectionListener(listSelectionListener); |
803 |
|
if (mouseInputListener == null) |
804 |
|
mouseInputListener = createMouseInputListener(); |
805 |
list.addMouseListener(mouseInputListener); |
list.addMouseListener(mouseInputListener); |
|
list.addKeyListener(keyListener); |
|
806 |
list.addMouseMotionListener(mouseInputListener); |
list.addMouseMotionListener(mouseInputListener); |
807 |
|
if (propertyChangeListener == null) |
808 |
|
propertyChangeListener = createPropertyChangeListener(); |
809 |
list.addPropertyChangeListener(propertyChangeListener); |
list.addPropertyChangeListener(propertyChangeListener); |
810 |
|
|
811 |
|
// FIXME: Are these two really needed? At least they are not documented. |
812 |
|
keyListener = new KeyHandler(); |
813 |
list.addComponentListener(componentListener); |
list.addComponentListener(componentListener); |
814 |
|
componentListener = new ComponentHandler(); |
815 |
|
list.addKeyListener(keyListener); |
816 |
} |
} |
817 |
|
|
818 |
/** |
/** |
1108 |
} |
} |
1109 |
return loc; |
return loc; |
1110 |
} |
} |
1111 |
|
|
1112 |
|
/** |
1113 |
|
* Creates and returns the focus listener for this UI. |
1114 |
|
* |
1115 |
|
* @return the focus listener for this UI |
1116 |
|
*/ |
1117 |
|
protected FocusListener createFocusListener() |
1118 |
|
{ |
1119 |
|
return new FocusHandler(); |
1120 |
|
} |
1121 |
|
|
1122 |
|
/** |
1123 |
|
* Creates and returns the list data listener for this UI. |
1124 |
|
* |
1125 |
|
* @return the list data listener for this UI |
1126 |
|
*/ |
1127 |
|
protected ListDataListener createListDataListener() |
1128 |
|
{ |
1129 |
|
return new ListDataHandler(); |
1130 |
|
} |
1131 |
|
|
1132 |
|
/** |
1133 |
|
* Creates and returns the list selection listener for this UI. |
1134 |
|
* |
1135 |
|
* @return the list selection listener for this UI |
1136 |
|
*/ |
1137 |
|
protected ListSelectionListener createListSelectionListener() |
1138 |
|
{ |
1139 |
|
return new ListSelectionHandler(); |
1140 |
|
} |
1141 |
|
|
1142 |
|
/** |
1143 |
|
* Creates and returns the mouse input listener for this UI. |
1144 |
|
* |
1145 |
|
* @return the mouse input listener for this UI |
1146 |
|
*/ |
1147 |
|
protected MouseInputListener createMouseInputListener() |
1148 |
|
{ |
1149 |
|
return new MouseInputHandler(); |
1150 |
|
} |
1151 |
|
|
1152 |
|
/** |
1153 |
|
* Creates and returns the property change listener for this UI. |
1154 |
|
* |
1155 |
|
* @return the property change listener for this UI |
1156 |
|
*/ |
1157 |
|
protected PropertyChangeListener createPropertyChangeListener() |
1158 |
|
{ |
1159 |
|
return new PropertyChangeHandler(); |
1160 |
|
} |
1161 |
|
|
1162 |
|
/** |
1163 |
|
* Selects the next list item and force it to be visible. |
1164 |
|
*/ |
1165 |
|
protected void selectNextIndex() |
1166 |
|
{ |
1167 |
|
int index = list.getSelectedIndex(); |
1168 |
|
index++; |
1169 |
|
list.setSelectedIndex(index); |
1170 |
|
list.ensureIndexIsVisible(index); |
1171 |
|
} |
1172 |
|
|
1173 |
|
/** |
1174 |
|
* Selects the previous list item and force it to be visible. |
1175 |
|
*/ |
1176 |
|
protected void selectPreviousIndex() |
1177 |
|
{ |
1178 |
|
int index = list.getSelectedIndex(); |
1179 |
|
index--; |
1180 |
|
list.setSelectedIndex(index); |
1181 |
|
list.ensureIndexIsVisible(index); |
1182 |
|
} |
1183 |
} |
} |