1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-29 18:52:13 +01:00

Mouse scroll wheel fix for MenuScroller

This commit is contained in:
Federico Fissore 2013-10-17 16:58:56 +02:00
parent 1877703920
commit 4a47eef28a

View File

@ -470,38 +470,46 @@ public class MenuScroller {
} }
private void refreshMenu() { private void refreshMenu() {
if (menuItems != null && menuItems.length > 0) { if (menuItems == null || menuItems.length == 0) {
firstIndex = Math.max(topFixedCount, firstIndex); return;
firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex); }
upItem.setEnabled(firstIndex > topFixedCount); int newFirstIndex = Math.max(topFixedCount, firstIndex);
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount); newFirstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, newFirstIndex);
menu.removeAll(); if (newFirstIndex < 0) {
for (int i = 0; i < topFixedCount; i++) { return;
menu.add(menuItems[i]); }
}
firstIndex = newFirstIndex;
upItem.setEnabled(firstIndex > topFixedCount);
downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);
menu.removeAll();
for (int i = 0; i < topFixedCount; i++) {
menu.add(menuItems[i]);
}
/*if (topFixedCount > 0) { /*if (topFixedCount > 0) {
menu.addSeparator(); menu.addSeparator();
}*/ }*/
menu.add(upItem); menu.add(upItem);
for (int i = firstIndex; i < scrollCount + firstIndex; i++) { for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
menu.add(menuItems[i]); menu.add(menuItems[i]);
} }
menu.add(downItem); menu.add(downItem);
/*if (bottomFixedCount > 0) { /*if (bottomFixedCount > 0) {
menu.addSeparator(); menu.addSeparator();
}*/ }*/
for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) { for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
menu.add(menuItems[i]); menu.add(menuItems[i]);
}
JComponent parent = (JComponent) upItem.getParent();
parent.revalidate();
parent.repaint();
} }
JComponent parent = (JComponent) upItem.getParent();
parent.revalidate();
parent.repaint();
} }
private class MouseScrollListener implements MouseWheelListener { private class MouseScrollListener implements MouseWheelListener {