1
36
37
40
41
42 import javax.swing.*;
43 import javax.swing.event.*;
44 import javax.swing.text.*;
45 import javax.swing.border.*;
46 import javax.swing.colorchooser.*;
47 import javax.swing.filechooser.*;
48 import javax.accessibility.*;
49
50 import java.awt.*;
51 import java.awt.event.*;
52 import java.beans.*;
53 import java.util.*;
54 import java.io.*;
55 import java.applet.*;
56 import java.net.*;
57
58
64 public class InternalFrameDemo extends DemoModule {
65 int windowCount = 0;
66 JDesktopPane desktop = null;
67
68 ImageIcon icon1, icon2, icon3, icon4;
69 ImageIcon smIcon1, smIcon2, smIcon3, smIcon4;
70
71 public Integer FIRST_FRAME_LAYER = new Integer(1);
72 public Integer DEMO_FRAME_LAYER = new Integer(2);
73 public Integer PALETTE_LAYER = new Integer(3);
74
75 public int FRAME0_X = 15;
76 public int FRAME0_Y = 280;
77
78 public int FRAME0_WIDTH = 320;
79 public int FRAME0_HEIGHT = 230;
80
81 public int FRAME_WIDTH = 225;
82 public int FRAME_HEIGHT = 150;
83
84 public int PALETTE_X = 375;
85 public int PALETTE_Y = 20;
86
87 public int PALETTE_WIDTH = 260;
88 public int PALETTE_HEIGHT = 260;
89
90 JCheckBox windowResizable = null;
91 JCheckBox windowClosable = null;
92 JCheckBox windowIconifiable = null;
93 JCheckBox windowMaximizable = null;
94
95 JTextField windowTitleField = null;
96 JLabel windowTitleLabel = null;
97
98
99
102 public static void main(String[] args) {
103 InternalFrameDemo demo = new InternalFrameDemo(null);
104 demo.mainImpl();
105 }
106
107
110 public InternalFrameDemo(SwingSet2 swingset) {
111 super(swingset, "InternalFrameDemo", "toolbar/JDesktop.gif");
112
113 icon1 = createImageIcon("ImageClub/misc/fish.gif", getString("InternalFrameDemo.fish"));
115 icon2 = createImageIcon("ImageClub/misc/moon.gif", getString("InternalFrameDemo.moon"));
116 icon3 = createImageIcon("ImageClub/misc/sun.gif", getString("InternalFrameDemo.sun"));
117 icon4 = createImageIcon("ImageClub/misc/cab.gif", getString("InternalFrameDemo.cab"));
118
119 smIcon1 = createImageIcon("ImageClub/misc/fish_small.gif", getString("InternalFrameDemo.fish"));
120 smIcon2 = createImageIcon("ImageClub/misc/moon_small.gif", getString("InternalFrameDemo.moon"));
121 smIcon3 = createImageIcon("ImageClub/misc/sun_small.gif", getString("InternalFrameDemo.sun"));
122 smIcon4 = createImageIcon("ImageClub/misc/cab_small.gif", getString("InternalFrameDemo.cab"));
123
124 desktop = new JDesktopPane();
126 getDemoPanel().add(desktop, BorderLayout.CENTER);
127
128 createInternalFramePalette();
130
131 JInternalFrame frame1 = createInternalFrame(icon1, FIRST_FRAME_LAYER, 1, 1);
133 frame1.setBounds(FRAME0_X, FRAME0_Y, FRAME0_WIDTH, FRAME0_HEIGHT);
134
135 createInternalFrame(icon1, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
137 createInternalFrame(icon3, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
138 createInternalFrame(icon4, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
139 createInternalFrame(icon2, DEMO_FRAME_LAYER, FRAME_WIDTH, FRAME_HEIGHT);
140 }
141
142
143
144
147 public JInternalFrame createInternalFrame(Icon icon, Integer layer, int width, int height) {
148 JInternalFrame jif = new JInternalFrame();
149
150 if(!windowTitleField.getText().equals(getString("InternalFrameDemo.frame_label"))) {
151 jif.setTitle(windowTitleField.getText() + " ");
152 } else {
153 jif = new JInternalFrame(getString("InternalFrameDemo.frame_label") + " " + windowCount + " ");
154 }
155
156 jif.setClosable(windowClosable.isSelected());
158 jif.setMaximizable(windowMaximizable.isSelected());
159 jif.setIconifiable(windowIconifiable.isSelected());
160 jif.setResizable(windowResizable.isSelected());
161
162 jif.setBounds(20*(windowCount%10), 20*(windowCount%10), width, height);
163 jif.setContentPane(new ImageScroller(this, icon, 0, windowCount));
164
165 windowCount++;
166
167 desktop.add(jif, layer);
168
169
171 try {
172 jif.setSelected(true);
173 } catch (java.beans.PropertyVetoException e2) {
174 }
175
176 jif.show();
177
178 return jif;
179 }
180
181 public JInternalFrame createInternalFramePalette() {
182 JInternalFrame palette = new JInternalFrame(
183 getString("InternalFrameDemo.palette_label")
184 );
185 palette.putClientProperty("JInternalFrame.isPalette", Boolean.TRUE);
186 palette.getContentPane().setLayout(new BorderLayout());
187 palette.setBounds(PALETTE_X, PALETTE_Y, PALETTE_WIDTH, PALETTE_HEIGHT);
188 palette.setResizable(true);
189 palette.setIconifiable(true);
190 desktop.add(palette, PALETTE_LAYER);
191
192 JButton b1 = new JButton(smIcon1);
196 JButton b2 = new JButton(smIcon2);
197 JButton b3 = new JButton(smIcon3);
198 JButton b4 = new JButton(smIcon4);
199
200 b1.addActionListener(new ShowFrameAction(this, icon1));
202 b2.addActionListener(new ShowFrameAction(this, icon2));
203 b3.addActionListener(new ShowFrameAction(this, icon3));
204 b4.addActionListener(new ShowFrameAction(this, icon4));
205
206 JPanel p = new JPanel();
208 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
209
210 JPanel buttons1 = new JPanel();
211 buttons1.setLayout(new BoxLayout(buttons1, BoxLayout.X_AXIS));
212
213 JPanel buttons2 = new JPanel();
214 buttons2.setLayout(new BoxLayout(buttons2, BoxLayout.X_AXIS));
215
216 buttons1.add(b1);
217 buttons1.add(Box.createRigidArea(HGAP15));
218 buttons1.add(b2);
219
220 buttons2.add(b3);
221 buttons2.add(Box.createRigidArea(HGAP15));
222 buttons2.add(b4);
223
224 p.add(Box.createRigidArea(VGAP10));
225 p.add(buttons1);
226 p.add(Box.createRigidArea(VGAP15));
227 p.add(buttons2);
228 p.add(Box.createRigidArea(VGAP10));
229
230 palette.getContentPane().add(p, BorderLayout.NORTH);
231
232 p = new JPanel() {
236 Insets insets = new Insets(10,15,10,5);
237 public Insets getInsets() {
238 return insets;
239 }
240 };
241 p.setLayout(new GridLayout(1,2));
242
243
244 Box box = new Box(BoxLayout.Y_AXIS);
245 windowResizable = new JCheckBox(getString("InternalFrameDemo.resizable_label"), true);
246 windowIconifiable = new JCheckBox(getString("InternalFrameDemo.iconifiable_label"), true);
247
248 box.add(Box.createGlue());
249 box.add(windowResizable);
250 box.add(windowIconifiable);
251 box.add(Box.createGlue());
252 p.add(box);
253
254 box = new Box(BoxLayout.Y_AXIS);
255 windowClosable = new JCheckBox(getString("InternalFrameDemo.closable_label"), true);
256 windowMaximizable = new JCheckBox(getString("InternalFrameDemo.maximizable_label"), true);
257
258 box.add(Box.createGlue());
259 box.add(windowClosable);
260 box.add(windowMaximizable);
261 box.add(Box.createGlue());
262 p.add(box);
263
264 palette.getContentPane().add(p, BorderLayout.CENTER);
265
266
267 p = new JPanel() {
271 Insets insets = new Insets(0,0,10,0);
272 public Insets getInsets() {
273 return insets;
274 }
275 };
276
277 windowTitleField = new JTextField(getString("InternalFrameDemo.frame_label"));
278 windowTitleLabel = new JLabel(getString("InternalFrameDemo.title_text_field_label"));
279
280 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
281 p.add(Box.createRigidArea(HGAP5));
282 p.add(windowTitleLabel, BorderLayout.WEST);
283 p.add(Box.createRigidArea(HGAP5));
284 p.add(windowTitleField, BorderLayout.CENTER);
285 p.add(Box.createRigidArea(HGAP5));
286
287 palette.getContentPane().add(p, BorderLayout.SOUTH);
288
289 palette.show();
290
291 return palette;
292 }
293
294
295 class ShowFrameAction extends AbstractAction {
296 InternalFrameDemo demo;
297 Icon icon;
298
299
300 public ShowFrameAction(InternalFrameDemo demo, Icon icon) {
301 this.demo = demo;
302 this.icon = icon;
303 }
304
305 public void actionPerformed(ActionEvent e) {
306 demo.createInternalFrame(icon,
307 getDemoFrameLayer(),
308 getFrameWidth(),
309 getFrameHeight()
310 );
311 }
312 }
313
314 public int getFrameWidth() {
315 return FRAME_WIDTH;
316 }
317
318 public int getFrameHeight() {
319 return FRAME_HEIGHT;
320 }
321
322 public Integer getDemoFrameLayer() {
323 return DEMO_FRAME_LAYER;
324 }
325
326 class ImageScroller extends JScrollPane {
327
328 public ImageScroller(InternalFrameDemo demo, Icon icon, int layer, int count) {
329 super();
330 JPanel p = new JPanel();
331 p.setBackground(Color.white);
332 p.setLayout(new BorderLayout() );
333
334 p.add(new JLabel(icon), BorderLayout.CENTER);
335
336 getViewport().add(p);
337 getHorizontalScrollBar().setUnitIncrement(10);
338 getVerticalScrollBar().setUnitIncrement(10);
339 }
340
341 public Dimension getMinimumSize() {
342 return new Dimension(25, 25);
343 }
344
345 }
346
347 void updateDragEnabled(boolean dragEnabled) {
348 windowTitleField.setDragEnabled(dragEnabled);
349 }
350
351 }
352