Skip to content

Commit

Permalink
A way to make the scrolling menu on Tools | Boards menu more accessib…
Browse files Browse the repository at this point in the history
…le friendly - but it's ugly
  • Loading branch information
Joe Wegner committed Aug 23, 2019
1 parent 710667d commit a908b7b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/src/processing/app/tools/MenuScroller.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package processing.app.tools;

import processing.app.PreferencesData;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
Expand Down Expand Up @@ -278,6 +280,9 @@ public MenuScroller(JPopupMenu menu, int scrollCount, int interval,
scrollCount = autoSizeScrollCount;
}

// if (PreferencesData.getBoolean("ide.accessible")) {
// interval = 1000;
// }
if (scrollCount <= 0 || interval <= 0) {
throw new IllegalArgumentException("scrollCount and interval must be greater than 0");
}
Expand Down Expand Up @@ -567,6 +572,29 @@ public MenuScrollTimer(final int increment, int interval) {
public void actionPerformed(ActionEvent e) {
firstIndex += increment * accelerator;
refreshMenu();
if (PreferencesData.getBoolean("ide.accessible")) {
String itemClassName;
int keyEvent;
if (increment > 0) {
itemClassName = menuItems[firstIndex + scrollCount - 1].getClass().getName();
keyEvent = KeyEvent.VK_UP;
}
else {
itemClassName = menuItems[firstIndex].getClass().getName();
keyEvent = KeyEvent.VK_DOWN;
}

// if next item is a separator just go on like normal, otherwise move the cursor back to that item is read
// by a screen reader and the user can continue to use their arrow keys to navigate the list
if (!itemClassName.equals(JSeparator.class.getName()) ) {
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Component comp = manager.getFocusOwner();
KeyEvent event = new KeyEvent(comp,
KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0,
keyEvent, KeyEvent.CHAR_UNDEFINED);
comp.dispatchEvent(event);
}
}
}
});
}
Expand Down

0 comments on commit a908b7b

Please sign in to comment.