Changeset 7463 in josm
- Timestamp:
- 2014-08-30T01:59:31+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r7005 r7463 54 54 } 55 55 56 /* (non-Javadoc)57 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#download(boolean, org.openstreetmap.josm.data.Bounds, org.openstreetmap.josm.gui.progress.ProgressMonitor)58 */59 56 @Override 60 57 public Future<?> download(boolean newLayer, Bounds downloadArea, … … 63 60 } 64 61 65 /* (non-Javadoc)66 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask#loadUrl(boolean, java.lang.String, org.openstreetmap.josm.gui.progress.ProgressMonitor)67 */68 62 @Override 69 63 public Future<?> loadUrl(boolean new_layer, String url, … … 84 78 } 85 79 86 /* (non-Javadoc)87 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask.DownloadTask#parseDataSet()88 */89 80 @Override 90 81 protected DataSet parseDataSet() throws OsmTransferException { … … 92 83 } 93 84 94 /* (non-Javadoc)95 * @see org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask.DownloadTask#finish()96 */97 85 @Override 98 86 protected void finish() { -
trunk/src/org/openstreetmap/josm/actions/search/PushbackTokenizer.java
r7083 r7463 32 32 } 33 33 34 /* (non-Javadoc)35 * @see java.lang.Object#toString()36 */37 34 @Override 38 35 public String toString() { -
trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java
r7291 r7463 33 33 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 34 34 import org.openstreetmap.josm.data.imagery.Shape; 35 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 35 36 import org.openstreetmap.josm.gui.layer.ImageryLayer; 36 37 import org.openstreetmap.josm.gui.layer.Layer; … … 38 39 import org.openstreetmap.josm.tools.ImageProvider; 39 40 40 public class ImageryMenu extends JMenu implements MapView.LayerChangeListener { 41 /** 42 * Imagery menu, holding entries for imagery preferences, offset actions and dynamic imagery entries 43 * depending on current maview coordinates. 44 * @since 3737 45 */ 46 public class ImageryMenu extends JMenu implements LayerChangeListener { 41 47 42 48 private Action offsetAction = new JosmAction( … … 83 89 private final MapRectifierWMSmenuAction rectaction = new MapRectifierWMSmenuAction(); 84 90 91 /** 92 * Constructs a new {@code ImageryMenu}. 93 * @param subMenu submenu in that contains plugin-managed additional imagery layers 94 */ 85 95 public ImageryMenu(JMenu subMenu) { 86 96 super(tr("Imagery")); … … 107 117 private void setupMenuScroller() { 108 118 if (!GraphicsEnvironment.isHeadless()) { 109 int menuItemHeight = singleOffset.getPreferredSize().height; 110 MenuScroller.setScrollerFor(this, 111 MenuScroller.computeScrollCount(this, menuItemHeight)); 119 MenuScroller.setScrollerFor(this, 150, 2); 112 120 } 113 121 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r7291 r7463 570 570 final JMenu menu = new JMenu(tr(name)); 571 571 if (!GraphicsEnvironment.isHeadless()) { 572 int menuItemHeight = new JMenu().add(newAction).getPreferredSize().height; 573 MenuScroller.setScrollerFor(menu, 574 MenuScroller.computeScrollCount(menu, menuItemHeight)); 572 MenuScroller.setScrollerFor(menu); 575 573 } 576 574 return addMenu(menu, name, mnemonicKey, position, relativeHelpTopic); -
trunk/src/org/openstreetmap/josm/gui/MenuScroller.java
r7452 r7463 2 2 * MenuScroller.java 1.5.0 04/02/12 3 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 4 5 */ 5 6 package org.openstreetmap.josm.gui; … … 9 10 import java.awt.Dimension; 10 11 import java.awt.Graphics; 11 import java.awt.GraphicsConfiguration;12 import java.awt.Insets;13 12 import java.awt.event.ActionEvent; 14 13 import java.awt.event.ActionListener; 15 14 import java.awt.event.MouseWheelEvent; 16 15 import java.awt.event.MouseWheelListener; 16 import java.util.Arrays; 17 17 18 18 import javax.swing.Icon; 19 import javax.swing.J Component;19 import javax.swing.JFrame; 20 20 import javax.swing.JMenu; 21 21 import javax.swing.JMenuItem; 22 22 import javax.swing.JPopupMenu; 23 23 import javax.swing.JSeparator; 24 import javax.swing.MenuSelectionManager;25 24 import javax.swing.Timer; 26 25 import javax.swing.event.ChangeEvent; … … 30 29 31 30 import org.openstreetmap.josm.Main; 31 import org.openstreetmap.josm.tools.WindowGeometry; 32 32 33 33 /** 34 34 * A class that provides scrolling capabilities to a long menu dropdown or 35 35 * popup menu. A number of items can optionally be frozen at the top of the menu. 36 * <P> 37 * <B>Implementation note:</B> The default number of items to display 38 * at a time is 15, and the default scrolling interval is 150 milliseconds. 39 * <P> 36 * <p> 37 * <b>Implementation note:</B> The default scrolling interval is 150 milliseconds. 38 * <p> 40 39 * @author Darryl, https://tips4java.wordpress.com/2009/02/01/menu-scroller/ 40 * @since 4593 41 41 */ 42 42 public class MenuScroller { … … 48 48 private final MenuScrollListener menuListener = new MenuScrollListener(); 49 49 private final MouseWheelListener mouseWheelListener = new MouseScrollListener(); 50 private int scrollCount;51 50 private int interval; 52 51 private int topFixedCount; 53 52 private int firstIndex = 0; 54 private int keepVisibleIndex = -1;55 53 56 54 private static final int ARROW_ICON_HEIGHT = 10; 57 55 58 /** 59 * Computes the number of items to display at once for the given component and a given item height. 60 * @param comp The menu 61 * @param itemHeight Average item height 62 * @return the number of items to display at once 63 * @since 7291 64 */ 65 public static int computeScrollCount(JComponent comp, int itemHeight) { 56 private int computeScrollCount(int startIndex) { 66 57 int result = 15; 67 if ( comp != null && itemHeight > 0) {58 if (menu != null) { 68 59 // Compute max height of current screen 69 int maxHeight = 0; 70 GraphicsConfiguration gc = comp.getGraphicsConfiguration(); 71 if (gc == null && Main.parent != null) { 72 gc = Main.parent.getGraphicsConfiguration(); 73 } 74 if (gc != null) { 75 // Max displayable height (max screen height - vertical insets) 76 Insets insets = comp.getToolkit().getScreenInsets(gc); 77 maxHeight = gc.getBounds().height - insets.top - insets.bottom; 78 } 79 80 // Remove height of our two arrow icons + 2 pixels each for borders (arbitrary value) 81 maxHeight -= 2*(ARROW_ICON_HEIGHT+2); 82 83 if (maxHeight > 0) { 84 result = (maxHeight/itemHeight)-1; 60 int maxHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - ((JFrame)Main.parent).getInsets().top; 61 62 // Remove top fixed part height 63 if (topFixedCount > 0) { 64 for (int i = 0; i < topFixedCount; i++) { 65 maxHeight -= menuItems[i].getPreferredSize().height; 66 } 67 maxHeight -= new JSeparator().getPreferredSize().height; 68 } 69 70 // Remove height of our two arrow items + insets 71 maxHeight -= menu.getInsets().top; 72 maxHeight -= upItem.getPreferredSize().height; 73 maxHeight -= downItem.getPreferredSize().height; 74 maxHeight -= menu.getInsets().bottom; 75 76 // Compute scroll count 77 result = 0; 78 int height = 0; 79 for (int i = startIndex; i < menuItems.length && height <= maxHeight; i++, result++) { 80 height += menuItems[i].getPreferredSize().height; 81 } 82 83 if (height > maxHeight) { 84 // Remove extra item from count 85 result--; 86 } else { 87 // Increase scroll count to take into account upper items that will be displayed 88 // after firstIndex is updated 89 for (int i=startIndex-1; i >= 0 && height <= maxHeight; i--, result++) { 90 height += menuItems[i].getPreferredSize().height; 91 } 92 if (height > maxHeight) { 93 result--; 94 } 85 95 } 86 96 } … … 89 99 90 100 /** 91 * Registers a menu to be scrolled with the default number of items to 92 * display at a time and the default scrolling interval. 101 * Registers a menu to be scrolled with the default scrolling interval. 93 102 * 94 103 * @param menu the menu … … 100 109 101 110 /** 102 * Registers a popup menu to be scrolled with the default number of items to 103 * display at a time and the default scrolling interval. 111 * Registers a popup menu to be scrolled with the default scrolling interval. 104 112 * 105 113 * @param menu the popup menu … … 111 119 112 120 /** 113 * Registers a menu to be scrolled with the default number of items to 114 * display at a time and the specified scrolling interval. 121 * Registers a menu to be scrolled, with the specified scrolling interval. 115 122 * 116 123 * @param menu the menu 117 * @param scrollCount the number of items to display at a time118 * @return the MenuScroller119 * @throws IllegalArgumentException if scrollCount is 0 or negative120 */121 public static MenuScroller setScrollerFor(JMenu menu, int scrollCount) {122 return new MenuScroller(menu, scrollCount);123 }124 125 /**126 * Registers a popup menu to be scrolled with the default number of items to127 * display at a time and the specified scrolling interval.128 *129 * @param menu the popup menu130 * @param scrollCount the number of items to display at a time131 * @return the MenuScroller132 * @throws IllegalArgumentException if scrollCount is 0 or negative133 */134 public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount) {135 return new MenuScroller(menu, scrollCount);136 }137 138 /**139 * Registers a menu to be scrolled, with the specified number of items to140 * display at a time and the specified scrolling interval.141 *142 * @param menu the menu143 * @param scrollCount the number of items to be displayed at a time144 124 * @param interval the scroll interval, in milliseconds 145 125 * @return the MenuScroller 146 126 * @throws IllegalArgumentException if scrollCount or interval is 0 or negative 147 * /148 public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval) {149 return new MenuScroller(menu, scrollCount, interval);150 }151 152 /** 153 * Registers a popup menu to be scrolled, with the specified number of items to154 * display at a time andthe specified scrolling interval.127 * @since 7463 128 */ 129 public static MenuScroller setScrollerFor(JMenu menu, int interval) { 130 return new MenuScroller(menu, interval); 131 } 132 133 /** 134 * Registers a popup menu to be scrolled, with the specified scrolling interval. 155 135 * 156 136 * @param menu the popup menu 157 * @param scrollCount the number of items to be displayed at a time158 137 * @param interval the scroll interval, in milliseconds 159 138 * @return the MenuScroller 160 139 * @throws IllegalArgumentException if scrollCount or interval is 0 or negative 161 * /162 public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval) {163 return new MenuScroller(menu, scrollCount, interval);164 }165 166 /** 167 * Registers a menu to be scrolled, with the specified number of items168 * to display in the scrolling region,the specified scrolling interval,140 * @since 7463 141 */ 142 public static MenuScroller setScrollerFor(JPopupMenu menu, int interval) { 143 return new MenuScroller(menu, interval); 144 } 145 146 /** 147 * Registers a menu to be scrolled, with the specified scrolling interval, 169 148 * and the specified numbers of items fixed at the top of the menu. 170 149 * 171 150 * @param menu the menu 172 * @param scrollCount the number of items to display in the scrolling portion173 151 * @param interval the scroll interval, in milliseconds 174 152 * @param topFixedCount the number of items to fix at the top. May be 0. … … 176 154 * negative or if topFixedCount is negative 177 155 * @return the MenuScroller 178 */ 179 public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval, 180 int topFixedCount) { 181 return new MenuScroller(menu, scrollCount, interval, topFixedCount); 182 } 183 184 /** 185 * Registers a popup menu to be scrolled, with the specified number of items 186 * to display in the scrolling region, the specified scrolling interval, 156 * @since 7463 157 */ 158 public static MenuScroller setScrollerFor(JMenu menu, int interval, int topFixedCount) { 159 return new MenuScroller(menu, interval, topFixedCount); 160 } 161 162 /** 163 * Registers a popup menu to be scrolled, with the specified scrolling interval, 187 164 * and the specified numbers of items fixed at the top of the popup menu. 188 165 * 189 166 * @param menu the popup menu 190 * @param scrollCount the number of items to display in the scrolling portion 167 * @param interval the scroll interval, in milliseconds 168 * @param topFixedCount the number of items to fix at the top. May be 0 169 * @throws IllegalArgumentException if scrollCount or interval is 0 or 170 * negative or if topFixedCount is negative 171 * @return the MenuScroller 172 * @since 7463 173 */ 174 public static MenuScroller setScrollerFor(JPopupMenu menu, int interval, int topFixedCount) { 175 return new MenuScroller(menu, interval, topFixedCount); 176 } 177 178 /** 179 * Constructs a <code>MenuScroller</code> that scrolls a menu with the 180 * default scrolling interval. 181 * 182 * @param menu the menu 183 * @throws IllegalArgumentException if scrollCount is 0 or negative 184 */ 185 public MenuScroller(JMenu menu) { 186 this(menu, 150); 187 } 188 189 /** 190 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the 191 * default scrolling interval. 192 * 193 * @param menu the popup menu 194 * @throws IllegalArgumentException if scrollCount is 0 or negative 195 */ 196 public MenuScroller(JPopupMenu menu) { 197 this(menu, 150); 198 } 199 200 /** 201 * Constructs a <code>MenuScroller</code> that scrolls a menu with the 202 * specified scrolling interval. 203 * 204 * @param menu the menu 205 * @param interval the scroll interval, in milliseconds 206 * @throws IllegalArgumentException if scrollCount or interval is 0 or negative 207 * @since 7463 208 */ 209 public MenuScroller(JMenu menu, int interval) { 210 this(menu, interval, 0); 211 } 212 213 /** 214 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the 215 * specified scrolling interval. 216 * 217 * @param menu the popup menu 218 * @param interval the scroll interval, in milliseconds 219 * @throws IllegalArgumentException if scrollCount or interval is 0 or negative 220 * @since 7463 221 */ 222 public MenuScroller(JPopupMenu menu, int interval) { 223 this(menu, interval, 0); 224 } 225 226 /** 227 * Constructs a <code>MenuScroller</code> that scrolls a menu with the 228 * specified scrolling interval, and the specified numbers of items fixed at 229 * the top of the menu. 230 * 231 * @param menu the menu 191 232 * @param interval the scroll interval, in milliseconds 192 233 * @param topFixedCount the number of items to fix at the top. May be 0 193 234 * @throws IllegalArgumentException if scrollCount or interval is 0 or 194 235 * negative or if topFixedCount is negative 195 * @return the MenuScroller 196 */ 197 public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval, 198 int topFixedCount) { 199 return new MenuScroller(menu, scrollCount, interval, topFixedCount); 200 } 201 202 /** 203 * Constructs a <code>MenuScroller</code> that scrolls a menu with the 204 * default number of items to display at a time, and default scrolling 205 * interval. 206 * 207 * @param menu the menu 208 */ 209 public MenuScroller(JMenu menu) { 210 this(menu, computeScrollCount(menu, 30)); 236 * @since 7463 237 */ 238 public MenuScroller(JMenu menu, int interval, int topFixedCount) { 239 this(menu.getPopupMenu(), interval, topFixedCount); 211 240 } 212 241 213 242 /** 214 243 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the 215 * default number of items to display at a time, and default scrolling216 * interval.244 * specified scrolling interval, and the specified numbers of items fixed at 245 * the top of the popup menu. 217 246 * 218 247 * @param menu the popup menu 219 */220 public MenuScroller(JPopupMenu menu) {221 this(menu, computeScrollCount(menu, 30));222 }223 224 /**225 * Constructs a <code>MenuScroller</code> that scrolls a menu with the226 * specified number of items to display at a time, and default scrolling227 * interval.228 *229 * @param menu the menu230 * @param scrollCount the number of items to display at a time231 * @throws IllegalArgumentException if scrollCount is 0 or negative232 */233 public MenuScroller(JMenu menu, int scrollCount) {234 this(menu, scrollCount, 150);235 }236 237 /**238 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the239 * specified number of items to display at a time, and default scrolling240 * interval.241 *242 * @param menu the popup menu243 * @param scrollCount the number of items to display at a time244 * @throws IllegalArgumentException if scrollCount is 0 or negative245 */246 public MenuScroller(JPopupMenu menu, int scrollCount) {247 this(menu, scrollCount, 150);248 }249 250 /**251 * Constructs a <code>MenuScroller</code> that scrolls a menu with the252 * specified number of items to display at a time, and specified scrolling253 * interval.254 *255 * @param menu the menu256 * @param scrollCount the number of items to display at a time257 * @param interval the scroll interval, in milliseconds258 * @throws IllegalArgumentException if scrollCount or interval is 0 or negative259 */260 public MenuScroller(JMenu menu, int scrollCount, int interval) {261 this(menu, scrollCount, interval, 0);262 }263 264 /**265 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the266 * specified number of items to display at a time, and specified scrolling267 * interval.268 *269 * @param menu the popup menu270 * @param scrollCount the number of items to display at a time271 * @param interval the scroll interval, in milliseconds272 * @throws IllegalArgumentException if scrollCount or interval is 0 or negative273 */274 public MenuScroller(JPopupMenu menu, int scrollCount, int interval) {275 this(menu, scrollCount, interval, 0);276 }277 278 /**279 * Constructs a <code>MenuScroller</code> that scrolls a menu with the280 * specified number of items to display in the scrolling region, the281 * specified scrolling interval, and the specified numbers of items fixed at282 * the top of the menu.283 *284 * @param menu the menu285 * @param scrollCount the number of items to display in the scrolling portion286 248 * @param interval the scroll interval, in milliseconds 287 249 * @param topFixedCount the number of items to fix at the top. May be 0 288 250 * @throws IllegalArgumentException if scrollCount or interval is 0 or 289 251 * negative or if topFixedCount is negative 290 */ 291 public MenuScroller(JMenu menu, int scrollCount, int interval, int topFixedCount) { 292 this(menu.getPopupMenu(), scrollCount, interval, topFixedCount); 293 } 294 295 /** 296 * Constructs a <code>MenuScroller</code> that scrolls a popup menu with the 297 * specified number of items to display in the scrolling region, the 298 * specified scrolling interval, and the specified numbers of items fixed at 299 * the top of the popup menu. 300 * 301 * @param menu the popup menu 302 * @param scrollCount the number of items to display in the scrolling portion 303 * @param interval the scroll interval, in milliseconds 304 * @param topFixedCount the number of items to fix at the top. May be 0 305 * @throws IllegalArgumentException if scrollCount or interval is 0 or 306 * negative or if topFixedCount is negative 307 */ 308 public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount) { 309 if (scrollCount <= 0 || interval <= 0) { 310 throw new IllegalArgumentException("scrollCount and interval must be greater than 0"); 252 * @since 7463 253 */ 254 public MenuScroller(JPopupMenu menu, int interval, int topFixedCount) { 255 if (interval <= 0) { 256 throw new IllegalArgumentException("interval must be greater than 0"); 311 257 } 312 258 if (topFixedCount < 0) { … … 316 262 upItem = new MenuScrollItem(MenuIcon.UP, -1); 317 263 downItem = new MenuScrollItem(MenuIcon.DOWN, +1); 318 setScrollCount(scrollCount);319 264 setInterval(interval); 320 265 setTopFixedCount(topFixedCount); … … 347 292 downItem.setInterval(interval); 348 293 this.interval = interval; 349 }350 351 /**352 * Returns the number of items in the scrolling portion of the menu.353 *354 * @return the number of items to display at a time355 */356 public int getscrollCount() {357 return scrollCount;358 }359 360 /**361 * Sets the number of items in the scrolling portion of the menu.362 *363 * @param scrollCount the number of items to display at a time364 * @throws IllegalArgumentException if scrollCount is 0 or negative365 */366 public void setScrollCount(int scrollCount) {367 if (scrollCount <= 0) {368 throw new IllegalArgumentException("scrollCount must be greater than 0");369 }370 this.scrollCount = scrollCount;371 MenuSelectionManager.defaultManager().clearSelectedPath();372 294 } 373 295 … … 393 315 } 394 316 this.topFixedCount = topFixedCount; 395 }396 397 /**398 * Scrolls the specified item into view each time the menu is opened. Call this method with399 * <code>null</code> to restore the default behavior, which is to show the menu as it last400 * appeared.401 *402 * @param item the item to keep visible403 * @see #keepVisible(int)404 */405 public void keepVisible(JMenuItem item) {406 if (item == null) {407 keepVisibleIndex = -1;408 } else {409 int index = menu.getComponentIndex(item);410 keepVisibleIndex = index;411 }412 }413 414 /**415 * Scrolls the item at the specified index into view each time the menu is opened. Call this416 * method with <code>-1</code> to restore the default behavior, which is to show the menu as417 * it last appeared.418 *419 * @param index the index of the item to keep visible420 * @see #keepVisible(javax.swing.JMenuItem)421 */422 public void keepVisible(int index) {423 keepVisibleIndex = index;424 317 } 425 318 … … 453 346 if (menuItems != null && menuItems.length > 0) { 454 347 455 int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems); 456 457 firstIndex = Math.max(topFixedCount, firstIndex); 458 firstIndex = Math.min(numOfNonSepItems - scrollCount, firstIndex); 459 460 upItem.setEnabled(firstIndex > topFixedCount); 461 downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems); 462 463 menu.removeAll(); 464 for (int i = 0; i < topFixedCount; i++) { 465 menu.add(menuItems[i]); 466 } 467 if (topFixedCount > 0) { 468 menu.addSeparator(); 469 } 470 471 menu.add(upItem); 472 for (int i = firstIndex; i < scrollCount + firstIndex; i++) { 473 menu.add(menuItems[i]); 474 } 475 menu.add(downItem); 476 477 int preferredWidth = 0; 348 int allItemsHeight = 0; 478 349 for (Component item : menuItems) { 479 preferredWidth = Math.max(preferredWidth, item.getPreferredSize().width); 480 } 481 menu.setPreferredSize(new Dimension(preferredWidth, menu.getPreferredSize().height)); 482 483 JComponent parent = (JComponent) upItem.getParent(); 484 parent.revalidate(); 485 parent.repaint(); 350 allItemsHeight += item.getPreferredSize().height; 351 } 352 353 int allowedHeight = WindowGeometry.getMaxDimensionOnScreen(menu).height - ((JFrame)Main.parent).getInsets().top; 354 355 boolean mustSCroll = allItemsHeight > allowedHeight; 356 357 if (mustSCroll) { 358 firstIndex = Math.max(topFixedCount, firstIndex); 359 int scrollCount = computeScrollCount(firstIndex); 360 firstIndex = Math.min(menuItems.length - scrollCount, firstIndex); 361 362 upItem.setEnabled(firstIndex > topFixedCount); 363 downItem.setEnabled(firstIndex + scrollCount < menuItems.length); 364 365 menu.removeAll(); 366 for (int i = 0; i < topFixedCount; i++) { 367 menu.add(menuItems[i]); 368 } 369 if (topFixedCount > 0) { 370 menu.addSeparator(); 371 } 372 373 menu.add(upItem); 374 for (int i = firstIndex; i < scrollCount + firstIndex; i++) { 375 menu.add(menuItems[i]); 376 } 377 menu.add(downItem); 378 379 int preferredWidth = 0; 380 for (Component item : menuItems) { 381 preferredWidth = Math.max(preferredWidth, item.getPreferredSize().width); 382 } 383 menu.setPreferredSize(new Dimension(preferredWidth, menu.getPreferredSize().height)); 384 385 } else if (!Arrays.equals(menu.getComponents(), menuItems)) { 386 // Scroll is not needed but menu is not up to date 387 menu.removeAll(); 388 for (Component item : menuItems) { 389 menu.add(item); 390 } 391 } 392 393 menu.revalidate(); 394 menu.repaint(); 486 395 } 487 396 } … … 506 415 private void setMenuItems() { 507 416 menuItems = menu.getComponents(); 508 int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems); 509 if (keepVisibleIndex >= topFixedCount 510 && keepVisibleIndex <= numOfNonSepItems 511 && (keepVisibleIndex > firstIndex + scrollCount 512 || keepVisibleIndex < firstIndex)) { 513 firstIndex = Math.min(firstIndex, keepVisibleIndex); 514 firstIndex = Math.max(firstIndex, keepVisibleIndex - scrollCount + 1); 515 } 516 if (numOfNonSepItems > topFixedCount + scrollCount) { 517 refreshMenu(); 518 } 417 refreshMenu(); 519 418 } 520 419 … … 606 505 @Override 607 506 public void mouseWheelMoved(MouseWheelEvent mwe) { 608 if (getNumberOfNonSeparatorItems(menu.getComponents()) > scrollCount) { 609 firstIndex += mwe.getWheelRotation(); 610 refreshMenu(); 611 } 612 mwe.consume(); // (Comment 16, Huw) 613 } 614 } 615 616 private int getNumberOfNonSeparatorItems(Component[] items) { 617 int result = 0; 618 for (Component c : items) { 619 if (!(c instanceof JSeparator)) { 620 result++; 621 } 622 } 623 return result; 507 firstIndex += mwe.getWheelRotation(); 508 refreshMenu(); 509 mwe.consume(); 510 } 624 511 } 625 512 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r7425 r7463 216 216 } 217 217 if (menuItemHeight > 0) { 218 int scrollcount = MenuScroller.computeScrollCount(subMenu, menuItemHeight);219 218 if (subMenu instanceof JMenu) { 220 MenuScroller.setScrollerFor((JMenu) subMenu , scrollcount);219 MenuScroller.setScrollerFor((JMenu) subMenu); 221 220 } else if (subMenu instanceof JPopupMenu) { 222 MenuScroller.setScrollerFor((JPopupMenu)subMenu , scrollcount);221 MenuScroller.setScrollerFor((JPopupMenu)subMenu); 223 222 } 224 223 } -
trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java
r7012 r7463 6 6 import java.awt.Component; 7 7 import java.awt.Dimension; 8 import java.awt.GraphicsConfiguration; 8 9 import java.awt.GraphicsDevice; 9 10 import java.awt.GraphicsEnvironment; 11 import java.awt.Insets; 10 12 import java.awt.Point; 11 13 import java.awt.Rectangle; … … 14 16 import java.util.regex.Matcher; 15 17 import java.util.regex.Pattern; 18 19 import javax.swing.JComponent; 16 20 17 21 import org.openstreetmap.josm.Main; … … 367 371 } 368 372 return virtualBounds; 373 } 374 375 /** 376 * Computes the maximum dimension for a component to fit in screen displaying {@code component}. 377 * @param component The component to get current screen info from. Must not be {@code null} 378 * @return the maximum dimension for a component to fit in current screen 379 * @throws IllegalArgumentException if {@code component} is null 380 * @since 7463 381 */ 382 public static Dimension getMaxDimensionOnScreen(JComponent component) { 383 CheckParameterUtil.ensureParameterNotNull(component, "component"); 384 // Compute max dimension of current screen 385 Dimension result = new Dimension(); 386 GraphicsConfiguration gc = component.getGraphicsConfiguration(); 387 if (gc == null && Main.parent != null) { 388 gc = Main.parent.getGraphicsConfiguration(); 389 } 390 if (gc != null) { 391 // Max displayable dimension (max screen dimension - insets) 392 Rectangle bounds = gc.getBounds(); 393 Insets insets = component.getToolkit().getScreenInsets(gc); 394 result.width = bounds.width - insets.left - insets.right; 395 result.height = bounds.height - insets.top - insets.bottom; 396 } 397 return result; 369 398 } 370 399
Note:
See TracChangeset
for help on using the changeset viewer.