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.table.AbstractTableModel;
038: import javax.swing.table.TableModel;
039: import javax.swing.tree.DefaultMutableTreeNode;
040: import javax.swing.tree.DefaultTreeModel;
041: import javax.swing.tree.TreeModel;
042:
043: import com.jgoodies.forms.factories.Borders;
044: import com.jgoodies.looks.LookUtils;
045: import com.jgoodies.uif_lite.component.UIFSplitPane;
046:
047: /**
048: * Contains nested split panels and demonstrates how ClearLook
049: * removes obsolete decorations.
050: *
051: * @author Karsten Lentzsch
052: * @version $Revision: 1.5 $
053: *
054: * @see UIFSplitPane
055: */
056: final class SplitTab {
057:
058: /**
059: * Builds and returns the panel.
060: */
061: JComponent build() {
062: JPanel panel = new JPanel(new BorderLayout());
063: panel.setOpaque(false);
064: panel.setBorder(Borders.DIALOG_BORDER);
065: panel.add(buildHorizontalSplit());
066: return panel;
067: }
068:
069: /**
070: * Builds and returns the horizontal split using stripped split panes.<p>
071: *
072: * Nesting split panes often leads to duplicate borders.
073: * However, a look&feel should not remove borders completely
074: * - unless he has good knowledge about the context: the surrounding
075: * components in the component tree and the border states.
076: */
077: private JComponent buildHorizontalSplit() {
078: JComponent left = new JScrollPane(buildTree());
079: left.setPreferredSize(new Dimension(200, 100));
080:
081: JComponent upperRight = new JScrollPane(buildTextArea());
082: upperRight.setPreferredSize(new Dimension(100, 100));
083:
084: JComponent lowerRight = new JScrollPane(buildTable());
085: lowerRight.setPreferredSize(new Dimension(100, 100));
086:
087: JSplitPane verticalSplit = UIFSplitPane
088: .createStrippedSplitPane(JSplitPane.VERTICAL_SPLIT,
089: upperRight, lowerRight);
090: verticalSplit.setOpaque(false);
091: JSplitPane horizontalSplit = UIFSplitPane
092: .createStrippedSplitPane(JSplitPane.HORIZONTAL_SPLIT,
093: left, verticalSplit);
094: horizontalSplit.setOpaque(false);
095: return horizontalSplit;
096: }
097:
098: /**
099: * Builds and returns a sample tree.
100: */
101: private JTree buildTree() {
102: JTree tree = new JTree(createSampleTreeModel());
103: tree.expandRow(3);
104: tree.expandRow(2);
105: tree.expandRow(1);
106: return tree;
107: }
108:
109: /**
110: * Builds and returns a sample text area.
111: */
112: private JTextArea buildTextArea() {
113: JTextArea area = new JTextArea();
114: area
115: .setText("May\nI\nKindly\nRemind you that a\nMargin\nImproves a text's readability.");
116: return area;
117: }
118:
119: /**
120: * Builds and returns a sample table.
121: */
122: private JTable buildTable() {
123: TableModel model = new SampleTableModel(
124: createSampleTableData(), new String[] { "Artist",
125: "Title ", "Free" });
126: JTable table = new JTable(model);
127:
128: table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
129: table.getColumnModel().getColumn(0).setPreferredWidth(100);
130: table.getColumnModel().getColumn(1).setPreferredWidth(250);
131: table.getColumnModel().getColumn(2).setPreferredWidth(50);
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
137: .setRowHeight(Math.max(minimumRowHeight,
138: defaultRowHeight));
139: return table;
140: }
141:
142: /**
143: * Creates and returns a sample tree model.
144: */
145: private TreeModel createSampleTreeModel() {
146: DefaultMutableTreeNode root = new DefaultMutableTreeNode(
147: "Musicians");
148: DefaultMutableTreeNode parent;
149:
150: //
151: parent = new DefaultMutableTreeNode("Drums");
152: root.add(parent);
153: parent.add(new DefaultMutableTreeNode("Elvin Jones"));
154: parent.add(new DefaultMutableTreeNode("Jack DeJohnette"));
155: parent.add(new DefaultMutableTreeNode("Rashied Ali"));
156:
157: //
158: parent = new DefaultMutableTreeNode("Piano");
159: root.add(parent);
160: parent.add(new DefaultMutableTreeNode(
161: "Alexander von Schlippenbach"));
162: parent.add(new DefaultMutableTreeNode("McCoy Tyner"));
163: parent.add(new DefaultMutableTreeNode("Sun Ra"));
164:
165: parent = new DefaultMutableTreeNode("Saxophon");
166: root.add(parent);
167: parent.add(new DefaultMutableTreeNode("Albert Ayler"));
168: parent.add(new DefaultMutableTreeNode("Archie Shepp"));
169: parent.add(new DefaultMutableTreeNode("Charlie Parker"));
170: parent.add(new DefaultMutableTreeNode("John Coltrane"));
171: parent.add(new DefaultMutableTreeNode("Ornette Coleman"));
172: parent.add(new DefaultMutableTreeNode("Pharoa Sanders"));
173: parent.add(new DefaultMutableTreeNode("Sonny Rollins"));
174:
175: return new DefaultTreeModel(root);
176: }
177:
178: /**
179: * Creates and returns sample table data.
180: */
181: private Object[][] createSampleTableData() {
182: return new Object[][] {
183: { "Albert Ayler", "Greenwich Village", Boolean.TRUE },
184: { "Carla Bley", "Escalator Over the Hill", Boolean.TRUE },
185: { "Frank Zappa", "Yo' Mama", Boolean.TRUE },
186: { "John Coltrane", "Ascension", Boolean.TRUE },
187: { "Miles Davis", "In a Silent Way", Boolean.TRUE },
188: { "Pharoa Sanders", "Karma", Boolean.TRUE },
189: { "Wayne Shorter", "Juju", Boolean.TRUE },
190: { "", "", Boolean.FALSE }, { "", "", Boolean.FALSE },
191: { "", "", Boolean.FALSE }, { "", "", Boolean.FALSE },
192: { "", "", Boolean.FALSE }, { "", "", Boolean.FALSE },
193: { "", "", Boolean.FALSE }, { "", "", Boolean.FALSE },
194: { "", "", Boolean.FALSE }, };
195: }
196:
197: private static final class SampleTableModel extends
198: AbstractTableModel {
199:
200: private final String[] columnNames;
201: private final Object[][] rowData;
202:
203: SampleTableModel(Object[][] rowData, String[] columnNames) {
204: this .columnNames = columnNames;
205: this .rowData = rowData;
206: }
207:
208: public String getColumnName(int column) {
209: return columnNames[column].toString();
210: }
211:
212: public int getRowCount() {
213: return rowData.length;
214: }
215:
216: public int getColumnCount() {
217: return columnNames.length;
218: }
219:
220: public Class getColumnClass(int column) {
221: return column == 2 ? Boolean.class : super
222: .getColumnClass(column);
223: }
224:
225: public Object getValueAt(int row, int col) {
226: return rowData[row][col];
227: }
228:
229: public boolean isCellEditable(int row, int column) {
230: return true;
231: }
232:
233: public void setValueAt(Object value, int row, int col) {
234: rowData[row][col] = value;
235: fireTableCellUpdated(row, col);
236: }
237: }
238:
239: }
|