Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SplitPane.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.config.IdentityManager;
  26. import com.dmdirc.interfaces.ConfigChangeListener;
  27. import java.awt.Component;
  28. import javax.swing.JSplitPane;
  29. /**
  30. * JSplit pane that snaps around its components preferred size.
  31. */
  32. public class SplitPane extends JSplitPane implements ConfigChangeListener {
  33. /**
  34. * A version number for this class. It should be changed whenever the class
  35. * structure is changed (or anything else that would prevent serialized
  36. * objects being unserialized with the new class).
  37. */
  38. private static final long serialVersionUID = 2;
  39. /** use one touch expandable? */
  40. private boolean useOneTouchExpandable;
  41. /** Global config manager. */
  42. private ConfigManager config;
  43. /** Orientation type . */
  44. public enum Orientation {
  45. /** Horizontal orientation. */
  46. HORIZONTAL,
  47. /** Vertical orientation. */
  48. VERTICAL;
  49. }
  50. /**
  51. * Instantiates a new snapping split pane. Defaults to using a horizontal
  52. * split, two null components and snapping to the left component.
  53. */
  54. public SplitPane() {
  55. this(Orientation.HORIZONTAL, null, null);
  56. }
  57. /**
  58. * Instantiates a new snapping split pane. Defaults to using a horizontal
  59. * split, two null components and snapping to the left component.
  60. *
  61. * @param orientation Split pane orientation
  62. */
  63. public SplitPane(final Orientation orientation) {
  64. this(orientation, null, null);
  65. }
  66. /**
  67. * Instantiates a new snapping split pane. Defaults to using two null
  68. * components.
  69. *
  70. * @param orientation Split pane orientation
  71. * <code>JSplitPane.HORIZONTAL_SPLIT</code> or
  72. * <code>JSplitPane.VERTICAL_SPLIT</code>
  73. * @param leftComponent left component
  74. * @param rightComponent right component
  75. */
  76. public SplitPane(final Orientation orientation,
  77. final Component leftComponent, final Component rightComponent) {
  78. super((orientation.equals(Orientation.HORIZONTAL))
  79. ? HORIZONTAL_SPLIT : VERTICAL_SPLIT,
  80. true, leftComponent, rightComponent);
  81. config = IdentityManager.getGlobalConfig();
  82. useOneTouchExpandable = config.getOptionBool(
  83. "ui", "useOneTouchExpandable");
  84. setOneTouchExpandable(useOneTouchExpandable);
  85. setContinuousLayout(true);
  86. getActionMap().setParent(null);
  87. getActionMap().clear();
  88. config.addChangeListener("ui", "useOneTouchExpandable", this);
  89. }
  90. /** {@inheritDoc} */
  91. @Override
  92. public void configChanged(final String domain, final String key) {
  93. useOneTouchExpandable = config.getOptionBool(
  94. "ui", "useOneTouchExpandable");
  95. UIUtilities.invokeLater(new Runnable() {
  96. /** {@inheritDoc} */
  97. @Override
  98. public void run() {
  99. setOneTouchExpandable(useOneTouchExpandable);
  100. }
  101. });
  102. }
  103. }