OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [examples/] [gnu/] [classpath/] [examples/] [awt/] [Demo.java] - Blame information for rev 781

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 781 jeremybenn
/* Demo.java -- Shows examples of AWT components
2
   Copyright (C) 1998, 1999, 2002, 2004, 2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath examples.
5
 
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.
10
 
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.
15
 
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., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA. */
20
 
21
package gnu.classpath.examples.awt;
22
 
23
import java.awt.BorderLayout;
24
import java.awt.Button;
25
import java.awt.Canvas;
26
import java.awt.Checkbox;
27
import java.awt.CheckboxGroup;
28
import java.awt.CheckboxMenuItem;
29
import java.awt.Choice;
30
import java.awt.Color;
31
import java.awt.Cursor;
32
import java.awt.Dialog;
33
import java.awt.Dimension;
34
import java.awt.DisplayMode;
35
import java.awt.FileDialog;
36
import java.awt.FlowLayout;
37
import java.awt.Font;
38
import java.awt.Frame;
39
import java.awt.Graphics;
40
import java.awt.GraphicsDevice;
41
import java.awt.GraphicsEnvironment;
42
import java.awt.GridLayout;
43
import java.awt.Image;
44
import java.awt.Insets;
45
import java.awt.Label;
46
import java.awt.List;
47
import java.awt.Menu;
48
import java.awt.MenuBar;
49
import java.awt.MenuItem;
50
import java.awt.MenuShortcut;
51
import java.awt.Panel;
52
import java.awt.ScrollPane;
53
import java.awt.TextField;
54
import java.awt.Toolkit;
55
import java.awt.Window;
56
import java.awt.datatransfer.DataFlavor;
57
import java.awt.datatransfer.StringSelection;
58
import java.awt.datatransfer.Transferable;
59
import java.awt.datatransfer.UnsupportedFlavorException;
60
import java.awt.dnd.DnDConstants;
61
import java.awt.dnd.DragGestureEvent;
62
import java.awt.dnd.DragGestureListener;
63
import java.awt.dnd.DragSource;
64
import java.awt.dnd.DragSourceContext;
65
import java.awt.dnd.DragSourceDragEvent;
66
import java.awt.dnd.DragSourceDropEvent;
67
import java.awt.dnd.DragSourceEvent;
68
import java.awt.dnd.DragSourceListener;
69
import java.awt.dnd.DropTarget;
70
import java.awt.dnd.DropTargetDragEvent;
71
import java.awt.dnd.DropTargetDropEvent;
72
import java.awt.dnd.DropTargetEvent;
73
import java.awt.dnd.DropTargetListener;
74
import java.awt.dnd.InvalidDnDOperationException;
75
import java.awt.event.ActionEvent;
76
import java.awt.event.ActionListener;
77
import java.awt.event.ItemEvent;
78
import java.awt.event.ItemListener;
79
import java.awt.event.MouseAdapter;
80
import java.awt.event.MouseEvent;
81
import java.awt.event.WindowAdapter;
82
import java.awt.event.WindowEvent;
83
import java.net.URL;
84
import java.util.Enumeration;
85
import java.util.Hashtable;
86
import java.util.Vector;
87
 
88
class Demo
89
{
90
  public static void main(String args[])
91
  {
92
    MainWindow f = new MainWindow();
93
    f.show();
94
  }
95
 
96
  static interface SubWindow
97
  {
98
    public void init ();
99
  }
100
 
101
  static class PrettyPanel extends Panel
102
  {
103
    Insets myInsets;
104
 
105
    public PrettyPanel ()
106
    {
107
      myInsets = new Insets (10, 10, 10, 10);
108
    }
109
    public Insets getInsets ()
110
    {
111
      return myInsets;
112
    }
113
  }
114
 
115
  static abstract class PrettyFrame extends Frame
116
  {
117
    public PrettyFrame ()
118
    {
119
      ((BorderLayout) getLayout ()).setHgap (5);
120
      ((BorderLayout) getLayout ()).setVgap (5);
121
    }
122
 
123
    public Insets getInsets()
124
    {
125
      Insets oldInsets = super.getInsets ();
126
      return new Insets (oldInsets.top+10,
127
                         oldInsets.left+10,
128
                         oldInsets.bottom+10,
129
                         oldInsets.right+10);
130
    }
131
  }
132
 
133
  static abstract class SubFrame extends PrettyFrame implements SubWindow
134
  {
135
    boolean initted = false;
136
 
137
    public void setVisible (boolean visible)
138
    {
139
      if (!initted && visible)
140
        init();
141
      super.setVisible (visible);
142
    }
143
  }
144
 
145
  static class MainWindow extends PrettyFrame implements ActionListener
146
  {
147
    Button closeButton;
148
 
149
    Hashtable windows;
150
    Vector buttons;
151
 
152
    void addSubWindow (String name, SubWindow w)
153
    {
154
      Button b = new Button (name);
155
      b.addActionListener (this);
156
 
157
      buttons.addElement (b);
158
      windows.put (b, w);
159
    }
160
 
161
    MainWindow ()
162
    {
163
      MenuBar mb = new MenuBar ();
164
      Menu menu = new Menu ("File");
165
      Menu submenu = new Menu ("Testing", true);
166
      submenu.add (new CheckboxMenuItem ("FooBar"));
167
      submenu.add (new CheckboxMenuItem ("BarFoo"));
168
      menu.add (submenu);
169
      menu.add (new MenuItem("Orange"));
170
      MenuItem quit = new MenuItem("Quit", new MenuShortcut('Q'));
171
      quit.addActionListener(new ActionListener()
172
        {
173
          public void actionPerformed(ActionEvent e)
174
          {
175
            System.exit(0);
176
          }
177
        });
178
      menu.add(quit);
179
      mb.add (menu);
180
 
181
      menu = new Menu("Edit", true);
182
      menu.add(new MenuItem("Cut"));
183
      menu.add(new MenuItem("Copy"));
184
      menu.add(new MenuItem("Paste"));
185
      mb.add (menu);
186
 
187
      Menu helpMenu = new Menu("Help");
188
      helpMenu.add(new MenuItem("About"));
189
      mb.add(helpMenu);
190
      mb.setHelpMenu(helpMenu);
191
 
192
      setMenuBar (mb);
193
 
194
      String version = System.getProperty("gnu.classpath.version");
195
      add (new Label ("GNU Classpath " + version), "North");
196
 
197
      closeButton = new Button ("Close");
198
      closeButton.addActionListener (this);
199
      closeButton.setFont (new Font ("Serif", Font.BOLD | Font.ITALIC, 18));
200
      add (closeButton, "South");
201
 
202
      windows = new Hashtable ();
203
      buttons = new Vector ();
204
 
205
      addSubWindow ("Buttons", new ButtonsWindow ());
206
      addSubWindow ("Cursors", new CursorsWindow ());
207
      addSubWindow ("Dialog", new DialogWindow (this));
208
      addSubWindow ("File", new FileWindow (this));
209
      addSubWindow ("Labels", new LabelWindow ());
210
      addSubWindow ("List", new ListWindow ());
211
      addSubWindow ("Radio Buttons", new RadioWindow ());
212
      addSubWindow ("TextField", new TextFieldWindow ());
213
      addSubWindow ("RandomTests", new TestWindow (this));
214
      addSubWindow ("RoundRect", new RoundRectWindow ());
215
      addSubWindow ("Animation", new AnimationWindow ());
216
      addSubWindow ("Resolution", new ResolutionWindow ());
217
      addSubWindow ("Fullscreen", new FullscreenWindow ());
218
      addSubWindow ("Drag n' Drop", new DragDropWindow ());
219
 
220
      Panel sp = new Panel();
221
      PrettyPanel p = new PrettyPanel();
222
      p.setLayout (new GridLayout (windows.size(), 1));
223
 
224
      for (Enumeration e = buttons.elements (); e.hasMoreElements (); )
225
        {
226
          p.add ((Button) e.nextElement ());
227
        }
228
 
229
      sp.add (p);
230
      add (sp, "Center");
231
 
232
      setTitle ("AWT Demo");
233
      pack();
234
    }
235
 
236
    public void actionPerformed (ActionEvent evt)
237
    {
238
      Button source = (Button) evt.getSource ();
239
 
240
      if (source==closeButton)
241
        {
242
          dispose();
243
          System.exit (0);
244
        }
245
 
246
      Window w = (Window) windows.get (source);
247
      if (w.isVisible ())
248
        w.dispose ();
249
      else
250
        {
251
          if (w instanceof Dialog)
252
            {
253
              w.show();
254
            }
255
          else
256
            {
257
              w.setVisible (true);
258
            }
259
        }
260
    }
261
  }
262
 
263
  static class ButtonsWindow extends SubFrame implements ActionListener
264
  {
265
    Button b[] = new Button [9];
266
 
267
    public void init ()
268
    {
269
      initted = true;
270
      Panel p = new Panel ();
271
      p.setLayout (new GridLayout (0, 3, 5, 5));
272
 
273
      for (int i=0; i<9; i++)
274
        {
275
          b[i]=new Button ("button" + (i+1));
276
          b[i].addActionListener (this);
277
        }
278
 
279
      p.add (b[0]);
280
      p.add (b[6]);
281
      p.add (b[4]);
282
      p.add (b[8]);
283
      p.add (b[1]);
284
      p.add (b[7]);
285
      p.add (b[3]);
286
      p.add (b[5]);
287
      p.add (b[2]);
288
 
289
      add (p, "North");
290
 
291
      Button cb = new Button ("close");
292
      cb.addActionListener(new ActionListener () {
293
          public void actionPerformed (ActionEvent e) {
294
            dispose();
295
          }
296
        });
297
      add (cb, "South");
298
      setTitle ("Buttons");
299
      pack();
300
    }
301
 
302
    public void actionPerformed (ActionEvent evt)
303
    {
304
      Button source = (Button) evt.getSource ();
305
 
306
      for (int i = 0; i < 9; i++)
307
        {
308
          if (source == b[i])
309
            {
310
              int i2 = ((i + 1) == 9) ? 0 : (i + 1);
311
              if (b[i2].isVisible())
312
                b[i2].setVisible(false);
313
              else
314
                b[i2].setVisible(true);
315
            }
316
        }
317
    }
318
  }
319
 
320
 
321
  static class DialogWindow extends Dialog implements SubWindow
322
  {
323
    Label text;
324
    Frame parent;
325
    boolean initted = false;
326
 
327
    public DialogWindow (Frame f)
328
    {
329
      super (f, true);
330
 
331
      this.parent = f;
332
 
333
      addWindowListener (new WindowAdapter ()
334
        {
335
          public void windowClosing (WindowEvent e)
336
          {
337
            text.setVisible (false);
338
            hide ();
339
          }
340
        });
341
    }
342
 
343
    public void setVisible (boolean visible)
344
    {
345
      if (!initted && visible)
346
        init();
347
      super.setVisible (visible);
348
    }
349
 
350
    public void show ()
351
    {
352
      if (!initted)
353
        init();
354
      super.show ();
355
    }
356
 
357
    public void init ()
358
    {
359
      text = new Label ("Dialog Test");
360
      text.setAlignment (Label.CENTER);
361
 
362
      add (text, "North");
363
      text.setVisible (false);
364
 
365
      Panel p = new PrettyPanel();
366
 
367
      Button cb = new Button ("OK");
368
      cb.addActionListener(new ActionListener () {
369
          public void actionPerformed (ActionEvent e)
370
          {
371
            text.setVisible (false);
372
            hide();
373
          }
374
        });
375
 
376
      p.setLayout (new GridLayout (1, 3));
377
      ((GridLayout) p.getLayout ()).setHgap (5);
378
      ((GridLayout) p.getLayout ()).setVgap (5);
379
      p.add (cb);
380
 
381
      Button toggle = new Button ("Toggle");
382
      p.add (toggle);
383
 
384
      toggle.addActionListener(new ActionListener () {
385
          public void actionPerformed (ActionEvent e)
386
          {
387
            if (text.isVisible ())
388
              text.setVisible (false);
389
            else
390
              text.setVisible (true);
391
            doLayout();
392
          }
393
        });
394
 
395
      Button subdlg = new Button ("SubDialog");
396
      p.add (subdlg);
397
 
398
      subdlg.addActionListener(new ActionListener () {
399
          public void actionPerformed (ActionEvent e)
400
          {
401
            DialogWindow sw = new DialogWindow (parent);
402
            sw.show ();
403
          }
404
        });
405
 
406
      add (p, "South");
407
      setTitle ("Dialog");
408
      pack();
409
    }
410
  }
411
 
412
  static class CursorsWindow extends SubFrame implements ItemListener
413
  {
414
    Choice cursorChoice;
415
    Canvas cursorCanvas;
416
 
417
    public void init ()
418
    {
419
      cursorChoice = new Choice();
420
      cursorChoice.add ("Default");
421
      cursorChoice.add ("Crosshair");
422
      cursorChoice.add ("Text");
423
      cursorChoice.add ("Wait");
424
      cursorChoice.add ("Southwest Resize");
425
      cursorChoice.add ("Southeast Resize");
426
      cursorChoice.add ("Northwest Resize");
427
      cursorChoice.add ("Northeast Resize");
428
      cursorChoice.add ("North Resize");
429
      cursorChoice.add ("South Resize");
430
      cursorChoice.add ("West Resize");
431
      cursorChoice.add ("East Resize");
432
      cursorChoice.add ("Hand");
433
      cursorChoice.add ("Move");
434
 
435
      cursorChoice.addItemListener(this);
436
 
437
      add (cursorChoice, "North");
438
 
439
      cursorCanvas = new Canvas ()
440
        {
441
          public void paint (Graphics g)
442
          {
443
            Dimension d = this.getSize();
444
            g.setColor(Color.white);
445
            g.fillRect(0, 0, d.width, d.height/2);
446
            g.setColor(Color.black);
447
            g.fillRect(0, d.height/2, d.width, d.height/2);
448
            g.setColor(this.getBackground());
449
            g.fillRect(d.width/3, d.height/3, d.width/3,
450
                        d.height/3);
451
          }
452
        };
453
 
454
      cursorCanvas.setSize (80,80);
455
 
456
      add (cursorCanvas, "Center");
457
 
458
      Button cb = new Button ("Close");
459
      cb.addActionListener(new ActionListener () {
460
          public void actionPerformed (ActionEvent e) {
461
            dispose();
462
          }
463
        });
464
 
465
      add (cb, "South");
466
      setTitle ("Cursors");
467
      pack();
468
    }
469
 
470
    public void itemStateChanged (ItemEvent e)
471
    {
472
      int index = cursorChoice.getSelectedIndex();
473
      cursorCanvas.setCursor(Cursor.getPredefinedCursor(index));
474
    }
475
  }
476
 
477
  static class TextFieldWindow extends SubFrame implements ItemListener
478
  {
479
    Checkbox editable, visible, sensitive;
480
    TextField text;
481
 
482
    public void init ()
483
    {
484
      initted = true;
485
      text = new TextField ("hello world");
486
      add (text, "North");
487
 
488
      Panel p = new Panel();
489
      p.setLayout (new GridLayout (3, 1));
490
      ((GridLayout) p.getLayout ()).setHgap (5);
491
      ((GridLayout) p.getLayout ()).setVgap (5);
492
 
493
      editable = new Checkbox("Editable", true);
494
      p.add (editable);
495
      editable.addItemListener (this);
496
 
497
      visible = new Checkbox("Visible", true);
498
      p.add (visible);
499
      visible.addItemListener (this);
500
 
501
      sensitive = new Checkbox("Sensitive", true);
502
      p.add (sensitive);
503
      sensitive.addItemListener (this);
504
 
505
      add (p, "Center");
506
 
507
      Button cb = new Button ("Close");
508
      cb.addActionListener(new ActionListener () {
509
          public void actionPerformed (ActionEvent e) {
510
            dispose();
511
          }
512
        });
513
 
514
      add (cb, "South");
515
      setTitle ("TextField");
516
      pack();
517
    }
518
 
519
    public void itemStateChanged (ItemEvent e)
520
    {
521
      boolean on=true;
522
 
523
      if (e.getStateChange () == ItemEvent.DESELECTED)
524
        on=false;
525
      if (e.getSource() == editable)
526
        text.setEditable (on);
527
      if (e.getSource() == visible)
528
        if (on)
529
          text.setEchoChar ((char) 0);
530
        else
531
          text.setEchoChar ('*');
532
      if (e.getSource() == sensitive)
533
        text.setEnabled (on);
534
 
535
    }
536
  }
537
 
538
  static class FileWindow extends FileDialog implements SubWindow
539
  {
540
    boolean initted = false;
541
 
542
    public FileWindow (MainWindow mw)
543
    {
544
      super (mw);
545
    }
546
 
547
    public void setVisible (boolean visible)
548
    {
549
      if (!initted && visible)
550
        init();
551
      super.setVisible (visible);
552
    }
553
 
554
    public void init()
555
    {
556
      initted = true;
557
    }
558
  }
559
 
560
  static class LabelWindow extends SubFrame
561
  {
562
    public void init ()
563
    {
564
      initted = true;
565
 
566
      Panel p = new Panel();
567
      p.setLayout (new GridLayout (3, 1));
568
      ((GridLayout) p.getLayout ()).setHgap (5);
569
      ((GridLayout) p.getLayout ()).setVgap (5);
570
 
571
      p.add (new Label ("left justified label", Label.LEFT));
572
      p.add (new Label ("center justified label", Label.CENTER));
573
      p.add (new Label ("right justified label", Label.RIGHT));
574
 
575
      add (p, "Center");
576
 
577
      Button cb = new Button ("Close");
578
      cb.addActionListener(new ActionListener () {
579
          public void actionPerformed (ActionEvent e) {
580
            dispose();
581
          }
582
        });
583
 
584
      add (cb, "South");
585
      setTitle ("Labels");
586
      pack();
587
    }
588
  }
589
 
590
  static class ListWindow extends SubFrame
591
  {
592
    public void init ()
593
    {
594
      initted = true;
595
 
596
      Panel p = new Panel ();
597
      p.setLayout (new GridLayout (3, 1));
598
 
599
      List l = new List (5, true);
600
      for (int i = 0; i < 10; i++)
601
        l.add ("List item " + i);
602
 
603
      p.add (l);
604
 
605
      add (p, "Center");
606
 
607
      Button cb = new Button ("Close");
608
      cb.addActionListener(new ActionListener () {
609
          public void actionPerformed (ActionEvent e) {
610
            dispose();
611
          }
612
        });
613
 
614
      add (cb, "South");
615
      setTitle ("List");
616
      pack();
617
    }
618
  }
619
 
620
 
621
  static class RadioWindow extends SubFrame
622
  {
623
    public void init ()
624
    {
625
      initted = true;
626
 
627
      Panel p = new Panel();
628
      p.setLayout (new GridLayout (3, 1));
629
      ((GridLayout) p.getLayout ()).setHgap (5);
630
      ((GridLayout) p.getLayout ()).setVgap (5);
631
 
632
      final CheckboxGroup cg = new CheckboxGroup();
633
      final Checkbox[] boxes = new Checkbox[3];
634
      for (int i = 0; i < 3; ++i)
635
        {
636
          boxes[i] = new Checkbox("button" + i, cg, i == 0);
637
          p.add(boxes[i]);
638
        }
639
 
640
      add (p, "North");
641
 
642
      p = new Panel();
643
      p.setLayout (new GridLayout (1, 3));
644
      ((GridLayout) p.getLayout ()).setHgap (5);
645
      ((GridLayout) p.getLayout ()).setVgap (5);
646
 
647
      for (int i = 0; i < 3; ++i)
648
        {
649
          final int val = i;
650
          Button tweak = new Button ("Set " + i);
651
          tweak.addActionListener(new ActionListener ()
652
            {
653
              public void actionPerformed (ActionEvent e)
654
              {
655
                cg.setSelectedCheckbox(boxes[val]);
656
              }
657
            });
658
          p.add(tweak);
659
        }
660
 
661
      add (p, "Center");
662
 
663
      Button cb = new Button ("Close");
664
      cb.addActionListener(new ActionListener () {
665
          public void actionPerformed (ActionEvent e) {
666
            dispose();
667
          }
668
        });
669
 
670
      add (cb, "South");
671
      setTitle ("Radio Buttons");
672
      pack();
673
    }
674
  }
675
 
676
  static class TestWindow extends SubFrame
677
  {
678
    static int xs = 5, ys = 5;
679
    final Frame parent;
680
 
681
    public TestWindow(Frame f)
682
    {
683
      parent = f;
684
    }
685
 
686
    public void init()
687
    {
688
      initted = true;
689
 
690
      addWindowListener (new WindowAdapter ()
691
        {
692
          public void windowClosing (WindowEvent e)
693
          {
694
            hide ();
695
          }
696
        });
697
 
698
      Panel pan = new Panel();
699
 
700
      final Label l = new Label ("Pithy Message:");
701
      l.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR));
702
      pan.add (l);
703
 
704
      TextField tf = new TextField("Hello world!");
705
      pan.add(tf);
706
      add(pan,"North");
707
 
708
      final Image img;
709
      URL imageurl;
710
      imageurl = this.getClass()
711
        .getResource("/gnu/classpath/examples/icons/big-warning.png");
712
      img = Toolkit.getDefaultToolkit().createImage(imageurl);
713
 
714
      final Canvas ch = new Canvas()
715
        {
716
          public void paint (Graphics g)
717
          {
718
            g.drawImage(img, xs + 25, ys + 25, this);
719
 
720
            Font font = new Font ("Serif", Font.PLAIN, 18);
721
            g.setFont (font);
722
            g.setXORMode (Color.red);
723
 
724
            g.drawString("Hi Red!", xs + 15, ys + 10);
725
            g.setColor (Color.blue);
726
            g.drawLine (xs, ys, xs + 100, ys + 100);
727
 
728
          }
729
        };
730
      ch.setSize(150, 150);
731
      add(ch, "Center");
732
 
733
      final ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
734
      final Panel p = new Panel();
735
      p.add(new Button("Stop"));
736
      p.add(new Button("evil"));
737
      p.add(new Button("hoarders"));
738
      p.add(new Button("use"));
739
      p.add(new Button("GNU!"));
740
 
741
      sp.add(p);
742
      add(sp, "South");
743
 
744
      Panel east_panel = new Panel();
745
      east_panel.setLayout(new GridLayout (0,1));
746
 
747
      CheckboxGroup group = new CheckboxGroup();
748
      Checkbox cb = new Checkbox("one", group, true);
749
      east_panel.add(cb);
750
      cb = new Checkbox("two", group, false);
751
      east_panel.add(cb);
752
 
753
      add(east_panel,"East");
754
 
755
      final Button wb = new Button();
756
      wb.setLabel("Hello World!");
757
      wb.addActionListener(new ActionListener()
758
        {
759
          public void actionPerformed (ActionEvent e)
760
          {
761
            l.setText ("Hello World!");
762
 
763
            final Dialog d = new Dialog(parent);
764
            d.setLayout(new FlowLayout());
765
            d.setModal(true);
766
            Button b = new Button("foobar");
767
            b.addMouseListener(new MouseAdapter()
768
              {
769
                public void mousePressed (MouseEvent me)
770
                {
771
                  d.hide ();
772
                }
773
              });
774
            d.add (b);
775
 
776
            List ch = new List();
777
            ch.add("Ding");
778
            ch.add("September");
779
            ch.add("Red");
780
            ch.add("Quassia");
781
            ch.add("Pterodactyl");
782
            d.add(ch);
783
 
784
            d.pack ();
785
            d.show ();
786
          }
787
        });
788
 
789
      wb.addMouseListener(new MouseAdapter()
790
        {
791
          public void mousePressed(MouseEvent e) {
792
            xs++;
793
            ys++;
794
            ch.repaint ();
795
          }
796
        });
797
 
798
      add(wb,"West");
799
 
800
      pack();
801
      show();
802
 
803
      sp.setScrollPosition (10,0);
804
 
805
      Toolkit t = Toolkit.getDefaultToolkit();
806
      t.beep();
807
    }
808
  }
809
 
810
  static class ResolutionWindow extends SubFrame
811
  {
812
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
813
 
814
    public void init ()
815
    {
816
      initted = true;
817
 
818
      setTitle("Change Screen Resolution");
819
      final List list = new List();
820
      DisplayMode[] modes = gd.getDisplayModes();
821
 
822
      for (int i=0;i<modes.length;i++ )
823
        list.add(modes[i].getWidth()  + "x"
824
                 + modes[i].getHeight()
825
                 + ((modes[i].getBitDepth() != DisplayMode.BIT_DEPTH_MULTI)
826
                   ? "x" + modes[i].getBitDepth() + "bpp"
827
                   : "")
828
                 + ((modes[i].getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN)
829
                   ? "@" + modes[i].getRefreshRate() + "Hz"
830
                   : ""));
831
 
832
      ActionListener al = new ActionListener()
833
      {
834
        public void actionPerformed(ActionEvent ae)
835
        {
836
          int i = list.getSelectedIndex();
837
          gd.setDisplayMode(gd.getDisplayModes()[i]);
838
        }
839
      };
840
 
841
      Button b = new Button("Switch");
842
      Button c = new Button("Close");
843
 
844
      list.addActionListener(al);
845
      b.addActionListener(al);
846
 
847
      c.addActionListener(new ActionListener () {
848
        public void actionPerformed (ActionEvent e) {
849
          dispose();
850
        }
851
      });
852
 
853
      setLayout(new GridLayout(3, 1, 5, 5));
854
      add(list);
855
      add(b);
856
      add(c);
857
 
858
      pack();
859
    }
860
  }
861
 
862
  static class DragDropWindow
863
      extends SubFrame
864
      implements ActionListener, DropTargetListener
865
  {
866
    DragLabel source = new DragLabel("Drag and drop me to the following Button",
867
                                     Label.CENTER);
868
 
869
    Button target = new Button();
870
 
871
    public void init()
872
    {
873
      source.setForeground(Color.red);
874
      add(source, BorderLayout.NORTH);
875
 
876
      target.addActionListener(this);
877
      add(target, BorderLayout.SOUTH);
878
 
879
      new DropTarget(target, DnDConstants.ACTION_COPY_OR_MOVE, this);
880
 
881
      setSize(205, 100);
882
 
883
      pack();
884
    }
885
 
886
    public void actionPerformed(ActionEvent e)
887
    {
888
      Button b = (Button) e.getSource();
889
      b.setLabel("");
890
    }
891
 
892
    public void dragEnter(DropTargetDragEvent e)
893
    {
894
    }
895
 
896
    public void dragExit(DropTargetEvent e)
897
    {
898
    }
899
 
900
    public void dragOver(DropTargetDragEvent e)
901
    {
902
    }
903
 
904
    public void drop(DropTargetDropEvent e)
905
    {
906
      try
907
        {
908
          Transferable t = e.getTransferable();
909
 
910
          if (e.isDataFlavorSupported(DataFlavor.stringFlavor))
911
            {
912
              e.acceptDrop(e.getDropAction());
913
 
914
              String s;
915
              s = (String) t.getTransferData(DataFlavor.stringFlavor);
916
 
917
              target.setLabel(s);
918
 
919
              e.dropComplete(true);
920
            }
921
          else
922
            e.rejectDrop();
923
        }
924
      catch (java.io.IOException e2)
925
        {
926
        }
927
      catch (UnsupportedFlavorException e2)
928
        {
929
        }
930
    }
931
 
932
    public void dropActionChanged(DropTargetDragEvent e)
933
    {
934
    }
935
 
936
    class DragLabel
937
        extends Label
938
        implements DragGestureListener, DragSourceListener
939
    {
940
      private DragSource ds = DragSource.getDefaultDragSource();
941
 
942
      public DragLabel(String s, int alignment)
943
      {
944
        super(s, alignment);
945
        int action = DnDConstants.ACTION_COPY_OR_MOVE;
946
        ds.createDefaultDragGestureRecognizer(this, action, this);
947
      }
948
 
949
      public void dragGestureRecognized(DragGestureEvent e)
950
      {
951
        try
952
          {
953
            Transferable t = new StringSelection(getText());
954
            e.startDrag(DragSource.DefaultCopyNoDrop, t, this);
955
          }
956
        catch (InvalidDnDOperationException e2)
957
          {
958
            System.out.println(e2);
959
          }
960
      }
961
 
962
      public void dragDropEnd(DragSourceDropEvent e)
963
      {
964
        if (e.getDropSuccess() == false)
965
          return;
966
 
967
        int action = e.getDropAction();
968
        if ((action & DnDConstants.ACTION_MOVE) != 0)
969
          setText("");
970
      }
971
 
972
      public void dragEnter(DragSourceDragEvent e)
973
      {
974
        DragSourceContext ctx = e.getDragSourceContext();
975
 
976
        int action = e.getDropAction();
977
        if ((action & DnDConstants.ACTION_COPY) != 0)
978
          ctx.setCursor(DragSource.DefaultCopyDrop);
979
        else
980
          ctx.setCursor(DragSource.DefaultCopyNoDrop);
981
      }
982
 
983
      public void dragExit(DragSourceEvent e)
984
      {
985
      }
986
 
987
      public void dragOver(DragSourceDragEvent e)
988
      {
989
      }
990
 
991
      public void dropActionChanged(DragSourceDragEvent e)
992
      {
993
      }
994
    }
995
  }
996
 
997
  static class FullscreenWindow extends SubFrame
998
  {
999
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
1000
 
1001
    public void init ()
1002
    {
1003
      initted = true;
1004
 
1005
      setTitle("Fullscreen Exclusive Mode");
1006
 
1007
      ActionListener al = new ActionListener()
1008
      {
1009
        public void actionPerformed(ActionEvent ae)
1010
        {
1011
          if (gd.getFullScreenWindow() == FullscreenWindow.this)
1012
            gd.setFullScreenWindow(null);
1013
          else
1014
            gd.setFullScreenWindow(FullscreenWindow.this);
1015
        }
1016
      };
1017
 
1018
      Button b = new Button("Toggle Fullscreen");
1019
      Button c = new Button("Close");
1020
 
1021
      b.addActionListener(al);
1022
 
1023
      c.addActionListener(new ActionListener () {
1024
        public void actionPerformed (ActionEvent e) {
1025
          gd.setFullScreenWindow(null);
1026
          dispose();
1027
        }
1028
      });
1029
 
1030
      setLayout(new GridLayout(3, 1, 5, 5));
1031
      add(b);
1032
      add(c);
1033
 
1034
      pack();
1035
    }
1036
  }
1037
 
1038
  static class RoundRectWindow extends SubFrame
1039
  {
1040
    public void init ()
1041
    {
1042
      initted = true;
1043
      setTitle("RoundRect");
1044
      setLayout(new BorderLayout());
1045
      add(new DrawRoundRect(), "West");
1046
      Button cb = new Button ("Close");
1047
      cb.addActionListener(new ActionListener () {
1048
          public void actionPerformed (ActionEvent e) {
1049
            dispose();
1050
          }
1051
        });
1052
      add(cb, "Center");
1053
      add(new FillRoundRect(), "East");
1054
      pack();
1055
    }
1056
 
1057
    static class DrawRoundRect extends Panel
1058
    {
1059
 
1060
      public Dimension getPreferredSize()
1061
      {
1062
        return new Dimension(500, 500);
1063
      }
1064
 
1065
      public void paint( Graphics g )
1066
      {
1067
        // left side
1068
 
1069
        // rectangles should be identical
1070
        g.setColor(Color.red);
1071
        g.drawRect(50, 50, 300, 100);
1072
        g.setColor(Color.black);
1073
        g.drawRoundRect(50, 50, 300, 100, 0, 0);
1074
 
1075
        // small round corners
1076
        g.setColor(Color.red);
1077
        g.drawRect(50, 200, 300, 100);
1078
        g.setColor(Color.black);
1079
        g.drawRoundRect(50, 200, 300, 100, 25, 25);
1080
 
1081
        // round ends
1082
        g.setColor(Color.red);
1083
        g.drawRect(50, 350, 300, 100);
1084
        g.setColor(Color.black);
1085
        g.drawRoundRect(50, 350, 300, 100, 25, 100);
1086
 
1087
        // right side
1088
 
1089
        // circle only
1090
        g.setColor(Color.blue);
1091
        g.drawOval(375, 50, 100, 100);
1092
 
1093
        // round rectangle should exactly cover circle
1094
        g.setColor(Color.blue);
1095
        g.drawOval(375, 200, 100, 100);
1096
        g.setColor(Color.black);
1097
        g.drawRoundRect(375, 200, 100, 100, 100, 100);
1098
 
1099
        // round rectangle should look like a circle
1100
        g.setColor(Color.red);
1101
        g.drawRect(375, 350, 100, 100);
1102
        g.setColor(Color.black);
1103
        g.drawRoundRect(375, 350, 100, 100, 100, 100);
1104
      }
1105
    }
1106
 
1107
    static class FillRoundRect extends Panel
1108
    {
1109
 
1110
      public Dimension getPreferredSize()
1111
      {
1112
        return new Dimension(500, 500);
1113
      }
1114
 
1115
      public void paint( Graphics g )
1116
      {
1117
        // left side
1118
 
1119
        // rectangles should be identical
1120
        g.setColor(Color.red);
1121
        g.fillRect(50, 50, 300, 100);
1122
        g.setColor(Color.black);
1123
        g.fillRoundRect(50, 50, 300, 100, 0, 0);
1124
 
1125
        // small round corners
1126
        g.setColor(Color.red);
1127
        g.fillRect(50, 200, 300, 100);
1128
        g.setColor(Color.black);
1129
        g.fillRoundRect(50, 200, 300, 100, 25, 25);
1130
 
1131
        // round ends
1132
        g.setColor(Color.red);
1133
        g.fillRect(50, 350, 300, 100);
1134
        g.setColor(Color.black);
1135
        g.fillRoundRect(50, 350, 300, 100, 25, 100);
1136
 
1137
        // right side
1138
 
1139
        // circle only
1140
        g.setColor(Color.blue);
1141
        g.fillOval(375, 50, 100, 100);
1142
 
1143
        // round rectangle should exactly cover circle
1144
        g.setColor(Color.blue);
1145
        g.fillOval(375, 200, 100, 100);
1146
        g.setColor(Color.black);
1147
        g.fillRoundRect(375, 200, 100, 100, 100, 100);
1148
 
1149
        // round rectangle should look like a circle
1150
        g.setColor(Color.red);
1151
        g.fillRect(375, 350, 100, 100);
1152
        g.setColor(Color.black);
1153
        g.fillRoundRect(375, 350, 100, 100, 100, 100);
1154
      }
1155
    }
1156
  }
1157
 
1158
  static class AnimationWindow extends SubFrame
1159
  {
1160
    AnimationApplet a;
1161
    public void init ()
1162
    {
1163
      initted = true;
1164
      setTitle("Animation");
1165
      Button cb = new Button ("Close");
1166
      cb.addActionListener(new ActionListener () {
1167
          public void actionPerformed (ActionEvent e)
1168
          {
1169
            if (a != null)
1170
              {
1171
                a.destroy();
1172
                dispose();
1173
              }
1174
          }
1175
        });
1176
      a = new AnimationApplet();
1177
      add(a, "Center");
1178
      add(cb, "South");
1179
      pack();
1180
    }
1181
 
1182
    public void show()
1183
    {
1184
      super.show();
1185
      a.init();
1186
      a.run();
1187
    }
1188
  }
1189
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.