Changeset 7452 in josm
 Timestamp:
 20140828T16:08:11+02:00 (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/org/openstreetmap/josm/gui/MenuScroller.java
r7346 r7452 33 33 /** 34 34 * A class that provides scrolling capabilities to a long menu dropdown or 35 * popup menu. A number of items can optionally be frozen at the top and/or 36 * bottom of the menu. 35 * popup menu. A number of items can optionally be frozen at the top of the menu. 37 36 * <P> 38 37 * <B>Implementation note:</B> The default number of items to display … … 52 51 private int interval; 53 52 private int topFixedCount; 54 private int bottomFixedCount;55 53 private int firstIndex = 0; 56 54 private int keepVisibleIndex = 1; … … 169 167 * Registers a menu to be scrolled, with the specified number of items 170 168 * to display in the scrolling region, the specified scrolling interval, 171 * and the specified numbers of items fixed at the top and bottom of the 172 * menu. 169 * and the specified numbers of items fixed at the top of the menu. 173 170 * 174 171 * @param menu the menu … … 176 173 * @param interval the scroll interval, in milliseconds 177 174 * @param topFixedCount the number of items to fix at the top. May be 0. 178 * @param bottomFixedCount the number of items to fix at the bottom. May be 0179 175 * @throws IllegalArgumentException if scrollCount or interval is 0 or 180 * negative or if topFixedCount or bottomFixedCountis negative176 * negative or if topFixedCount is negative 181 177 * @return the MenuScroller 182 178 */ 183 179 public static MenuScroller setScrollerFor(JMenu menu, int scrollCount, int interval, 184 int topFixedCount, int bottomFixedCount) { 185 return new MenuScroller(menu, scrollCount, interval, 186 topFixedCount, bottomFixedCount); 180 int topFixedCount) { 181 return new MenuScroller(menu, scrollCount, interval, topFixedCount); 187 182 } 188 183 … … 190 185 * Registers a popup menu to be scrolled, with the specified number of items 191 186 * to display in the scrolling region, the specified scrolling interval, 192 * and the specified numbers of items fixed at the top and bottom of the 193 * popup menu. 187 * and the specified numbers of items fixed at the top of the popup menu. 194 188 * 195 189 * @param menu the popup menu … … 197 191 * @param interval the scroll interval, in milliseconds 198 192 * @param topFixedCount the number of items to fix at the top. May be 0 199 * @param bottomFixedCount the number of items to fix at the bottom. May be 0200 193 * @throws IllegalArgumentException if scrollCount or interval is 0 or 201 * negative or if topFixedCount or bottomFixedCountis negative194 * negative or if topFixedCount is negative 202 195 * @return the MenuScroller 203 196 */ 204 197 public static MenuScroller setScrollerFor(JPopupMenu menu, int scrollCount, int interval, 205 int topFixedCount, int bottomFixedCount) { 206 return new MenuScroller(menu, scrollCount, interval, 207 topFixedCount, bottomFixedCount); 198 int topFixedCount) { 199 return new MenuScroller(menu, scrollCount, interval, topFixedCount); 208 200 } 209 201 … … 267 259 */ 268 260 public MenuScroller(JMenu menu, int scrollCount, int interval) { 269 this(menu, scrollCount, interval, 0 , 0);261 this(menu, scrollCount, interval, 0); 270 262 } 271 263 … … 281 273 */ 282 274 public MenuScroller(JPopupMenu menu, int scrollCount, int interval) { 283 this(menu, scrollCount, interval, 0 , 0);275 this(menu, scrollCount, interval, 0); 284 276 } 285 277 … … 288 280 * specified number of items to display in the scrolling region, the 289 281 * specified scrolling interval, and the specified numbers of items fixed at 290 * the top and bottomof the menu.282 * the top of the menu. 291 283 * 292 284 * @param menu the menu … … 294 286 * @param interval the scroll interval, in milliseconds 295 287 * @param topFixedCount the number of items to fix at the top. May be 0 296 * @param bottomFixedCount the number of items to fix at the bottom. May be 0297 288 * @throws IllegalArgumentException if scrollCount or interval is 0 or 298 * negative or if topFixedCount or bottomFixedCount is negative 299 */ 300 public MenuScroller(JMenu menu, int scrollCount, int interval, 301 int topFixedCount, int bottomFixedCount) { 302 this(menu.getPopupMenu(), scrollCount, interval, topFixedCount, bottomFixedCount); 289 * 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); 303 293 } 304 294 … … 307 297 * specified number of items to display in the scrolling region, the 308 298 * specified scrolling interval, and the specified numbers of items fixed at 309 * the top and bottomof the popup menu.299 * the top of the popup menu. 310 300 * 311 301 * @param menu the popup menu … … 313 303 * @param interval the scroll interval, in milliseconds 314 304 * @param topFixedCount the number of items to fix at the top. May be 0 315 * @param bottomFixedCount the number of items to fix at the bottom. May be 0316 305 * @throws IllegalArgumentException if scrollCount or interval is 0 or 317 * negative or if topFixedCount or bottomFixedCount is negative 318 */ 319 public MenuScroller(JPopupMenu menu, int scrollCount, int interval, 320 int topFixedCount, int bottomFixedCount) { 306 * negative or if topFixedCount is negative 307 */ 308 public MenuScroller(JPopupMenu menu, int scrollCount, int interval, int topFixedCount) { 321 309 if (scrollCount <= 0  interval <= 0) { 322 310 throw new IllegalArgumentException("scrollCount and interval must be greater than 0"); 323 311 } 324 if (topFixedCount < 0  bottomFixedCount < 0) {325 throw new IllegalArgumentException("topFixedCount and bottomFixedCountcannot be negative");312 if (topFixedCount < 0) { 313 throw new IllegalArgumentException("topFixedCount cannot be negative"); 326 314 } 327 315 … … 331 319 setInterval(interval); 332 320 setTopFixedCount(topFixedCount); 333 setBottomFixedCount(bottomFixedCount);334 321 335 322 this.menu = menu; … … 406 393 } 407 394 this.topFixedCount = topFixedCount; 408 }409 410 /**411 * Returns the number of items fixed at the bottom of the menu or popup menu.412 *413 * @return the number of items414 */415 public int getBottomFixedCount() {416 return bottomFixedCount;417 }418 419 /**420 * Sets the number of items to fix at the bottom of the menu or popup menu.421 *422 * @param bottomFixedCount the number of items423 */424 public void setBottomFixedCount(int bottomFixedCount) {425 this.bottomFixedCount = bottomFixedCount;426 395 } 427 396 … … 487 456 488 457 firstIndex = Math.max(topFixedCount, firstIndex); 489 firstIndex = Math.min(numOfNonSepItems  bottomFixedCount scrollCount, firstIndex);458 firstIndex = Math.min(numOfNonSepItems  scrollCount, firstIndex); 490 459 491 460 upItem.setEnabled(firstIndex > topFixedCount); 492 downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems  bottomFixedCount);461 downItem.setEnabled(firstIndex + scrollCount < numOfNonSepItems); 493 462 494 463 menu.removeAll(); … … 505 474 } 506 475 menu.add(downItem); 507 508 if (bottomFixedCount > 0) {509 menu.addSeparator();510 }511 for (int i = menuItems.length  bottomFixedCount; i < menuItems.length; i++) {512 menu.add(menuItems[i]);513 }514 476 515 477 int preferredWidth = 0; … … 546 508 int numOfNonSepItems = getNumberOfNonSeparatorItems(menuItems); 547 509 if (keepVisibleIndex >= topFixedCount 548 && keepVisibleIndex <= numOfNonSepItems  bottomFixedCount510 && keepVisibleIndex <= numOfNonSepItems 549 511 && (keepVisibleIndex > firstIndex + scrollCount 550 512  keepVisibleIndex < firstIndex)) { … … 552 514 firstIndex = Math.max(firstIndex, keepVisibleIndex  scrollCount + 1); 553 515 } 554 if (numOfNonSepItems > topFixedCount + scrollCount + bottomFixedCount) {516 if (numOfNonSepItems > topFixedCount + scrollCount) { 555 517 refreshMenu(); 556 518 }
Note: See TracChangeset
for help on using the changeset viewer.