aboutsummaryrefslogtreecommitdiff
path: root/libjava/gnu/java/awt/peer/gtk/Test.java
blob: 7ecb593f12527772500f1eefda0f0cd00a75ad65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* Test.java -- Tests the GTK Toolkit
   Copyright (C) 1998, 1999 Free Software Foundation, Inc.

This file is part of GNU Classpath.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */


import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.peer.*;
import java.awt.datatransfer.*;
import gnu.java.awt.image.*;
import java.io.*;

class Test
{
  static int xs = 5, ys = 5;

  public static void main(String args[])
    {
      if (args.length == 0)
	{ 
	  Properties prop=System.getProperties ();
	  prop.put ("awt.toolkit","gnu.java.awt.peer.gtk.GtkToolkit");
	}

      final Frame f=new Frame();
      f.setTitle ("Red Hat Classpath");
      
//        f.addComponentListener (new ComponentAdapter() {
//  	public void componentMoved (ComponentEvent e) {
//  	  System.out.println("component moved");
//  	}
//  	public void componentResized (ComponentEvent e) {
//  	  System.out.println("component resized");
//  	}
//        });
      f.setSize(200,200);

      Panel pan=new Panel();

      final Label l = new Label ("Pithy Message:");
      l.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR));
      pan.add (l);

      TextField tf = new TextField("Hello world!");
      pan.add(tf);

      final Image img;
      img = Toolkit.getDefaultToolkit ().createImage (new XBMDecoder ("fvwm.xbm"));


      final Canvas ch = new Canvas () { 

	  public void update (Graphics g)
	  {
	    System.out.println ("update called");
	    super.update (g);
	  }
	public void paint (Graphics g) {
	  g.drawString("Hello world!", xs+5, ys+10);
	  g.setColor (Color.blue);
	  g.drawLine (xs,ys,xs+20,ys+20);

//  	  System.out.println (TextArea.SCROLLBARS_BOTH);
//  	  System.out.println (TextArea.SCROLLBARS_HORIZONTAL_ONLY);
//  	  System.out.println (TextArea.SCROLLBARS_VERTICAL_ONLY);

//  	  Font f1 = new Font ("TimesRoman", Font.PLAIN, 10);
//  	  System.out.println (f1.getName ());
//  	  System.out.println (f1.getFamily ());

//  	  Font font = new Font ("Serif", Font.PLAIN, 18); 
//  	  g.setFont (font);
//  	  g.setXORMode (Color.red);


//  	  System.out.println (g.getFontMetrics (font).stringWidth ("foobar"));

//        System.out.println (g.drawImage (img, 0, 0, this));
	}
      };

      ch.setSize(60, 60);
//        List ch=new List();
//        ch.add("Ding");
//        ch.add("September");
//        ch.add("Red");
//        ch.add("Quassia");
//        ch.add("Pterodactyl");

//        ch.addMouseListener(new MouseAdapter() {
//  	public void mousePressed(MouseEvent e) {
//  	  System.out.println("mouse pressed ch");
//  	  System.out.println("shift = " + e.isShiftDown());
//  	  System.out.println("meta = " + e.isMetaDown());
//  	  System.out.println("alt = " + e.isAltDown());
//  	  System.out.println("ctrl = " + e.isControlDown());
//  	  System.out.println("x = " + e.getX());
//  	  System.out.println("y = " + e.getY());
//  	  System.out.println("clickcount = " + e.getClickCount());
//  	  System.out.println("when = " + e.getWhen());
//  	  System.out.println();
//  	}
//  	public void mouseReleased(MouseEvent e) {
//  	  System.out.println("mouse released ch");
//  	}
//  	public void mouseClicked(MouseEvent e) {
//  	  System.out.println("mouse clicked ch");
//  	}
//        });

      pan.add(ch);
      f.add(pan,"North");

      final ScrollPane sp=new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
      System.out.println ("ALWAYS HERE: " + ScrollPane.SCROLLBARS_ALWAYS);
      System.out.println ("ALWAYS" + ScrollPane.SCROLLBARS_ALWAYS);
      System.out.println ("NEEDED" + ScrollPane.SCROLLBARS_AS_NEEDED);
      System.out.println ("NEVER " + ScrollPane.SCROLLBARS_NEVER);


      final Panel p=new Panel();
      System.out.println ("PREFERED: " + p.getPreferredSize ());
      p.add(new Button("Stop"));
      System.out.println ("PREFERED: " + p.getPreferredSize ());
      p.add(new Button("evil"));
      System.out.println ("PREFERED: " + p.getPreferredSize ());
      p.add(new Button("hoarders"));
      p.add(new Button("use"));
      p.add(new Button("GNU"));
      p.add(new Scrollbar(Scrollbar.HORIZONTAL));
      System.out.println ("PREFERED: " + p.getPreferredSize ());

      sp.add(p);
      f.add(sp,"South");

      Panel east_panel = new Panel();
      east_panel.setLayout(new GridLayout (0,1));

//        CheckboxGroup group = new CheckboxGroup();

//        Checkbox cb=new Checkbox("one", group, true);
//        east_panel.add(cb);
//        cb=new Checkbox("two", group, false);
//        east_panel.add(cb);

//        cb.addMouseListener(new MouseAdapter() {
//  	  public void mousePressed(MouseEvent e) {
//  	  System.out.println("mouse pressed cb");
//  	  System.out.println("shift = " + e.isShiftDown());
//  	  System.out.println("meta = " + e.isMetaDown());
//  	  System.out.println("alt = " + e.isAltDown());
//  	  System.out.println("ctrl = " + e.isControlDown());
//  	  System.out.println("x = " + e.getX());
//  	  System.out.println("y = " + e.getY());
//  	  System.out.println("clickcount = " + e.getClickCount());
//  	  System.out.println("when = " + e.getWhen());
//  	  System.out.println();
//  	}
//  	public void mouseReleased(MouseEvent e) {
//  	  System.out.println("mouse released cb");
//  	}
//  	public void mouseClicked(MouseEvent e) {
//  	  System.out.println("mouse clicked cb");
//  	}
//  	public void mouseEntered(MouseEvent e) {
//  	  System.out.println("mouse entered cb");
//  	}
//  	public void mouseExited(MouseEvent e) {
//  	  System.out.println("mouse exited cb");
//  	}
//        });

      f.add(east_panel,"East");

      final Button wb=new Button();
      wb.setLabel("Destroy Frame on Click");
      wb.addActionListener (new ActionListener () {
	public void actionPerformed (ActionEvent e) {
	  ScrollPanePeer peer = (ScrollPanePeer)sp.getPeer ();
	  if (peer != null)
	    {
	      System.out.println (peer.getHScrollbarHeight ());
	      System.out.println (peer.getVScrollbarWidth ());
	    }

	  l.setText ("Hello World!");
	  System.out.println ("PREFERED: " + p.getPreferredSize ());

	  final Dialog d = new Dialog (f);
	  d.setModal (true);
	  Button b = new Button ("foobar");
	  b.addMouseListener (new MouseAdapter () {
	      public void mousePressed (MouseEvent me) {
		System.out.println ("I got called");
		d.hide ();

//  		System.out.println (ScrollPane.SCROLLBARS_ALWAYS);
//  		System.out.println (ScrollPane.SCROLLBARS_AS_NEEDED);
//  		System.out.println (ScrollPane.SCROLLBARS_NEVER);
	      }
	    });
	  d.add (b);
	  d.pack ();
	  d.show ();
	  System.out.println ("hello world");
//  	  System.out.println ("action listener on wb called");
//  	  Clipboard clip = Toolkit.getDefaultToolkit ().getSystemClipboard ();
//  	  StringSelection ss = new StringSelection("123456789");
//  	  clip.setContents (ss, ss);
//  	  Transferable t = clip.getContents (this);
//  	  try {
//  	    System.out.println (t.getTransferData (DataFlavor.stringFlavor));
//  	  } catch (Exception ex) {
//  	    ex.printStackTrace ();
//  	  }
//  	  System.exit (0);
	}
      });

      wb.addMouseListener(new MouseAdapter() {
	public void mousePressed(MouseEvent e) {
	  System.out.println("mouse pressed wb");
	  xs++;
	  ys++;
	  ch.repaint ();
	}
	public void mouseReleased(MouseEvent e) {
	  System.out.println("mouse released wb");
	}
	public void mouseClicked(MouseEvent e) {
	  System.out.println("mouse clicked wb");
	}
	public void mouseEntered(MouseEvent e) {
	  System.out.println("mouse entered wb");
	}
	public void mouseExited(MouseEvent e) {
	  System.out.println("mouse exited wb");
	}
      });

      f.add(wb,"West");
      
      f.pack();
      f.show();

      sp.setScrollPosition (10,0);

      Toolkit t = Toolkit.getDefaultToolkit();
      /* t.beep(); */
      System.out.println("screen size: " + t.getScreenSize());
      System.out.println("resolution : " + t.getScreenResolution());
//        try {
//  	Thread.sleep (5000);
//        } catch (InterruptedException e) {}
//        f.setSize(500,500);

      System.out.println ("background of canvas: " + ch.getBackground ());
      System.out.println ("foreground of canvas: " + ch.getForeground ());

      System.out.println("done");
    }
}