Changeset 7291 in josm for trunk/src/org
- Timestamp:
- 2014-07-05T18:38:07+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
r7186 r7291 8 8 import java.awt.GraphicsEnvironment; 9 9 import java.awt.MenuComponent; 10 import java.awt.Toolkit;11 10 import java.awt.event.ActionEvent; 12 11 import java.util.ArrayList; … … 108 107 private void setupMenuScroller() { 109 108 if (!GraphicsEnvironment.isHeadless()) { 110 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;111 109 int menuItemHeight = singleOffset.getPreferredSize().height; 112 MenuScroller.setScrollerFor(this, (screenHeight / menuItemHeight)-1); 110 MenuScroller.setScrollerFor(this, 111 MenuScroller.computeScrollCount(this, menuItemHeight)); 113 112 } 114 113 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r7131 r7291 8 8 import java.awt.Component; 9 9 import java.awt.GraphicsEnvironment; 10 import java.awt.Toolkit;11 10 import java.awt.event.KeyEvent; 12 11 import java.util.HashMap; … … 571 570 final JMenu menu = new JMenu(tr(name)); 572 571 if (!GraphicsEnvironment.isHeadless()) { 573 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;574 572 int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height; 575 MenuScroller.setScrollerFor(menu, screenHeight / menuItemHeight); 573 MenuScroller.setScrollerFor(menu, 574 MenuScroller.computeScrollCount(menu, menuItemHeight)); 576 575 } 577 576 return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic); -
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 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r6340 r7291 11 11 import java.awt.Graphics; 12 12 import java.awt.GridBagLayout; 13 import java.awt.Toolkit;14 13 import java.awt.event.ActionEvent; 15 14 import java.awt.image.BufferedImage; … … 206 205 } 207 206 if (menuItemHeight > 0) { 208 int scrollcount = (Toolkit.getDefaultToolkit().getScreenSize().height / menuItemHeight) - 1;207 int scrollcount = MenuScroller.computeScrollCount(subMenu, menuItemHeight); 209 208 if (subMenu instanceof JMenu) { 210 209 MenuScroller.setScrollerFor((JMenu) subMenu, scrollcount);
Note:
See TracChangeset
for help on using the changeset viewer.