001: /*
002: * Copyright (c) 2000-2006 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.uif_lite.component;
032:
033: import java.awt.Component;
034:
035: import javax.swing.BorderFactory;
036: import javax.swing.JButton;
037: import javax.swing.JSplitPane;
038: import javax.swing.UIManager;
039: import javax.swing.plaf.SplitPaneUI;
040: import javax.swing.plaf.basic.BasicSplitPaneUI;
041:
042: /**
043: * A <code>JSplitPane</code> subclass that can try to remove the divider border.
044: * Useful if the splitted components render their own borders.
045: * Note that this feature is not supported by all look&feels.
046: * Some look&feel implementation will always show a divider border,
047: * and conversely, others will never show a divider border.
048: *
049: * @author Karsten Lentzsch
050: * @version $Revision: 1.2 $
051: *
052: * @see javax.swing.plaf.basic.BasicSplitPaneUI
053: */
054:
055: public final class UIFSplitPane extends JSplitPane {
056:
057: /**
058: * Holds the name of the bound property that tries to show or hide
059: * the split pane's divider border.
060: *
061: * @see #isDividerBorderVisible()
062: * @see #setDividerBorderVisible(boolean)
063: */
064: public static final String PROPERTYNAME_DIVIDER_BORDER_VISIBLE = "dividerBorderVisible";
065:
066: /**
067: * Determines whether the divider border shall be removed when
068: * the UI is updated.
069: *
070: * @see #isDividerBorderVisible()
071: * @see #setDividerBorderVisible(boolean)
072: */
073: private boolean dividerBorderVisible;
074:
075: // Instance Creation *****************************************************
076:
077: /**
078: * Constructs a <code>UIFSplitPane</code> configured to arrange the child
079: * components side-by-side horizontally with no continuous
080: * layout, using two buttons for the components.
081: */
082: public UIFSplitPane() {
083: this (JSplitPane.HORIZONTAL_SPLIT, false, new JButton(UIManager
084: .getString("SplitPane.leftButtonText")), new JButton(
085: UIManager.getString("SplitPane.rightButtonText")));
086: }
087:
088: /**
089: * Constructs a <code>UIFSplitPane</code> configured with the
090: * specified orientation and no continuous layout.
091: *
092: * @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
093: * <code>JSplitPane.VERTICAL_SPLIT</code>
094: * @throws IllegalArgumentException if <code>orientation</code>
095: * is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.
096: */
097: public UIFSplitPane(int newOrientation) {
098: this (newOrientation, false);
099: }
100:
101: /**
102: * Constructs a <code>UIFSplitPane</code> with the specified
103: * orientation and redrawing style.
104: *
105: * @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
106: * <code>JSplitPane.VERTICAL_SPLIT</code>
107: * @param newContinuousLayout a boolean, true for the components to
108: * redraw continuously as the divider changes position, false
109: * to wait until the divider position stops changing to redraw
110: * @throws IllegalArgumentException if <code>orientation</code>
111: * is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
112: */
113: public UIFSplitPane(int newOrientation, boolean newContinuousLayout) {
114: this (newOrientation, newContinuousLayout, null, null);
115: }
116:
117: /**
118: * Constructs a <code>UIFSplitPane</code> with the specified orientation
119: * and the given componenents.
120: *
121: * @param orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
122: * <code>JSplitPane.VERTICAL_SPLIT</code>
123: * @param leftComponent the <code>Component</code> that will
124: * appear on the left of a horizontally-split pane,
125: * or at the top of a vertically-split pane
126: * @param rightComponent the <code>Component</code> that will
127: * appear on the right of a horizontally-split pane,
128: * or at the bottom of a vertically-split pane
129: * @throws IllegalArgumentException if <code>orientation</code>
130: * is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
131: */
132: public UIFSplitPane(int orientation, Component leftComponent,
133: Component rightComponent) {
134: this (orientation, false, leftComponent, rightComponent);
135: }
136:
137: /**
138: * Constructs a <code>UIFSplitPane</code> with the specified orientation,
139: * redrawing style, and given components.
140: *
141: * @param orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
142: * <code>JSplitPane.VERTICAL_SPLIT</code>
143: * @param continuousLayout a boolean, true for the components to
144: * redraw continuously as the divider changes position, false
145: * to wait until the divider position stops changing to redraw
146: * @param leftComponent the <code>Component</code> that will
147: * appear on the left
148: * of a horizontally-split pane, or at the top of a
149: * vertically-split pane
150: * @param rightComponent the <code>Component</code> that will
151: * appear on the right
152: * of a horizontally-split pane, or at the bottom of a
153: * vertically-split pane
154: * @throws IllegalArgumentException if <code>orientation</code>
155: * is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
156: */
157: public UIFSplitPane(int orientation, boolean continuousLayout,
158: Component leftComponent, Component rightComponent) {
159: super (orientation, continuousLayout, leftComponent,
160: rightComponent);
161: dividerBorderVisible = false;
162: }
163:
164: /**
165: * Constructs a <code>UIFSplitPane</code>,
166: * i.e. a <code>JSplitPane</code> that has no borders.
167: * Also disabled the one touch exandable property.
168: *
169: * @param orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
170: * <code>JSplitPane.VERTICAL_SPLIT</code>
171: * @param leftComponent the <code>Component</code> that will
172: * appear on the left of a horizontally-split pane,
173: * or at the top of a vertically-split pane
174: * @param rightComponent the <code>Component</code> that will
175: * appear on the right of a horizontally-split pane,
176: * or at the bottom of a vertically-split pane
177: * @throws IllegalArgumentException if <code>orientation</code>
178: * is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
179: */
180: public static UIFSplitPane createStrippedSplitPane(int orientation,
181: Component leftComponent, Component rightComponent) {
182: UIFSplitPane split = new UIFSplitPane(orientation,
183: leftComponent, rightComponent);
184: split.setBorder(BorderFactory.createEmptyBorder());
185: split.setOneTouchExpandable(false);
186: return split;
187: }
188:
189: // Accessing Properties **************************************************
190:
191: /**
192: * Checks and answers whether the divider border shall be visible
193: * or invisible.
194: * Note that this feature is not supported by all look&feels.
195: * Some look&feel implementation will always show a divider border,
196: * and conversely, others will never show a divider border.
197: *
198: * @return the desired (but potentially inaccurate) divider border visiblity
199: */
200: public boolean isDividerBorderVisible() {
201: return dividerBorderVisible;
202: }
203:
204: /**
205: * Makes the divider border visible or invisible.
206: * Note that this feature is not supported by all look&feels.
207: * Some look&feel implementation will always show a divider border,
208: * and conversely, others will never show a divider border.
209: *
210: * @param newVisibility true for visible, false for invisible
211: */
212: public void setDividerBorderVisible(boolean newVisibility) {
213: boolean oldVisibility = isDividerBorderVisible();
214: if (oldVisibility == newVisibility)
215: return;
216: dividerBorderVisible = newVisibility;
217: firePropertyChange(PROPERTYNAME_DIVIDER_BORDER_VISIBLE,
218: oldVisibility, newVisibility);
219: }
220:
221: // Changing the Divider Border Visibility *********************************
222:
223: /**
224: * Updates the UI and sets an empty divider border. The divider border
225: * may be restored by a L&F at UI installation time. And so, we
226: * try to reset it each time the UI is changed.
227: */
228: public void updateUI() {
229: super .updateUI();
230: if (!isDividerBorderVisible())
231: setEmptyDividerBorder();
232: }
233:
234: /**
235: * Sets an empty divider border if and only if the UI is
236: * an instance of <code>BasicSplitPaneUI</code>.
237: */
238: private void setEmptyDividerBorder() {
239: SplitPaneUI splitPaneUI = getUI();
240: if (splitPaneUI instanceof BasicSplitPaneUI) {
241: BasicSplitPaneUI basicUI = (BasicSplitPaneUI) splitPaneUI;
242: basicUI.getDivider().setBorder(
243: BorderFactory.createEmptyBorder());
244: }
245: }
246:
247: }
|