Changeset 7291 in josm for trunk/src/org/openstreetmap/josm/gui/MenuScroller.java
- Timestamp:
- 2014-07-05T18:38:07+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MenuScroller.java
r6987 r7291 9 9 import java.awt.Dimension; 10 10 import java.awt.Graphics; 11 import java.awt.GraphicsConfiguration; 12 import java.awt.Insets; 11 13 import java.awt.event.ActionEvent; 12 14 import java.awt.event.ActionListener; … … 26 28 import javax.swing.event.PopupMenuListener; 27 29 30 import org.openstreetmap.josm.Main; 31 28 32 /** 29 33 * A class that provides scrolling capabilities to a long menu dropdown or … … 32 36 * <P> 33 37 * <B>Implementation note:</B> The default number of items to display 34 * at a time is 15, and the default scrolling interval is 1 25milliseconds.38 * at a time is 15, and the default scrolling interval is 150 milliseconds. 35 39 * <P> 36 40 * @author Darryl, https://tips4java.wordpress.com/2009/02/01/menu-scroller/ … … 51 55 private int keepVisibleIndex = -1; 52 56 57 private static final int ARROW_ICON_HEIGHT = 10; 58 59 /** 60 * Computes the number of items to display at once for the given component and a given item height. 61 * @param comp The menu 62 * @param itemHeight Average item height 63 * @return the number of items to display at once 64 * @since 7291 65 */ 66 public static int computeScrollCount(JComponent comp, int itemHeight) { 67 int result = 15; 68 if (comp != null && itemHeight > 0) { 69 // Compute max height of current screen 70 int maxHeight = 0; 71 GraphicsConfiguration gc = comp.getGraphicsConfiguration(); 72 if (gc == null && Main.parent != null) { 73 gc = Main.parent.getGraphicsConfiguration(); 74 } 75 if (gc != null) { 76 // Max displayable height (max screen height - vertical insets) 77 Insets insets = comp.getToolkit().getScreenInsets(gc); 78 maxHeight = gc.getBounds().height - insets.top - insets.bottom; 79 } 80 81 // Remove height of our two arrow icons + 2 pixels each for borders (arbitrary value) 82 maxHeight -= 2*(ARROW_ICON_HEIGHT+2); 83 84 if (maxHeight > 0) { 85 result = (maxHeight/itemHeight)-2; 86 } 87 } 88 return result; 89 } 90 53 91 /** 54 92 * Registers a menu to be scrolled with the default number of items to … … 177 215 */ 178 216 public MenuScroller(JMenu menu) { 179 this(menu, 15);217 this(menu, computeScrollCount(menu, 30)); 180 218 } 181 219 … … 188 226 */ 189 227 public MenuScroller(JPopupMenu menu) { 190 this(menu, 15);228 this(menu, computeScrollCount(menu, 30)); 191 229 } 192 230 … … 594 632 @Override 595 633 public int getIconHeight() { 596 return 10;634 return ARROW_ICON_HEIGHT; 597 635 } 598 636 }
Note:
See TracChangeset
for help on using the changeset viewer.