KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > UIFSplitPane


1 /*
2  * Copyright (c) 2003 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package org.columba.core.gui.base;
31
32 import java.awt.Component JavaDoc;
33
34 import javax.swing.JButton JavaDoc;
35 import javax.swing.JSplitPane JavaDoc;
36 import javax.swing.UIManager JavaDoc;
37 import javax.swing.border.Border JavaDoc;
38 import javax.swing.border.EmptyBorder JavaDoc;
39 import javax.swing.plaf.SplitPaneUI JavaDoc;
40 import javax.swing.plaf.basic.BasicSplitPaneUI JavaDoc;
41
42
43 /**
44  * A <code>JSplitPane</code> subclass that can try to remove the divider border.
45  * Useful if the splitted components render their own borders.
46  * Note that this feature is not supported by all look&amp;feels.
47  * Some look&amp;feel implementation will always show a divider border,
48  * and conversely, others will never show a divider border.
49  *
50  * @author Karsten Lentzsch
51  * @version $Revision: 1.1 $
52  *
53  * @see javax.swing.plaf.basic.BasicSplitPaneUI
54  */

55 public final class UIFSplitPane extends JSplitPane JavaDoc {
56     /**
57  * Holds an empty border that is reused for the split pane itself
58  * and the divider.
59  */

60     private static final Border JavaDoc EMPTY_BORDER = new EmptyBorder JavaDoc(0, 0, 0, 0);
61
62     /**
63  * Determines whether the divider border shall be removed when
64  * the UI is updated.
65  *
66  * @see #isDividerBorderVisible()
67  * @see #setDividerBorderVisible(boolean)
68  */

69     private boolean dividerBorderVisible;
70
71     // Instance Creation *****************************************************
72

73     /**
74  * Constructs a <code>UIFSplitPane</code> configured to arrange the child
75  * components side-by-side horizontally with no continuous
76  * layout, using two buttons for the components.
77  */

78     public UIFSplitPane() {
79         this(JSplitPane.HORIZONTAL_SPLIT, false,
80             new JButton JavaDoc(UIManager.getString("SplitPane.leftButtonText")),
81             new JButton JavaDoc(UIManager.getString("SplitPane.rightButtonText")));
82     }
83
84     /**
85  * Constructs a <code>UIFSplitPane</code> configured with the
86  * specified orientation and no continuous layout.
87  *
88  * @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
89  * <code>JSplitPane.VERTICAL_SPLIT</code>
90  * @throws IllegalArgumentException if <code>orientation</code>
91  * is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.
92  */

93     public UIFSplitPane(int newOrientation) {
94         this(newOrientation, false);
95     }
96
97     /**
98  * Constructs a <code>UIFSplitPane</code> with the specified
99  * orientation and redrawing style.
100  *
101  * @param newOrientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
102  * <code>JSplitPane.VERTICAL_SPLIT</code>
103  * @param newContinuousLayout a boolean, true for the components to
104  * redraw continuously as the divider changes position, false
105  * to wait until the divider position stops changing to redraw
106  * @throws IllegalArgumentException if <code>orientation</code>
107  * is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
108  */

109     public UIFSplitPane(int newOrientation, boolean newContinuousLayout) {
110         this(newOrientation, newContinuousLayout, null, null);
111     }
112
113     /**
114  * Constructs a <code>UIFSplitPane</code> with the specified orientation
115  * and the given componenents.
116  *
117  * @param orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
118  * <code>JSplitPane.VERTICAL_SPLIT</code>
119  * @param leftComponent the <code>Component</code> that will
120  * appear on the left of a horizontally-split pane,
121  * or at the top of a vertically-split pane
122  * @param rightComponent the <code>Component</code> that will
123  * appear on the right of a horizontally-split pane,
124  * or at the bottom of a vertically-split pane
125  * @throws IllegalArgumentException if <code>orientation</code>
126  * is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
127  */

128     public UIFSplitPane(int orientation, Component JavaDoc leftComponent,
129         Component JavaDoc rightComponent) {
130         this(orientation, false, leftComponent, rightComponent);
131     }
132
133     /**
134  * Constructs a <code>UIFSplitPane</code> with the specified orientation,
135  * redrawing style, and given components.
136  *
137  * @param orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
138  * <code>JSplitPane.VERTICAL_SPLIT</code>
139  * @param continuousLayout a boolean, true for the components to
140  * redraw continuously as the divider changes position, false
141  * to wait until the divider position stops changing to redraw
142  * @param leftComponent the <code>Component</code> that will
143  * appear on the left
144  * of a horizontally-split pane, or at the top of a
145  * vertically-split pane
146  * @param rightComponent the <code>Component</code> that will
147  * appear on the right
148  * of a horizontally-split pane, or at the bottom of a
149  * vertically-split pane
150  * @throws IllegalArgumentException if <code>orientation</code>
151  * is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
152  */

153     public UIFSplitPane(int orientation, boolean continuousLayout,
154         Component JavaDoc leftComponent, Component JavaDoc rightComponent) {
155         super(orientation, continuousLayout, leftComponent, rightComponent);
156         dividerBorderVisible = false;
157     }
158
159     /**
160  * Constructs a <code>UIFSplitPane</code>,
161  * i.e. a <code>JSplitPane</code> that has no borders.
162  * Also disabled the one touch exandable property.
163  *
164  * @param orientation <code>JSplitPane.HORIZONTAL_SPLIT</code> or
165  * <code>JSplitPane.VERTICAL_SPLIT</code>
166  * @param leftComponent the <code>Component</code> that will
167  * appear on the left of a horizontally-split pane,
168  * or at the top of a vertically-split pane
169  * @param rightComponent the <code>Component</code> that will
170  * appear on the right of a horizontally-split pane,
171  * or at the bottom of a vertically-split pane
172  * @throws IllegalArgumentException if <code>orientation</code>
173  * is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
174  */

175     public static UIFSplitPane createStrippedSplitPane(int orientation,
176         Component JavaDoc leftComponent, Component JavaDoc rightComponent) {
177         UIFSplitPane split = new UIFSplitPane(orientation, leftComponent,
178                 rightComponent);
179         split.setBorder(EMPTY_BORDER);
180         split.setOneTouchExpandable(false);
181
182         return split;
183     }
184
185     // Accessing Properties **************************************************
186

187     /**
188  * Checks and answers whether the divider border shall be visible
189  * or invisible.
190  * Note that this feature is not supported by all look&amp;feels.
191  * Some look&amp;feel implementation will always show a divider border,
192  * and conversely, others will never show a divider border.
193  *
194  * @return the desired (but potentially inaccurate) divider border visiblity
195  */

196     public boolean isDividerBorderVisible() {
197         return dividerBorderVisible;
198     }
199
200     /**
201  * Makes the divider border visible or invisible.
202  * Note that this feature is not supported by all look&amp;feels.
203  * Some look&amp;feel implementation will always show a divider border,
204  * and conversely, others will never show a divider border.
205  *
206  * @param newVisibility true for visible, false for invisible
207  */

208     public void setDividerBorderVisible(boolean newVisibility) {
209         boolean oldVisibility = isDividerBorderVisible();
210
211         if (oldVisibility == newVisibility) {
212             return;
213         }
214
215         dividerBorderVisible = newVisibility;
216         firePropertyChange("dividerBorderVisible", oldVisibility, newVisibility);
217     }
218
219     // Changing the Divider Border Visibility *********************************
220

221     /**
222  * Updates the UI and sets an empty divider border. The divider border
223  * may be restored by a L&F at UI installation time. And so, we
224  * try to reset it each time the UI is changed.
225  */

226     public void updateUI() {
227         super.updateUI();
228
229         if (!isDividerBorderVisible()) {
230             setEmptyDividerBorder();
231         }
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 JavaDoc splitPaneUI = getUI();
240
241         if (splitPaneUI instanceof BasicSplitPaneUI JavaDoc) {
242             BasicSplitPaneUI JavaDoc basicUI = (BasicSplitPaneUI JavaDoc) splitPaneUI;
243             basicUI.getDivider().setBorder(EMPTY_BORDER);
244         }
245     }
246 }
247
Popular Tags