KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.awt.GridLayout JavaDoc;
36
37 import javax.swing.*;
38 import javax.swing.border.Border JavaDoc;
39 import javax.swing.border.EmptyBorder JavaDoc;
40
41 import com.jgoodies.forms.factories.Borders;
42 import com.jgoodies.looks.LookUtils;
43 import com.jgoodies.looks.plastic.PlasticInternalFrameUI;
44
45 /**
46  * Demos the <code>JDesktopPane</code>.
47  *
48  * @author Karsten Lentzsch
49  * @version $Revision: 1.6 $
50  */

51 final class DesktopTab {
52     
53     private static final float SIZE_FACTOR = LookUtils.IS_LOW_RESOLUTION ? 1f : 1.175f;
54
55     /**
56      * Builds the panel.
57      */

58     JComponent build() {
59         JPanel panel = new JPanel(new BorderLayout JavaDoc());
60         panel.setBorder(Borders.DIALOG_BORDER);
61         panel.add(new JScrollPane(buildDesktopPane()));
62         return panel;
63     }
64
65     private JComponent buildDesktopPane() {
66         int gap = (int) (10 * SIZE_FACTOR);
67         int originX1 = 10;
68         int extentX1 = (int) (193 * SIZE_FACTOR);
69         int originX2 = originX1 + extentX1 + gap;
70         int extentX2 = extentX1;
71         int originX3 = originX2 + extentX2 + gap;
72         int extentX3 = (int) (150 * SIZE_FACTOR);
73         
74         JDesktopPane desktop = new JDesktopPane();
75         JInternalFrame frame;
76
77         frame = new JInternalFrame("Navigation", true, true, true, true);
78         frame.setContentPane(buildFrame1ContentPane());
79         frame.setBounds(originX1, 10, extentX1, 320);
80         desktop.add(frame);
81         frame.setVisible(true);
82
83         frame = new JInternalFrame("Properties", true, false, true, true);
84         frame.setContentPane(buildFrame2ContentPane());
85         frame.setBounds(originX2, 10, extentX2, 320);
86         desktop.add(frame);
87         frame.setVisible(true);
88
89         JInternalFrame palette =
90             new JInternalFrame("Palette1", true, true, true, true);
91         palette.putClientProperty(
92             PlasticInternalFrameUI.IS_PALETTE,
93             Boolean.TRUE);
94         palette.setContentPane(buildPaletteContentPane());
95         palette.setBounds(originX3, 10, extentX3, 150);
96         palette.setVisible(true);
97         desktop.add(palette, JLayeredPane.PALETTE_LAYER);
98
99         palette = new JInternalFrame("Palette2", true, true, true, true);
100         palette.putClientProperty(
101             PlasticInternalFrameUI.IS_PALETTE,
102             Boolean.TRUE);
103         palette.setContentPane(buildBackgroundTestContentPane());
104         palette.setBounds(originX3, 170, extentX3, 160);
105         palette.setVisible(true);
106         desktop.add(palette, JLayeredPane.PALETTE_LAYER);
107
108         return desktop;
109     }
110
111     private JComponent buildFrame1ContentPane() {
112         JScrollPane scrollPane = new JScrollPane(new JTree());
113         scrollPane.setPreferredSize(new Dimension JavaDoc(100, 140));
114         return scrollPane;
115     }
116
117     private JComponent buildFrame2ContentPane() {
118         JScrollPane scrollPane = new JScrollPane(buildTable());
119         scrollPane.setPreferredSize(new Dimension JavaDoc(100, 140));
120         return scrollPane;
121     }
122
123     private JComponent buildPaletteContentPane() {
124         Border JavaDoc CARD_DIALOG_BORDER = new EmptyBorder JavaDoc(10, 6, 7, 6);
125         Box box = Box.createVerticalBox();
126         box.add(new JCheckBox("be consistent", true));
127         box.add(Box.createVerticalStrut(6));
128         box.add(new JCheckBox("use less ink", true));
129
130         JPanel generalTab = new JPanel(new BorderLayout JavaDoc());
131         generalTab.add(box);
132         generalTab.setBorder(CARD_DIALOG_BORDER);
133
134         JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
135         tabbedPane.add(generalTab, "General");
136         tabbedPane.add(new JLabel("Test1"), "Filter");
137         return tabbedPane;
138     }
139
140     private JComponent buildBackgroundTestContentPane() {
141         JTextArea area1 =
142             new JTextArea("Background should be\nthe same as below.");
143         area1.setBackground(UIManager.getColor("control"));
144         JTextArea area2 =
145             new JTextArea("Background should be\nthe same as above.");
146         area2.setOpaque(false);
147         JPanel grid = new JPanel(new GridLayout JavaDoc(2, 1));
148         grid.add(area1);
149         grid.add(area2);
150         grid.setOpaque(false);
151         return grid;
152     }
153
154     /**
155      * Builds and answers a sample table.
156      */

157     private JTable buildTable() {
158         JTable table = new JTable(
159                 createSampleTableData(),
160                 new String JavaDoc[] { "Key", "Value" });
161
162         //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
163
table.getColumnModel().getColumn(0).setPreferredWidth(95);
164         table.getColumnModel().getColumn(1).setPreferredWidth(95);
165         table.setRowSelectionInterval(2, 2);
166         return table;
167     }
168
169     /**
170      * Creates and answers sample table data.
171      */

172     private String JavaDoc[][] createSampleTableData() {
173         return new String JavaDoc[][] {
174             { "Name", "Karsten" },
175             { "Sex", "Male" },
176             { "Date of Birth", "5-Dec-1967" },
177             { "Place of Birth", "Kiel" },
178             { "Profession", "UI Designer"},
179             { "Business", "Freelancer" },
180             { "", "" },
181             { "", "" },
182             { "", "" },
183             { "", "" },
184             { "", "" },
185             { "", "" },
186             { "", "" },
187             { "", "" },
188             { "", "" },
189             { "", "" },
190             { "", "" },
191             { "", "" },
192             { "", "" },
193         };
194     }
195
196 }
Popular Tags