001/*
002 * $Id: JXTaskPaneContainer.java 4147 2012-02-01 17:13:24Z kschaefe $
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 */
021package org.jdesktop.swingx;
022
023import java.awt.event.ContainerAdapter;
024import java.awt.event.ContainerEvent;
025
026import org.jdesktop.beans.JavaBean;
027import org.jdesktop.swingx.plaf.LookAndFeelAddons;
028import org.jdesktop.swingx.plaf.TaskPaneContainerAddon;
029import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
030
031/**
032 * <code>JXTaskPaneContainer</code> provides an elegant view
033 * to display a list of tasks ordered by groups ({@link org.jdesktop.swingx.JXTaskPane}s).
034 * 
035 * <p>
036 * Although {@link org.jdesktop.swingx.JXTaskPane} can be added to any other
037 * container, the <code>JXTaskPaneContainer</code> will provide better
038 * fidelity when it comes to matching the look and feel of the host operating
039 * system than any other panel. As example, when using on a Windows platform,
040 * the <code>JXTaskPaneContainer</code> will be painted with a light gradient
041 * background. Also <code>JXTaskPaneContainer</code> takes care of using the
042 * right {@link java.awt.LayoutManager} (as required by
043 * {@link org.jdesktop.swingx.JXCollapsiblePane}) so that
044 * {@link org.jdesktop.swingx.JXTaskPane} behaves correctly when collapsing and
045 * expanding its content.
046 *  
047 * <p>
048 * <code>JXTaskPaneContainer<code> can be added to a JScrollPane.
049 * 
050 * <p>
051 * Example:
052 * <pre>
053 * <code>
054 * JXFrame frame = new JXFrame();
055 * 
056 * // a container to put all JXTaskPane together
057 * JXTaskPaneContainer taskPaneContainer = new JXTaskPaneContainer();
058 * 
059 * // add JXTaskPanes to the container
060 * JXTaskPane actionPane = createActionPane();
061 * JXTaskPane miscActionPane = createMiscActionPane();
062 * JXTaskPane detailsPane = createDetailsPane();
063 * taskPaneContainer.add(actionPane);
064 * taskPaneContainer.add(miscActionPane);
065 * taskPaneContainer.add(detailsPane);
066 *
067 * // put the action list on the left in a JScrollPane
068 * // as we have several taskPane and we want to make sure they
069 * // all get visible.   
070 * frame.add(new JScrollPane(taskPaneContainer), BorderLayout.EAST);
071 * 
072 * // and a file browser in the middle
073 * frame.add(fileBrowser, BorderLayout.CENTER);
074 * 
075 * frame.pack().
076 * frame.setVisible(true);
077 * </code>
078 * </pre>
079 *
080 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
081 * 
082 * @javabean.attribute
083 *          name="isContainer"
084 *          value="Boolean.TRUE"
085 *          rtexpr="true"
086 * 
087 * @javabean.class
088 *          name="JXTaskPaneContainer"
089 *          shortDescription="A component that contains JTaskPaneGroups."
090 *          stopClass="java.awt.Component"
091 * 
092 * @javabean.icons
093 *          mono16="JXTaskPaneContainer16-mono.gif"
094 *          color16="JXTaskPaneContainer16.gif"
095 *          mono32="JXTaskPaneContainer32-mono.gif"
096 *          color32="JXTaskPaneContainer32.gif"
097 */
098@JavaBean
099public class JXTaskPaneContainer extends JXPanel {
100
101    public final static String uiClassID = "swingx/TaskPaneContainerUI";
102
103    // ensure at least the default ui is registered
104    static {
105        LookAndFeelAddons.contribute(new TaskPaneContainerAddon());
106    }
107
108    /**
109     * Creates a new empty task pane.
110     */
111    public JXTaskPaneContainer() {
112        super(null);
113        updateUI();
114
115        addContainerListener(new ContainerAdapter() {
116            @Override
117            public void componentRemoved(ContainerEvent e) {
118                repaint();
119            }
120        });
121        setScrollableHeightHint(ScrollableSizeHint.VERTICAL_STRETCH);
122    }
123    
124    /**
125     * {@inheritDoc}
126     */
127    @Override
128    public TaskPaneContainerUI getUI() {
129        return (TaskPaneContainerUI) super.getUI();
130    }
131  
132    /**
133     * Notification from the <code>UIManager</code> that the L&F has changed.
134     * Replaces the current UI object with the latest version from the
135     * <code>UIManager</code>.
136     * 
137     * @see javax.swing.JComponent#updateUI
138     */
139    @Override
140    public void updateUI() {
141        setUI((TaskPaneContainerUI) LookAndFeelAddons.getUI(this,
142                TaskPaneContainerUI.class));
143    }
144
145    /**
146     * Sets the L&F object that renders this component.
147     * 
148     * @param ui the <code>TaskPaneContainerUI</code> L&F object
149     * @see javax.swing.UIDefaults#getUI
150     * 
151     * @beaninfo bound: true hidden: true description: The UI object that
152     *           implements the taskpane's LookAndFeel.
153     */
154    public void setUI(TaskPaneContainerUI ui) {
155        super.setUI(ui);
156    }
157
158    /**
159     * Returns the name of the L&F class that renders this component.
160     * 
161     * @return the string {@link #uiClassID}
162     * @see javax.swing.JComponent#getUIClassID
163     * @see javax.swing.UIDefaults#getUI
164     */
165    @Override
166    public String getUIClassID() {
167        return uiClassID;
168    }
169}