001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.core.gui.search;
019:
020: import java.awt.Dimension;
021: import java.awt.Rectangle;
022:
023: import javax.swing.JComponent;
024: import javax.swing.JPanel;
025: import javax.swing.JViewport;
026: import javax.swing.Scrollable;
027:
028: import org.jdesktop.swingx.VerticalLayout;
029:
030: /**
031: * StackedBox class
032: * Stacks components vertically in boxes. Each box is created with a title and a
033: * component.
034: * @author fdietz
035: */
036: public class StackedBox extends JPanel implements Scrollable {
037:
038: /**
039: * serialVersionUID
040: */
041: private static final long serialVersionUID = 6499186046747795448L;
042:
043: /**
044: * StackedBox default constructor
045: */
046: public StackedBox() {
047: setLayout(new VerticalLayout());
048: setOpaque(true);
049:
050: }
051:
052: /**
053: * Adds a new component to this <code>StackedBox</code>
054: *
055: * @param box
056: */
057: public void addBox(JComponent box) {
058: add(box);
059: }
060:
061: /**
062: * @see Scrollable#getPreferredScrollableViewportSize()
063: */
064: public Dimension getPreferredScrollableViewportSize() {
065: return getPreferredSize();
066: }
067:
068: /**
069: * @see Scrollable#getScrollableBlockIncrement(java.awt.Rectangle, int, int)
070: */
071: public int getScrollableBlockIncrement(Rectangle visibleRect,
072: int orientation, int direction) {
073: return 10;
074: }
075:
076: /**
077: * @see Scrollable#getScrollableTracksViewportHeight()
078: */
079: public boolean getScrollableTracksViewportHeight() {
080: if (getParent() instanceof JViewport) {
081: return (((JViewport) getParent()).getHeight() > getPreferredSize().height);
082: } else {
083: return false;
084: }
085: }
086:
087: /**
088: * @see Scrollable#getScrollableTracksViewportWidth()
089: */
090: public boolean getScrollableTracksViewportWidth() {
091: return true;
092: }
093:
094: /**
095: * @see Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
096: */
097: public int getScrollableUnitIncrement(Rectangle visibleRect,
098: int orientation, int direction) {
099: return 10;
100: }
101: }
|