001: /*
002: * Copyright (c) 2001-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.looks.demo;
032:
033: import java.awt.BorderLayout;
034: import java.awt.Dimension;
035:
036: import javax.swing.*;
037: import javax.swing.border.EmptyBorder;
038: import javax.swing.tree.DefaultMutableTreeNode;
039: import javax.swing.tree.DefaultTreeModel;
040: import javax.swing.tree.TreeModel;
041:
042: import com.jgoodies.forms.factories.Borders;
043: import com.jgoodies.looks.Options;
044: import com.jgoodies.uif_lite.component.Factory;
045: import com.jgoodies.uif_lite.panel.SimpleInternalFrame;
046:
047: /**
048: * Demonstrates optionals settings for the JGoodies
049: * tabbed panes using two <code>SimpleInternalFrame</code>.
050: *
051: * @author Karsten Lentzsch
052: * @version $Revision: 1.4 $
053: */
054: final class TabTestTab {
055:
056: /**
057: * Builds and returns the panel.
058: */
059: JComponent build() {
060: JPanel panel = new JPanel(new BorderLayout());
061: panel.setOpaque(false);
062: panel.setBorder(Borders.DIALOG_BORDER);
063: panel.add(buildHorizontalSplit());
064: return panel;
065: }
066:
067: /**
068: * Builds and returns the horizontal split using stripped split panes.<p>
069: *
070: * Nesting split panes often leads to duplicate borders.
071: * However, a look&feel should not remove borders completely
072: * - unless he has good knowledge about the context: the surrounding
073: * components in the component tree and the border states.
074: */
075: private JComponent buildHorizontalSplit() {
076: JSplitPane pane = Factory.createStrippedSplitPane(
077: JSplitPane.HORIZONTAL_SPLIT, buildMainLeftPanel(),
078: buildMainRightPanel(), 0.2f);
079: pane.setOpaque(false);
080: return pane;
081: }
082:
083: /**
084: * Builds and returns a panel that uses a tabbed pane with embedded tabs
085: * enabled.
086: */
087: private JComponent buildMainLeftPanel() {
088: JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
089: tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY,
090: Boolean.TRUE);
091: tabbedPane.addTab("Tree", Factory
092: .createStrippedScrollPane(buildTree()));
093: tabbedPane.addTab("Help", Factory
094: .createStrippedScrollPane(buildHelp()));
095:
096: SimpleInternalFrame sif = new SimpleInternalFrame(
097: "Embedded Tabs");
098: sif.setPreferredSize(new Dimension(150, 100));
099: sif.add(tabbedPane);
100: return sif;
101: }
102:
103: /**
104: * Builds and returns a sample tree.
105: */
106: private JTree buildTree() {
107: JTree tree = new JTree(createSampleTreeModel());
108: tree.putClientProperty(Options.TREE_LINE_STYLE_KEY,
109: Options.TREE_LINE_STYLE_NONE_VALUE);
110: tree.expandRow(3);
111: tree.expandRow(2);
112: tree.expandRow(1);
113: return tree;
114: }
115:
116: private JComponent buildHelp() {
117: JTextArea area = new JTextArea(
118: "\n This tabbed pane uses\n embedded tabs.");
119: return area;
120: }
121:
122: /**
123: * Builds and returns a tabbed pane with the no-content-border enabled.
124: */
125: private JComponent buildMainRightPanel() {
126: JTabbedPane tabbedPane = new JTabbedPane();
127: tabbedPane.putClientProperty(Options.NO_CONTENT_BORDER_KEY,
128: Boolean.TRUE);
129: tabbedPane.addTab("Top", buildSplittedTabs(JTabbedPane.TOP));
130: tabbedPane.addTab("Bottom",
131: buildSplittedTabs(JTabbedPane.BOTTOM));
132: tabbedPane.addTab("Left", buildSplittedTabs(JTabbedPane.LEFT));
133: tabbedPane
134: .addTab("Right", buildSplittedTabs(JTabbedPane.RIGHT));
135:
136: SimpleInternalFrame sif = new SimpleInternalFrame(
137: "Tabbed Pane without Content Border");
138: sif.setPreferredSize(new Dimension(300, 100));
139: sif.add(tabbedPane);
140: return sif;
141: }
142:
143: /**
144: * Builds and returns a split pane with tabs using different tab layouts
145: * on the left and right-hand side. The tab on the left-hand side uses
146: * the <code>WRAP_TAB_LAYOUT</code>, the tab on the right side uses
147: * the <code>SCROLL_TAB_LAYOUT</code>.
148: * The tabs are positioned using the specified orientation.
149: *
150: * @param tabPlacement the placement for the tabs relative to the content
151: * @throws IllegalArgumentException if tab placement is not
152: * one of the supported values
153: */
154: private JComponent buildSplittedTabs(int tabPlacement) {
155: int orientation = (tabPlacement == JTabbedPane.TOP || tabPlacement == JTabbedPane.BOTTOM) ? JSplitPane.HORIZONTAL_SPLIT
156: : JSplitPane.VERTICAL_SPLIT;
157: JComponent split = Factory
158: .createStrippedSplitPane(orientation, buildTabPanel(
159: tabPlacement, JTabbedPane.WRAP_TAB_LAYOUT),
160: buildTabPanel(tabPlacement,
161: JTabbedPane.SCROLL_TAB_LAYOUT), 0.5f);
162: split.setOpaque(false);
163: JPanel panel = new JPanel(new BorderLayout());
164: panel.add(split, BorderLayout.CENTER);
165: panel.setBorder(new EmptyBorder(20, 20, 20, 20));
166: return panel;
167: }
168:
169: /**
170: * Builds and returns a sample tabbed pane with the specified orientation
171: * and tab layout style.
172: *
173: * @param tabPlacement the placement for the tabs relative to the content
174: * @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
175: * @throws IllegalArgumentException if tab placement or tab layout policy is not
176: * one of the supported values
177: */
178: private JComponent buildTabPanel(int tabPlacement,
179: int tabLayoutPolicy) {
180: JTabbedPane tabbedPane = new JTabbedPane(tabPlacement,
181: tabLayoutPolicy);
182: String[] colors = { "Black", "White", "Red", "Green", "Blue",
183: "Yellow" };
184: for (int i = 0; i < colors.length; i++) {
185: String color = colors[i];
186: JPanel filler = new JPanel(null);
187: filler.setOpaque(false);
188: tabbedPane.addTab(color, filler);
189: }
190: return tabbedPane;
191: }
192:
193: /**
194: * Creates and returns a sample tree model.
195: */
196: private TreeModel createSampleTreeModel() {
197: DefaultMutableTreeNode root = new DefaultMutableTreeNode(
198: "Musicians");
199: DefaultMutableTreeNode parent;
200:
201: //
202: parent = new DefaultMutableTreeNode("Drums");
203: root.add(parent);
204: parent.add(new DefaultMutableTreeNode("Elvin Jones"));
205: parent.add(new DefaultMutableTreeNode("Jack DeJohnette"));
206: parent.add(new DefaultMutableTreeNode("Rashied Ali"));
207:
208: //
209: parent = new DefaultMutableTreeNode("Piano");
210: root.add(parent);
211: parent.add(new DefaultMutableTreeNode("McCoy Tyner"));
212: parent.add(new DefaultMutableTreeNode("Sun Ra"));
213:
214: parent = new DefaultMutableTreeNode("Saxophon");
215: root.add(parent);
216: parent.add(new DefaultMutableTreeNode("Albert Ayler"));
217: parent.add(new DefaultMutableTreeNode("Archie Shepp"));
218: parent.add(new DefaultMutableTreeNode("Charlie Parker"));
219: parent.add(new DefaultMutableTreeNode("John Coltrane"));
220: parent.add(new DefaultMutableTreeNode("Ornette Coleman"));
221: parent.add(new DefaultMutableTreeNode("Pharoa Sanders"));
222: parent.add(new DefaultMutableTreeNode("Sonny Rollins"));
223:
224: return new DefaultTreeModel(root);
225: }
226:
227: }
|