264 } 265 } 266 }; 267 } 268 269 protected void installKeyboardActions() { 270 super.installKeyboardActions(); 271 272 ActionMap actionMap = new ActionMapUIResource(); 273 274 actionMap.put("aquaSelectNext", highlightNextAction); 275 actionMap.put("aquaSelectPrevious", highlightPreviousAction); 276 actionMap.put("aquaEnterPressed", triggerSelectionAction); 277 actionMap.put("aquaSpacePressed", toggleSelectionAction); 278 279 actionMap.put("aquaSelectHome", highlightFirstAction); 280 actionMap.put("aquaSelectEnd", highlightLastAction); 281 actionMap.put("aquaSelectPageUp", highlightPageUpAction); 282 actionMap.put("aquaSelectPageDown", highlightPageDownAction); 283 284 SwingUtilities.replaceUIActionMap(comboBox, actionMap); 285 } 286 287 abstract class ComboBoxAction extends AbstractAction { 288 public void actionPerformed(final ActionEvent e) { 289 if (!comboBox.isEnabled() || !comboBox.isShowing()) return; 290 291 if (comboBox.isPopupVisible()) { 292 final AquaComboBoxUI ui = (AquaComboBoxUI)comboBox.getUI(); 293 performComboBoxAction(ui); 294 } else { 295 comboBox.setPopupVisible(true); 296 } 297 } 298 299 abstract void performComboBoxAction(final AquaComboBoxUI ui); 300 } 301 302 /** 303 * Hilight _but do not select_ the next item in the list. 371 @Override 372 void performComboBoxAction(final AquaComboBoxUI ui) { 373 final int current = listBox.getSelectedIndex(); 374 final int last = listBox.getLastVisibleIndex(); 375 376 if (current != last) { 377 listBox.setSelectedIndex(last); 378 return; 379 } 380 381 final int page = listBox.getVisibleRect().height / listBox.getCellBounds(0, 0).height; 382 final int end = listBox.getModel().getSize() - 1; 383 int target = last + page; 384 if (target > end) target = end; 385 386 listBox.ensureIndexIsVisible(target); 387 listBox.setSelectedIndex(target); 388 } 389 }; 390 391 // For <rdar://problem/3759984> Java 1.4.2_5: Serializing Swing components not working 392 // Inner classes were using a this reference and then trying to serialize the AquaComboBoxUI 393 // We shouldn't do that. But we need to be able to get the popup from other classes, so we need 394 // a public accessor. 395 public ComboPopup getPopup() { 396 return popup; 397 } 398 399 protected LayoutManager createLayoutManager() { 400 return new AquaComboBoxLayoutManager(); 401 } 402 403 class AquaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager { 404 public void layoutContainer(final Container parent) { 405 if (arrowButton != null && !comboBox.isEditable()) { 406 final Insets insets = comboBox.getInsets(); 407 final int width = comboBox.getWidth(); 408 final int height = comboBox.getHeight(); 409 arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom)); 410 return; | 264 } 265 } 266 }; 267 } 268 269 protected void installKeyboardActions() { 270 super.installKeyboardActions(); 271 272 ActionMap actionMap = new ActionMapUIResource(); 273 274 actionMap.put("aquaSelectNext", highlightNextAction); 275 actionMap.put("aquaSelectPrevious", highlightPreviousAction); 276 actionMap.put("aquaEnterPressed", triggerSelectionAction); 277 actionMap.put("aquaSpacePressed", toggleSelectionAction); 278 279 actionMap.put("aquaSelectHome", highlightFirstAction); 280 actionMap.put("aquaSelectEnd", highlightLastAction); 281 actionMap.put("aquaSelectPageUp", highlightPageUpAction); 282 actionMap.put("aquaSelectPageDown", highlightPageDownAction); 283 284 actionMap.put("aquaHidePopup", hideAction); 285 286 SwingUtilities.replaceUIActionMap(comboBox, actionMap); 287 } 288 289 abstract class ComboBoxAction extends AbstractAction { 290 public void actionPerformed(final ActionEvent e) { 291 if (!comboBox.isEnabled() || !comboBox.isShowing()) return; 292 293 if (comboBox.isPopupVisible()) { 294 final AquaComboBoxUI ui = (AquaComboBoxUI)comboBox.getUI(); 295 performComboBoxAction(ui); 296 } else { 297 comboBox.setPopupVisible(true); 298 } 299 } 300 301 abstract void performComboBoxAction(final AquaComboBoxUI ui); 302 } 303 304 /** 305 * Hilight _but do not select_ the next item in the list. 373 @Override 374 void performComboBoxAction(final AquaComboBoxUI ui) { 375 final int current = listBox.getSelectedIndex(); 376 final int last = listBox.getLastVisibleIndex(); 377 378 if (current != last) { 379 listBox.setSelectedIndex(last); 380 return; 381 } 382 383 final int page = listBox.getVisibleRect().height / listBox.getCellBounds(0, 0).height; 384 final int end = listBox.getModel().getSize() - 1; 385 int target = last + page; 386 if (target > end) target = end; 387 388 listBox.ensureIndexIsVisible(target); 389 listBox.setSelectedIndex(target); 390 } 391 }; 392 393 Action hideAction = new ComboBoxAction() { 394 @Override 395 void performComboBoxAction(final AquaComboBoxUI ui) { 396 comboBox.firePopupMenuCanceled(); 397 comboBox.setPopupVisible(false); 398 } 399 }; 400 401 // For <rdar://problem/3759984> Java 1.4.2_5: Serializing Swing components not working 402 // Inner classes were using a this reference and then trying to serialize the AquaComboBoxUI 403 // We shouldn't do that. But we need to be able to get the popup from other classes, so we need 404 // a public accessor. 405 public ComboPopup getPopup() { 406 return popup; 407 } 408 409 protected LayoutManager createLayoutManager() { 410 return new AquaComboBoxLayoutManager(); 411 } 412 413 class AquaComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager { 414 public void layoutContainer(final Container parent) { 415 if (arrowButton != null && !comboBox.isEditable()) { 416 final Insets insets = comboBox.getInsets(); 417 final int width = comboBox.getWidth(); 418 final int height = comboBox.getHeight(); 419 arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom)); 420 return; |