001/*
002 * $Id: BasicTaskPaneContainerUI.java 3475 2009-08-28 08:30:47Z kleopatra $
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.plaf.basic;
022
023import java.awt.LayoutManager;
024
025import javax.swing.JComponent;
026import javax.swing.LookAndFeel;
027import javax.swing.plaf.ComponentUI;
028import javax.swing.plaf.UIResource;
029
030import org.jdesktop.swingx.JXTaskPaneContainer;
031import org.jdesktop.swingx.VerticalLayout;
032import org.jdesktop.swingx.plaf.LookAndFeelAddons;
033import org.jdesktop.swingx.plaf.TaskPaneContainerUI;
034
035/**
036 * Base implementation of the <code>JXTaskPaneContainer</code> UI.
037 * 
038 * @author <a href="mailto:fred@L2FProd.com">Frederic Lavigne</a>
039 * @author Karl Schaefer
040 */
041public class BasicTaskPaneContainerUI extends TaskPaneContainerUI {
042    /**
043     * A {@code UIResource} implementation of {@code VerticalLayout}.
044     * 
045     * @author Karl George Schaefer
046     */
047    protected class VerticalLayoutUIResource extends VerticalLayout implements UIResource {
048        /**
049         * The default layout. 
050         */
051        public VerticalLayoutUIResource() {
052            super();
053        }
054
055        /**
056         * Defines a layout with the specified gap.
057         * 
058         * @param gap
059         *            the gap between components
060         */
061        public VerticalLayoutUIResource(int gap) {
062            super(gap);
063        }
064    }
065    
066  /**
067   * Returns a new instance of BasicTaskPaneContainerUI.
068   * BasicTaskPaneContainerUI delegates are allocated one per
069   * JXTaskPaneContainer.
070   * 
071   * @return A new TaskPaneContainerUI implementation for the Basic look and
072   *         feel.
073   */
074  public static ComponentUI createUI(JComponent c) {
075    return new BasicTaskPaneContainerUI();
076  }
077
078  /**
079   * The task pane container managed by this UI delegate.
080   */
081  protected JXTaskPaneContainer taskPane;
082
083  /**
084   * {@inheritDoc}
085   */
086  @Override
087public void installUI(JComponent c) {
088    super.installUI(c);
089    taskPane = (JXTaskPaneContainer)c;
090    installDefaults();
091    
092    LayoutManager manager = taskPane.getLayout();
093    
094    if (manager == null || manager instanceof UIResource) {
095        taskPane.setLayout(createDefaultLayout());
096    }
097  }
098
099    /**
100     * Installs the default colors, border, and painter of the task pane
101     * container.
102     */
103    protected void installDefaults() {
104        LookAndFeel.installColors(taskPane, "TaskPaneContainer.background",
105                "TaskPaneContainer.foreground");
106        LookAndFeel.installBorder(taskPane, "TaskPaneContainer.border");
107        LookAndFeelAddons.installBackgroundPainter(taskPane,
108                "TaskPaneContainer.backgroundPainter");
109        LookAndFeel.installProperty(taskPane, "opaque", Boolean.TRUE);
110    }
111    
112    /**
113     * Constructs a layout manager to be used by the Look and Feel.
114     * @return the layout manager for the current Look and Feel
115     */
116    protected LayoutManager createDefaultLayout() {
117        return new VerticalLayoutUIResource(14);
118    }
119    
120    /**
121     * {@inheritDoc}
122     */
123    @Override
124    public void uninstallUI(JComponent c) {
125        uninstallDefaults();
126        
127        super.uninstallUI(c);
128    }
129
130    /**
131     * Uninstalls the default colors, border, and painter of the task pane
132     * container.
133     */
134    protected void uninstallDefaults() {
135        LookAndFeel.uninstallBorder(taskPane);
136        LookAndFeelAddons.uninstallBackgroundPainter(taskPane);
137    }
138}