001    /*
002     * $Id: JXTaskPaneContainer.java,v 1.6 2005/10/10 18:01:59 rbair Exp $
003     *
004     * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
005     * Santa Clara, California 95054, U.S.A. All rights reserved.
006     *
007     * This library is free software; you can redistribute it and/or
008     * modify it under the terms of the GNU Lesser General Public
009     * License as published by the Free Software Foundation; either
010     * version 2.1 of the License, or (at your option) any later version.
011     * 
012     * This library is distributed in the hope that it will be useful,
013     * but WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
015     * Lesser General Public License for more details.
016     * 
017     * You should have received a copy of the GNU Lesser General Public
018     * License along with this library; if not, write to the Free Software
019     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
020     */
021    package org.jdesktop.swingx;
022    
023    import java.awt.Dimension;
024    import java.awt.Rectangle;
025    
026    import javax.swing.JComponent;
027    import javax.swing.JViewport;
028    import javax.swing.Scrollable;
029    
030    import org.jdesktop.swingx.plaf.JXTaskPaneContainerAddon;
031    import org.jdesktop.swingx.plaf.LookAndFeelAddons;
032    import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
033    
034    /**
035     * <code>JXTaskPaneContainer</code> provides an elegant view
036     * to display a list of tasks ordered by groups ({@link org.jdesktop.swingx.JXTaskPane}.
037     * 
038     * <p>
039     * Although {@link org.jdesktop.swingx.JXTaskPane} can be added to any other
040     * container, the <code>JXTaskPaneContainer</code> will provide better
041     * fidelity when it comes to matching the look and feel of the host operating
042     * system than any other panel. As example, when using on a Windows platform,
043     * the <code>JXTaskPaneContainer</code> will be painted with light gradient
044     * background. Also <code>JXTaskPaneContainer</code> takes care of using the
045     * right {@link java.awt.LayoutManager} (as required by
046     * {@link org.jdesktop.swingx.JXCollapsiblePane}) so that
047     * {@link org.jdesktop.swingx.JXTaskPane} behaves correctly when collapsing and
048     * expanding its content.
049     *  
050     * <p>
051     * <code>JXTaskPaneContainer<code> can be added to a JScrollPane.
052     * 
053     * <p>
054     * Example:
055     * <pre>
056     * <code>
057     * JXFrame frame = new JXFrame();
058     * 
059     * // a container to put all JXTaskPane together
060     * JXTaskPaneContainer taskPaneContainer = new JXTaskPaneContainer();
061     * 
062     * // add JXTaskPanes to the container
063     * JXTaskPane actionPane = createActionPane();
064     * JXTaskPane miscActionPane = createMiscActionPane();
065     * JXTaskPane detailsPane = createDetailsPane();
066     * taskPaneContainer.add(actionPane);
067     * taskPaneContainer.add(miscActionPane);
068     * taskPaneContainer.add(detailsPane);
069     *
070     * // put the action list on the left in a JScrollPane
071     * // as we have several taskPane and we want to make sure they
072     * // all get visible.   
073     * frame.add(new JScrollPane(taskPaneContainer), BorderLayout.EAST);
074     * 
075     * // and a file browser in the middle
076     * frame.add(fileBrowser, BorderLayout.CENTER);
077     * 
078     * frame.pack().
079     * frame.setVisible(true);
080     * </code>
081     * </pre>
082     *
083     * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
084     * 
085     * @javabean.attribute
086     *          name="isContainer"
087     *          value="Boolean.TRUE"
088     *          rtexpr="true"
089     * 
090     * @javabean.class
091     *          name="JXTaskPaneContainer"
092     *          shortDescription="A component that contains JTaskPaneGroups."
093     *          stopClass="java.awt.Component"
094     * 
095     * @javabean.icons
096     *          mono16="JXTaskPaneContainer16-mono.gif"
097     *          color16="JXTaskPaneContainer16.gif"
098     *          mono32="JXTaskPaneContainer32-mono.gif"
099     *          color32="JXTaskPaneContainer32.gif"
100     */
101    public class JXTaskPaneContainer extends JComponent implements Scrollable {
102    
103      public final static String uiClassID = "swingx/TaskPaneContainerUI";
104      
105      // ensure at least the default ui is registered
106      static {
107        LookAndFeelAddons.contribute(new JXTaskPaneContainerAddon());
108      }
109    
110      /**
111       * Creates a new empty taskpane.
112       */
113      public JXTaskPaneContainer() {
114        updateUI();
115      }
116    
117      /**
118       * Notification from the <code>UIManager</code> that the L&F has changed.
119       * Replaces the current UI object with the latest version from the <code>UIManager</code>.
120       * 
121       * @see javax.swing.JComponent#updateUI
122       */
123      public void updateUI() {
124        setUI((TaskPaneContainerUI)LookAndFeelAddons.getUI(this, TaskPaneContainerUI.class));
125      }
126    
127      /**
128       * Sets the L&F object that renders this component.
129       * 
130       * @param ui the <code>TaskPaneContainerUI</code> L&F object
131       * @see javax.swing.UIDefaults#getUI
132       * 
133       * @beaninfo bound: true hidden: true description: The UI object that
134       * implements the taskpane's LookAndFeel.
135       */
136      public void setUI(TaskPaneContainerUI ui) {
137        super.setUI(ui);
138      }
139    
140      /**
141       * Returns the name of the L&F class that renders this component.
142       * 
143       * @return the string {@link #uiClassID}
144       * @see javax.swing.JComponent#getUIClassID
145       * @see javax.swing.UIDefaults#getUI
146       */
147      public String getUIClassID() {
148        return uiClassID;
149      }
150    
151      /**
152       * Adds a <code>JXTaskPane</code> to this JXTaskPaneContainer.
153       * 
154       * @param group
155       */
156      public void add(JXTaskPane group) {
157        super.add(group);
158      }
159    
160      /**
161       * Removes a <code>JXTaskPane</code> from this JXTaskPaneContainer.
162       * 
163       * @param group
164       */
165      public void remove(JXTaskPane group) {
166        super.remove(group);
167      }
168    
169      /**
170       * @see Scrollable#getPreferredScrollableViewportSize()
171       */
172      public Dimension getPreferredScrollableViewportSize() {
173        return getPreferredSize();
174      }
175    
176      /**
177       * @see Scrollable#getScrollableBlockIncrement(java.awt.Rectangle, int, int)
178       */
179      public int getScrollableBlockIncrement(
180        Rectangle visibleRect,
181        int orientation,
182        int direction) {
183        return 10;
184      }
185      
186      /**
187       * @see Scrollable#getScrollableTracksViewportHeight()
188       */
189      public boolean getScrollableTracksViewportHeight() {
190        if (getParent() instanceof JViewport) {
191          return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
192        } else {
193          return false;
194        }
195      }
196      
197      /**
198       * @see Scrollable#getScrollableTracksViewportWidth()
199       */
200      public boolean getScrollableTracksViewportWidth() {
201        return true;
202      }
203      
204      /**
205       * @see Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
206       */
207      public int getScrollableUnitIncrement(
208        Rectangle visibleRect,
209        int orientation,
210        int direction) {
211        return 10;
212      }
213      
214    }