001: /*
002: * This class has been derived from work done by Karsten Lentzsch in his
003: * examples for the JGoodies looks package. Modifications: Copyright (c) 2005
004: * beck et al. projects GmbH
005: */
006:
007: /*
008: * Copyright (c) 2001-2004 JGoodies Karsten Lentzsch. All Rights Reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * o Redistributions of source code must retain the above copyright notice, this
014: * list of conditions and the following disclaimer.
015: *
016: * o Redistributions in binary form must reproduce the above copyright notice,
017: * this list of conditions and the following disclaimer in the documentation
018: * and/or other materials provided with the distribution.
019: *
020: * o Neither the name of JGoodies Karsten Lentzsch nor the names of its
021: * contributors may be used to endorse or promote products derived from this
022: * software without specific prior written permission.
023: *
024: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
025: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
026: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
027: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
028: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
029: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
030: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
031: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
032: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
033: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGE.
035: */
036:
037: package org.gui4j.core.swing;
038:
039: import java.awt.Component;
040:
041: import javax.swing.JSplitPane;
042: import javax.swing.border.Border;
043: import javax.swing.border.EmptyBorder;
044: import javax.swing.plaf.SplitPaneUI;
045: import javax.swing.plaf.basic.BasicSplitPaneUI;
046:
047: /**
048: * A <code>JSplitPane</code> subclass that can try to remove the divider
049: * border. Useful if the splitted components render their own borders. Note that
050: * this feature is not supported by all look&feels. Some look&feel
051: * implementation will always show a divider border, and conversely, others will
052: * never show a divider border.
053: *
054: * @author Karsten Lentzsch
055: * @author Kay Krüger-Barvels
056: *
057: * @see javax.swing.plaf.basic.BasicSplitPaneUI
058: */
059: public class JSplitPaneExtended extends JSplitPane {
060:
061: /**
062: * Holds an empty border that is reused for the split pane itself and the
063: * divider.
064: */
065: private static final Border EMPTY_BORDER = new EmptyBorder(0, 0, 0,
066: 0);
067:
068: /**
069: * Determines whether the divider border shall be removed when the UI is
070: * updated.
071: *
072: * @see #setDividerBorderVisible(boolean)
073: */
074: private Boolean dividerBorderVisible;
075:
076: public JSplitPaneExtended(int newOrientation,
077: Component newLeftComponent, Component newRightComponent) {
078: super (newOrientation, newLeftComponent, newRightComponent);
079: }
080:
081: /**
082: * Checks and answers whether the divider border shall be visible or
083: * invisible. Note that this feature is not supported by all look&feels.
084: * Some look&feel implementation will always show a divider border, and
085: * conversely, others will never show a divider border.
086: *
087: * @return the desired (but potentially inaccurate) divider border visiblity
088: */
089: private Boolean isDividerBorderVisible() {
090: return dividerBorderVisible;
091: }
092:
093: /**
094: * Makes the divider border visible or invisible. Note that this feature is
095: * not supported by all look&feels. Some look&feel implementation
096: * will always show a divider border, and conversely, others will never show
097: * a divider border.
098: *
099: * @param newVisibility
100: * true for visible, false for invisible
101: */
102: public void setDividerBorderVisible(boolean newVisibility) {
103: if (isDividerBorderVisible() == null
104: || isDividerBorderVisible().booleanValue() != newVisibility) {
105: dividerBorderVisible = new Boolean(newVisibility);
106: updateUI();
107: }
108: }
109:
110: /**
111: * Updates the UI and sets an empty divider border. The divider border may
112: * be restored by a L&F at UI installation time. And so, we try to reset it
113: * each time the UI is changed.
114: */
115: public void updateUI() {
116: super .updateUI();
117: if (isDividerBorderVisible() != null
118: && !(isDividerBorderVisible().booleanValue()))
119: setEmptyDividerBorder();
120: }
121:
122: /**
123: * Sets an empty divider border if and only if the UI is an instance of
124: * <code>BasicSplitPaneUI</code>.
125: */
126: private void setEmptyDividerBorder() {
127: SplitPaneUI splitPaneUI = getUI();
128: if (splitPaneUI instanceof BasicSplitPaneUI) {
129: BasicSplitPaneUI basicUI = (BasicSplitPaneUI) splitPaneUI;
130: basicUI.getDivider().setBorder(EMPTY_BORDER);
131: }
132: }
133:
134: }
|