Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

SplitPane.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2006-2013 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.components;
  23. import com.dmdirc.addons.ui_swing.UIUtilities;
  24. import com.dmdirc.config.ConfigManager;
  25. import com.dmdirc.interfaces.ConfigChangeListener;
  26. import java.awt.Component;
  27. import javax.swing.JSplitPane;
  28. /**
  29. * JSplit pane that snaps around its components preferred size.
  30. */
  31. public class SplitPane extends JSplitPane implements ConfigChangeListener {
  32. /**
  33. * A version number for this class. It should be changed whenever the class
  34. * structure is changed (or anything else that would prevent serialized
  35. * objects being unserialized with the new class).
  36. */
  37. private static final long serialVersionUID = 2;
  38. /** use one touch expandable? */
  39. private boolean useOneTouchExpandable;
  40. /** Global config manager. */
  41. private ConfigManager config;
  42. /** Orientation type . */
  43. public enum Orientation {
  44. /** Horizontal orientation. */
  45. HORIZONTAL,
  46. /** Vertical orientation. */
  47. VERTICAL;
  48. }
  49. /**
  50. * Instantiates a new snapping split pane. Defaults to using a horizontal
  51. * split, two null components and snapping to the left component.
  52. *
  53. * @param manager Config manager to read values from
  54. */
  55. public SplitPane(final ConfigManager manager) {
  56. this(manager, Orientation.HORIZONTAL, null, null);
  57. }
  58. /**
  59. * Instantiates a new snapping split pane. Defaults to using a horizontal
  60. * split, two null components and snapping to the left component.
  61. *
  62. * @param manager Config manager to read values from
  63. * @param orientation Split pane orientation
  64. */
  65. public SplitPane(final ConfigManager manager, final Orientation orientation) {
  66. this(manager, orientation, null, null);
  67. }
  68. /**
  69. * Instantiates a new snapping split pane. Defaults to using two null
  70. * components.
  71. *
  72. * @param manager Config manager to read values from
  73. * @param orientation Split pane orientation
  74. * <code>JSplitPane.HORIZONTAL_SPLIT</code> or
  75. * <code>JSplitPane.VERTICAL_SPLIT</code>
  76. * @param leftComponent left component
  77. * @param rightComponent right component
  78. */
  79. public SplitPane(final ConfigManager manager, final Orientation orientation,
  80. final Component leftComponent, final Component rightComponent) {
  81. super((orientation.equals(Orientation.HORIZONTAL))
  82. ? HORIZONTAL_SPLIT : VERTICAL_SPLIT,
  83. true, leftComponent, rightComponent);
  84. config = manager;
  85. useOneTouchExpandable = config.getOptionBool(
  86. "ui", "useOneTouchExpandable");
  87. setOneTouchExpandable(useOneTouchExpandable);
  88. setContinuousLayout(true);
  89. getActionMap().setParent(null);
  90. getActionMap().clear();
  91. config.addChangeListener("ui", "useOneTouchExpandable", this);
  92. }
  93. /** {@inheritDoc} */
  94. @Override
  95. public void configChanged(final String domain, final String key) {
  96. useOneTouchExpandable = config.getOptionBool(
  97. "ui", "useOneTouchExpandable");
  98. UIUtilities.invokeLater(new Runnable() {
  99. /** {@inheritDoc} */
  100. @Override
  101. public void run() {
  102. setOneTouchExpandable(useOneTouchExpandable);
  103. }
  104. });
  105. }
  106. }