You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowMenuScroller.java 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. *
  3. * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.addons.ui_swing.framemanager.windowmenu;
  24. import com.dmdirc.addons.ui_swing.UIUtilities;
  25. import com.dmdirc.addons.ui_swing.components.MenuScroller;
  26. import com.dmdirc.config.IdentityManager;
  27. import com.dmdirc.interfaces.ConfigChangeListener;
  28. import javax.swing.JMenu;
  29. /**
  30. * Window menu scroller.
  31. */
  32. public class WindowMenuScroller implements ConfigChangeListener {
  33. /** Menu scroller. */
  34. private MenuScroller scroller;
  35. /** Config domain. */
  36. private String configDomain;
  37. /** Menu to scroll. */
  38. private JMenu menu;
  39. /** Fixed menu item count. */
  40. private int fixedCount;
  41. /**
  42. * Creates a new menu scroller for the window menu.
  43. *
  44. * @param menu Menu to create scroller for
  45. * @param configDomain Domain to check config settings in
  46. * @param fixedCount Number of fixed items in the menu
  47. */
  48. public WindowMenuScroller(final JMenu menu, final String configDomain,
  49. final int fixedCount) {
  50. if (IdentityManager.getGlobalConfig() == null) {
  51. throw new IllegalArgumentException("null global config");
  52. }
  53. this.menu = menu;
  54. this.configDomain = configDomain;
  55. this.fixedCount = fixedCount;
  56. this.scroller = new MenuScroller(menu,
  57. IdentityManager.getGlobalConfig().getOptionInt(configDomain,
  58. "windowMenuItems"),
  59. IdentityManager.getGlobalConfig().getOptionInt(configDomain,
  60. "windowMenuScrollInterval"), fixedCount, 0);
  61. scroller.setShowSeperators(false);
  62. IdentityManager.getGlobalConfig().addChangeListener(configDomain,
  63. "windowMenuItems", this);
  64. IdentityManager.getGlobalConfig().addChangeListener(configDomain,
  65. "windowMenuScrollInterval", this);
  66. }
  67. /** {@inheritDoc} */
  68. @Override
  69. public void configChanged(final String domain, final String key) {
  70. UIUtilities.invokeLater(new Runnable() {
  71. /** {@inheritDoc} */
  72. @Override
  73. public void run() {
  74. scroller.dispose();
  75. scroller = new MenuScroller(menu,
  76. IdentityManager.getGlobalConfig().getOptionInt(
  77. configDomain, "windowMenuItems"),
  78. IdentityManager.getGlobalConfig().getOptionInt(
  79. configDomain, "windowMenuScrollInterval"), fixedCount,
  80. 0);
  81. scroller.setShowSeperators(false);
  82. }
  83. });
  84. }
  85. }