|
3 | 3 | */ |
4 | 4 | package processing.app.tools; |
5 | 5 |
|
| 6 | +import processing.app.PreferencesData; |
| 7 | + |
6 | 8 | import javax.swing.*; |
7 | 9 | import javax.swing.event.ChangeEvent; |
8 | 10 | import javax.swing.event.ChangeListener; |
@@ -278,6 +280,9 @@ public MenuScroller(JPopupMenu menu, int scrollCount, int interval, |
278 | 280 | scrollCount = autoSizeScrollCount; |
279 | 281 | } |
280 | 282 |
|
| 283 | +// if (PreferencesData.getBoolean("ide.accessible")) { |
| 284 | +// interval = 1000; |
| 285 | +// } |
281 | 286 | if (scrollCount <= 0 || interval <= 0) { |
282 | 287 | throw new IllegalArgumentException("scrollCount and interval must be greater than 0"); |
283 | 288 | } |
@@ -567,6 +572,29 @@ public MenuScrollTimer(final int increment, int interval) { |
567 | 572 | public void actionPerformed(ActionEvent e) { |
568 | 573 | firstIndex += increment * accelerator; |
569 | 574 | refreshMenu(); |
| 575 | + if (PreferencesData.getBoolean("ide.accessible")) { |
| 576 | + String itemClassName; |
| 577 | + int keyEvent; |
| 578 | + if (increment > 0) { |
| 579 | + itemClassName = menuItems[firstIndex + scrollCount - 1].getClass().getName(); |
| 580 | + keyEvent = KeyEvent.VK_UP; |
| 581 | + } |
| 582 | + else { |
| 583 | + itemClassName = menuItems[firstIndex].getClass().getName(); |
| 584 | + keyEvent = KeyEvent.VK_DOWN; |
| 585 | + } |
| 586 | + |
| 587 | + // if next item is a separator just go on like normal, otherwise move the cursor back to that item is read |
| 588 | + // by a screen reader and the user can continue to use their arrow keys to navigate the list |
| 589 | + if (!itemClassName.equals(JSeparator.class.getName()) ) { |
| 590 | + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); |
| 591 | + Component comp = manager.getFocusOwner(); |
| 592 | + KeyEvent event = new KeyEvent(comp, |
| 593 | + KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, |
| 594 | + keyEvent, KeyEvent.CHAR_UNDEFINED); |
| 595 | + comp.dispatchEvent(event); |
| 596 | + } |
| 597 | + } |
570 | 598 | } |
571 | 599 | }); |
572 | 600 | } |
|
0 commit comments