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.Border;
038: import javax.swing.border.EmptyBorder;
039:
040: import com.jgoodies.forms.factories.Borders;
041: import com.jgoodies.looks.LookUtils;
042: import com.jgoodies.looks.plastic.PlasticInternalFrameUI;
043:
044: /**
045: * Demos the <code>JDesktopPane</code>.
046: *
047: * @author Karsten Lentzsch
048: * @version $Revision: 1.5 $
049: */
050: final class DesktopTab {
051:
052: private static final float SIZE_FACTOR = LookUtils.IS_LOW_RESOLUTION ? 1f
053: : 1.175f;
054:
055: /**
056: * Builds the panel.
057: */
058: JComponent build() {
059: JPanel panel = new JPanel(new BorderLayout());
060: panel.setOpaque(false);
061: panel.setBorder(Borders.DIALOG_BORDER);
062: panel.add(new JScrollPane(buildDesktopPane()));
063: return panel;
064: }
065:
066: private JComponent buildDesktopPane() {
067: int gap = (int) (10 * SIZE_FACTOR);
068: int originX1 = 10;
069: int extentX1 = (int) (193 * SIZE_FACTOR);
070: int originX2 = originX1 + extentX1 + gap;
071: int extentX2 = extentX1;
072: int originX3 = originX2 + extentX2 + gap;
073: int extentX3 = (int) (150 * SIZE_FACTOR);
074:
075: JDesktopPane desktop = new JDesktopPane();
076: JInternalFrame frame;
077:
078: frame = new JInternalFrame("Navigation", true, true, true, true);
079: frame.setContentPane(buildFrame1ContentPane());
080: frame.setBounds(originX1, 10, extentX1, 320);
081: desktop.add(frame);
082: frame.setVisible(true);
083:
084: frame = new JInternalFrame("Properties", true, false, true,
085: true);
086: frame.setContentPane(buildFrame2ContentPane());
087: frame.setBounds(originX2, 10, extentX2, 320);
088: desktop.add(frame);
089: frame.setVisible(true);
090:
091: JInternalFrame palette = new JInternalFrame("Palette1", true,
092: true, true, true);
093: palette.putClientProperty(PlasticInternalFrameUI.IS_PALETTE,
094: Boolean.TRUE);
095: palette.setContentPane(buildPaletteContentPane());
096: palette.setBounds(originX3, 10, extentX3, 150);
097: palette.setVisible(true);
098: desktop.add(palette, JLayeredPane.PALETTE_LAYER);
099:
100: return desktop;
101: }
102:
103: private JComponent buildFrame1ContentPane() {
104: JScrollPane scrollPane = new JScrollPane(new JTree());
105: scrollPane.setPreferredSize(new Dimension(100, 140));
106: return scrollPane;
107: }
108:
109: private JComponent buildFrame2ContentPane() {
110: JScrollPane scrollPane = new JScrollPane(buildTable());
111: scrollPane.setPreferredSize(new Dimension(100, 140));
112: return scrollPane;
113: }
114:
115: private JComponent buildPaletteContentPane() {
116: JCheckBox check1 = new JCheckBox("be consistent", true);
117: check1.setContentAreaFilled(false);
118: JCheckBox check2 = new JCheckBox("use less ink", true);
119: check2.setContentAreaFilled(false);
120: final Border cardDialogBorder = new EmptyBorder(10, 6, 7, 6);
121: Box box = Box.createVerticalBox();
122: box.add(check1);
123: box.add(Box.createVerticalStrut(6));
124: box.add(check2);
125:
126: JPanel generalTab = new JPanel(new BorderLayout());
127: generalTab.setOpaque(false);
128: generalTab.add(box);
129: generalTab.setBorder(cardDialogBorder);
130:
131: JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
132: tabbedPane.add(generalTab, "General");
133: tabbedPane.add(new JLabel("Test1"), "Filter");
134: return tabbedPane;
135: }
136:
137: /**
138: * Builds and answers a sample table.
139: */
140: private JTable buildTable() {
141: JTable table = new JTable(createSampleTableData(),
142: new String[] { "Key", "Value" });
143:
144: //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
145: table.getColumnModel().getColumn(0).setPreferredWidth(95);
146: table.getColumnModel().getColumn(1).setPreferredWidth(95);
147: table.setRowSelectionInterval(2, 2);
148: return table;
149: }
150:
151: /**
152: * Creates and answers sample table data.
153: */
154: private String[][] createSampleTableData() {
155: return new String[][] { { "Name", "Karsten" },
156: { "Sex", "Male" }, { "Date of Birth", "5-Dec-1967" },
157: { "Place of Birth", "Kiel" },
158: { "Profession", "UI Designer" },
159: { "Business", "Freelancer" }, { "", "" }, { "", "" },
160: { "", "" }, { "", "" }, { "", "" }, { "", "" },
161: { "", "" }, { "", "" }, { "", "" }, { "", "" },
162: { "", "" }, { "", "" }, { "", "" }, };
163: }
164:
165: }
|