FSF GCC merge 02/23/03
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / Test.java
blob7ecb593f12527772500f1eefda0f0cd00a75ad65
1 /* Test.java -- Tests the GTK Toolkit
2 Copyright (C) 1998, 1999 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)
9 any later version.
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
19 02111-1307 USA.
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
24 combination.
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. */
39 import java.util.*;
40 import java.awt.*;
41 import java.awt.event.*;
42 import java.awt.peer.*;
43 import java.awt.datatransfer.*;
44 import gnu.java.awt.image.*;
45 import java.io.*;
47 class Test
49 static int xs = 5, ys = 5;
51 public static void main(String args[])
53 if (args.length == 0)
55 Properties prop=System.getProperties ();
56 prop.put ("awt.toolkit","gnu.java.awt.peer.gtk.GtkToolkit");
59 final Frame f=new Frame();
60 f.setTitle ("Red Hat Classpath");
62 // f.addComponentListener (new ComponentAdapter() {
63 // public void componentMoved (ComponentEvent e) {
64 // System.out.println("component moved");
65 // }
66 // public void componentResized (ComponentEvent e) {
67 // System.out.println("component resized");
68 // }
69 // });
70 f.setSize(200,200);
72 Panel pan=new Panel();
74 final Label l = new Label ("Pithy Message:");
75 l.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR));
76 pan.add (l);
78 TextField tf = new TextField("Hello world!");
79 pan.add(tf);
81 final Image img;
82 img = Toolkit.getDefaultToolkit ().createImage (new XBMDecoder ("fvwm.xbm"));
85 final Canvas ch = new Canvas () {
87 public void update (Graphics g)
89 System.out.println ("update called");
90 super.update (g);
92 public void paint (Graphics g) {
93 g.drawString("Hello world!", xs+5, ys+10);
94 g.setColor (Color.blue);
95 g.drawLine (xs,ys,xs+20,ys+20);
97 // System.out.println (TextArea.SCROLLBARS_BOTH);
98 // System.out.println (TextArea.SCROLLBARS_HORIZONTAL_ONLY);
99 // System.out.println (TextArea.SCROLLBARS_VERTICAL_ONLY);
101 // Font f1 = new Font ("TimesRoman", Font.PLAIN, 10);
102 // System.out.println (f1.getName ());
103 // System.out.println (f1.getFamily ());
105 // Font font = new Font ("Serif", Font.PLAIN, 18);
106 // g.setFont (font);
107 // g.setXORMode (Color.red);
110 // System.out.println (g.getFontMetrics (font).stringWidth ("foobar"));
112 // System.out.println (g.drawImage (img, 0, 0, this));
116 ch.setSize(60, 60);
117 // List ch=new List();
118 // ch.add("Ding");
119 // ch.add("September");
120 // ch.add("Red");
121 // ch.add("Quassia");
122 // ch.add("Pterodactyl");
124 // ch.addMouseListener(new MouseAdapter() {
125 // public void mousePressed(MouseEvent e) {
126 // System.out.println("mouse pressed ch");
127 // System.out.println("shift = " + e.isShiftDown());
128 // System.out.println("meta = " + e.isMetaDown());
129 // System.out.println("alt = " + e.isAltDown());
130 // System.out.println("ctrl = " + e.isControlDown());
131 // System.out.println("x = " + e.getX());
132 // System.out.println("y = " + e.getY());
133 // System.out.println("clickcount = " + e.getClickCount());
134 // System.out.println("when = " + e.getWhen());
135 // System.out.println();
136 // }
137 // public void mouseReleased(MouseEvent e) {
138 // System.out.println("mouse released ch");
139 // }
140 // public void mouseClicked(MouseEvent e) {
141 // System.out.println("mouse clicked ch");
142 // }
143 // });
145 pan.add(ch);
146 f.add(pan,"North");
148 final ScrollPane sp=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
149 System.out.println ("ALWAYS HERE: " + ScrollPane.SCROLLBARS_ALWAYS);
150 System.out.println ("ALWAYS" + ScrollPane.SCROLLBARS_ALWAYS);
151 System.out.println ("NEEDED" + ScrollPane.SCROLLBARS_AS_NEEDED);
152 System.out.println ("NEVER " + ScrollPane.SCROLLBARS_NEVER);
155 final Panel p=new Panel();
156 System.out.println ("PREFERED: " + p.getPreferredSize ());
157 p.add(new Button("Stop"));
158 System.out.println ("PREFERED: " + p.getPreferredSize ());
159 p.add(new Button("evil"));
160 System.out.println ("PREFERED: " + p.getPreferredSize ());
161 p.add(new Button("hoarders"));
162 p.add(new Button("use"));
163 p.add(new Button("GNU"));
164 p.add(new Scrollbar(Scrollbar.HORIZONTAL));
165 System.out.println ("PREFERED: " + p.getPreferredSize ());
167 sp.add(p);
168 f.add(sp,"South");
170 Panel east_panel = new Panel();
171 east_panel.setLayout(new GridLayout (0,1));
173 // CheckboxGroup group = new CheckboxGroup();
175 // Checkbox cb=new Checkbox("one", group, true);
176 // east_panel.add(cb);
177 // cb=new Checkbox("two", group, false);
178 // east_panel.add(cb);
180 // cb.addMouseListener(new MouseAdapter() {
181 // public void mousePressed(MouseEvent e) {
182 // System.out.println("mouse pressed cb");
183 // System.out.println("shift = " + e.isShiftDown());
184 // System.out.println("meta = " + e.isMetaDown());
185 // System.out.println("alt = " + e.isAltDown());
186 // System.out.println("ctrl = " + e.isControlDown());
187 // System.out.println("x = " + e.getX());
188 // System.out.println("y = " + e.getY());
189 // System.out.println("clickcount = " + e.getClickCount());
190 // System.out.println("when = " + e.getWhen());
191 // System.out.println();
192 // }
193 // public void mouseReleased(MouseEvent e) {
194 // System.out.println("mouse released cb");
195 // }
196 // public void mouseClicked(MouseEvent e) {
197 // System.out.println("mouse clicked cb");
198 // }
199 // public void mouseEntered(MouseEvent e) {
200 // System.out.println("mouse entered cb");
201 // }
202 // public void mouseExited(MouseEvent e) {
203 // System.out.println("mouse exited cb");
204 // }
205 // });
207 f.add(east_panel,"East");
209 final Button wb=new Button();
210 wb.setLabel("Destroy Frame on Click");
211 wb.addActionListener (new ActionListener () {
212 public void actionPerformed (ActionEvent e) {
213 ScrollPanePeer peer = (ScrollPanePeer)sp.getPeer ();
214 if (peer != null)
216 System.out.println (peer.getHScrollbarHeight ());
217 System.out.println (peer.getVScrollbarWidth ());
220 l.setText ("Hello World!");
221 System.out.println ("PREFERED: " + p.getPreferredSize ());
223 final Dialog d = new Dialog (f);
224 d.setModal (true);
225 Button b = new Button ("foobar");
226 b.addMouseListener (new MouseAdapter () {
227 public void mousePressed (MouseEvent me) {
228 System.out.println ("I got called");
229 d.hide ();
231 // System.out.println (ScrollPane.SCROLLBARS_ALWAYS);
232 // System.out.println (ScrollPane.SCROLLBARS_AS_NEEDED);
233 // System.out.println (ScrollPane.SCROLLBARS_NEVER);
236 d.add (b);
237 d.pack ();
238 d.show ();
239 System.out.println ("hello world");
240 // System.out.println ("action listener on wb called");
241 // Clipboard clip = Toolkit.getDefaultToolkit ().getSystemClipboard ();
242 // StringSelection ss = new StringSelection("123456789");
243 // clip.setContents (ss, ss);
244 // Transferable t = clip.getContents (this);
245 // try {
246 // System.out.println (t.getTransferData (DataFlavor.stringFlavor));
247 // } catch (Exception ex) {
248 // ex.printStackTrace ();
249 // }
250 // System.exit (0);
254 wb.addMouseListener(new MouseAdapter() {
255 public void mousePressed(MouseEvent e) {
256 System.out.println("mouse pressed wb");
257 xs++;
258 ys++;
259 ch.repaint ();
261 public void mouseReleased(MouseEvent e) {
262 System.out.println("mouse released wb");
264 public void mouseClicked(MouseEvent e) {
265 System.out.println("mouse clicked wb");
267 public void mouseEntered(MouseEvent e) {
268 System.out.println("mouse entered wb");
270 public void mouseExited(MouseEvent e) {
271 System.out.println("mouse exited wb");
275 f.add(wb,"West");
277 f.pack();
278 f.show();
280 sp.setScrollPosition (10,0);
282 Toolkit t = Toolkit.getDefaultToolkit();
283 /* t.beep(); */
284 System.out.println("screen size: " + t.getScreenSize());
285 System.out.println("resolution : " + t.getScreenResolution());
286 // try {
287 // Thread.sleep (5000);
288 // } catch (InterruptedException e) {}
289 // f.setSize(500,500);
291 System.out.println ("background of canvas: " + ch.getBackground ());
292 System.out.println ("foreground of canvas: " + ch.getForeground ());
294 System.out.println("done");