1 | /* |
2 | * Copyright (c) 2003 Sun Microsystems, Inc. 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 |
6 | * are met: |
7 | * |
8 | * -Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * |
11 | * -Redistribution in binary form must reproduct the above copyright |
12 | * notice, this list of conditions and the following disclaimer in |
13 | * the documentation and/or other materials provided with the distribution. |
14 | * |
15 | * Neither the name of Sun Microsystems, Inc. or the names of contributors |
16 | * may be used to endorse or promote products derived from this software |
17 | * without specific prior written permission. |
18 | * |
19 | * This software is provided "AS IS," without a warranty of any kind. ALL |
20 | * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING |
21 | * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
22 | * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT |
23 | * BE LIABLE FOR ANY DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT |
24 | * OF OR RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR ITS |
25 | * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST |
26 | * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, |
27 | * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY |
28 | * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN |
29 | * IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
30 | * |
31 | * You acknowledge that Software is not designed, licensed or intended for |
32 | * use in the design, construction, operation or maintenance of any nuclear |
33 | * facility. |
34 | */ |
35 | |
36 | /* |
37 | * @(#)InternalFrameDemo.java 1.10 03/01/23 |
38 | */ |
39 | |
40 | |
41 | import javax.swing.*; |
42 | import javax.swing.event.*; |
43 | import javax.swing.text.*; |
44 | import javax.swing.border.*; |
45 | import javax.swing.colorchooser.*; |
46 | import javax.swing.filechooser.*; |
47 | import javax.accessibility.*; |
48 | |
49 | import java.awt.*; |
50 | import java.awt.event.*; |
51 | import java.beans.*; |
52 | import java.util.*; |
53 | import java.io.*; |
54 | import java.applet.*; |
55 | import java.net.*; |
56 | |
57 | /** |
58 | * Internal Frames Demo |
59 | * |
60 | * @version 1.10 01/23/03 |
61 | * @author Jeff Dinkins |
62 | */ |
63 | public class InternalFrameDemo extends DemoModule { |
64 | int windowCount = 0; |
65 | JDesktopPane desktop = null; |
66 | |
67 | ImageIcon icon1, icon2, icon3, icon4; |
68 | ImageIcon smIcon1, smIcon2, smIcon3, smIcon4; |
69 | |
70 | public Integer FIRST_FRAME_LAYER = new Integer(1); |
71 | public Integer DEMO_FRAME_LAYER = new Integer(2); |
72 | public Integer PALETTE_LAYER = new Integer(3); |
73 | |
74 | public int FRAME0_X = 15; |
75 | public int FRAME0_Y = 280; |
76 | |
77 | public int FRAME0_WIDTH = 320; |
78 | public int FRAME0_HEIGHT = 230; |
79 | |
80 | public int FRAME_WIDTH = 225; |
81 | public int FRAME_HEIGHT = 150; |
82 | |
83 | public int PALETTE_X = 375; |
84 | public int PALETTE_Y = 20; |
85 | |
86 | public int PALETTE_WIDTH = 260; |
87 | public int PALETTE_HEIGHT = 230; |
88 | |
89 | JCheckBox windowResizable = null; |
90 | JCheckBox windowClosable = null; |
91 | JCheckBox windowIconifiable = null; |
92 | JCheckBox windowMaximizable = null; |
93 | |
94 | JTextField windowTitleField = null; |
95 | JLabel windowTitleLabel = null; |
96 | |
97 | |
98 | /** |
99 | * main method allows us to run as a standalone demo. |
100 | */ |
101 | public static void main(String[] args) { |
102 | InternalFrameDemo demo = new InternalFrameDemo(null); |
103 | demo.mainImpl(); |
104 | } |
105 | |
106 | /** |
107 | * InternalFrameDemo Constructor |
108 | */ |
109 | public InternalFrameDemo(SwingSet2 swingset) { |
110 | super(swingset, "InternalFrameDemo", "toolbar/JDesktop.gif"); |
111 | |
112 | // preload all the icons we need for this demo |
113 | icon1 = createImageIcon("ImageClub/misc/fish.gif", getString("InternalFrameDemo.fish")); |
114 | icon2 = createImageIcon("ImageClub/misc/moon.gif", getString("InternalFrameDemo.moon")); |
115 | icon3 = createImageIcon("ImageClub/misc/sun.gif", getString("InternalFrameDemo.sun")); |
116 | icon4 = createImageIcon("ImageClub/misc/cab.gif", getString("InternalFrameDemo.cab")); |
117 | |
118 | smIcon1 = createImageIcon("ImageClub/misc/fish_small.gif", getString("InternalFrameDemo.fish")); |
119 | smIcon2 = createImageIcon("ImageClub/misc/moon_small.gif", getString("InternalFrameDemo.moon")); |
120 | smIcon3 = createImageIcon("ImageClub/misc/sun_small.gif", getString("InternalFrameDemo.sun")); |
121 | smIcon4 = createImageIcon("ImageClub/misc/cab_small.gif", getString("InternalFrameDemo.cab")); |
122 | |
123 | // Create the desktop pane |
124 | desktop = new JDesktopPane(); |
125 | getDemoPanel().add(desktop, BorderLayout.CENTER); |
126 | |
127 | // Create the "frame maker" palette |
128 | createInternalFramePalette(); |
129 | |
130 | // Create an initial internal frame to show |
131 | JInternalFrame frame1 = createInternalFrame(icon1, FIRST_FRAME_LAYER, 1, 1); |
132 | frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT); |
133 | |
134 | // Create four more starter windows |
135 | createInternalFrame(icon1, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); |
136 | createInternalFrame(icon3, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); |
137 | createInternalFrame(icon4, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); |
138 | createInternalFrame(icon2, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT); |
139 | } |
140 | |
141 | |
142 | |
143 | /** |
144 | * Create an internal frame and add a scrollable imageicon to it |
145 | */ |
146 | public JInternalFrame createInternalFrame(Icon icon, Integer layer, int width, int height) { |
147 | JInternalFrame jif = new JInternalFrame(); |
148 | |
149 | if(!windowTitleField.getText().equals(getString("InternalFrameDemo.frame_label"))) { |
150 | jif.setTitle(windowTitleField.getText() + " "); |
151 | } else { |
152 | jif = new JInternalFrame(getString("InternalFrameDemo.frame_label") + " " + windowCount + " "); |
153 | } |
154 | |
155 | // set properties |
156 | jif.setClosable(windowClosable.isSelected()); |
157 | jif.setMaximizable(windowMaximizable.isSelected()); |
158 | jif.setIconifiable(windowIconifiable.isSelected()); |
159 | jif.setResizable(windowResizable.isSelected()); |
160 | |
161 | jif.setBounds(20*(windowCount%10), 20*(windowCount%10), width, height); |
162 | jif.setContentPane(new ImageScroller(this, icon, 0, windowCount)); |
163 | |
164 | windowCount++; |
165 | |
166 | desktop.add(jif, layer); |
167 | |
168 | // Set this internal frame to be selected |
169 | |
170 | try { |
171 | jif.setSelected(true); |
172 | } catch (java.beans.PropertyVetoException e2) { |
173 | } |
174 | |
175 | jif.show(); |
176 | |
177 | return jif; |
178 | } |
179 | |
180 | public JInternalFrame createInternalFramePalette() { |
181 | JInternalFrame palette = new JInternalFrame( |
182 | getString("InternalFrameDemo.palette_label") |
183 | ); |
184 | palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); |
185 | palette.getContentPane().setLayout(new BorderLayout()); |
186 | palette.setBounds(PALETTE_X, PALETTE_Y, PALETTE_WIDTH, PALETTE_HEIGHT); |
187 | palette.setResizable(true); |
188 | palette.setIconifiable(true); |
189 | desktop.add(palette, PALETTE_LAYER); |
190 | |
191 | // ************************************* |
192 | // * Create create frame maker buttons * |
193 | // ************************************* |
194 | JButton b1 = new JButton(smIcon1); |
195 | JButton b2 = new JButton(smIcon2); |
196 | JButton b3 = new JButton(smIcon3); |
197 | JButton b4 = new JButton(smIcon4); |
198 | |
199 | // add frame maker actions |
200 | b1.addActionListener(new ShowFrameAction(this, icon1)); |
201 | b2.addActionListener(new ShowFrameAction(this, icon2)); |
202 | b3.addActionListener(new ShowFrameAction(this, icon3)); |
203 | b4.addActionListener(new ShowFrameAction(this, icon4)); |
204 | |
205 | // add frame maker buttons to panel |
206 | JPanel p = new JPanel(); |
207 | p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
208 | |
209 | JPanel buttons1 = new JPanel(); |
210 | buttons1.setLayout(new BoxLayout(buttons1, BoxLayout.X_AXIS)); |
211 | |
212 | JPanel buttons2 = new JPanel(); |
213 | buttons2.setLayout(new BoxLayout(buttons2, BoxLayout.X_AXIS)); |
214 | |
215 | buttons1.add(b1); |
216 | buttons1.add(Box.createRigidArea(HGAP15)); |
217 | buttons1.add(b2); |
218 | |
219 | buttons2.add(b3); |
220 | buttons2.add(Box.createRigidArea(HGAP15)); |
221 | buttons2.add(b4); |
222 | |
223 | p.add(Box.createRigidArea(VGAP10)); |
224 | p.add(buttons1); |
225 | p.add(Box.createRigidArea(VGAP15)); |
226 | p.add(buttons2); |
227 | p.add(Box.createRigidArea(VGAP10)); |
228 | |
229 | palette.getContentPane().add(p, BorderLayout.NORTH); |
230 | |
231 | // ************************************ |
232 | // * Create frame property checkboxes * |
233 | // ************************************ |
234 | p = new JPanel() { |
235 | Insets insets = new Insets(10,15,10,5); |
236 | public Insets getInsets() { |
237 | return insets; |
238 | } |
239 | }; |
240 | p.setLayout(new GridLayout(1,2)); |
241 | |
242 | |
243 | Box box = new Box(BoxLayout.Y_AXIS); |
244 | windowResizable = new JCheckBox(getString("InternalFrameDemo.resizable_label"), true); |
245 | windowIconifiable = new JCheckBox(getString("InternalFrameDemo.iconifiable_label"), true); |
246 | |
247 | box.add(windowResizable); |
248 | box.add(windowIconifiable); |
249 | p.add(box); |
250 | |
251 | box = new Box(BoxLayout.Y_AXIS); |
252 | windowClosable = new JCheckBox(getString("InternalFrameDemo.closable_label"), true); |
253 | windowMaximizable = new JCheckBox(getString("InternalFrameDemo.maximizable_label"), true); |
254 | |
255 | box.add(windowClosable); |
256 | box.add(windowMaximizable); |
257 | p.add(box); |
258 | |
259 | palette.getContentPane().add(p, BorderLayout.CENTER); |
260 | |
261 | |
262 | // ************************************ |
263 | // * Create Frame title textfield * |
264 | // ************************************ |
265 | p = new JPanel() { |
266 | Insets insets = new Insets(0,0,10,0); |
267 | public Insets getInsets() { |
268 | return insets; |
269 | } |
270 | }; |
271 | |
272 | windowTitleField = new JTextField(getString("InternalFrameDemo.frame_label")); |
273 | windowTitleLabel = new JLabel(getString("InternalFrameDemo.title_text_field_label")); |
274 | |
275 | p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
276 | p.add(Box.createRigidArea(HGAP5)); |
277 | p.add(windowTitleLabel, BorderLayout.WEST); |
278 | p.add(Box.createRigidArea(HGAP5)); |
279 | p.add(windowTitleField, BorderLayout.CENTER); |
280 | p.add(Box.createRigidArea(HGAP5)); |
281 | |
282 | palette.getContentPane().add(p, BorderLayout.SOUTH); |
283 | |
284 | palette.show(); |
285 | |
286 | return palette; |
287 | } |
288 | |
289 | |
290 | class ShowFrameAction extends AbstractAction { |
291 | InternalFrameDemo demo; |
292 | Icon icon; |
293 | |
294 | |
295 | public ShowFrameAction(InternalFrameDemo demo, Icon icon) { |
296 | this.demo = demo; |
297 | this.icon = icon; |
298 | } |
299 | |
300 | public void actionPerformed(ActionEvent e) { |
301 | demo.createInternalFrame(icon, |
302 | getDemoFrameLayer(), |
303 | getFrameWidth(), |
304 | getFrameHeight() |
305 | ); |
306 | } |
307 | } |
308 | |
309 | public int getFrameWidth() { |
310 | return FRAME_WIDTH; |
311 | } |
312 | |
313 | public int getFrameHeight() { |
314 | return FRAME_HEIGHT; |
315 | } |
316 | |
317 | public Integer getDemoFrameLayer() { |
318 | return DEMO_FRAME_LAYER; |
319 | } |
320 | |
321 | class ImageScroller extends JScrollPane { |
322 | |
323 | public ImageScroller(InternalFrameDemo demo, Icon icon, int layer, int count) { |
324 | super(); |
325 | JPanel p = new JPanel(); |
326 | p.setBackground(Color.white); |
327 | p.setLayout(new BorderLayout() ); |
328 | |
329 | p.add(new JLabel(icon), BorderLayout.CENTER); |
330 | |
331 | getViewport().add(p); |
332 | getHorizontalScrollBar().setUnitIncrement(10); |
333 | getVerticalScrollBar().setUnitIncrement(10); |
334 | } |
335 | |
336 | public Dimension getMinimumSize() { |
337 | return new Dimension(25, 25); |
338 | } |
339 | |
340 | } |
341 | |
342 | |
343 | } |