197 |
|
|
198 |
public void keyPressed( KeyEvent evt ) |
public void keyPressed( KeyEvent evt ) |
199 |
{ |
{ |
200 |
if (evt.getKeyCode() == KeyEvent.VK_DOWN) |
int lead = BasicListUI.this.list.getLeadSelectionIndex(); |
201 |
|
int max = BasicListUI.this.list.getModel().getSize() - 1; |
202 |
|
// Do nothing if list is empty |
203 |
|
if (max == -1) |
204 |
|
return; |
205 |
|
|
206 |
|
// Process the key event. Bindings can be found in |
207 |
|
// javax.swing.plaf.basic.BasicLookAndFeel.java |
208 |
|
if ((evt.getKeyCode() == KeyEvent.VK_DOWN) |
209 |
|
|| (evt.getKeyCode() == KeyEvent.VK_KP_DOWN)) |
210 |
{ |
{ |
|
int lead = BasicListUI.this.list.getLeadSelectionIndex(); |
|
|
int max = BasicListUI.this.list.getModel().getSize() - 1; |
|
211 |
if (!evt.isShiftDown()) |
if (!evt.isShiftDown()) |
212 |
{ |
{ |
213 |
BasicListUI.this.list.clearSelection(); |
BasicListUI.this.list.clearSelection(); |
219 |
setLeadSelectionIndex(Math.min(lead+1,max)); |
setLeadSelectionIndex(Math.min(lead+1,max)); |
220 |
} |
} |
221 |
} |
} |
222 |
else if (evt.getKeyCode() == KeyEvent.VK_UP) |
else if ((evt.getKeyCode() == KeyEvent.VK_UP) |
223 |
|
|| (evt.getKeyCode() == KeyEvent.VK_KP_UP)) |
224 |
{ |
{ |
|
int lead = BasicListUI.this.list.getLeadSelectionIndex(); |
|
225 |
if (!evt.isShiftDown()) |
if (!evt.isShiftDown()) |
226 |
{ |
{ |
227 |
BasicListUI.this.list.clearSelection(); |
BasicListUI.this.list.clearSelection(); |
233 |
setLeadSelectionIndex(Math.max(lead-1,0)); |
setLeadSelectionIndex(Math.max(lead-1,0)); |
234 |
} |
} |
235 |
} |
} |
236 |
|
else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) |
237 |
|
{ |
238 |
|
// FIXME: implement, need JList.ensureIndexIsVisible to work |
239 |
|
} |
240 |
|
else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) |
241 |
|
{ |
242 |
|
// FIXME: implement, need JList.ensureIndexIsVisible to work |
243 |
|
} |
244 |
|
else if (evt.getKeyCode() == KeyEvent.VK_BACK_SLASH |
245 |
|
&& evt.isControlDown()) |
246 |
|
{ |
247 |
|
BasicListUI.this.list.clearSelection(); |
248 |
|
} |
249 |
|
else if ((evt.getKeyCode() == KeyEvent.VK_HOME) |
250 |
|
|| evt.getKeyCode() == KeyEvent.VK_END) |
251 |
|
{ |
252 |
|
// index is either 0 for HOME, or last cell for END |
253 |
|
int index = (evt.getKeyCode() == KeyEvent.VK_HOME) ? 0 : max; |
254 |
|
|
255 |
|
if (!evt.isShiftDown() ||(BasicListUI.this.list.getSelectionMode() |
256 |
|
== ListSelectionModel.SINGLE_SELECTION)) |
257 |
|
BasicListUI.this.list.setSelectedIndex(index); |
258 |
|
else if (BasicListUI.this.list.getSelectionMode() == |
259 |
|
ListSelectionModel.SINGLE_INTERVAL_SELECTION) |
260 |
|
BasicListUI.this.list.setSelectionInterval |
261 |
|
(BasicListUI.this.list.getAnchorSelectionIndex(), index); |
262 |
|
else |
263 |
|
BasicListUI.this.list.getSelectionModel(). |
264 |
|
setLeadSelectionIndex(index); |
265 |
|
} |
266 |
|
else if ((evt.getKeyCode() == KeyEvent.VK_A || evt.getKeyCode() |
267 |
|
== KeyEvent.VK_SLASH) && evt.isControlDown()) |
268 |
|
{ |
269 |
|
BasicListUI.this.list.setSelectionInterval(0, max); |
270 |
|
} |
271 |
|
else if (evt.getKeyCode() == KeyEvent.VK_SPACE && evt.isControlDown()) |
272 |
|
{ |
273 |
|
BasicListUI.this.list.getSelectionModel(). |
274 |
|
setLeadSelectionIndex(Math.min(lead+1,max)); |
275 |
|
} |
276 |
|
|
277 |
} |
} |
278 |
} |
} |
279 |
|
|