KickJava   Java API By Example, From Geeks To Geeks.

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


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.tree.DefaultMutableTreeNode JavaDoc;
38 import javax.swing.tree.DefaultTreeModel JavaDoc;
39 import javax.swing.tree.TreeModel JavaDoc;
40
41 import com.jgoodies.forms.factories.Borders;
42 import com.jgoodies.looks.LookUtils;
43 import com.jgoodies.uif_lite.component.UIFSplitPane;
44
45 /**
46  * Contains nested split panels and demonstrates how ClearLook
47  * removes obsolete decorations.
48  *
49  * @author Karsten Lentzsch
50  * @version $Revision: 1.7 $
51  *
52  * @see UIFSplitPane
53  */

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

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

76     private JComponent buildHorizontalSplit() {
77         JComponent left = new JScrollPane(buildTree());
78         left.setPreferredSize(new Dimension JavaDoc(200, 100));
79
80         JComponent upperRight = new JScrollPane(buildTextArea());
81         upperRight.setPreferredSize(new Dimension JavaDoc(100, 100));
82
83         JComponent lowerRight = new JScrollPane(buildTable());
84         lowerRight.setPreferredSize(new Dimension JavaDoc(100, 100));
85
86         JSplitPane verticalSplit = UIFSplitPane.createStrippedSplitPane(
87                     JSplitPane.VERTICAL_SPLIT,
88                     upperRight,
89                     lowerRight);
90         return UIFSplitPane.createStrippedSplitPane(
91             JSplitPane.HORIZONTAL_SPLIT,
92             left,
93             verticalSplit);
94     }
95     
96
97     /**
98      * Builds and returns a sample tree.
99      */

100     private JTree buildTree() {
101         JTree tree = new JTree(createSampleTreeModel());
102         tree.expandRow(3);
103         tree.expandRow(2);
104         tree.expandRow(1);
105         return tree;
106     }
107
108     
109     /**
110      * Builds and returns a sample text area.
111      */

112     private JTextArea buildTextArea() {
113         JTextArea area = new JTextArea();
114         area.setText(
115             "May\nI\nKindly\nRemind you that a\nMargin\nImproves a text's readability.");
116         return area;
117     }
118     
119
120     /**
121      * Builds and returns a sample table.
122      */

123     private JTable buildTable() {
124         JTable table =
125             new JTable(
126                 createSampleTableData(),
127                 new String JavaDoc[] { "Artist", "Title " });
128
129         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
130         table.getColumnModel().getColumn(0).setPreferredWidth(100);
131         table.getColumnModel().getColumn(1).setPreferredWidth(300);
132         table.setRowSelectionInterval(2, 2);
133         int tableFontSize = table.getFont().getSize();
134         int minimumRowHeight = tableFontSize + 6;
135         int defaultRowHeight = LookUtils.IS_LOW_RESOLUTION ? 17 : 18;
136         table.setRowHeight(Math.max(minimumRowHeight, defaultRowHeight));
137         return table;
138     }
139
140     
141     /**
142      * Creates and returns a sample tree model.
143      */

144     private TreeModel JavaDoc createSampleTreeModel() {
145         DefaultMutableTreeNode JavaDoc root = new DefaultMutableTreeNode JavaDoc("Musicians");
146         DefaultMutableTreeNode JavaDoc parent;
147
148         //
149
parent = new DefaultMutableTreeNode JavaDoc("Drums");
150         root.add(parent);
151         parent.add(new DefaultMutableTreeNode JavaDoc("Elvin Jones"));
152         parent.add(new DefaultMutableTreeNode JavaDoc("Jack DeJohnette"));
153         parent.add(new DefaultMutableTreeNode JavaDoc("Rashied Ali"));
154
155         //
156
parent = new DefaultMutableTreeNode JavaDoc("Piano");
157         root.add(parent);
158         parent.add(new DefaultMutableTreeNode JavaDoc("Alexander von Schlippenbach"));
159         parent.add(new DefaultMutableTreeNode JavaDoc("McCoy Tyner"));
160         parent.add(new DefaultMutableTreeNode JavaDoc("Sun Ra"));
161
162         parent = new DefaultMutableTreeNode JavaDoc("Saxophon");
163         root.add(parent);
164         parent.add(new DefaultMutableTreeNode JavaDoc("Albert Ayler"));
165         parent.add(new DefaultMutableTreeNode JavaDoc("Archie Shepp"));
166         parent.add(new DefaultMutableTreeNode JavaDoc("Charlie Parker"));
167         parent.add(new DefaultMutableTreeNode JavaDoc("John Coltrane"));
168         parent.add(new DefaultMutableTreeNode JavaDoc("Ornette Coleman"));
169         parent.add(new DefaultMutableTreeNode JavaDoc("Pharoa Sanders"));
170         parent.add(new DefaultMutableTreeNode JavaDoc("Sonny Rollins"));
171
172         return new DefaultTreeModel JavaDoc(root);
173     }
174
175     
176     /**
177      * Creates and returns sample table data.
178      */

179     private String JavaDoc[][] createSampleTableData() {
180         return new String JavaDoc[][] {
181             { "Albert Ayler", "Greenwich Village" },
182             { "Carla Bley", "Escalator Over the Hill" },
183             { "Frank Zappa", "Yo' Mama" },
184             { "John Coltrane", "Ascension" },
185             { "Miles Davis", "In a Silent Way" },
186             { "Pharoa Sanders", "Karma" },
187             { "Wayne Shorter", "Juju" },
188             { "", "" },
189             { "", "" },
190             { "", "" },
191             { "", "" },
192             { "", "" },
193             { "", "" },
194             { "", "" },
195             { "", "" },
196             { "", "" },
197         };
198     }
199
200 }
Popular Tags