001 /*
002 * $Id: BasicTaskPaneContainerUI.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.plaf.basic;
022
023 import java.awt.LayoutManager;
024
025 import javax.swing.JComponent;
026 import javax.swing.LookAndFeel;
027 import javax.swing.plaf.ComponentUI;
028 import javax.swing.plaf.UIResource;
029
030 import org.jdesktop.swingx.JXTaskPaneContainer;
031 import org.jdesktop.swingx.VerticalLayout;
032 import org.jdesktop.swingx.plaf.LookAndFeelAddons;
033 import 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 */
041 public 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 public void installUI(JComponent c) {
087 super.installUI(c);
088 taskPane = (JXTaskPaneContainer)c;
089 installDefaults();
090
091 LayoutManager manager = taskPane.getLayout();
092
093 if (manager == null || manager instanceof UIResource) {
094 taskPane.setLayout(createDefaultLayout());
095 }
096 }
097
098 /**
099 * Installs the default colors, border, and painter of the task pane
100 * container.
101 */
102 protected void installDefaults() {
103 LookAndFeel.installColors(taskPane, "TaskPaneContainer.background",
104 "TaskPaneContainer.foreground");
105 LookAndFeel.installBorder(taskPane, "TaskPaneContainer.border");
106 LookAndFeelAddons.installBackgroundPainter(taskPane,
107 "TaskPaneContainer.backgroundPainter");
108 LookAndFeel.installProperty(taskPane, "opaque", Boolean.TRUE);
109 }
110
111 /**
112 * Constructs a layout manager to be used by the Look and Feel.
113 * @return the layout manager for the current Look and Feel
114 */
115 protected LayoutManager createDefaultLayout() {
116 return new VerticalLayoutUIResource(14);
117 }
118
119 /**
120 * {@inheritDoc}
121 */
122 public void uninstallUI(JComponent c) {
123 uninstallDefaults();
124
125 super.uninstallUI(c);
126 }
127
128 /**
129 * Uninstalls the default colors, border, and painter of the task pane
130 * container.
131 */
132 protected void uninstallDefaults() {
133 LookAndFeel.uninstallBorder(taskPane);
134 LookAndFeelAddons.uninstallBackgroundPainter(taskPane);
135 }
136 }