summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2004-08-01 21:31:11 +0000
committerMark Wielaard <mark@klomp.org>2004-08-01 21:31:11 +0000
commit9e4bac1508eb2b10e7c244c8eca7fa94847250c4 (patch)
treee6ae8c806137b4dc80cd50131ad3bc2508d81e08 /examples
parent61b14b381e9be23aada1a8cb38d6d3fdd1090d3b (diff)
downloadclasspath-9e4bac1508eb2b10e7c244c8eca7fa94847250c4.tar.gz
* NEWS: Mention new examples.
* Makefile.am (SUBDIRS): Add examples directory. * configure.ac (AC_CONFIG_FILES): Add examples/Makefile. * lib/standard.omit: Remove TestAWT.java and Test.java * gnu/java/awt/peer/gtk/TestAWT.java: Removed. * gnu/java/awt/peer/gtk/Test.java: Removed. * examples/README: New file. * examples/Makefile.am: New file. * examples/gnu/classpath/examples/icons/*.png: New icon resources. * examples/gnu/classpath/examples/awt/Demo.java: New class. * examples/gnu/classpath/examples/swing/Demo.java: New class.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am84
-rw-r--r--examples/README47
-rw-r--r--examples/gnu/classpath/examples/awt/Demo.java861
-rw-r--r--examples/gnu/classpath/examples/icons/big-fullscreen.pngbin0 -> 3768 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/big-home.pngbin0 -> 4135 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/big-warning.pngbin0 -> 2250 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-copy.pngbin0 -> 285 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-cut.pngbin0 -> 328 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-go-back.pngbin0 -> 523 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-go-down.pngbin0 -> 536 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-go-forward.pngbin0 -> 522 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-mic.pngbin0 -> 590 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-new.pngbin0 -> 349 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-open.pngbin0 -> 448 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-paste.pngbin0 -> 563 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-quit.pngbin0 -> 507 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-save-as.pngbin0 -> 751 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-save.pngbin0 -> 539 bytes
-rw-r--r--examples/gnu/classpath/examples/icons/stock-spell-check.pngbin0 -> 374 bytes
-rw-r--r--examples/gnu/classpath/examples/swing/Demo.java754
20 files changed, 1746 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 000000000..a4cd8e234
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,84 @@
+## Input file for automake to generate the Makefile.in used by configure
+
+# Setup the compiler to use the GNU Classpath library we just build
+GCJ = @GCJ@
+JIKES = @JIKES@
+if FOUND_GCJ
+JCOMPILER = $(GCJ) --bootclasspath '$(top_builddir)/lib' --classpath . -C
+else
+if FOUND_JIKES
+JCOMPILER = $(JIKES) -bootclasspath '' -extdirs '' -sourcepath '' --classpath $(top_builddir)/lib:.
+else
+error dunno how to setup the JCOMPILER and compile
+endif
+endif
+
+# All our example java source files
+EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java
+
+# The zip files with classes we want to produce.
+EXAMPLE_ZIP = examples.zip
+
+# Extra objects that will not exist until configure-time
+BUILT_SOURCES = $(EXAMPLE_ZIP)
+
+# the png icons we use in some of the examples.
+EXAMPLE_ICONS = $(srcdir)/gnu/classpath/examples/icons/*.png
+
+# Some architecture independent data to be installed.
+example_DATA = $(EXAMPLE_ZIP) README
+
+# Where we want these data files installed.
+exampledir = $(pkgdatadir)/examples
+
+# Make sure all sources and icons are also installed so users can use them.
+# (Be careful to strip off the srcdir part of the path when installing.)
+install-data-local:
+ srcdir_cnt=`echo $(srcdir) | wc -c`; \
+ for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
+ f=`echo $$file | cut -c$$srcdir_cnt-`; \
+ fdir=`dirname $$f`; \
+ if test ! -d $(DESTDIR)/$(pkgdatadir)/examples/$$fdir; then \
+ echo "$(mkinstalldirs) $(DESTDIR)/$(pkgdatadir)/examples/$$fdir"; \
+ $(mkinstalldirs) $(DESTDIR)/$(pkgdatadir)/examples/$$fdir; \
+ fi; \
+ echo "$(INSTALL_DATA) $$file $(DESTDIR)/$(pkgdatadir)/examples/$$f"; \
+ $(INSTALL_DATA) $$file $(DESTDIR)/$(pkgdatadir)/examples/$$f; \
+ done
+
+uninstall-local:
+ srcdir_cnt=`echo $(srcdir) | wc -c`; \
+ for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
+ f=`echo $$file | cut -c$$srcdir_cnt-`; \
+ echo "rm -f $(DESTDIR)/$(pkgdatadir)/examples/$$f"; \
+ rm -f $(DESTDIR)/$(pkgdatadir)/examples/$$f; \
+ done
+
+# Make sure everything is included in the distribution.
+EXTRA_DIST = README
+dist-hook:
+ srcdir_cnt=`echo $(srcdir) | wc -c`; \
+ for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
+ f=`echo $$file | cut -c$$srcdir_cnt-`; \
+ fdir=`dirname $$f`; \
+ if test ! -d $(distdir)/$$fdir; then \
+ echo "$(makeinstalldirs) $(distdir)/$$fdir"; \
+ $(mkinstalldirs) $(distdir)/$$fdir; \
+ fi; \
+ echo "cp -p $$file $(distdir)/$$f"; \
+ cp -p $$file $(distdir)/$$f; \
+ done
+
+# To generate the example zip just depend on the sources and ignore the
+# class files. Always regenerate all .class files and remove them immediatly.
+# And copy the png icons we use to the classes dir so they get also included.
+$(EXAMPLE_ZIP): $(EXAMPLE_JAVA_FILES)
+ mkdir -p classes/gnu/classpath/examples/icons
+ cp $(EXAMPLE_ICONS) classes/gnu/classpath/examples/icons
+ $(JCOMPILER) -d classes $(EXAMPLE_JAVA_FILES)
+ cd classes; $(ZIP) -r ../$(EXAMPLE_ZIP) .; cd ..
+ rm -rf classes
+
+# Zip file be gone! (and make sure the classes are gone too)
+clean-local:
+ rm -f $(EXAMPLE_ZIP) classes
diff --git a/examples/README b/examples/README
new file mode 100644
index 000000000..ca10ef4be
--- /dev/null
+++ b/examples/README
@@ -0,0 +1,47 @@
+These examples show how the GNU Classpath library can be used.
+
+Each example has its own package under gnu.classpath.examples and has a
+class Demo which contains a main() method to run that particular example.
+
+The examples can be compiled and run with gcj as follows:
+
+ gcj -o swingdemo --main=gnu.classpath.examples.swing.Demo \
+ gnu/classpath/examples/swing/Demo.java
+ ./swingdemo
+
+Or with a traditional byte code interpreter like:
+
+ gcj -C gnu/classpath/examples/awt/Demo.java
+ gij gnu.classpath.examples.awt.Demo
+
+The installation also comes with an examples.zip archive that contains
+all needed resources and compiled byte code class files that can be
+run as follows:
+
+ kaffe -classpath examples.zip gnu.classpath.examples.awt.Demo
+ kaffe -classpath examples.zip gnu.classpath.examples.swing.Demo
+
+All example code is distributed under the GNU General Public License (GPL).
+
+The example icons used in some of the examples come from gnome-icon-theme
+version 1.2.3 and are also distributed under the GPL.
+All these images are stored in the directory gnu/classpath/examples/icons/.
+
+More free icons can be found in the gnome-icon-theme package:
+http://ftp.gnome.org/pub/GNOME/sources/gnome-icon-theme/
+
+
+GNU Classpath examples are 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 examples 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 examples; see the file COPYING. If not,
+write to the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
diff --git a/examples/gnu/classpath/examples/awt/Demo.java b/examples/gnu/classpath/examples/awt/Demo.java
new file mode 100644
index 000000000..5be8d6a28
--- /dev/null
+++ b/examples/gnu/classpath/examples/awt/Demo.java
@@ -0,0 +1,861 @@
+/* Demo.java -- Shows examples of AWT components
+ Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+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. */
+
+package gnu.classpath.examples.awt;
+
+import java.awt.*;
+import java.awt.List;
+import java.awt.event.*;
+import java.net.URL;
+import java.util.*;
+
+class Demo
+{
+ public static void main(String args[])
+ {
+ MainWindow f = new MainWindow();
+ f.show();
+ }
+
+ static interface SubWindow
+ {
+ public void init ();
+ }
+
+ static class PrettyPanel extends Panel
+ {
+ Insets myInsets;
+
+ public PrettyPanel ()
+ {
+ myInsets = new Insets (10, 10, 10, 10);
+ }
+ public Insets getInsets ()
+ {
+ return myInsets;
+ }
+ }
+
+ static abstract class PrettyFrame extends Frame
+ {
+ public PrettyFrame ()
+ {
+ ((BorderLayout) getLayout ()).setHgap (5);
+ ((BorderLayout) getLayout ()).setVgap (5);
+ }
+
+ public Insets getInsets()
+ {
+ Insets oldInsets = super.getInsets ();
+ return new Insets (oldInsets.top+10,
+ oldInsets.left+10,
+ oldInsets.bottom+10,
+ oldInsets.right+10);
+ }
+ }
+
+ static abstract class SubFrame extends PrettyFrame implements SubWindow
+ {
+ boolean initted = false;
+
+ public void setVisible (boolean visible)
+ {
+ if (!initted && visible)
+ init();
+ super.setVisible (visible);
+ }
+ }
+
+ static class MainWindow extends PrettyFrame implements ActionListener
+ {
+ Button closeButton;
+
+ Hashtable windows;
+ Vector buttons;
+
+ void addSubWindow (String name, SubWindow w)
+ {
+ Button b = new Button (name);
+ b.addActionListener (this);
+
+ buttons.addElement (b);
+ windows.put (b, w);
+ }
+
+ MainWindow ()
+ {
+ MenuBar mb = new MenuBar ();
+ Menu menu = new Menu ("File");
+ Menu submenu = new Menu ("Testing", true);
+ submenu.add (new CheckboxMenuItem ("FooBar"));
+ submenu.add (new CheckboxMenuItem ("BarFoo"));
+ menu.add (submenu);
+ menu.add (new MenuItem("Orange"));
+ MenuItem quit = new MenuItem("Quit", new MenuShortcut('Q'));
+ quit.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ System.exit(0);
+ }
+ });
+ menu.add(quit);
+ mb.add (menu);
+ menu = new Menu("Edit", true);
+ menu.add(new MenuItem("Cut"));
+ menu.add(new MenuItem("Copy"));
+ menu.add(new MenuItem("Paste"));
+ mb.add (menu);
+
+ setMenuBar (mb);
+
+ String version = System.getProperty("gnu.classpath.version");
+ add (new Label ("GNU Classpath " + version), "North");
+
+ closeButton = new Button ("Close");
+ closeButton.addActionListener (this);
+ closeButton.setFont (new Font ("Serif", Font.BOLD | Font.ITALIC, 18));
+ add (closeButton, "South");
+
+ windows = new Hashtable ();
+ buttons = new Vector ();
+
+ addSubWindow ("Buttons", new ButtonsWindow ());
+ addSubWindow ("Cursors", new CursorsWindow ());
+ addSubWindow ("Dialog", new DialogWindow (this));
+ addSubWindow ("File", new FileWindow (this));
+ addSubWindow ("Labels", new LabelWindow ());
+ addSubWindow ("List", new ListWindow ());
+ addSubWindow ("Radio Buttons", new RadioWindow ());
+ addSubWindow ("TextField", new TextFieldWindow ());
+ addSubWindow ("RandomTests", new TestWindow (this));
+ addSubWindow ("RoundRect", new RoundRectWindow ());
+
+ Panel sp = new Panel();
+ PrettyPanel p = new PrettyPanel();
+ p.setLayout (new GridLayout (windows.size(), 1));
+
+ for (Enumeration e = buttons.elements (); e.hasMoreElements (); )
+ {
+ p.add ((Button) e.nextElement ());
+ }
+
+ sp.add (p);
+ add (sp, "Center");
+
+ setTitle ("AWT Demo");
+ pack();
+ }
+
+ public void actionPerformed (ActionEvent evt)
+ {
+ Button source = (Button) evt.getSource ();
+
+ if (source==closeButton)
+ {
+ dispose();
+ System.exit (0);
+ }
+
+ Window w = (Window) windows.get (source);
+ if (w.isVisible ())
+ w.dispose ();
+ else
+ {
+ if (w instanceof Dialog)
+ {
+ w.show();
+ }
+ else
+ {
+ w.setVisible (true);
+ }
+ }
+ }
+ }
+
+ static class ButtonsWindow extends SubFrame implements ActionListener
+ {
+ Button b[] = new Button [9];
+
+ public void init ()
+ {
+ initted = true;
+ Panel p = new Panel ();
+ p.setLayout (new GridLayout (0, 3, 5, 5));
+
+ for (int i=0; i<9; i++)
+ {
+ b[i]=new Button ("button" + (i+1));
+ b[i].addActionListener (this);
+ }
+
+ p.add (b[0]);
+ p.add (b[6]);
+ p.add (b[4]);
+ p.add (b[8]);
+ p.add (b[1]);
+ p.add (b[7]);
+ p.add (b[3]);
+ p.add (b[5]);
+ p.add (b[2]);
+
+ add (p, "North");
+
+ Button cb = new Button ("close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+ add (cb, "South");
+ setTitle ("Buttons");
+ pack();
+ }
+
+ public void actionPerformed (ActionEvent evt)
+ {
+ Button source = (Button) evt.getSource ();
+
+ for (int i = 0; i < 9; i++)
+ {
+ if (source == b[i])
+ {
+ int i2 = ((i + 1) == 9) ? 0 : (i + 1);
+ if (b[i2].isVisible())
+ b[i2].setVisible(false);
+ else
+ b[i2].setVisible(true);
+ }
+ }
+ }
+ }
+
+
+ static class DialogWindow extends Dialog implements SubWindow
+ {
+ Label text;
+ Frame parent;
+ boolean initted = false;
+
+ public DialogWindow (Frame f)
+ {
+ super (f, true);
+
+ this.parent = f;
+
+ addWindowListener (new WindowAdapter ()
+ {
+ public void windowClosing (WindowEvent e)
+ {
+ text.setVisible (false);
+ hide ();
+ }
+ });
+ }
+
+ public void setVisible (boolean visible)
+ {
+ if (!initted && visible)
+ init();
+ super.setVisible (visible);
+ }
+
+ public void show ()
+ {
+ if (!initted)
+ init();
+ super.show ();
+ }
+
+ public void init ()
+ {
+ text = new Label ("Dialog Test");
+ text.setAlignment (Label.CENTER);
+
+ add (text, "North");
+ text.setVisible (false);
+
+ Panel p = new PrettyPanel();
+
+ Button cb = new Button ("OK");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e)
+ {
+ text.setVisible (false);
+ hide();
+ }
+ });
+
+ p.setLayout (new GridLayout (1, 3));
+ ((GridLayout) p.getLayout ()).setHgap (5);
+ ((GridLayout) p.getLayout ()).setVgap (5);
+ p.add (cb);
+
+ Button toggle = new Button ("Toggle");
+ p.add (toggle);
+
+ toggle.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e)
+ {
+ if (text.isVisible ())
+ text.setVisible (false);
+ else
+ text.setVisible (true);
+ doLayout();
+ }
+ });
+
+ Button subdlg = new Button ("SubDialog");
+ p.add (subdlg);
+
+ subdlg.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e)
+ {
+ DialogWindow sw = new DialogWindow (parent);
+ sw.show ();
+ }
+ });
+
+ add (p, "South");
+ setTitle ("Dialog");
+ pack();
+ }
+ }
+
+ static class CursorsWindow extends SubFrame implements ItemListener
+ {
+ Choice cursorChoice;
+ Canvas cursorCanvas;
+
+ public void init ()
+ {
+ cursorChoice = new Choice();
+ cursorChoice.add ("Default");
+ cursorChoice.add ("Crosshair");
+ cursorChoice.add ("Text");
+ cursorChoice.add ("Wait");
+ cursorChoice.add ("Southwest Resize");
+ cursorChoice.add ("Southeast Resize");
+ cursorChoice.add ("Northwest Resize");
+ cursorChoice.add ("Northeast Resize");
+ cursorChoice.add ("North Resize");
+ cursorChoice.add ("South Resize");
+ cursorChoice.add ("West Resize");
+ cursorChoice.add ("East Resize");
+ cursorChoice.add ("Hand");
+ cursorChoice.add ("Move");
+
+ cursorChoice.addItemListener(this);
+
+ add (cursorChoice, "North");
+
+ cursorCanvas = new Canvas ()
+ {
+ public void paint (Graphics g)
+ {
+ Dimension d = this.getSize();
+ g.setColor(Color.white);
+ g.fillRect(0, 0, d.width, d.height/2);
+ g.setColor(Color.black);
+ g.fillRect(0, d.height/2, d.width, d.height/2);
+ g.setColor(this.getBackground());
+ g.fillRect(d.width/3, d.height/3, d.width/3,
+ d.height/3);
+ }
+ };
+
+ cursorCanvas.setSize (80,80);
+
+ add (cursorCanvas, "Center");
+
+ Button cb = new Button ("Close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+
+ add (cb, "South");
+ setTitle ("Cursors");
+ pack();
+ }
+
+ public void itemStateChanged (ItemEvent e)
+ {
+ int index = cursorChoice.getSelectedIndex();
+ cursorCanvas.setCursor(Cursor.getPredefinedCursor(index));
+ }
+ }
+
+ static class TextFieldWindow extends SubFrame implements ItemListener
+ {
+ Checkbox editable, visible, sensitive;
+ TextField text;
+
+ public void init ()
+ {
+ initted = true;
+ text = new TextField ("hello world");
+ add (text, "North");
+
+ Panel p = new Panel();
+ p.setLayout (new GridLayout (3, 1));
+ ((GridLayout) p.getLayout ()).setHgap (5);
+ ((GridLayout) p.getLayout ()).setVgap (5);
+
+ editable = new Checkbox("Editable", true);
+ p.add (editable);
+ editable.addItemListener (this);
+
+ visible = new Checkbox("Visible", true);
+ p.add (visible);
+ visible.addItemListener (this);
+
+ sensitive = new Checkbox("Sensitive", true);
+ p.add (sensitive);
+ sensitive.addItemListener (this);
+
+ add (p, "Center");
+
+ Button cb = new Button ("Close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+
+ add (cb, "South");
+ setTitle ("TextField");
+ pack();
+ }
+
+ public void itemStateChanged (ItemEvent e)
+ {
+ boolean on=true;
+
+ if (e.getStateChange () == ItemEvent.DESELECTED)
+ on=false;
+ if (e.getSource() == editable)
+ text.setEditable (on);
+ if (e.getSource() == visible)
+ if (on)
+ text.setEchoChar ((char) 0);
+ else
+ text.setEchoChar ('*');
+ if (e.getSource() == sensitive)
+ text.setEnabled (on);
+
+ }
+ }
+
+ static class FileWindow extends FileDialog implements SubWindow
+ {
+ boolean initted = false;
+
+ public FileWindow (MainWindow mw)
+ {
+ super (mw);
+ }
+
+ public void setVisible (boolean visible)
+ {
+ if (!initted && visible)
+ init();
+ super.setVisible (visible);
+ }
+
+ public void init()
+ {
+ initted = true;
+ }
+ }
+
+ static class LabelWindow extends SubFrame
+ {
+ public void init ()
+ {
+ initted = true;
+
+ Panel p = new Panel();
+ p.setLayout (new GridLayout (3, 1));
+ ((GridLayout) p.getLayout ()).setHgap (5);
+ ((GridLayout) p.getLayout ()).setVgap (5);
+
+ p.add (new Label ("left justified label", Label.LEFT));
+ p.add (new Label ("center justified label", Label.CENTER));
+ p.add (new Label ("right justified label", Label.RIGHT));
+
+ add (p, "Center");
+
+ Button cb = new Button ("Close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+
+ add (cb, "South");
+ setTitle ("Labels");
+ pack();
+ }
+ }
+
+ static class ListWindow extends SubFrame
+ {
+ public void init ()
+ {
+ initted = true;
+
+ Panel p = new Panel ();
+ p.setLayout (new GridLayout (3, 1));
+
+ List l = new List (5, true);
+ for (int i = 0; i < 10; i++)
+ l.add ("List item " + i);
+
+ p.add (l);
+
+ add (p, "Center");
+
+ Button cb = new Button ("Close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+
+ add (cb, "South");
+ setTitle ("List");
+ pack();
+ }
+ }
+
+
+ static class RadioWindow extends SubFrame
+ {
+ public void init ()
+ {
+ initted = true;
+
+ Panel p = new Panel();
+ p.setLayout (new GridLayout (3, 1));
+ ((GridLayout) p.getLayout ()).setHgap (5);
+ ((GridLayout) p.getLayout ()).setVgap (5);
+
+ final CheckboxGroup cg = new CheckboxGroup();
+ final Checkbox[] boxes = new Checkbox[3];
+ for (int i = 0; i < 3; ++i)
+ {
+ boxes[i] = new Checkbox("button" + i, cg, i == 0);
+ p.add(boxes[i]);
+ }
+
+ add (p, "North");
+
+ p = new Panel();
+ p.setLayout (new GridLayout (1, 3));
+ ((GridLayout) p.getLayout ()).setHgap (5);
+ ((GridLayout) p.getLayout ()).setVgap (5);
+
+ for (int i = 0; i < 3; ++i)
+ {
+ final int val = i;
+ Button tweak = new Button ("Set " + i);
+ tweak.addActionListener(new ActionListener ()
+ {
+ public void actionPerformed (ActionEvent e)
+ {
+ cg.setSelectedCheckbox(boxes[val]);
+ }
+ });
+ p.add(tweak);
+ }
+
+ add (p, "Center");
+
+ Button cb = new Button ("Close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+
+ add (cb, "South");
+ setTitle ("Radio Buttons");
+ pack();
+ }
+ }
+
+ static class TestWindow extends SubFrame
+ {
+ static int xs = 5, ys = 5;
+ private final Frame parent;
+
+ public TestWindow(Frame f)
+ {
+ parent = f;
+ }
+
+ public void init()
+ {
+ initted = true;
+
+ addWindowListener (new WindowAdapter ()
+ {
+ public void windowClosing (WindowEvent e)
+ {
+ hide ();
+ }
+ });
+
+ 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);
+ add(pan,"North");
+
+ final Image img;
+ URL imageurl;
+ imageurl = this.getClass()
+ .getResource("/gnu/classpath/examples/icons/big-warning.png");
+ img = Toolkit.getDefaultToolkit().createImage(imageurl);
+
+ final Canvas ch = new Canvas()
+ {
+ public void paint (Graphics g)
+ {
+ g.drawImage(img, xs + 25, ys + 25, this);
+
+ Font font = new Font ("Serif", Font.PLAIN, 18);
+ g.setFont (font);
+ g.setXORMode (Color.red);
+
+ g.drawString("Hi Red!", xs + 15, ys + 10);
+ g.setColor (Color.blue);
+ g.drawLine (xs, ys, xs + 100, ys + 100);
+
+ }
+ };
+ ch.setSize(150, 150);
+ add(ch, "Center");
+
+ final ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
+ final Panel p = new Panel();
+ p.add(new Button("Stop"));
+ p.add(new Button("evil"));
+ p.add(new Button("hoarders"));
+ p.add(new Button("use"));
+ p.add(new Button("GNU!"));
+
+ sp.add(p);
+ 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);
+
+ add(east_panel,"East");
+
+ final Button wb = new Button();
+ wb.setLabel("Hello World!");
+ wb.addActionListener(new ActionListener()
+ {
+ public void actionPerformed (ActionEvent e)
+ {
+ l.setText ("Hello World!");
+
+ final Dialog d = new Dialog(parent);
+ d.setLayout(new FlowLayout());
+ d.setModal(true);
+ Button b = new Button("foobar");
+ b.addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed (MouseEvent me)
+ {
+ d.hide ();
+ }
+ });
+ d.add (b);
+
+ List ch = new List();
+ ch.add("Ding");
+ ch.add("September");
+ ch.add("Red");
+ ch.add("Quassia");
+ ch.add("Pterodactyl");
+ d.add(ch);
+
+ d.pack ();
+ d.show ();
+ }
+ });
+
+ wb.addMouseListener(new MouseAdapter()
+ {
+ public void mousePressed(MouseEvent e) {
+ xs++;
+ ys++;
+ ch.repaint ();
+ }
+ });
+
+ add(wb,"West");
+
+ pack();
+ show();
+
+ sp.setScrollPosition (10,0);
+
+ Toolkit t = Toolkit.getDefaultToolkit();
+ t.beep();
+ }
+ }
+
+ static class RoundRectWindow extends SubFrame
+ {
+ public void init ()
+ {
+ initted = true;
+ setTitle("RoundRect");
+ setLayout(new BorderLayout());
+ add(new DrawRoundRect(), "West");
+ Button cb = new Button ("Close");
+ cb.addActionListener(new ActionListener () {
+ public void actionPerformed (ActionEvent e) {
+ dispose();
+ }
+ });
+ add(cb, "Center");
+ add(new FillRoundRect(), "East");
+ pack();
+ }
+
+ static class DrawRoundRect extends Panel
+ {
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(500, 500);
+ }
+
+ public void paint( Graphics g )
+ {
+ // left side
+
+ // rectangles should be identical
+ g.setColor(Color.red);
+ g.drawRect(50, 50, 300, 100);
+ g.setColor(Color.black);
+ g.drawRoundRect(50, 50, 300, 100, 0, 0);
+
+ // small round corners
+ g.setColor(Color.red);
+ g.drawRect(50, 200, 300, 100);
+ g.setColor(Color.black);
+ g.drawRoundRect(50, 200, 300, 100, 25, 25);
+
+ // round ends
+ g.setColor(Color.red);
+ g.drawRect(50, 350, 300, 100);
+ g.setColor(Color.black);
+ g.drawRoundRect(50, 350, 300, 100, 25, 100);
+
+ // right side
+
+ // circle only
+ g.setColor(Color.blue);
+ g.drawOval(375, 50, 100, 100);
+
+ // round rectangle should exactly cover circle
+ g.setColor(Color.blue);
+ g.drawOval(375, 200, 100, 100);
+ g.setColor(Color.black);
+ g.drawRoundRect(375, 200, 100, 100, 100, 100);
+
+ // round rectangle should look like a circle
+ g.setColor(Color.red);
+ g.drawRect(375, 350, 100, 100);
+ g.setColor(Color.black);
+ g.drawRoundRect(375, 350, 100, 100, 100, 100);
+ }
+ }
+
+ static class FillRoundRect extends Panel
+ {
+
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(500, 500);
+ }
+
+ public void paint( Graphics g )
+ {
+ // left side
+
+ // rectangles should be identical
+ g.setColor(Color.red);
+ g.fillRect(50, 50, 300, 100);
+ g.setColor(Color.black);
+ g.fillRoundRect(50, 50, 300, 100, 0, 0);
+
+ // small round corners
+ g.setColor(Color.red);
+ g.fillRect(50, 200, 300, 100);
+ g.setColor(Color.black);
+ g.fillRoundRect(50, 200, 300, 100, 25, 25);
+
+ // round ends
+ g.setColor(Color.red);
+ g.fillRect(50, 350, 300, 100);
+ g.setColor(Color.black);
+ g.fillRoundRect(50, 350, 300, 100, 25, 100);
+
+ // right side
+
+ // circle only
+ g.setColor(Color.blue);
+ g.fillOval(375, 50, 100, 100);
+
+ // round rectangle should exactly cover circle
+ g.setColor(Color.blue);
+ g.fillOval(375, 200, 100, 100);
+ g.setColor(Color.black);
+ g.fillRoundRect(375, 200, 100, 100, 100, 100);
+
+ // round rectangle should look like a circle
+ g.setColor(Color.red);
+ g.fillRect(375, 350, 100, 100);
+ g.setColor(Color.black);
+ g.fillRoundRect(375, 350, 100, 100, 100, 100);
+ }
+ }
+ }
+
+}
diff --git a/examples/gnu/classpath/examples/icons/big-fullscreen.png b/examples/gnu/classpath/examples/icons/big-fullscreen.png
new file mode 100644
index 000000000..12ca14678
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/big-fullscreen.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/big-home.png b/examples/gnu/classpath/examples/icons/big-home.png
new file mode 100644
index 000000000..3a8f055a0
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/big-home.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/big-warning.png b/examples/gnu/classpath/examples/icons/big-warning.png
new file mode 100644
index 000000000..dc8c8a457
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/big-warning.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-copy.png b/examples/gnu/classpath/examples/icons/stock-copy.png
new file mode 100644
index 000000000..f2f83e34c
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-copy.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-cut.png b/examples/gnu/classpath/examples/icons/stock-cut.png
new file mode 100644
index 000000000..f887e1569
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-cut.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-go-back.png b/examples/gnu/classpath/examples/icons/stock-go-back.png
new file mode 100644
index 000000000..bd5607c6b
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-go-back.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-go-down.png b/examples/gnu/classpath/examples/icons/stock-go-down.png
new file mode 100644
index 000000000..c8f54fb91
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-go-down.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-go-forward.png b/examples/gnu/classpath/examples/icons/stock-go-forward.png
new file mode 100644
index 000000000..bc5bcc519
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-go-forward.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-mic.png b/examples/gnu/classpath/examples/icons/stock-mic.png
new file mode 100644
index 000000000..62fc914c6
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-mic.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-new.png b/examples/gnu/classpath/examples/icons/stock-new.png
new file mode 100644
index 000000000..db8b08748
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-new.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-open.png b/examples/gnu/classpath/examples/icons/stock-open.png
new file mode 100644
index 000000000..b1b22e5ed
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-open.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-paste.png b/examples/gnu/classpath/examples/icons/stock-paste.png
new file mode 100644
index 000000000..35f67d647
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-paste.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-quit.png b/examples/gnu/classpath/examples/icons/stock-quit.png
new file mode 100644
index 000000000..60a6e40e6
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-quit.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-save-as.png b/examples/gnu/classpath/examples/icons/stock-save-as.png
new file mode 100644
index 000000000..9d7f9a4cb
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-save-as.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-save.png b/examples/gnu/classpath/examples/icons/stock-save.png
new file mode 100644
index 000000000..0bc44aba4
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-save.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/icons/stock-spell-check.png b/examples/gnu/classpath/examples/icons/stock-spell-check.png
new file mode 100644
index 000000000..6f154fd9f
--- /dev/null
+++ b/examples/gnu/classpath/examples/icons/stock-spell-check.png
Binary files differ
diff --git a/examples/gnu/classpath/examples/swing/Demo.java b/examples/gnu/classpath/examples/swing/Demo.java
new file mode 100644
index 000000000..0e85413c2
--- /dev/null
+++ b/examples/gnu/classpath/examples/swing/Demo.java
@@ -0,0 +1,754 @@
+/* SwingDemo.java -- An example of using the javax.swing UI.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath examples.
+
+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.
+*/
+
+
+package gnu.classpath.examples.swing;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.font.*;
+import java.awt.geom.*;
+import java.awt.image.*;
+
+import javax.swing.*;
+import javax.swing.event.*;
+import javax.swing.plaf.*;
+import javax.swing.plaf.basic.*;
+import javax.swing.border.*;
+
+import java.net.URL;
+import java.util.*;
+
+public class Demo
+{
+ JFrame frame;
+ static Color blueGray = new Color(0xdc, 0xda, 0xd5);
+
+ static class GNULookAndFeel extends BasicLookAndFeel
+ {
+ public boolean isNativeLookAndFeel() { return true; }
+ public boolean isSupportedLookAndFeel() { return true; }
+ public String getDescription() { return "GNU Look and Feel"; }
+ public String getID() { return "GNULookAndFeel"; }
+ public String getName() { return "GNU"; }
+
+ static UIDefaults LAF_defaults;
+
+ public UIDefaults getDefaults()
+ {
+ if (LAF_defaults == null)
+ {
+ LAF_defaults = super.getDefaults();
+ Object[] myDefaults = new Object[] {
+ "Button.background", new ColorUIResource(blueGray),
+ "CheckBox.background", new ColorUIResource(blueGray),
+ "CheckBoxMenuItem.background", new ColorUIResource(blueGray),
+ "ToolBar.background", new ColorUIResource(blueGray),
+ "Panel.background", new ColorUIResource(blueGray),
+ "Slider.background", new ColorUIResource(blueGray),
+ "OptionPane.background", new ColorUIResource(blueGray),
+ "ProgressBar.background", new ColorUIResource(blueGray),
+ "TabbedPane.background", new ColorUIResource(blueGray),
+ "Label.background", new ColorUIResource(blueGray),
+ "Menu.background", new ColorUIResource(blueGray),
+ "MenuBar.background", new ColorUIResource(blueGray),
+ "MenuItem.background", new ColorUIResource(blueGray),
+ "ScrollBar.background", new ColorUIResource(blueGray)
+ };
+ LAF_defaults.putDefaults(myDefaults);
+ }
+ return LAF_defaults;
+ }
+ }
+
+ static
+ {
+ try
+ {
+ UIManager.setLookAndFeel(new GNULookAndFeel());
+ }
+ catch (UnsupportedLookAndFeelException e)
+ {
+ System.err.println("Cannot install GNULookAndFeel, exiting");
+ System.exit(1);
+ }
+ }
+
+ static Icon stockIcon(String s)
+ {
+ return getIcon("/gnu/classpath/examples/icons/stock-" + s + ".png", s);
+ }
+
+ static Icon bigStockIcon(String s)
+ {
+ return getIcon("/gnu/classpath/examples/icons/big-" + s + ".png", s);
+ }
+
+ static Icon getIcon(String location, String name)
+ {
+ URL url = Demo.class.getResource(location);
+ if (url == null) System.err.println("WARNING " + location + " not found.");
+ return new ImageIcon(url, name);
+ }
+
+ static JMenuBar mkMenuBar()
+ {
+ JMenuBar bar = new JMenuBar();
+
+ JMenu file = new JMenu("File");
+ JMenu edit = new JMenu("Edit");
+ JMenu help = new JMenu("Help");
+
+ file.setMnemonic(KeyEvent.VK_F);
+ edit.setMnemonic(KeyEvent.VK_E);
+ help.setMnemonic(KeyEvent.VK_H);
+
+ file.add(new JMenuItem("New", stockIcon("new")));
+ file.add(new JMenuItem("Open", stockIcon("open")));
+
+ JMenu recent = new JMenu("Recent Files...");
+ recent.add(new JMenuItem("war-and-peace.txt"));
+ recent.add(new JMenuItem("taming-of-shrew.txt"));
+ recent.add(new JMenuItem("sun-also-rises.txt"));
+ file.add(recent);
+ file.add(new JMenuItem("Save", stockIcon("save")));
+ file.add(new JMenuItem("Save as...", stockIcon("save-as")));
+
+ JMenuItem exit = new JMenuItem("Exit", stockIcon("quit"));
+ exit.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ System.exit(1);
+ }
+ });
+
+ file.add(exit);
+
+ edit.add(new JMenuItem("Cut", stockIcon("cut")));
+ edit.add(new JMenuItem("Copy", stockIcon("copy")));
+ edit.add(new JMenuItem("Paste", stockIcon("paste")));
+
+ JMenu preferences = new JMenu("Preferences...");
+ preferences.add(new JCheckBoxMenuItem("Microphone Active",
+ stockIcon("mic")));
+ preferences.add(new JCheckBoxMenuItem("Check Spelling",
+ stockIcon("spell-check")));
+ preferences.add(new JCheckBoxMenuItem("World Peace"));
+ edit.add(preferences);
+
+ help.add(new JMenuItem("just play with the widgets"));
+ help.add(new JMenuItem("and enjoy the sensation of"));
+ help.add(new JMenuItem("your neural connections growing"));
+
+ bar.add(file);
+ bar.add(edit);
+ bar.add(help);
+ return bar;
+ }
+
+ static void triggerDialog(final JButton but, final String dir)
+ {
+ but.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ JOptionPane.showConfirmDialog(but,
+ "Sure you want to go " + dir + "?",
+ "Confirm",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.QUESTION_MESSAGE,
+ bigStockIcon("warning"));
+ }
+ });
+ }
+
+ static JToolBar mkToolBar()
+ {
+ JToolBar bar = new JToolBar();
+
+ JButton b = mkButton(stockIcon("go-back"));
+ triggerDialog(b, "back");
+ bar.add(b);
+
+ b = mkButton(stockIcon("go-down"));
+ triggerDialog(b, "down");
+ bar.add(b);
+
+ b = mkButton(stockIcon("go-forward"));
+ triggerDialog(b, "forward");
+ bar.add(b);
+ return bar;
+ }
+
+ static String valign2str(int a)
+ {
+ switch (a)
+ {
+ case SwingConstants.CENTER:
+ return "Center";
+ case SwingConstants.TOP:
+ return "Top";
+ case SwingConstants.BOTTOM:
+ return "Bottom";
+ default:
+ return "Unknown";
+ }
+ }
+
+ static String halign2str(int a)
+ {
+ switch (a)
+ {
+ case SwingConstants.CENTER:
+ return "Center";
+ case SwingConstants.RIGHT:
+ return "Right";
+ case SwingConstants.LEFT:
+ return "Left";
+ default:
+ return "Unknown";
+ }
+ }
+
+ static JButton mkButton(String title, Icon icon,
+ int hAlign, int vAlign,
+ int hPos, int vPos)
+ {
+ JButton b;
+ if (icon == null)
+ b = new JButton(title);
+ else if (title == null)
+ b = new JButton(icon);
+ else
+ b = new JButton(title, icon);
+
+ if (hAlign != -1) b.setHorizontalAlignment(hAlign);
+ if (vAlign != -1) b.setVerticalAlignment(vAlign);
+ if (hPos != -1) b.setHorizontalTextPosition(hPos);
+ if (vPos != -1) b.setVerticalTextPosition(vPos);
+ return b;
+ }
+
+ static JButton mkButton(String title)
+ {
+ return mkButton(title, null, -1, -1, -1, -1);
+ }
+
+ static JButton mkButton(Icon i)
+ {
+ return mkButton(null, i, -1, -1, -1, -1);
+ }
+
+
+ static JPanel mkButtonWorld()
+ {
+ Icon ii = bigStockIcon("home");
+ int CENTER = SwingConstants.CENTER;
+ int TOP = SwingConstants.TOP;
+ int BOTTOM = SwingConstants.BOTTOM;
+
+ int[] valigns = new int[] {SwingConstants.CENTER,
+ SwingConstants.TOP,
+ SwingConstants.BOTTOM};
+
+ int[] haligns = new int[] {SwingConstants.CENTER,
+ SwingConstants.RIGHT,
+ SwingConstants.LEFT};
+
+ Border[] borders = new Border[] {
+ new SoftBevelBorder(BevelBorder.RAISED),
+ new SoftBevelBorder(BevelBorder.LOWERED),
+ new BevelBorder(BevelBorder.RAISED),
+
+ LineBorder.createBlackLineBorder(),
+ new MatteBorder(2, 2, 2, 2, Color.GREEN),
+ LineBorder.createGrayLineBorder(),
+
+ new BevelBorder(BevelBorder.LOWERED),
+ new EtchedBorder(EtchedBorder.RAISED),
+ new EtchedBorder(EtchedBorder.LOWERED)
+ };
+
+ JComponent[] comps = new JComponent[3*3];
+
+ int q = 0;
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(3, 3));
+
+ for (int i = 0; i < 3; ++i)
+ for (int j = 0; j < 3; ++j)
+ {
+ JButton b = mkButton(halign2str(haligns[i])
+ + valign2str(valigns[j]),
+ ii,
+ -1, -1, haligns[i], valigns[j]);
+ b.setBorder(borders[q++]);
+ JPanel tmp = new JPanel();
+ tmp.setBorder(new MatteBorder(5, 5, 5, 5, blueGray));
+ tmp.add(b);
+ panel.add(tmp);
+ }
+
+ return panel;
+ }
+
+ private static class CheckCellRenderer
+ extends JCheckBox implements ListCellRenderer
+ {
+ public Component getListCellRendererComponent(JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ setSelected(isSelected);
+ setText(value.toString());
+
+ return this;
+ }
+ }
+
+ private static class LabelCellRenderer
+ extends DefaultListCellRenderer
+ {
+ public Component getListCellRendererComponent(JList list,
+ Object value,
+ int index,
+ boolean isSelected,
+ boolean cellHasFocus)
+ {
+ Component c = super.getListCellRendererComponent(list, value, index,
+ isSelected,
+ cellHasFocus);
+
+ return c;
+ }
+ }
+
+ public static JScrollPane mkScrollPane(JComponent inner)
+ {
+ JScrollPane jsp;
+ jsp = new JScrollPane(inner,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+ return jsp;
+ }
+
+ public static JPanel mkListWorld()
+ {
+
+ String foo[] = new String[] {
+ "non alcoholic ",
+ "carbonated ",
+ "malted ",
+ "fresh squeezed ",
+ "imported ",
+ "high fructose ",
+ "enriched "
+ };
+
+ String bar[] = new String[] {
+ "orange juice",
+ "ginger beer",
+ "yak milk",
+ "corn syrup",
+ "herbal remedy"
+ };
+
+ final DefaultListModel mod = new DefaultListModel();
+ final JList list1 = new JList(mod);
+ final JList list2 = new JList(mod);
+
+ list2.setSelectionModel(list1.getSelectionModel());
+ for (int i = 0; i < bar.length; ++i)
+ for (int j = 0; j < foo.length; ++j)
+ mod.addElement(foo[j] + bar[i]);
+
+ list1.setCellRenderer(new LabelCellRenderer());
+ list2.setCellRenderer(new CheckCellRenderer());
+
+ JButton add = mkButton("add element");
+ add.addActionListener(new ActionListener()
+ {
+ int i = 0;
+ public void actionPerformed(ActionEvent e)
+ {
+ mod.addElement("new element " + i);
+ ++i;
+ }
+ });
+
+ JButton del = mkButton("delete selected");
+ del.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ for (int i = 0; i < mod.getSize(); ++i)
+ if (list1.isSelectedIndex(i))
+ mod.remove(i);
+ }
+ });
+
+
+ JSplitPane splitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
+ splitter.add(mkScrollPane(list1), JSplitPane.LEFT);
+ splitter.add(mkScrollPane(list2), JSplitPane.RIGHT);
+
+ JPanel p1 = new JPanel();
+ p1.setLayout(new BorderLayout());
+
+ JPanel p2 = new JPanel();
+ p2.setLayout(new GridLayout(1, 2));
+ p2.add(add);
+ p2.add(del);
+
+ p1.add(p2, BorderLayout.NORTH);
+ p1.add(splitter, BorderLayout.CENTER);
+ return p1;
+ }
+
+
+ static JPanel mkDesktopWorld()
+ {
+
+ final JDesktopPane desk = new JDesktopPane();
+ desk.setDesktopManager(new DefaultDesktopManager());
+ desk.setPreferredSize(new Dimension(300,300));
+ desk.setMinimumSize(new Dimension(300,300));
+ JButton but = mkButton("add frame");
+ but.addActionListener(new ActionListener()
+ {
+ int i = 10;
+ public void actionPerformed(ActionEvent e)
+ {
+ JInternalFrame f;
+ f = new JInternalFrame("internal", true, true, true, true);
+ f.getContentPane().setLayout(new BorderLayout());
+ f.getContentPane().add(mkToolBar(), BorderLayout.NORTH);
+ f.getContentPane().add(mkButton(bigStockIcon("fullscreen")),
+ BorderLayout.CENTER);
+ desk.add(f);
+ f.setBounds(i, i, 250, 200);
+ i += 30;
+ }
+ });
+
+ JPanel panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+ panel.add(desk, BorderLayout.CENTER);
+ panel.add(but, BorderLayout.NORTH);
+ but.doClick();
+ but.doClick();
+ return panel;
+ }
+
+ static JTabbedPane mkTabbedPane()
+ {
+ JTabbedPane tabs = new JTabbedPane();
+
+ tabs.add("Button world!", mkButtonWorld());
+ tabs.add("List world!", mkListWorld());
+ tabs.add("Desktop world!", mkDesktopWorld());
+ return tabs;
+ }
+
+ static JComponent mkSliders()
+ {
+ JSlider slider = new JSlider();
+ slider.setPaintTrack(true);
+ slider.setPaintTicks(true);
+ slider.setMajorTickSpacing(30);
+ slider.setInverted(false);
+ JProgressBar progress = new JProgressBar();
+ BoundedRangeModel model = new DefaultBoundedRangeModel(10, 1, 0, 100);
+ progress.setModel(model);
+ slider.setModel(model);
+ JPanel panel = new JPanel();
+ panel.setLayout(new GridLayout(1, 2));
+ panel.add(slider);
+ panel.add(progress);
+ return panel;
+ }
+
+ public Demo()
+ {
+ frame = new JFrame("Swing Activity Board");
+ frame.setJMenuBar(mkMenuBar());
+ JComponent component = (JComponent) frame.getContentPane();
+ component.setLayout(new BorderLayout());
+ component.add(mkToolBar(), BorderLayout.NORTH);
+ component.add(mkTabbedPane(), BorderLayout.CENTER);
+ component.add(mkButtonBar(), BorderLayout.SOUTH);
+
+ frame.pack();
+ frame.show();
+ }
+
+ public static class LaterMain
+ implements Runnable
+ {
+ public void run()
+ {
+ Demo demo = new Demo();
+ }
+ }
+
+ public static void main(String args[])
+ {
+ SwingUtilities.invokeLater(new LaterMain());
+ }
+
+ public static JCheckBox mkCheckbox(String label)
+ {
+ JCheckBox c = new JCheckBox(label);
+ c.setFont(new Font("Luxi", Font.PLAIN, 14));
+ return c;
+ }
+
+ public static JRadioButton mkRadio(String label)
+ {
+ JRadioButton c = new JRadioButton(label);
+ c.setFont(new Font("Luxi", Font.PLAIN, 14));
+ return c;
+ }
+
+ public static JList mkList(Object[] elts)
+ {
+ JList list = new JList(elts);
+ list.setFont(new Font("Luxi", Font.PLAIN, 14));
+ return list;
+ }
+
+ public static JTabbedPane mkTabs(String[] names)
+ {
+ JTabbedPane tabs = new JTabbedPane();
+ for (int i = 0; i < names.length; ++i)
+ {
+ tabs.addTab(names[i], mkButton(names[i]));
+ }
+ return tabs;
+ }
+
+
+ public static JButton mkBigButton(String title)
+ {
+ JButton b = new JButton(title);
+ b.setMargin(new Insets(5,5,5,5));
+ b.setFont(new Font("Luxi", Font.PLAIN, 14));
+ return b;
+ }
+
+ public static JToggleButton mkToggle(String title)
+ {
+ JToggleButton b = new JToggleButton(title);
+ b.setMargin(new Insets(5,5,5,5));
+ b.setFont(new Font("Luxi", Font.PLAIN, 14));
+ return b;
+ }
+
+ public static JPanel mkPanel(JComponent[] inners)
+ {
+ JPanel p = new JPanel();
+ for (int i = 0; i < inners.length; ++i)
+ {
+ p.add(inners[i]);
+ }
+ return p;
+ }
+
+ public static JScrollBar mkScrollBar()
+ {
+ JScrollBar scrollbar = new JScrollBar();
+ return scrollbar;
+ }
+
+ public static JPanel mkViewportBox(final JComponent inner)
+ {
+ final JViewport port = new JViewport();
+ port.setView(inner);
+ JButton left = mkBigButton("left");
+ JButton right = mkBigButton("right");
+
+ left.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ Point p = port.getViewPosition();
+ port.setViewPosition(new Point(p.x - 10, p.y));
+ }
+ });
+
+ right.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ Point p = port.getViewPosition();
+ port.setViewPosition(new Point(p.x + 10, p.y));
+ }
+ });
+
+ return mkPanel(new JComponent[] {port, left, right});
+ }
+
+ public static JPanel mkListPanel(Object[] elts)
+ {
+ final DefaultListModel mod = new DefaultListModel();
+ final JList list1 = new JList(mod);
+ final JList list2 = new JList(mod);
+
+ list2.setSelectionModel(list1.getSelectionModel());
+ for (int i = 0; i < elts.length; ++i)
+ mod.addElement(elts[i]);
+ list1.setCellRenderer(new LabelCellRenderer());
+ list2.setCellRenderer(new CheckCellRenderer());
+
+ JButton add = mkBigButton("add element");
+ add.addActionListener(new ActionListener()
+ {
+ int i = 0;
+ public void actionPerformed(ActionEvent e)
+ {
+ mod.addElement("new element " + i);
+ ++i;
+ }
+ });
+
+ JButton del = mkBigButton("delete selected");
+ del.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ for (int i = 0; i < mod.getSize(); ++i)
+ if (list1.isSelectedIndex(i))
+ mod.remove(i);
+ }
+ });
+
+ return mkPanel(new JComponent[] {list1, //mkScrollPane(list1),
+ list2, //mkScrollPane(list2),
+ mkPanel(new JComponent[] {add, del})});
+ }
+
+
+ public static JButton mkDisposerButton(final JFrame c)
+ {
+ JButton close = mkBigButton("Close");
+ close.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ c.dispose();
+ }
+ });
+ return close;
+ }
+
+ private static class PopUpAction
+ implements ActionListener
+ {
+ private JComponent inner;
+ private String name;
+
+ PopUpAction(String n, JComponent i, JPanel p)
+ {
+ name = n;
+ inner = i;
+
+ JButton b = mkBigButton(name);
+ b.addActionListener(this);
+ p.add(b);
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ JFrame frame = new JFrame(name);
+ frame.getContentPane().setLayout(new BorderLayout());
+ frame.getContentPane().add(inner, BorderLayout.CENTER);
+ frame.getContentPane().add(mkDisposerButton(frame), BorderLayout.SOUTH);
+ frame.pack();
+ frame.show();
+ }
+ }
+
+ private JPanel mkButtonBar()
+ {
+ JPanel panel = new JPanel ();
+ panel.setLayout(new FlowLayout());
+
+ new PopUpAction("Buttons",
+ mkPanel(new JComponent[]
+ {mkBigButton("mango"),
+ mkBigButton("guava"),
+ mkBigButton("lemon")}),
+ panel);
+
+ new PopUpAction("Toggles",
+ mkToggle("cool and refreshing"),
+ panel);
+
+ new PopUpAction("Checkbox",
+ mkCheckbox("ice cold"),
+ panel);
+
+ new PopUpAction("Radio",
+ mkRadio("delicious"),
+ panel);
+
+ new PopUpAction("Slider",
+ mkSliders(),
+ panel);
+
+ new PopUpAction("List",
+ mkListPanel(new String[] { "hello",
+ "this",
+ "is",
+ "a",
+ "list"}),
+ panel);
+
+ new PopUpAction("Scrollbar",
+ mkScrollBar(),
+ panel);
+
+ new PopUpAction("Viewport",
+ mkViewportBox(mkBigButton("View Me!")),
+ panel);
+
+ new PopUpAction("ScrollPane",
+ mkScrollPane(mkBigButton("Scroll Me!")),
+ panel);
+
+ new PopUpAction("TabPane",
+ mkTabs(new String[] {"happy",
+ "sad",
+ "indifferent"}),
+ panel);
+
+ JButton exitDisposer = mkDisposerButton(frame);
+ panel.add(exitDisposer);
+
+ return panel;
+ }
+
+}