1
35
36
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
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
101 public static void main(String[] args) {
102 InternalFrameDemo demo = new InternalFrameDemo(null);
103 demo.mainImpl();
104 }
105
106
109 public InternalFrameDemo(SwingSet2 swingset) {
110 super(swingset, "InternalFrameDemo", "toolbar/JDesktop.gif");
111
112 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 desktop = new JDesktopPane();
125 getDemoPanel().add(desktop, BorderLayout.CENTER);
126
127 createInternalFramePalette();
129
130 JInternalFrame frame1 = createInternalFrame(icon1, FIRST_FRAME_LAYER, 1, 1);
132 frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT);
133
134 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
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 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
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 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 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 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 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 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 }
344