KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > demo > TabTestTab


1 /*
2  * Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.looks.demo;
32
33 import java.awt.BorderLayout JavaDoc;
34 import java.awt.Dimension JavaDoc;
35
36 import javax.swing.*;
37 import javax.swing.border.EmptyBorder JavaDoc;
38 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
39 import javax.swing.tree.DefaultTreeModel JavaDoc;
40 import javax.swing.tree.TreeModel JavaDoc;
41
42 import com.jgoodies.forms.factories.Borders;
43 import com.jgoodies.looks.Options;
44 import com.jgoodies.uif_lite.component.Factory;
45 import com.jgoodies.uif_lite.panel.SimpleInternalFrame;
46
47 /**
48  * Demonstrates optionals settings for the JGoodies
49  * tabbed panes using two <code>SimpleInternalFrame</code>.
50  *
51  * @author Karsten Lentzsch
52  * @version $Revision: 1.7 $
53  */

54 final class TabTestTab {
55
56     /**
57      * Builds and returns the panel.
58      */

59     JComponent build() {
60         JPanel panel = new JPanel(new BorderLayout JavaDoc());
61         panel.setBorder(Borders.DIALOG_BORDER);
62         panel.add(buildHorizontalSplit());
63         return panel;
64     }
65     
66
67     /**
68      * Builds and returns the horizontal split using stripped split panes.<p>
69      *
70      * Nesting split panes often leads to duplicate borders.
71      * However, a look&feel should not remove borders completely
72      * - unless he has good knowledge about the context: the surrounding
73      * components in the component tree and the border states.
74      */

75     private JComponent buildHorizontalSplit() {
76         return Factory.createStrippedSplitPane(
77             JSplitPane.HORIZONTAL_SPLIT,
78             buildMainLeftPanel(),
79             buildMainRightPanel(),
80             0.2f);
81     }
82     
83     
84     /**
85      * Builds and returns a panel that uses a tabbed pane with embedded tabs
86      * enabled.
87      */

88     private JComponent buildMainLeftPanel() {
89         JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
90         tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE);
91         tabbedPane.addTab("Tree", Factory.createStrippedScrollPane(buildTree()));
92         tabbedPane.addTab("Help", Factory.createStrippedScrollPane(buildHelp()));
93         
94         SimpleInternalFrame sif = new SimpleInternalFrame("Embedded Tabs");
95         sif.setPreferredSize(new Dimension JavaDoc(150, 100));
96         sif.add(tabbedPane);
97         return sif;
98     }
99     
100
101     /**
102      * Builds and returns a sample tree.
103      */

104     private JTree buildTree() {
105         JTree tree = new JTree(createSampleTreeModel());
106         tree.putClientProperty(Options.TREE_LINE_STYLE_KEY,
107                                Options.TREE_LINE_STYLE_NONE_VALUE);
108         tree.expandRow(3);
109         tree.expandRow(2);
110         tree.expandRow(1);
111         return tree;
112     }
113     
114     
115     private JComponent buildHelp() {
116         JTextArea area = new JTextArea("\n This tabbed pane uses\n embedded tabs.");
117         return area;
118     }
119     
120
121     /**
122      * Builds and returns a tabbed pane with the no-content-border enabled.
123      */

124     private JComponent buildMainRightPanel() {
125         JTabbedPane tabbedPane = new JTabbedPane();
126         tabbedPane.putClientProperty(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE);
127         tabbedPane.addTab("Top", buildSplittedTabs(JTabbedPane.TOP));
128         tabbedPane.addTab("Bottom", buildSplittedTabs(JTabbedPane.BOTTOM));
129         tabbedPane.addTab("Left", buildSplittedTabs(JTabbedPane.LEFT));
130         tabbedPane.addTab("Right", buildSplittedTabs(JTabbedPane.RIGHT));
131
132         SimpleInternalFrame sif = new SimpleInternalFrame("Tabbed Pane without Content Border");
133         sif.setPreferredSize(new Dimension JavaDoc(300, 100));
134         sif.add(tabbedPane);
135         return sif;
136     }
137     
138     
139     /**
140      * Builds and returns a split pane with tabs using different tab layouts
141      * on the left and right-hand side. The tab on the left-hand side uses
142      * the <code>WRAP_TAB_LAYOUT</code>, the tab on the right side uses
143      * the <code>SCROLL_TAB_LAYOUT</code>.
144      * The tabs are positioned using the specified orientation.
145      *
146      * @param tabPlacement the placement for the tabs relative to the content
147      * @throws IllegalArgumentException if tab placement is not
148      * one of the supported values
149      */

150     private JComponent buildSplittedTabs(int tabPlacement) {
151         int orientation = (tabPlacement == JTabbedPane.TOP
152                         || tabPlacement == JTabbedPane.BOTTOM)
153                         ? JSplitPane.HORIZONTAL_SPLIT
154                         : JSplitPane.VERTICAL_SPLIT;
155         JComponent split = Factory.createStrippedSplitPane(
156                 orientation,
157                 buildTabPanel(tabPlacement, JTabbedPane.WRAP_TAB_LAYOUT),
158                 buildTabPanel(tabPlacement, JTabbedPane.SCROLL_TAB_LAYOUT),
159                 0.5f);
160         JPanel panel = new JPanel(new BorderLayout JavaDoc());
161         panel.add(split, BorderLayout.CENTER);
162         panel.setBorder(new EmptyBorder JavaDoc(20, 20, 20, 20));
163         return panel;
164     }
165     
166     
167     /**
168      * Builds and returns a sample tabbed pane with the specified orientation
169      * and tab layout style.
170      *
171      * @param tabPlacement the placement for the tabs relative to the content
172      * @param tabLayoutPolicy the policy for laying out tabs when all tabs will not fit on one run
173      * @throws IllegalArgumentException if tab placement or tab layout policy is not
174      * one of the supported values
175      */

176     private JComponent buildTabPanel(int tabPlacement, int tabLayoutPolicy) {
177         JTabbedPane tabbedPane = new JTabbedPane(tabPlacement, tabLayoutPolicy);
178         String JavaDoc[] colors = {
179                 "Black", "White", "Red", "Green", "Blue", "Yellow" };
180         for (int i = 0; i < colors.length; i++) {
181             String JavaDoc color = colors[i];
182             tabbedPane.addTab(color, new JPanel(null));
183         }
184         return tabbedPane;
185     }
186     
187
188     /**
189      * Creates and returns a sample tree model.
190      */

191     private TreeModel JavaDoc createSampleTreeModel() {
192         DefaultMutableTreeNode JavaDoc root = new DefaultMutableTreeNode JavaDoc("Musicians");
193         DefaultMutableTreeNode JavaDoc parent;
194
195         //
196
parent = new DefaultMutableTreeNode JavaDoc("Drums");
197         root.add(parent);
198         parent.add(new DefaultMutableTreeNode JavaDoc("Elvin Jones"));
199         parent.add(new DefaultMutableTreeNode JavaDoc("Jack DeJohnette"));
200         parent.add(new DefaultMutableTreeNode JavaDoc("Rashied Ali"));
201
202         //
203
parent = new DefaultMutableTreeNode JavaDoc("Piano");
204         root.add(parent);
205         parent.add(new DefaultMutableTreeNode JavaDoc("McCoy Tyner"));
206         parent.add(new DefaultMutableTreeNode JavaDoc("Sun Ra"));
207
208         parent = new DefaultMutableTreeNode JavaDoc("Saxophon");
209         root.add(parent);
210         parent.add(new DefaultMutableTreeNode JavaDoc("Albert Ayler"));
211         parent.add(new DefaultMutableTreeNode JavaDoc("Archie Shepp"));
212         parent.add(new DefaultMutableTreeNode JavaDoc("Charlie Parker"));
213         parent.add(new DefaultMutableTreeNode JavaDoc("John Coltrane"));
214         parent.add(new DefaultMutableTreeNode JavaDoc("Ornette Coleman"));
215         parent.add(new DefaultMutableTreeNode JavaDoc("Pharoa Sanders"));
216         parent.add(new DefaultMutableTreeNode JavaDoc("Sonny Rollins"));
217
218         return new DefaultTreeModel JavaDoc(root);
219     }
220
221
222 }
Popular Tags