JXTaskPaneContainer.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:6k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: JXTaskPaneContainer.java,v 1.6 2005/10/10 18:01:59 rbair Exp $
  3.  *
  4.  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.swingx;
  22. import java.awt.Dimension;
  23. import java.awt.Rectangle;
  24. import javax.swing.JComponent;
  25. import javax.swing.JViewport;
  26. import javax.swing.Scrollable;
  27. import org.jdesktop.swingx.plaf.JXTaskPaneContainerAddon;
  28. import org.jdesktop.swingx.plaf.LookAndFeelAddons;
  29. import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
  30. /**
  31.  * <code>JXTaskPaneContainer</code> provides an elegant view
  32.  * to display a list of tasks ordered by groups ({@link org.jdesktop.swingx.JXTaskPane}.
  33.  * 
  34.  * <p>
  35.  * Although {@link org.jdesktop.swingx.JXTaskPane} can be added to any other
  36.  * container, the <code>JXTaskPaneContainer</code> will provide better
  37.  * fidelity when it comes to matching the look and feel of the host operating
  38.  * system than any other panel. As example, when using on a Windows platform,
  39.  * the <code>JXTaskPaneContainer</code> will be painted with light gradient
  40.  * background. Also <code>JXTaskPaneContainer</code> takes care of using the
  41.  * right {@link java.awt.LayoutManager} (as required by
  42.  * {@link org.jdesktop.swingx.JXCollapsiblePane}) so that
  43.  * {@link org.jdesktop.swingx.JXTaskPane} behaves correctly when collapsing and
  44.  * expanding its content.
  45.  *  
  46.  * <p>
  47.  * <code>JXTaskPaneContainer<code> can be added to a JScrollPane.
  48.  * 
  49.  * <p>
  50.  * Example:
  51.  * <pre>
  52.  * <code>
  53.  * JXFrame frame = new JXFrame();
  54.  * 
  55.  * // a container to put all JXTaskPane together
  56.  * JXTaskPaneContainer taskPaneContainer = new JXTaskPaneContainer();
  57.  * 
  58.  * // add JXTaskPanes to the container
  59.  * JXTaskPane actionPane = createActionPane();
  60.  * JXTaskPane miscActionPane = createMiscActionPane();
  61.  * JXTaskPane detailsPane = createDetailsPane();
  62.  * taskPaneContainer.add(actionPane);
  63.  * taskPaneContainer.add(miscActionPane);
  64.  * taskPaneContainer.add(detailsPane);
  65.  *
  66.  * // put the action list on the left in a JScrollPane
  67.  * // as we have several taskPane and we want to make sure they
  68.  * // all get visible.   
  69.  * frame.add(new JScrollPane(taskPaneContainer), BorderLayout.EAST);
  70.  * 
  71.  * // and a file browser in the middle
  72.  * frame.add(fileBrowser, BorderLayout.CENTER);
  73.  * 
  74.  * frame.pack().
  75.  * frame.setVisible(true);
  76.  * </code>
  77.  * </pre>
  78.  *
  79.  * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
  80.  * 
  81.  * @javabean.attribute
  82.  *          name="isContainer"
  83.  *          value="Boolean.TRUE"
  84.  *          rtexpr="true"
  85.  * 
  86.  * @javabean.class
  87.  *          name="JXTaskPaneContainer"
  88.  *          shortDescription="A component that contains JTaskPaneGroups."
  89.  *          stopClass="java.awt.Component"
  90.  * 
  91.  * @javabean.icons
  92.  *          mono16="JXTaskPaneContainer16-mono.gif"
  93.  *          color16="JXTaskPaneContainer16.gif"
  94.  *          mono32="JXTaskPaneContainer32-mono.gif"
  95.  *          color32="JXTaskPaneContainer32.gif"
  96.  */
  97. public class JXTaskPaneContainer extends JComponent implements Scrollable {
  98.   public final static String uiClassID = "swingx/TaskPaneContainerUI";
  99.   
  100.   // ensure at least the default ui is registered
  101.   static {
  102.     LookAndFeelAddons.contribute(new JXTaskPaneContainerAddon());
  103.   }
  104.   /**
  105.    * Creates a new empty taskpane.
  106.    */
  107.   public JXTaskPaneContainer() {
  108.     updateUI();
  109.   }
  110.   /**
  111.    * Notification from the <code>UIManager</code> that the L&F has changed.
  112.    * Replaces the current UI object with the latest version from the <code>UIManager</code>.
  113.    * 
  114.    * @see javax.swing.JComponent#updateUI
  115.    */
  116.   public void updateUI() {
  117.     setUI((TaskPaneContainerUI)LookAndFeelAddons.getUI(this, TaskPaneContainerUI.class));
  118.   }
  119.   /**
  120.    * Sets the L&F object that renders this component.
  121.    * 
  122.    * @param ui the <code>TaskPaneContainerUI</code> L&F object
  123.    * @see javax.swing.UIDefaults#getUI
  124.    * 
  125.    * @beaninfo bound: true hidden: true description: The UI object that
  126.    * implements the taskpane's LookAndFeel.
  127.    */
  128.   public void setUI(TaskPaneContainerUI ui) {
  129.     super.setUI(ui);
  130.   }
  131.   /**
  132.    * Returns the name of the L&F class that renders this component.
  133.    * 
  134.    * @return the string {@link #uiClassID}
  135.    * @see javax.swing.JComponent#getUIClassID
  136.    * @see javax.swing.UIDefaults#getUI
  137.    */
  138.   public String getUIClassID() {
  139.     return uiClassID;
  140.   }
  141.   /**
  142.    * Adds a <code>JXTaskPane</code> to this JXTaskPaneContainer.
  143.    * 
  144.    * @param group
  145.    */
  146.   public void add(JXTaskPane group) {
  147.     super.add(group);
  148.   }
  149.   /**
  150.    * Removes a <code>JXTaskPane</code> from this JXTaskPaneContainer.
  151.    * 
  152.    * @param group
  153.    */
  154.   public void remove(JXTaskPane group) {
  155.     super.remove(group);
  156.   }
  157.   /**
  158.    * @see Scrollable#getPreferredScrollableViewportSize()
  159.    */
  160.   public Dimension getPreferredScrollableViewportSize() {
  161.     return getPreferredSize();
  162.   }
  163.   /**
  164.    * @see Scrollable#getScrollableBlockIncrement(java.awt.Rectangle, int, int)
  165.    */
  166.   public int getScrollableBlockIncrement(
  167.     Rectangle visibleRect,
  168.     int orientation,
  169.     int direction) {
  170.     return 10;
  171.   }
  172.   
  173.   /**
  174.    * @see Scrollable#getScrollableTracksViewportHeight()
  175.    */
  176.   public boolean getScrollableTracksViewportHeight() {
  177.     if (getParent() instanceof JViewport) {
  178.       return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
  179.     } else {
  180.       return false;
  181.     }
  182.   }
  183.   
  184.   /**
  185.    * @see Scrollable#getScrollableTracksViewportWidth()
  186.    */
  187.   public boolean getScrollableTracksViewportWidth() {
  188.     return true;
  189.   }
  190.   
  191.   /**
  192.    * @see Scrollable#getScrollableUnitIncrement(java.awt.Rectangle, int, int)
  193.    */
  194.   public int getScrollableUnitIncrement(
  195.     Rectangle visibleRect,
  196.     int orientation,
  197.     int direction) {
  198.     return 10;
  199.   }
  200.   
  201. }