KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > search > StackedBox


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.gui.search;
19
20 import java.awt.Dimension JavaDoc;
21 import java.awt.Rectangle JavaDoc;
22
23 import javax.swing.JComponent JavaDoc;
24 import javax.swing.JPanel JavaDoc;
25 import javax.swing.JViewport JavaDoc;
26 import javax.swing.Scrollable JavaDoc;
27
28 import org.jdesktop.swingx.VerticalLayout;
29
30 /**
31  * StackedBox class
32  * Stacks components vertically in boxes. Each box is created with a title and a
33  * component.
34  * @author fdietz
35  */

36 public class StackedBox extends JPanel JavaDoc implements Scrollable JavaDoc {
37
38     /**
39      * serialVersionUID
40      */

41     private static final long serialVersionUID = 6499186046747795448L;
42
43
44     /**
45      * StackedBox default constructor
46      */

47     public StackedBox() {
48         setLayout(new VerticalLayout());
49         setOpaque(true);
50         
51     }
52
53     
54     /**
55      * Adds a new component to this <code>StackedBox</code>
56      *
57      * @param box
58      */

59     public void addBox(JComponent JavaDoc box) {
60         add(box);
61     }
62
63     /**
64      * @see Scrollable#getPreferredScrollableViewportSize()
65      */

66     public Dimension JavaDoc getPreferredScrollableViewportSize() {
67         return getPreferredSize();
68     }
69
70     /**
71      * @see Scrollable#getScrollableBlockIncrement(java.awt.Rectangle, int, int)
72      */

73     public int getScrollableBlockIncrement(Rectangle JavaDoc visibleRect,
74             int orientation, int direction) {
75         return 10;
76     }
77
78     /**
79      * @see Scrollable#getScrollableTracksViewportHeight()
80      */

81     public boolean getScrollableTracksViewportHeight() {
82         if (getParent() instanceof JViewport JavaDoc) {
83             return (((JViewport JavaDoc) getParent()).getHeight() > getPreferredSize().height);
84         } else {
85             return false;
86         }
87     }
88
89     /**
90      * @see Scrollable#getScrollableTracksViewportWidth()
91      */

92     public boolean getScrollableTracksViewportWidth() {
93         return true;
94     }
95
96     /**
97      * @see Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
98      */

99     public int getScrollableUnitIncrement(Rectangle JavaDoc visibleRect,
100             int orientation, int direction) {
101         return 10;
102     }
103 }
104
Popular Tags