1 /* TestAWT.java -- Tests the AWT like testgtk
2 Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import java
.awt
.event
.*;
42 import java
.awt
.peer
.*;
46 public static void main(String args
[])
50 Properties prop
= System
.getProperties ();
51 prop
.put ("awt.toolkit", "gnu.java.awt.peer.gtk.GtkToolkit");
53 MainWindow f
= new MainWindow();
54 System
.out
.println(f
.isDisplayable());
56 System
.out
.println(f
.isDisplayable());
65 class PrettyPanel
extends Panel
71 myInsets
= new Insets (10, 10, 10, 10);
73 public Insets
getInsets ()
79 abstract class PrettyFrame
extends Frame
83 ((BorderLayout
) getLayout ()).setHgap (5);
84 ((BorderLayout
) getLayout ()).setVgap (5);
87 // public Insets getInsets()
89 // Insets oldInsets = super.getInsets ();
90 // return new Insets (oldInsets.top+10,
92 // oldInsets.bottom+10,
93 // oldInsets.right+10);
97 abstract class SubFrame
extends PrettyFrame
implements SubWindow
99 boolean initted
= false;
101 public void setVisible (boolean visible
)
103 if (!initted
&& visible
)
105 super.setVisible (visible
);
109 class MainWindow
extends PrettyFrame
implements ActionListener
116 void addSubWindow (String name
, SubWindow w
)
118 Button b
= new Button (name
);
119 b
.addActionListener (this);
121 buttons
.addElement (b
);
127 MenuBar mb
= new MenuBar ();
128 Menu menu
= new Menu ("File");
129 Menu submenu
= new Menu ("Testing");
130 submenu
.add (new CheckboxMenuItem ("Foobar"));
136 add (new Label ("Classpath v0.0.0"), "North");
138 closeButton
= new Button ("Close");
139 closeButton
.addActionListener (this);
140 closeButton
.setFont (new Font ("Serif", Font
.BOLD
| Font
.ITALIC
, 18));
141 add (closeButton
, "South");
143 windows
= new Hashtable ();
144 buttons
= new Vector ();
146 addSubWindow ("Buttons", new ButtonsWindow ());
147 addSubWindow ("Cursors", new CursorsWindow ());
148 addSubWindow ("Dialog", new DialogWindow (this));
149 addSubWindow ("File", new FileWindow (this));
150 addSubWindow ("Labels", new LabelWindow ());
151 addSubWindow ("List", new ListWindow ());
152 addSubWindow ("Radio Buttons", new RadioWindow ());
153 addSubWindow ("TextField", new TextFieldWindow ());
155 Panel sp
= new Panel();
156 PrettyPanel p
= new PrettyPanel();
157 p
.setLayout (new GridLayout (windows
.size(), 1));
159 for (Enumeration e
= buttons
.elements (); e
.hasMoreElements (); )
161 p
.add ((Button
) e
.nextElement ());
167 setSize (200, 86 + (windows
.size ()*22));
168 setTitle ("TestAWT");
171 public void actionPerformed (ActionEvent evt
)
173 Button source
= (Button
) evt
.getSource ();
175 if (source
==closeButton
)
177 System
.getProperties ().list (System
.out
);
182 Window w
= (Window
) windows
.get (source
);
193 class ButtonsWindow
extends SubFrame
implements ActionListener
195 Button b
[] = new Button
[9];
200 Panel p
= new Panel ();
201 p
.setLayout (new GridLayout (0, 3, 5, 5));
203 for (int i
=0; i
<9; i
++)
205 b
[i
]=new Button ("button" + (i
+1));
206 b
[i
].addActionListener (this);
221 Button cb
= new Button ("close");
222 cb
.addActionListener(new ActionListener () {
223 public void actionPerformed (ActionEvent e
) {
228 setTitle ("Buttons");
231 public void actionPerformed (ActionEvent evt
)
233 Button source
= (Button
) evt
.getSource ();
235 for (int i
=0; i
<9; i
++)
239 int i2
=((i
+1)==9)?
0:(i
+1);
240 if (b
[i2
].isVisible())
241 b
[i2
].setVisible(false);
243 b
[i2
].setVisible(true);
250 class DialogWindow
extends Dialog
implements SubWindow
253 boolean initted
= false;
255 public DialogWindow (Frame f
)
260 public void setVisible (boolean visible
)
262 if (!initted
&& visible
)
264 super.setVisible (visible
);
269 text
= new Label ("Dialog Test");
270 text
.setAlignment (Label
.CENTER
);
273 text
.setVisible (false);
275 Panel p
= new PrettyPanel();
277 Button cb
= new Button ("OK");
278 cb
.addActionListener(new ActionListener () {
279 public void actionPerformed (ActionEvent e
)
285 p
.setLayout (new GridLayout (1, 2));
286 ((GridLayout
) p
.getLayout ()).setHgap (5);
287 ((GridLayout
) p
.getLayout ()).setVgap (5);
290 Button toggle
= new Button ("Toggle");
293 toggle
.addActionListener(new ActionListener () {
294 public void actionPerformed (ActionEvent e
)
296 if (text
.isVisible ())
297 text
.setVisible (false);
299 text
.setVisible (true);
310 class CursorsWindow
extends SubFrame
implements ItemListener
317 cursorChoice
= new Choice();
318 cursorChoice
.add ("Default");
319 cursorChoice
.add ("Crosshair");
320 cursorChoice
.add ("Text");
321 cursorChoice
.add ("Wait");
322 cursorChoice
.add ("Southwest Resize");
323 cursorChoice
.add ("Southeast Resize");
324 cursorChoice
.add ("Northwest Resize");
325 cursorChoice
.add ("Northeast Resize");
326 cursorChoice
.add ("North Resize");
327 cursorChoice
.add ("South Resize");
328 cursorChoice
.add ("West Resize");
329 cursorChoice
.add ("East Resize");
330 cursorChoice
.add ("Hand");
331 cursorChoice
.add ("Move");
333 cursorChoice
.addItemListener(this);
335 add (cursorChoice
, "North");
337 cursorCanvas
= new Canvas ()
339 public void paint (Graphics g
)
341 Dimension d
= this.getSize();
342 g
.setColor (Color
.white
);
343 g
.fillRect (0, 0, d
.width
, d
.height
/2);
344 g
.setColor (Color
.black
);
345 g
.fillRect (0, d
.height
/2, d
.width
, d
.height
/2);
346 g
.setColor (this.getBackground());
347 g
.fillRect (d
.width
/3, d
.height
/3, d
.width
/3,
352 cursorCanvas
.setSize (80,80);
354 add (cursorCanvas
, "Center");
356 Button cb
= new Button ("Close");
357 cb
.addActionListener(new ActionListener () {
358 public void actionPerformed (ActionEvent e
) {
364 setTitle ("Cursors");
368 public void itemStateChanged (ItemEvent e
)
370 cursorCanvas
.setCursor (Cursor
.getPredefinedCursor (cursorChoice
.getSelectedIndex()));
374 class TextFieldWindow
extends SubFrame
implements ItemListener
376 Checkbox editable
, visible
, sensitive
;
382 text
= new TextField ("hello world");
385 Panel p
= new Panel();
386 p
.setLayout (new GridLayout (3, 1));
387 ((GridLayout
) p
.getLayout ()).setHgap (5);
388 ((GridLayout
) p
.getLayout ()).setVgap (5);
390 editable
= new Checkbox("Editable", true);
392 editable
.addItemListener (this);
394 visible
= new Checkbox("Visible", true);
396 visible
.addItemListener (this);
398 sensitive
= new Checkbox("Sensitive", true);
400 sensitive
.addItemListener (this);
404 Button cb
= new Button ("Close");
405 cb
.addActionListener(new ActionListener () {
406 public void actionPerformed (ActionEvent e
) {
412 setTitle ("TextField");
416 public void itemStateChanged (ItemEvent e
)
420 if (e
.getStateChange () == ItemEvent
.DESELECTED
)
422 if (e
.getSource() == editable
)
423 text
.setEditable (on
);
424 if (e
.getSource() == visible
)
426 text
.setEchoChar ((char) 0);
428 text
.setEchoChar ('*');
429 if (e
.getSource() == sensitive
)
430 text
.setEnabled (on
);
435 class FileWindow
extends FileDialog
implements SubWindow
437 boolean initted
= false;
439 public FileWindow (MainWindow mw
)
444 public void setVisible (boolean visible
)
446 if (!initted
&& visible
)
448 super.setVisible (visible
);
457 class LabelWindow
extends SubFrame
463 Panel p
= new Panel();
464 p
.setLayout (new GridLayout (3, 1));
465 ((GridLayout
) p
.getLayout ()).setHgap (5);
466 ((GridLayout
) p
.getLayout ()).setVgap (5);
468 p
.add (new Label ("left justified label", Label
.LEFT
));
469 p
.add (new Label ("center justified label", Label
.CENTER
));
470 p
.add (new Label ("right justified label", Label
.RIGHT
));
474 Button cb
= new Button ("Close");
475 cb
.addActionListener(new ActionListener () {
476 public void actionPerformed (ActionEvent e
) {
487 class ListWindow
extends SubFrame
493 Panel p
= new Panel ();
494 p
.setLayout (new GridLayout (3, 1));
496 List l
= new List (5, true);
497 for (int i
= 0; i
< 10; i
++)
498 l
.add ("added item " + i
);
504 Button cb
= new Button ("Close");
505 cb
.addActionListener(new ActionListener () {
506 public void actionPerformed (ActionEvent e
) {
518 class RadioWindow
extends SubFrame
524 Panel p
= new Panel();
525 p
.setLayout (new GridLayout (3, 1));
526 ((GridLayout
) p
.getLayout ()).setHgap (5);
527 ((GridLayout
) p
.getLayout ()).setVgap (5);
529 final CheckboxGroup cg
= new CheckboxGroup();
530 final Checkbox
[] boxes
= new Checkbox
[3];
531 for (int i
= 0; i
< 3; ++i
)
533 boxes
[i
] = new Checkbox("button" + i
, cg
, i
== 0);
540 p
.setLayout (new GridLayout (1, 3));
541 ((GridLayout
) p
.getLayout ()).setHgap (5);
542 ((GridLayout
) p
.getLayout ()).setVgap (5);
544 for (int i
= 0; i
< 3; ++i
)
547 Button tweak
= new Button ("Set " + i
);
548 tweak
.addActionListener(new ActionListener ()
550 public void actionPerformed (ActionEvent e
)
552 cg
.setSelectedCheckbox(boxes
[val
]);
560 Button cb
= new Button ("Close");
561 cb
.addActionListener(new ActionListener () {
562 public void actionPerformed (ActionEvent e
) {
568 setTitle ("Radio Buttons");