| 1 | /**
|
|---|
| 2 | * MenuScroller.java 1.5.0 04/02/12
|
|---|
| 3 | * License: use / modify without restrictions (see https://tips4java.wordpress.com/about/)
|
|---|
| 4 | * Heavily modified for JOSM needs => drop unused features and replace static scrollcount approach by dynamic behaviour
|
|---|
| 5 | */
|
|---|
| 6 | package org.openstreetmap.josm.gui;
|
|---|
| 7 |
|
|---|
| 8 | import java.awt.Color;
|
|---|
| 9 | import java.awt.Component;
|
|---|
| 10 | import java.awt.Dimension;
|
|---|
| 11 | import java.awt.Graphics;
|
|---|
| 12 | import java.awt.event.ActionEvent;
|
|---|
| 13 | import java.awt.event.ActionListener;
|
|---|
| 14 | import java.awt.event.MouseWheelEvent;
|
|---|
| 15 | import java.awt.event.MouseWheelListener;
|
|---|
| 16 | import java.util.Arrays;
|
|---|
| 17 |
|
|---|
| 18 | import javax.swing.Icon;
|
|---|
| 19 | import javax.swing.JMenu;
|
|---|
| 20 | import javax.swing.JMenuItem;
|
|---|
| 21 | import javax.swing.JPopupMenu;
|
|---|
| 22 | import javax.swing.JSeparator;
|
|---|
| 23 | import javax.swing.Timer;
|
|---|
| 24 | import javax.swing.event.ChangeEvent;
|
|---|
| 25 | import javax.swing.event.ChangeListener;
|
|---|
| 26 | import javax.swing.event.PopupMenuEvent;
|
|---|
| 27 | import javax.swing.event.PopupMenuListener;
|
|---|
| 28 |
|
|---|
| 29 | import org.openstreetmap.josm.gui.util.WindowGeometry;
|
|---|
| 30 | import org.openstreetmap.josm.tools.Logging;
|
|---|
| 31 |
|
|---|
| 32 | /**
|
|---|
| 33 | * A class that provides scrolling capabilities to a long menu dropdown or
|
|---|
| 34 | * popup menu. A number of items can optionally be frozen at the top of the menu.
|
|---|
| 35 | * <p>
|
|---|
| 36 | * <b>Implementation note:</B> The default scrolling interval is 150 milliseconds.
|
|---|
| 37 | * <p>
|
|---|
| 38 | * @author Darryl, https://tips4java.wordpress.com/2009/02/01/menu-scroller/
|
|---|
| 39 | * @since 4593
|
|---|
| 40 | */
|
|---|
| 41 | public class MenuScroller {
|
|---|
| 42 |
|
|---|
| 43 | private JPopupMenu menu;
|
|---|
| 44 | private Component[] menuItems;
|
|---|
| 45 | private final MenuScrollItem upItem;
|
|---|
| 46 | private final MenuScrollItem downItem;
|
|---|
| 47 | private final MenuScrollListener menuListener = new MenuScrollListener();
|
|---|
| 48 | private final MouseWheelListener mouseWheelListener = new MouseScrollListener();
|
|---|
| 49 | private int topFixedCount;
|
|---|
| 50 | private int firstIndex;
|
|---|
| 51 |
|
|---|
| 52 | private static final int ARROW_ICON_HEIGHT = 10;
|
|---|
| 53 |
|
|---|
| 54 | private int computeScrollCount(int startIndex) {
|
|---|
| 55 | int result = 15;
|
|---|
| 56 | if (menu != null) {
|
|---|
| 57 | // Compute max height of current screen
|
|---|
| 58 | int maxHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - MainApplication.getMainFrame().getInsets().top;
|
|---|
| 59 |
|
|---|
| 60 | // Remove top fixed part height
|
|---|
| 61 | if (topFixedCount > 0) {
|
|---|
| 62 | for (int i = 0; i < topFixedCount; i++) {
|
|---|
| 63 | maxHeight -= menuItems[i].getPreferredSize().height;
|
|---|
| 64 | }
|
|---|
| 65 | maxHeight -= new JSeparator().getPreferredSize().height;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | // Remove height of our two arrow items + insets
|
|---|
| 69 | maxHeight -= menu.getInsets().top;
|
|---|
| 70 | maxHeight -= upItem.getPreferredSize().height;
|
|---|
| 71 | maxHeight -= downItem.getPreferredSize().height;
|
|---|
| 72 | maxHeight -= menu.getInsets().bottom;
|
|---|
| 73 |
|
|---|
| 74 | // Compute scroll count
|
|---|
| 75 | result = 0;
|
|---|
| 76 | int height = 0;
|
|---|
| 77 | for (int i = startIndex; i < menuItems.length && height <= maxHeight; i++, result++) {
|
|---|
| 78 | height += menuItems[i].getPreferredSize().height;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | if (height > maxHeight) {
|
|---|
| 82 | // Remove extra item from count
|
|---|
| 83 | result--;
|
|---|
| 84 | } else {
|
|---|
| 85 | // Increase scroll count to take into account upper items that will be displayed
|
|---|
| 86 | // after firstIndex is updated
|
|---|
| 87 | for (int i = startIndex-1; i >= 0 && height <= maxHeight; i--, result++) {
|
|---|
| 88 | height += menuItems[i].getPreferredSize().height;
|
|---|
| 89 | }
|
|---|
| 90 | if (height > maxHeight) {
|
|---|
| 91 | result--;
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 | return result;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | * Registers a menu to be scrolled with the default scrolling interval.
|
|---|
| 100 | *
|
|---|
| 101 | * @param menu the menu
|
|---|
| 102 | * @return the MenuScroller
|
|---|
| 103 | */
|
|---|
| 104 | public static MenuScroller setScrollerFor(JMenu menu) {
|
|---|
| 105 | return new MenuScroller(menu);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | /**
|
|---|
| 109 | * Registers a popup menu to be scrolled with the default scrolling interval.
|
|---|
| 110 | *
|
|---|
| 111 | * @param menu the popup menu
|
|---|
| 112 | * @return the MenuScroller
|
|---|
| 113 | */
|
|---|
| 114 | public static MenuScroller setScrollerFor(JPopupMenu menu) {
|
|---|
| 115 | return new MenuScroller(menu);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * Registers a menu to be scrolled, with the specified scrolling interval.
|
|---|
| 120 | *
|
|---|
| 121 | * @param menu the menu
|
|---|
| 122 | * @param interval the scroll interval, in milliseconds
|
|---|
| 123 | * @return the MenuScroller
|
|---|
| 124 | * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
|---|
| 125 | * @since 7463
|
|---|
| 126 | */
|
|---|
| 127 | public static MenuScroller setScrollerFor(JMenu menu, int interval) {
|
|---|
| 128 | return new MenuScroller(menu, interval);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | /**
|
|---|
| 132 | * Registers a popup menu to be scrolled, with the specified scrolling interval.
|
|---|
| 133 | *
|
|---|
| 134 | * @param menu the popup menu
|
|---|
| 135 | * @param interval the scroll interval, in milliseconds
|
|---|
| 136 | * @return the MenuScroller
|
|---|
| 137 | * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
|---|
| 138 | * @since 7463
|
|---|
| 139 | */
|
|---|
| 140 | public static MenuScroller setScrollerFor(JPopupMenu menu, int interval) {
|
|---|
| 141 | return new MenuScroller(menu, interval);
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | /**
|
|---|
| 145 | * Registers a menu to be scrolled, with the specified scrolling interval,
|
|---|
| 146 | * and the specified numbers of items fixed at the top of the menu.
|
|---|
| 147 | *
|
|---|
| 148 | * @param menu the menu
|
|---|
| 149 | * @param interval the scroll interval, in milliseconds
|
|---|
| 150 | * @param topFixedCount the number of items to fix at the top. May be 0.
|
|---|
| 151 | * @return the MenuScroller
|
|---|
| 152 | * @throws IllegalArgumentException if scrollCount or interval is 0 or
|
|---|
| 153 | * negative or if topFixedCount is negative
|
|---|
| 154 | * @since 7463
|
|---|
| 155 | */
|
|---|
| 156 | public static MenuScroller setScrollerFor(JMenu menu, int interval, int topFixedCount) {
|
|---|
| 157 | return new MenuScroller(menu, interval, topFixedCount);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | /**
|
|---|
| 161 | * Registers a popup menu to be scrolled, with the specified scrolling interval,
|
|---|
| 162 | * and the specified numbers of items fixed at the top of the popup menu.
|
|---|
| 163 | *
|
|---|
| 164 | * @param menu the popup menu
|
|---|
| 165 | * @param interval the scroll interval, in milliseconds
|
|---|
| 166 | * @param topFixedCount the number of items to fix at the top. May be 0
|
|---|
| 167 | * @return the MenuScroller
|
|---|
| 168 | * @throws IllegalArgumentException if scrollCount or interval is 0 or
|
|---|
| 169 | * negative or if topFixedCount is negative
|
|---|
| 170 | * @since 7463
|
|---|
| 171 | */
|
|---|
| 172 | public static MenuScroller setScrollerFor(JPopupMenu menu, int interval, int topFixedCount) {
|
|---|
| 173 | return new MenuScroller(menu, interval, topFixedCount);
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | /**
|
|---|
| 177 | * Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
|---|
| 178 | * default scrolling interval.
|
|---|
| 179 | *
|
|---|
| 180 | * @param menu the menu
|
|---|
| 181 | * @throws IllegalArgumentException if scrollCount is 0 or negative
|
|---|
| 182 | */
|
|---|
| 183 | public MenuScroller(JMenu menu) {
|
|---|
| 184 | this(menu, 150);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | /**
|
|---|
| 188 | * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
|---|
| 189 | * default scrolling interval.
|
|---|
| 190 | *
|
|---|
| 191 | * @param menu the popup menu
|
|---|
| 192 | * @throws IllegalArgumentException if scrollCount is 0 or negative
|
|---|
| 193 | */
|
|---|
| 194 | public MenuScroller(JPopupMenu menu) {
|
|---|
| 195 | this(menu, 150);
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | /**
|
|---|
| 199 | * Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
|---|
| 200 | * specified scrolling interval.
|
|---|
| 201 | *
|
|---|
| 202 | * @param menu the menu
|
|---|
| 203 | * @param interval the scroll interval, in milliseconds
|
|---|
| 204 | * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
|---|
| 205 | * @since 7463
|
|---|
| 206 | */
|
|---|
| 207 | public MenuScroller(JMenu menu, int interval) {
|
|---|
| 208 | this(menu, interval, 0);
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /**
|
|---|
| 212 | * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
|---|
| 213 | * specified scrolling interval.
|
|---|
| 214 | *
|
|---|
| 215 | * @param menu the popup menu
|
|---|
| 216 | * @param interval the scroll interval, in milliseconds
|
|---|
| 217 | * @throws IllegalArgumentException if scrollCount or interval is 0 or negative
|
|---|
| 218 | * @since 7463
|
|---|
| 219 | */
|
|---|
| 220 | public MenuScroller(JPopupMenu menu, int interval) {
|
|---|
| 221 | this(menu, interval, 0);
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /**
|
|---|
| 225 | * Constructs a <code>MenuScroller</code> that scrolls a menu with the
|
|---|
| 226 | * specified scrolling interval, and the specified numbers of items fixed at
|
|---|
| 227 | * the top of the menu.
|
|---|
| 228 | *
|
|---|
| 229 | * @param menu the menu
|
|---|
| 230 | * @param interval the scroll interval, in milliseconds
|
|---|
| 231 | * @param topFixedCount the number of items to fix at the top. May be 0
|
|---|
| 232 | * @throws IllegalArgumentException if scrollCount or interval is 0 or
|
|---|
| 233 | * negative or if topFixedCount is negative
|
|---|
| 234 | * @since 7463
|
|---|
| 235 | */
|
|---|
| 236 | public MenuScroller(JMenu menu, int interval, int topFixedCount) {
|
|---|
| 237 | this(menu.getPopupMenu(), interval, topFixedCount);
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | /**
|
|---|
| 241 | * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the
|
|---|
| 242 | * specified scrolling interval, and the specified numbers of items fixed at
|
|---|
| 243 | * the top of the popup menu.
|
|---|
| 244 | *
|
|---|
| 245 | * @param menu the popup menu
|
|---|
| 246 | * @param interval the scroll interval, in milliseconds
|
|---|
| 247 | * @param topFixedCount the number of items to fix at the top. May be 0
|
|---|
| 248 | * @throws IllegalArgumentException if scrollCount or interval is 0 or
|
|---|
| 249 | * negative or if topFixedCount is negative
|
|---|
| 250 | * @since 7463
|
|---|
| 251 | */
|
|---|
| 252 | public MenuScroller(JPopupMenu menu, int interval, int topFixedCount) {
|
|---|
| 253 | if (interval <= 0) {
|
|---|
| 254 | throw new IllegalArgumentException("interval must be greater than 0");
|
|---|
| 255 | }
|
|---|
| 256 | if (topFixedCount < 0) {
|
|---|
| 257 | throw new IllegalArgumentException("topFixedCount cannot be negative");
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | upItem = new MenuScrollItem(MenuIcon.UP, -1, interval);
|
|---|
| 261 | downItem = new MenuScrollItem(MenuIcon.DOWN, +1, interval);
|
|---|
| 262 | setTopFixedCount(topFixedCount);
|
|---|
| 263 |
|
|---|
| 264 | this.menu = menu;
|
|---|
| 265 | menu.addPopupMenuListener(menuListener);
|
|---|
| 266 | menu.addMouseWheelListener(mouseWheelListener);
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | /**
|
|---|
| 270 | * Returns the number of items fixed at the top of the menu or popup menu.
|
|---|
| 271 | *
|
|---|
| 272 | * @return the number of items
|
|---|
| 273 | */
|
|---|
| 274 | public int getTopFixedCount() {
|
|---|
| 275 | return topFixedCount;
|
|---|
| 276 | }
|
|---|
| 277 |
|
|---|
| 278 | /**
|
|---|
| 279 | * Sets the number of items to fix at the top of the menu or popup menu.
|
|---|
| 280 | *
|
|---|
| 281 | * @param topFixedCount the number of items
|
|---|
| 282 | */
|
|---|
| 283 | public void setTopFixedCount(int topFixedCount) {
|
|---|
| 284 | if (firstIndex <= topFixedCount) {
|
|---|
| 285 | firstIndex = topFixedCount;
|
|---|
| 286 | } else {
|
|---|
| 287 | firstIndex += (topFixedCount - this.topFixedCount);
|
|---|
| 288 | }
|
|---|
| 289 | this.topFixedCount = topFixedCount;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | /**
|
|---|
| 293 | * Removes this MenuScroller from the associated menu and restores the
|
|---|
| 294 | * default behavior of the menu.
|
|---|
| 295 | */
|
|---|
| 296 | public void dispose() {
|
|---|
| 297 | if (menu != null) {
|
|---|
| 298 | menu.removePopupMenuListener(menuListener);
|
|---|
| 299 | menu.removeMouseWheelListener(mouseWheelListener);
|
|---|
| 300 | menu.setPreferredSize(null);
|
|---|
| 301 | menu = null;
|
|---|
| 302 | }
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | private void refreshMenu() {
|
|---|
| 306 | if (menuItems != null && menuItems.length > 0) {
|
|---|
| 307 |
|
|---|
| 308 | int allItemsHeight = Arrays.stream(menuItems).mapToInt(item -> item.getPreferredSize().height).sum();
|
|---|
| 309 | int allowedHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - MainApplication.getMainFrame().getInsets().top;
|
|---|
| 310 | boolean mustScroll = allItemsHeight > allowedHeight;
|
|---|
| 311 | if (mustScroll) {
|
|---|
| 312 | firstIndex = Math.min(menuItems.length-1, Math.max(topFixedCount, firstIndex));
|
|---|
| 313 | int scrollCount = computeScrollCount(firstIndex);
|
|---|
| 314 | firstIndex = Math.min(menuItems.length - scrollCount, firstIndex);
|
|---|
| 315 |
|
|---|
| 316 | upItem.setEnabled(firstIndex > topFixedCount);
|
|---|
| 317 | downItem.setEnabled(firstIndex + scrollCount < menuItems.length);
|
|---|
| 318 |
|
|---|
| 319 | menu.removeAll();
|
|---|
| 320 | for (int i = 0; i < topFixedCount; i++) {
|
|---|
| 321 | menu.add(menuItems[i]);
|
|---|
| 322 | }
|
|---|
| 323 | if (topFixedCount > 0) {
|
|---|
| 324 | menu.addSeparator();
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | menu.add(upItem);
|
|---|
| 328 | for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
|
|---|
| 329 | menu.add(menuItems[i]);
|
|---|
| 330 | }
|
|---|
| 331 | menu.add(downItem);
|
|---|
| 332 |
|
|---|
| 333 | int preferredWidth = 0;
|
|---|
| 334 | for (Component item : menuItems) {
|
|---|
| 335 | preferredWidth = Math.max(preferredWidth, item.getPreferredSize().width);
|
|---|
| 336 | }
|
|---|
| 337 | menu.setPreferredSize(new Dimension(preferredWidth, menu.getPreferredSize().height));
|
|---|
| 338 |
|
|---|
| 339 | } else if (!Arrays.equals(menu.getComponents(), menuItems)) {
|
|---|
| 340 | // Scroll is not needed but menu is not up to date
|
|---|
| 341 | menu.removeAll();
|
|---|
| 342 | for (Component item : menuItems) {
|
|---|
| 343 | menu.add(item);
|
|---|
| 344 | }
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | menu.revalidate();
|
|---|
| 348 | menu.repaint();
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | private final class MenuScrollListener implements PopupMenuListener {
|
|---|
| 353 |
|
|---|
| 354 | @Override
|
|---|
| 355 | public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
|---|
| 356 | setMenuItems();
|
|---|
| 357 | }
|
|---|
| 358 |
|
|---|
| 359 | @Override
|
|---|
| 360 | public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
|---|
| 361 | restoreMenuItems();
|
|---|
| 362 | }
|
|---|
| 363 |
|
|---|
| 364 | @Override
|
|---|
| 365 | public void popupMenuCanceled(PopupMenuEvent e) {
|
|---|
| 366 | restoreMenuItems();
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | private void setMenuItems() {
|
|---|
| 370 | menuItems = menu.getComponents();
|
|---|
| 371 | refreshMenu();
|
|---|
| 372 | }
|
|---|
| 373 |
|
|---|
| 374 | private void restoreMenuItems() {
|
|---|
| 375 | menu.removeAll();
|
|---|
| 376 | for (Component component : menuItems) {
|
|---|
| 377 | menu.add(component);
|
|---|
| 378 | }
|
|---|
| 379 | }
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | private class MenuScrollTimer extends Timer {
|
|---|
| 383 |
|
|---|
| 384 | MenuScrollTimer(final int increment, int interval) {
|
|---|
| 385 | super(interval, new ActionListener() {
|
|---|
| 386 |
|
|---|
| 387 | @Override
|
|---|
| 388 | public void actionPerformed(ActionEvent e) {
|
|---|
| 389 | firstIndex += increment;
|
|---|
| 390 | refreshMenu();
|
|---|
| 391 | }
|
|---|
| 392 | });
|
|---|
| 393 | }
|
|---|
| 394 | }
|
|---|
| 395 |
|
|---|
| 396 | private class MenuScrollItem extends JMenuItem
|
|---|
| 397 | implements ChangeListener {
|
|---|
| 398 |
|
|---|
| 399 | private final MenuScrollTimer timer;
|
|---|
| 400 |
|
|---|
| 401 | MenuScrollItem(MenuIcon icon, int increment, int interval) {
|
|---|
| 402 | setIcon(icon);
|
|---|
| 403 | setDisabledIcon(icon);
|
|---|
| 404 | timer = new MenuScrollTimer(increment, interval);
|
|---|
| 405 | addChangeListener(this);
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | @Override
|
|---|
| 409 | public void stateChanged(ChangeEvent e) {
|
|---|
| 410 | if (isArmed() && !timer.isRunning()) {
|
|---|
| 411 | timer.start();
|
|---|
| 412 | }
|
|---|
| 413 | if (!isArmed() && timer.isRunning()) {
|
|---|
| 414 | timer.stop();
|
|---|
| 415 | }
|
|---|
| 416 | }
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 | private enum MenuIcon implements Icon {
|
|---|
| 420 |
|
|---|
| 421 | UP(9, 1, 9),
|
|---|
| 422 | DOWN(1, 9, 1);
|
|---|
| 423 | private static final int[] XPOINTS = {1, 5, 9};
|
|---|
| 424 | @SuppressWarnings("ImmutableEnumChecker")
|
|---|
| 425 | private final int[] yPoints;
|
|---|
| 426 |
|
|---|
| 427 | MenuIcon(int... yPoints) {
|
|---|
| 428 | this.yPoints = yPoints;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | @Override
|
|---|
| 432 | public void paintIcon(Component c, Graphics g, int x, int y) {
|
|---|
| 433 | Dimension size = c.getSize();
|
|---|
| 434 | Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
|
|---|
| 435 | g2.setColor(Color.GRAY);
|
|---|
| 436 | g2.drawPolygon(XPOINTS, yPoints, 3);
|
|---|
| 437 | if (c.isEnabled()) {
|
|---|
| 438 | g2.setColor(Color.BLACK);
|
|---|
| 439 | g2.fillPolygon(XPOINTS, yPoints, 3);
|
|---|
| 440 | }
|
|---|
| 441 | g2.dispose();
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | @Override
|
|---|
| 445 | public int getIconWidth() {
|
|---|
| 446 | return 0;
|
|---|
| 447 | }
|
|---|
| 448 |
|
|---|
| 449 | @Override
|
|---|
| 450 | public int getIconHeight() {
|
|---|
| 451 | return ARROW_ICON_HEIGHT;
|
|---|
| 452 | }
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | private final class MouseScrollListener implements MouseWheelListener {
|
|---|
| 456 | @Override
|
|---|
| 457 | public void mouseWheelMoved(MouseWheelEvent mwe) {
|
|---|
| 458 | firstIndex += mwe.getWheelRotation();
|
|---|
| 459 | refreshMenu();
|
|---|
| 460 | if (Logging.isDebugEnabled()) {
|
|---|
| 461 | Logging.debug("{0} consuming event {1}", getClass().getName(), mwe);
|
|---|
| 462 | }
|
|---|
| 463 | mwe.consume();
|
|---|
| 464 | }
|
|---|
| 465 | }
|
|---|
| 466 | }
|
|---|