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