Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (c) 2006-2014 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.interfaces.config.AggregateConfigProvider;
  25. import com.dmdirc.interfaces.config.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. /** A version number for this class. */
  33. private static final long serialVersionUID = 2;
  34. /** use one touch expandable? */
  35. private boolean useOneTouchExpandable;
  36. /** Global config manager. */
  37. private final AggregateConfigProvider config;
  38. /** Orientation type . */
  39. public enum Orientation {
  40. /** Horizontal orientation. */
  41. HORIZONTAL,
  42. /** Vertical orientation. */
  43. VERTICAL
  44. }
  45. /**
  46. * Instantiates a new snapping split pane. Defaults to using a horizontal split, two null
  47. * components and snapping to the left component.
  48. *
  49. * @param manager Config manager to read values from
  50. */
  51. public SplitPane(final AggregateConfigProvider manager) {
  52. this(manager, Orientation.HORIZONTAL, null, null);
  53. }
  54. /**
  55. * Instantiates a new snapping split pane. Defaults to using a horizontal split, two null
  56. * components and snapping to the left component.
  57. *
  58. * @param manager Config manager to read values from
  59. * @param orientation Split pane orientation
  60. */
  61. public SplitPane(final AggregateConfigProvider manager, final Orientation orientation) {
  62. this(manager, orientation, null, null);
  63. }
  64. /**
  65. * Instantiates a new snapping split pane. Defaults to using two null components.
  66. *
  67. * @param manager Config manager to read values from
  68. * @param orientation Split pane orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
  69. * <code>JSplitPane.VERTICAL_SPLIT</code>
  70. * @param leftComponent left component
  71. * @param rightComponent right component
  72. */
  73. public SplitPane(final AggregateConfigProvider manager, final Orientation orientation,
  74. final Component leftComponent, final Component rightComponent) {
  75. super((orientation.equals(Orientation.HORIZONTAL))
  76. ? HORIZONTAL_SPLIT : VERTICAL_SPLIT,
  77. true, leftComponent, rightComponent);
  78. config = manager;
  79. useOneTouchExpandable = config.getOptionBool(
  80. "ui", "useOneTouchExpandable");
  81. setOneTouchExpandable(useOneTouchExpandable);
  82. setContinuousLayout(true);
  83. getActionMap().setParent(null);
  84. getActionMap().clear();
  85. config.addChangeListener("ui", "useOneTouchExpandable", this);
  86. }
  87. @Override
  88. public void configChanged(final String domain, final String key) {
  89. useOneTouchExpandable = config.getOptionBool(
  90. "ui", "useOneTouchExpandable");
  91. UIUtilities.invokeLater(() -> setOneTouchExpandable(useOneTouchExpandable));
  92. }
  93. }