Changeset 7291 in josm for trunk/src


Ignore:
Timestamp:
2014-07-05T18:38:07+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10207 - fix menu scroller for multi monitors systems

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r7186 r7291  
    88import java.awt.GraphicsEnvironment;
    99import java.awt.MenuComponent;
    10 import java.awt.Toolkit;
    1110import java.awt.event.ActionEvent;
    1211import java.util.ArrayList;
     
    108107    private void setupMenuScroller() {
    109108        if (!GraphicsEnvironment.isHeadless()) {
    110             int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    111109            int menuItemHeight = singleOffset.getPreferredSize().height;
    112             MenuScroller.setScrollerFor(this, (screenHeight / menuItemHeight)-1);
     110            MenuScroller.setScrollerFor(this,
     111                    MenuScroller.computeScrollCount(this, menuItemHeight));
    113112        }
    114113    }
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r7131 r7291  
    88import java.awt.Component;
    99import java.awt.GraphicsEnvironment;
    10 import java.awt.Toolkit;
    1110import java.awt.event.KeyEvent;
    1211import java.util.HashMap;
     
    571570        final JMenu menu = new JMenu(tr(name));
    572571        if (!GraphicsEnvironment.isHeadless()) {
    573             int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
    574572            int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height;
    575             MenuScroller.setScrollerFor(menu, screenHeight / menuItemHeight);
     573            MenuScroller.setScrollerFor(menu,
     574                    MenuScroller.computeScrollCount(menu, menuItemHeight));
    576575        }
    577576        return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic);
  • trunk/src/org/openstreetmap/josm/gui/MenuScroller.java

    r6987 r7291  
    99import java.awt.Dimension;
    1010import java.awt.Graphics;
     11import java.awt.GraphicsConfiguration;
     12import java.awt.Insets;
    1113import java.awt.event.ActionEvent;
    1214import java.awt.event.ActionListener;
     
    2628import javax.swing.event.PopupMenuListener;
    2729
     30import org.openstreetmap.josm.Main;
     31
    2832/**
    2933 * A class that provides scrolling capabilities to a long menu dropdown or
     
    3236 * <P>
    3337 * <B>Implementation note:</B>  The default number of items to display
    34  * at a time is 15, and the default scrolling interval is 125 milliseconds.
     38 * at a time is 15, and the default scrolling interval is 150 milliseconds.
    3539 * <P>
    3640 * @author Darryl, https://tips4java.wordpress.com/2009/02/01/menu-scroller/
     
    5155    private int keepVisibleIndex = -1;
    5256
     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
    5391    /**
    5492     * Registers a menu to be scrolled with the default number of items to
     
    177215     */
    178216    public MenuScroller(JMenu menu) {
    179         this(menu, 15);
     217        this(menu, computeScrollCount(menu, 30));
    180218    }
    181219
     
    188226     */
    189227    public MenuScroller(JPopupMenu menu) {
    190         this(menu, 15);
     228        this(menu, computeScrollCount(menu, 30));
    191229    }
    192230
     
    594632        @Override
    595633        public int getIconHeight() {
    596             return 10;
     634            return ARROW_ICON_HEIGHT;
    597635        }
    598636    }
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r6340 r7291  
    1111import java.awt.Graphics;
    1212import java.awt.GridBagLayout;
    13 import java.awt.Toolkit;
    1413import java.awt.event.ActionEvent;
    1514import java.awt.image.BufferedImage;
     
    206205        }
    207206        if (menuItemHeight > 0) {
    208             int scrollcount = (Toolkit.getDefaultToolkit().getScreenSize().height / menuItemHeight) - 1;
     207            int scrollcount = MenuScroller.computeScrollCount(subMenu, menuItemHeight);
    209208            if (subMenu instanceof JMenu) {
    210209                MenuScroller.setScrollerFor((JMenu) subMenu, scrollcount);
Note: See TracChangeset for help on using the changeset viewer.