aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/examples
diff options
context:
space:
mode:
authorTom Tromey <tromey@gcc.gnu.org>2005-07-16 00:30:23 +0000
committerTom Tromey <tromey@gcc.gnu.org>2005-07-16 00:30:23 +0000
commitf911ba985aa7fe0096c386c5be385ac5825ea527 (patch)
treea0b991cf5866ae1d616639b906ac001811d74508 /libjava/classpath/examples
parent6f4434b39b261de5317dc81ddfdd94d2e1d62b11 (diff)
downloadgcc-f911ba985aa7fe0096c386c5be385ac5825ea527.zip
gcc-f911ba985aa7fe0096c386c5be385ac5825ea527.tar.gz
gcc-f911ba985aa7fe0096c386c5be385ac5825ea527.tar.bz2
Initial revision
From-SVN: r102074
Diffstat (limited to 'libjava/classpath/examples')
-rw-r--r--libjava/classpath/examples/.cvsignore3
-rw-r--r--libjava/classpath/examples/Makefile.am90
-rw-r--r--libjava/classpath/examples/README48
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/NamingService/Demo.java199
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/Demo.java89
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/comServer.java118
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/DirectTest.java344
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/RequestTest.java260
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterImplBase.java206
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterStub.java426
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comServant.java236
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester.java111
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/node.java55
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHelper.java160
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHolder.java100
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException.java70
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserExceptionHelper.java116
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThis.java61
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHelper.java102
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHolder.java37
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThis.java66
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHelper.java115
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHolder.java60
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/awt/Demo.java867
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/html/Demo.java131
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/big-fullscreen.pngbin0 -> 3768 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/big-home.pngbin0 -> 4135 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/big-warning.pngbin0 -> 2250 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-copy.pngbin0 -> 285 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-cut.pngbin0 -> 328 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-back.pngbin0 -> 523 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-down.pngbin0 -> 536 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-forward.pngbin0 -> 522 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-mic.pngbin0 -> 590 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-new.pngbin0 -> 349 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-open.pngbin0 -> 448 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-paste.pngbin0 -> 563 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-quit.pngbin0 -> 507 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-save-as.pngbin0 -> 751 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-save.pngbin0 -> 539 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/icons/stock-spell-check.pngbin0 -> 374 bytes
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/swing/Demo.java1074
-rw-r--r--libjava/classpath/examples/gnu/classpath/examples/swing/GNULookAndFeel.java85
43 files changed, 5229 insertions, 0 deletions
diff --git a/libjava/classpath/examples/.cvsignore b/libjava/classpath/examples/.cvsignore
new file mode 100644
index 0000000..cbe0850
--- /dev/null
+++ b/libjava/classpath/examples/.cvsignore
@@ -0,0 +1,3 @@
+Makefile
+Makefile.in
+examples.zip
diff --git a/libjava/classpath/examples/Makefile.am b/libjava/classpath/examples/Makefile.am
new file mode 100644
index 0000000..74abc11
--- /dev/null
+++ b/libjava/classpath/examples/Makefile.am
@@ -0,0 +1,90 @@
+## Input file for automake to generate the Makefile.in used by configure
+
+# Setup the compiler to use the GNU Classpath library we just build
+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
+if FOUND_GCJX
+JCOMPILER = $(GCJX) -bootclasspath '' -sourcepath '' -classpath $(top_builddir)/lib:.
+else
+if FOUND_ECJ
+JCOMPILER = $(ECJ) -bootclasspath '$(top_builddir)/lib' -classpath .
+else
+error dunno how to setup the JCOMPILER and compile
+endif
+endif
+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/libjava/classpath/examples/README b/libjava/classpath/examples/README
new file mode 100644
index 0000000..d850c2c
--- /dev/null
+++ b/libjava/classpath/examples/README
@@ -0,0 +1,48 @@
+This directory contains example programs that 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 are distributed in the hope that they 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, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/NamingService/Demo.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/NamingService/Demo.java
new file mode 100644
index 0000000..b4a3772
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/NamingService/Demo.java
@@ -0,0 +1,199 @@
+/* Demo.java -- Shows how to use Classpath transient naming service.
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.NamingService;
+
+import gnu.CORBA.IOR;
+import gnu.CORBA.NamingService.NamingServiceTransient;
+
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Object;
+import org.omg.CosNaming.Binding;
+import org.omg.CosNaming.BindingHolder;
+import org.omg.CosNaming.BindingIterator;
+import org.omg.CosNaming.BindingIteratorHolder;
+import org.omg.CosNaming.BindingListHolder;
+import org.omg.CosNaming.NameComponent;
+import org.omg.CosNaming.NamingContext;
+import org.omg.CosNaming.NamingContextExt;
+import org.omg.CosNaming.NamingContextExtHelper;
+import org.omg.CosNaming.NamingContextHelper;
+
+/**
+ * A simple test of the naming service.
+ *
+ * The main class of the GNU Classpath transient naming service is
+ * {@link gnu.CORBA.NamingService}. This class must be started
+ * before starting this example.
+ *
+ * This example should interoperate as with GNU Classpath naming
+ * service, as with Sun Microsystems transient and persistent
+ * naming services, included in releases 1.3 and 1.4 (tnameserv and
+ * orbd). To work with this example, the naming service must
+ * be started on the local host, at the port 900.
+ *
+ * The persistent naming service is currently under development.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class Demo
+{
+ public static void main(final String[] args)
+ {
+ // We create the following naming graph:
+ // <ROOT CONTEXT>
+ // |
+ // +--- <c.d context>
+ // | |
+ // | +--- obj
+ // |
+ // +--- xobj
+ //
+ // Where both obj and xobj are CORBA objects, representing the
+ // default naming service.
+ //
+ System.out.println("Starting the GNU Classpath " +
+ "built-in transient naming service"
+ );
+
+ new Thread()
+ {
+ public void run()
+ {
+ NamingServiceTransient.main(args);
+ }
+ }.start();
+
+ System.out.println("Waiting for three seconds for naming service to start:");
+ try
+ {
+ Thread.sleep(3000);
+ }
+ catch (InterruptedException ex)
+ {
+ }
+
+ try
+ {
+ ORB orb = ORB.init(args, null);
+
+ Object no = orb.resolve_initial_references("NameService");
+
+ System.out.println("Naming service IOR:" + orb.object_to_string(no));
+
+ System.out.println(IOR.parse(orb.object_to_string(no)));
+
+ NamingContextExt namer = NamingContextExtHelper.narrow(no);
+
+ System.out.println("Naming service: " + namer.getClass().getName());
+
+ NamingContext second = namer.new_context();
+
+ namer.rebind_context(namer.to_name("c.d"), second);
+ namer.rebind(namer.to_name("xobj"), no);
+
+ second.rebind(namer.to_name("obj"), no);
+
+ NamingContext nsec =
+ NamingContextHelper.narrow(namer.resolve_str("c.d"));
+
+ System.out.println(namer.resolve(namer.to_name("c.d/obj")));
+
+ // In all cases, this must be the same object (the naming
+ // service itself).
+ System.out.println(nsec.resolve(new NameComponent[]
+ {
+ new NameComponent("obj", "")
+ }
+ )
+ );
+ System.out.println(namer.resolve_str("xobj"));
+
+ // In all cases, this must be the same object (the naming
+ // service itself).
+ System.out.println(namer.resolve(new NameComponent[]
+ {
+ new NameComponent("c", "d"),
+ new NameComponent("obj", "")
+ }
+ )
+ );
+
+ System.out.println(namer.resolve_str("c.d/obj"));
+
+ System.out.println("Test binding list iterator:");
+
+ BindingListHolder lh = new BindingListHolder();
+ BindingIteratorHolder lih = new BindingIteratorHolder();
+
+ namer.list(0, lh, lih);
+
+ BindingIterator iter = lih.value;
+ BindingHolder binding = new BindingHolder();
+
+ while (iter.next_one(binding))
+ {
+ Binding b = binding.value;
+ System.out.println("NAME: " + namer.to_string(b.binding_name) +
+ " TYPE " + b.binding_type.value()
+ );
+ }
+
+ System.out.println("Testing binding list:");
+
+ iter.destroy();
+
+ namer.list(Integer.MAX_VALUE, lh, lih);
+
+ for (int i = 0; i < lh.value.length; i++)
+ {
+ Binding b = lh.value [ i ];
+ System.out.println("NAME: " + namer.to_string(b.binding_name) +
+ " TYPE " + b.binding_type.value()
+ );
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.exit(1);
+ }
+
+ System.exit(0);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/Demo.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/Demo.java
new file mode 100644
index 0000000..85f233a
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/Demo.java
@@ -0,0 +1,89 @@
+/* Demo.java -- Demonstrates simple CORBA client-server communications.
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication;
+
+import gnu.classpath.examples.CORBA.SimpleCommunication.communication.DirectTest;
+import gnu.classpath.examples.CORBA.SimpleCommunication.communication.RequestTest;
+
+
+/**
+ * This sample illustrates the CORBA communication between server
+ * and client. In this simple example both server and client are
+ * started on the same virtual machine. For the real interoperability
+ * tests, however, the server is started on the platform (library+jvm) of
+ * one vendor, and the client on the platform of another vendor.
+ *
+ * The interoperability is currently tested with Sun Microystems
+ * jre 1.4.
+ *
+ * This example required the current folder to be writable to pass
+ * the IOR references via shared file.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class Demo
+{
+ public static void main(final String[] args)
+ {
+ // Start the server.
+ new Thread()
+ {
+ public void run()
+ {
+ comServer.start_server(args);
+ }
+ }.start();
+
+ System.out.println("Waiting for three seconds for the server to start...");
+
+ // Pause some time for the server to start.
+ try {
+ Thread.sleep(3000);
+ }
+ catch (InterruptedException ex) {
+ }
+
+ // Test the stream oriented communication.
+ DirectTest.main(args);
+ // Test the request oriented communication.
+ RequestTest.main(args);
+
+ System.exit(0);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/comServer.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/comServer.java
new file mode 100644
index 0000000..d4e0c56
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/comServer.java
@@ -0,0 +1,118 @@
+/* comServer.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication;
+
+import gnu.classpath.examples.CORBA.SimpleCommunication.communication.comServant;
+
+import org.omg.CORBA.ORB;
+
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+
+/**
+ * This is the server class that handles the client requests,
+ * delegating the functionality to the {@link comServant}.
+ *
+ * When starting, the server writes the IOR.txt file into the current
+ * folder. With the information, stored in this file, the server
+ * should be reachable over Internet, unless blocked by security tools.
+ *
+ * This code is tested for interoperability with Sun Microsystems
+ * java implementation 1.4.2 (08.b03). Server, client of both can
+ * be started either on Sun's or on Classpath CORBA implementation,
+ * in any combinations.
+ *
+ * BE SURE TO START THIS SERVER BEFORE STARTING THE CLIENT.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class comServer
+{
+
+ public static void main(String[] args)
+ {
+ start_server(args);
+ }
+
+ public static ORB start_server(String[] args)
+ {
+ try
+ {
+ // Create and initialize the ORB.
+ final ORB orb = org.omg.CORBA.ORB.init(args, null);
+
+ // Create the servant and register it with the ORB.
+ comServant tester = new comServant();
+ orb.connect(tester);
+
+ // Storing the IOR reference.
+ String ior = orb.object_to_string(tester);
+ System.out.println("IOR: " + ior);
+
+ gnu.CORBA.IOR ii = gnu.CORBA.IOR.parse(ior);
+ System.out.println(ii);
+
+ // The file IOR.txt in the current folder will be used
+ // to find the object by clients.
+ FileOutputStream f = new FileOutputStream("IOR.txt");
+ PrintStream p = new PrintStream(f);
+ p.print(ior);
+ p.close();
+
+ System.out.println("The test server ready and waiting ...");
+
+ new Thread()
+ {
+ public void run()
+ {
+ // Start the thread, serving the invocations from clients.
+ orb.run();
+ }
+ }.start();
+
+ return orb;
+ }
+ catch (Exception e)
+ {
+ System.err.println("ERROR: " + e);
+ e.printStackTrace(System.out);
+ return null;
+ }
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/DirectTest.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/DirectTest.java
new file mode 100644
index 0000000..5cf372b
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/DirectTest.java
@@ -0,0 +1,344 @@
+/* DirectTest.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.ByteHolder;
+import org.omg.CORBA.DoubleHolder;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.ShortHolder;
+import org.omg.CORBA.StringHolder;
+import org.omg.CORBA.UserException;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+/**
+ * This code uses CORBA to call various methods of the remote object,
+ * passing data structures in both directions. It finds the server by
+ * reading the IOR.txt file that must be present in the folder,
+ * where the program has been started.
+ *
+ * The IOR.txt file is written by the server
+ * {@link gnu.classpath.examples.CORBA.SimpleCommunication.comServer}.
+ * The server should be reachable over Internet, unless blocked by
+ * security tools.
+ *
+ * This code is tested for interoperability with Sun Microsystems
+ * java implementation 1.4.2 (08.b03). Server, client of both can
+ * be started either on Sun's or on Classpath CORBA implementation,
+ * in any combinations.
+ *
+ * BE SURE TO START THE SERVER BEFORE STARTING THE CLIENT.
+ *
+ * This version uses direct casting. This is the most convenient
+ * method, but it is normally used together with the IDL compiler.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class DirectTest
+{
+ /*
+ * The IOR.txt file, used to find the server and the object on the server. is written when starting the accompanying
+ */
+ public static final String IOR_FILE = "IOR.txt";
+
+ /**
+ * The invocation target.
+ */
+ comTester object;
+
+ /**
+ * Get the object reference.
+ */
+ public static void main(String[] args)
+ {
+ try
+ {
+ ORB orb = org.omg.CORBA.ORB.init(args, null);
+
+ File f = new File(IOR_FILE);
+ char[] c = new char[ (int) f.length() ];
+ FileReader fr = new FileReader(f);
+ fr.read(c);
+ fr.close();
+
+ String ior = new String(c);
+ DirectTest we = new DirectTest();
+ we.object = (comTester) orb.string_to_object(ior);
+ we.Demo();
+ orb.shutdown(false);
+ }
+ catch (IOException ex)
+ {
+ System.out.println("Cannot find or read the IOR file " +
+ "in the current folder"
+ );
+ ex.printStackTrace();
+ }
+ }
+
+ /** Run all demos. */
+ public void Demo()
+ {
+ testHello();
+ testField();
+ testParameters();
+ testStringArray();
+ testStructure();
+ testWideNarrowStrings();
+ testTree();
+ testSystemException();
+ testUserException();
+ }
+
+ /**
+ * Test the field getter/setter.
+ */
+ public void testField()
+ {
+ System.out.println("***** Test the remote field getter/setter.");
+ System.out.println("The field value is now " + object.theField());
+ System.out.println("Setting it to 555");
+ object.theField(555);
+ System.out.println("The field value is now " + object.theField());
+ }
+
+ /** The simple invocation of the parameterless remote method. */
+ public void testHello()
+ {
+ System.out.println("***** Say hello (see the server console).");
+ object.sayHello();
+ }
+
+ /**
+ * Test passing multiple parameters in both directions.
+ */
+ public void testParameters()
+ {
+ System.out.println("***** Pass multiple parameters.");
+
+ // Holder classes are required to simulate passing
+ // "by reference" (modification is returned back to the server).
+ ByteHolder a_byte = new ByteHolder((byte) 0);
+ ShortHolder a_short = new ShortHolder((short) 3);
+ StringHolder a_string = new StringHolder("[string 4]");
+
+ // This is an 'out' parameter; the value must not be passed to servant.
+ DoubleHolder a_double = new DoubleHolder(56.789);
+
+ int returned = object.passSimple(a_byte, 2, a_short, a_string, a_double);
+
+ System.out.println(" Returned value " + returned);
+ System.out.println(" Returned parameters: ");
+ System.out.println(" octet " + a_byte.value);
+ System.out.println(" short " + a_short.value);
+ System.out.println(" string '" + a_string.value+"'");
+ System.out.println(" double " + a_double.value);
+ }
+
+ /**
+ * Test passing the string array, flexible size.
+ */
+ public void testStringArray()
+ {
+ System.out.println("***** Pass string array.");
+
+ String[] x = new String[] { "one", "two" };
+
+ // The array is passed as CORBA sequence, variable size is supported.
+ String[] y = object.passStrings(x);
+
+ for (int i = 0; i < y.length; i++)
+ {
+ System.out.println(" Passed " + x [ i ] + ", returned: " + y [ i ]);
+ }
+ }
+
+ /**
+ * Test passing the structures.
+ */
+ public void testStructure()
+ {
+ System.out.println("***** Pass structure");
+
+ passThis arg = new passThis();
+ arg.a = "A";
+ arg.b = "B";
+
+ returnThis r = object.passStructure(arg);
+
+ System.out.println(" Fields of the returned structure:");
+
+ System.out.println(" c: " + r.c);
+ System.out.println(" n: " + r.n);
+
+ // The field r.arra is declared as the fixed size CORBA array.
+ System.out.println(" r[0]: " + r.arra [ 0 ]);
+ System.out.println(" r[1]: " + r.arra [ 1 ]);
+ System.out.println(" r[3]: " + r.arra [ 2 ]);
+ }
+
+ /**
+ * Test catching the system exception, thrown on the remote side.
+ */
+ public void testSystemException()
+ {
+ System.out.println("**** Test system exception:");
+ try
+ {
+ // Negative parameter = system exception.
+ object.throwException(-55);
+ }
+ catch (BAD_OPERATION ex)
+ {
+ System.out.println(" The expected BAD_OPERATION, minor code " +
+ ex.minor + ", has been thrown on remote side."
+ );
+ }
+ catch (UserException uex)
+ {
+ throw new InternalError();
+ }
+ }
+
+ /**
+ * Test passing the tree structure. Any shape of the tree is
+ * supported without rewriting the code.
+ */
+ public void testTree()
+ {
+ // Manually create the tree of nodes:
+ // Root
+ // +-- a
+ // |
+ // +-- b
+ // +-- ba
+ // | |
+ // | +-- bac
+ // |
+ // +-- bb
+ System.out.println("***** Pass and return the tree.");
+
+ node n = nod("Root");
+
+ n.children = new node[] { nod("a"), nod("b") };
+ n.children [ 1 ].children = new node[] { nod("ba"), nod("bb") };
+ n.children [ 1 ].children [ 0 ].children = new node[] { nod("bac") };
+
+ nodeHolder nh = new nodeHolder(n);
+
+ // The server should add '++' to each node name.
+ object.passTree(nh);
+
+ // Convert the returned tree to some strig representation.
+ StringBuffer img = new StringBuffer();
+ getImage(img, nh.value);
+
+ System.out.println("Returned tree: " + img.toString());
+ }
+
+ /**
+ * Test catching the user exception, thrown on the remote side.
+ */
+ public void testUserException()
+ {
+ System.out.println("**** Test user exception:");
+ try
+ {
+ // The user exception contains one user-defined field that will
+ // be initialised to the passed parameter.
+ object.throwException(123);
+ throw new InternalError();
+ }
+ catch (ourUserException uex)
+ {
+ System.out.println(" The user exception with field " + uex.ourField +
+ ", has been thrown on remote side."
+ );
+ }
+ }
+
+ /**
+ * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
+ * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
+ * encodings.
+ */
+ public void testWideNarrowStrings()
+ {
+ System.out.println("**** Test 8 bit and 16 bit char strings");
+
+ String r = object.passCharacters("wide string", "narrow string");
+ System.out.println(" returned: '" + r + "'");
+ }
+
+ /**
+ * Get the string representation of the passed tree.
+ * @param b the string buffer to accumulate the representation.
+ * @param n the tree (root node).
+ */
+ private void getImage(StringBuffer b, node n)
+ {
+ b.append(n.name);
+ b.append(": (");
+
+ for (int i = 0; i < n.children.length; i++)
+ {
+ getImage(b, n.children [ i ]);
+ b.append(' ');
+ }
+ b.append(") ");
+ }
+
+ /**
+ * Create a node with the given header.
+ *
+ * @param hdr the node header.
+ * @return the created node.
+ */
+ private node nod(String hdr)
+ {
+ node n = new node();
+ n.children = new node[ 0 ];
+ n.name = hdr;
+
+ return n;
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/RequestTest.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/RequestTest.java
new file mode 100644
index 0000000..977fb42
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/RequestTest.java
@@ -0,0 +1,260 @@
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.ByteHolder;
+import org.omg.CORBA.DoubleHolder;
+import org.omg.CORBA.ExceptionList;
+import org.omg.CORBA.NVList;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.Request;
+import org.omg.CORBA.ShortHolder;
+import org.omg.CORBA.StringHolder;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.UnknownUserException;
+
+/**
+ * This code uses CORBA to call various methods of the remote object,
+ * passing data structures in both directions. It finds the server by
+ * reading the IOR.txt file that must be present in the folder,
+ * where the program has been started.
+ *
+ * The IOR.txt file is written by the server
+ * {@link gnu.classpath.examples.CORBA.SimpleCommunication.comServer}.
+ * The server should be reachable over Internet, unless blocked by
+ * security tools.
+ *
+ * This code is tested for interoperability with Sun Microsystems
+ * java implementation 1.4.2 (08.b03). Server, client of both can
+ * be started either on Sun's or on Classpath CORBA implementation,
+ * in any combinations.
+ *
+ * BE SURE TO START THE SERVER BEFORE STARTING THE CLIENT.
+ *
+ * Test invocations using org.omg.CORBA.Request. The methods are
+ * called by "name", like in java.lang.reflect.
+ * No need to have the local pre-compiled stub classes.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class RequestTest
+{
+ /*
+ * The IOR.txt file, used to find the server and the object on the server. is written when starting the accompanying
+ */
+ public static final String IOR_FILE = "IOR.txt";
+
+ /**
+ * The Object Request Brocker, used for various CORBA operations.
+ */
+ ORB orb;
+
+ /**
+ * Our remote object - the invocation target.
+ */
+ org.omg.CORBA.Object object;
+
+ /**
+ * Prepare for work. Read the file IOR.txt in the current folder
+ * and find the server using its information.
+ */
+ public static void main(String[] args)
+ {
+ RequestTest we = new RequestTest();
+
+ we.orb = org.omg.CORBA.ORB.init(new String[ 0 ], null);
+
+ char[] c = null;
+ try
+ {
+ File f = new File(IOR_FILE);
+ c = new char[ (int) f.length() ];
+
+ FileReader fr = new FileReader(f);
+ fr.read(c);
+ fr.close();
+ }
+ catch (IOException ex)
+ {
+ System.out.println("Unable to write the IOR.txt into the current folder");
+ ex.printStackTrace();
+ }
+
+ String ior = new String(c);
+
+ we.object = we.orb.string_to_object(ior);
+ we.Demo();
+ we.orb.shutdown(false);
+ }
+
+ /** Run all demos. */
+ public void Demo()
+ {
+ testHello();
+ try
+ {
+ testParameters();
+ }
+ catch (Exception ex)
+ {
+ // Not expected.
+ throw new InternalError();
+ }
+ testSystemException();
+ testUserException();
+ testWideNarrowStrings();
+ }
+
+ /**
+ * Send the hello message, one way.
+ */
+ public void testHello()
+ {
+ System.out.println("***** Test 'HELLO WORLD' (see the server console).");
+
+ Request hello =
+ object._create_request(null, "sayHello", orb.create_list(0), null);
+
+ // No response expected.
+ hello.send_oneway();
+ }
+
+ /**
+ * Test passing various parameters in both directions.
+ */
+ public void testParameters()
+ throws Exception
+ {
+ System.out.println("***** Test passing multiple parameters:");
+
+ Request r =
+ object._create_request(null, "passSimple", orb.create_list(0), null);
+
+ ByteHolder a_byte = new ByteHolder((byte) 0);
+ ShortHolder a_short = new ShortHolder((short) 3);
+ StringHolder a_string = new StringHolder("[string 4]");
+
+ // This is an 'out' parameter; the value must not be passed to servant.
+ DoubleHolder a_double = new DoubleHolder(56.789);
+
+ r.add_inout_arg().insert_octet((byte) 0);
+ r.add_in_arg().insert_long(2);
+ r.add_inout_arg().insert_short((short) 3);
+ r.add_inout_arg().insert_string("[string 4]");
+ r.add_out_arg().type(orb.get_primitive_tc(TCKind.tk_double));
+
+ NVList para = r.arguments();
+
+ System.out.println(" --- Parameters before invocation: ");
+
+ System.out.println(" octet " + para.item(0).value().extract_octet());
+ System.out.println(" long (in parameter) " +
+ para.item(1).value().extract_long()
+ );
+ System.out.println(" short " + para.item(2).value().extract_short());
+ System.out.println(" string " + para.item(3).value().extract_string());
+
+ // For the last parameter, the value is not set.
+ r.set_return_type(orb.get_primitive_tc(TCKind.tk_long));
+
+ r.invoke();
+
+ para = r.arguments();
+
+ System.out.println(" --- Parameters after invocation:");
+
+ System.out.println(" octet " + para.item(0).value().extract_octet());
+ System.out.println(" long (in parameter, must not be changed) " +
+ para.item(1).value().extract_long()
+ );
+ System.out.println(" short " + para.item(2).value().extract_short());
+ System.out.println(" string " + para.item(3).value().extract_string());
+ System.out.println(" double " + para.item(4).value().extract_double());
+
+ System.out.println(" Returned value " + r.result().value().extract_long());
+ }
+
+ /**
+ * Test catching the system exception, thrown on the remote side.
+ */
+ public void testSystemException()
+ {
+ System.out.println("**** Test system exception:");
+ try
+ {
+ ExceptionList exList = orb.create_exception_list();
+ exList.add(ourUserExceptionHelper.type());
+
+ Request rq =
+ object._create_request(null, "throwException", orb.create_list(1),
+ null, exList, null
+ );
+
+ rq.add_in_arg().insert_long(-55);
+
+ rq.invoke();
+
+ throw new InternalError();
+ }
+ catch (BAD_OPERATION ex)
+ {
+ System.out.println(" The expected BAD_OPERATION, minor code " +
+ ex.minor + ", has been thrown on remote side."
+ );
+ }
+ }
+
+ /**
+ * Test catching the user exception, thrown on the remote side.
+ */
+ public void testUserException()
+ {
+ System.out.println("**** Test user exception:");
+
+ ExceptionList exList = orb.create_exception_list();
+ exList.add(ourUserExceptionHelper.type());
+
+ Request rq =
+ object._create_request(null, "throwException", orb.create_list(1), null,
+ exList, null
+ );
+
+ rq.add_in_arg().insert_long(123);
+ rq.invoke();
+
+ UnknownUserException uku = (UnknownUserException) rq.env().exception();
+ ourUserException our_exception = ourUserExceptionHelper.extract(uku.except);
+
+ System.out.println(" Our user exception, field " + our_exception.ourField +
+ ", has been thrown on remote side."
+ );
+ }
+
+ /**
+ * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
+ * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
+ * encodings.
+ */
+ public void testWideNarrowStrings()
+ throws BAD_OPERATION
+ {
+ System.out.println("**** Test 8 bit and 16 bit char strings");
+
+ Request rq =
+ object._create_request(null, "passCharacters", orb.create_list(0), null);
+
+ rq.add_in_arg().insert_wstring("wide string");
+ rq.add_in_arg().insert_string("narrow string");
+
+ rq.set_return_type(orb.get_primitive_tc(TCKind.tk_wstring));
+
+ rq.invoke();
+
+ System.out.println(" Returned ' " + rq.result().value().extract_wstring());
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterImplBase.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterImplBase.java
new file mode 100644
index 0000000..4c8f5b9
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterImplBase.java
@@ -0,0 +1,206 @@
+/* _comTesterImplBase.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.ByteHolder;
+import org.omg.CORBA.CompletionStatus;
+import org.omg.CORBA.DoubleHolder;
+import org.omg.CORBA.ShortHolder;
+import org.omg.CORBA.StringHolder;
+import org.omg.CORBA.StringSeqHelper;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.InvokeHandler;
+import org.omg.CORBA.portable.ObjectImpl;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.ResponseHandler;
+
+/**
+ * The base for the class that is actually implementing the functionality
+ * of the object on the server side ({@link comServant} of our case).
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public abstract class _comTesterImplBase
+ extends ObjectImpl
+ implements comTester, InvokeHandler
+{
+/**
+ * When the server receives the request message from client, it
+ * calls this method.
+ *
+ * @param a_method the method name.
+ * @param in the CDR stream, from where the implementing code must
+ * read the method parameters.
+ * @param rh the response handler, used to get the stream where
+ * the returned values must be written.
+ *
+ * @return the stream, obtained from the response handler.
+ */
+ public OutputStream _invoke(String a_method, InputStream in,
+ ResponseHandler rh
+ )
+ {
+ OutputStream out;
+
+ /* Get the field value. */
+ if (a_method.equals("_get_theField"))
+ {
+ int result = (int) 0;
+ result = theField();
+ out = rh.createReply();
+ out.write_long(result);
+ }
+ else
+ /* Set the field value. */
+ if (a_method.equals("_set_theField"))
+ {
+ int newTheField = in.read_long();
+ theField(newTheField);
+ out = rh.createReply();
+ }
+ else
+ /* Logs calls to the file. */
+ if (a_method.equals("sayHello"))
+ {
+ sayHello();
+ out = rh.createReply();
+ }
+ else
+ /* Passes various parameters in both directions. */
+ if (a_method.equals("passSimple"))
+ {
+ ByteHolder an_octet = new ByteHolder();
+ an_octet.value = in.read_octet();
+
+ int a_long = in.read_long();
+ ShortHolder a_short = new ShortHolder();
+ a_short.value = in.read_short();
+
+ StringHolder a_string = new StringHolder();
+ a_string.value = in.read_string();
+
+ DoubleHolder a_double = new DoubleHolder();
+ int result = passSimple(an_octet, a_long, a_short, a_string, a_double);
+ out = rh.createReply();
+ out.write_long(result);
+ out.write_octet(an_octet.value);
+ out.write_short(a_short.value);
+ out.write_string(a_string.value);
+ out.write_double(a_double.value);
+ }
+ else
+ /* Passes the 'wide' (usually Unicode) string and the ordinary string. */
+ if (a_method.equals("passCharacters"))
+ {
+ String wide = in.read_wstring();
+ String narrow = in.read_string();
+ String result = null;
+ result = passCharacters(wide, narrow);
+ out = rh.createReply();
+ out.write_wstring(result);
+ }
+ else
+ /*
+ Throws either 'ourUserException' with the 'ourField' field
+ initialised to the passed positive value
+ or system exception (if the parameter is zero or negative).
+ */
+ if (a_method.equals("throwException"))
+ {
+ try
+ {
+ int parameter = in.read_long();
+ throwException(parameter);
+ out = rh.createReply();
+ }
+ catch (ourUserException exception)
+ {
+ out = rh.createExceptionReply();
+ ourUserExceptionHelper.write(out, exception);
+ }
+ }
+ else
+ /* Passes and returns the structures. */
+ if (a_method.equals("passStructure"))
+ {
+ passThis in_structure = passThisHelper.read(in);
+ returnThis result = null;
+ result = passStructure(in_structure);
+ out = rh.createReply();
+ returnThisHelper.write(out, result);
+ }
+ else
+ /* Passes and returns the string sequence. */
+ if (a_method.equals("passStrings"))
+ {
+ String[] arg = StringSeqHelper.read(in);
+ String[] result = null;
+ result = passStrings(arg);
+ out = rh.createReply();
+ StringSeqHelper.write(out, result);
+ }
+ else
+ /** Pass and return the tree structure */
+ if (a_method.equals("passTree"))
+ {
+ nodeHolder tree = new nodeHolder();
+ tree.value = nodeHelper.read(in);
+ passTree(tree);
+ out = rh.createReply();
+ nodeHelper.write(out, tree.value);
+ }
+
+ else
+ throw new BAD_OPERATION("No method: " + a_method, 0,
+ CompletionStatus.COMPLETED_MAYBE
+ );
+
+ return out;
+ }
+
+ /**
+ * Return an array of this object repository ids.
+ */
+ public String[] _ids()
+ {
+ // They are the same as for the stub.
+ return _comTesterStub._ids;
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterStub.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterStub.java
new file mode 100644
index 0000000..b71cd8e
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/_comTesterStub.java
@@ -0,0 +1,426 @@
+/* _comTesterStub.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.ByteHolder;
+import org.omg.CORBA.DoubleHolder;
+import org.omg.CORBA.MARSHAL;
+import org.omg.CORBA.ShortHolder;
+import org.omg.CORBA.StringHolder;
+import org.omg.CORBA.StringSeqHelper;
+import org.omg.CORBA.portable.ApplicationException;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.ObjectImpl;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.RemarshalException;
+
+/**
+ * The stub (proxy) class, representing the remote object on the client
+ * side. It has all the same methods as the actual implementation
+ * on the server side. These methods contain the code for remote
+ * invocation.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class _comTesterStub
+ extends ObjectImpl
+ implements comTester
+{
+ /**
+ * A string array of comTester repository ids.
+ */
+ public static String[] _ids =
+ {
+ "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester:1.0"
+ };
+
+ /**
+ * Return an array of comTester repository ids.
+ */
+ public String[] _ids()
+ {
+ return _ids;
+ }
+
+ /**
+ * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
+ * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
+ * encodings.
+ */
+ public String passCharacters(String wide, String narrow)
+ {
+ InputStream in = null;
+ try
+ {
+ // Get the output stream.
+ OutputStream out = _request("passCharacters", true);
+
+ // Write the parameters.
+
+ // The first string is passed as "wide"
+ // (usually 16 bit UTF-16) string.
+ out.write_wstring(wide);
+
+ // The second string is passed as "narrow"
+ // (usually 8 bit ISO8859_1) string.
+ out.write_string(narrow);
+
+ // Do the invocation.
+ in = _invoke(out);
+
+ // Read the method return value.
+ String result = in.read_wstring();
+ return result;
+ }
+ catch (ApplicationException ex)
+ {
+ // The exception has been throws on remote side, but we
+ // do not expect any. Throw the MARSHAL exception.
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ // This exception means that the parameters must be re-written.
+ return passCharacters(wide, narrow);
+ }
+ finally
+ {
+ // Release the resources, associated with the reply stream.
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ * Passes various parameters in both directions. The parameters that
+ * shoud also return the values are wrapped into holders.
+ */
+ public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
+ StringHolder a_string, DoubleHolder a_double
+ )
+ {
+ InputStream in = null;
+ try
+ {
+ // Get the stream where the parameters must be written:
+ OutputStream out = _request("passSimple", true);
+
+ // Write the parameters.
+ out.write_octet(an_octet.value);
+ out.write_long(a_long);
+ out.write_short(a_short.value);
+ out.write_string(a_string.value);
+
+ // Invoke the method.
+ in = _invoke(out);
+
+ // Read the returned values.
+ int result = in.read_long();
+
+ // Read the inout and out parameters.
+ an_octet.value = in.read_octet();
+ a_short.value = in.read_short();
+ a_string.value = in.read_string();
+ a_double.value = in.read_double();
+ return result;
+ }
+ catch (ApplicationException ex)
+ {
+ // Handle excepion on remote side.
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ // Handle instruction to resend the parameters.
+ return passSimple(an_octet, a_long, a_short, a_string, a_double);
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ Passes and returns the string sequence.
+ */
+ public String[] passStrings(String[] arg)
+ {
+ InputStream in = null;
+ try
+ {
+ // Get the stream where the parameters must be written:
+ OutputStream out = _request("passStrings", true);
+
+ // Wrap the string array using the string sequence helper.
+ StringSeqHelper.write(out, arg);
+
+ // Invoke the method.
+ in = _invoke(out);
+
+ // Read the returned result using the string sequence helper.
+ String[] result = StringSeqHelper.read(in);
+ return result;
+ }
+ catch (ApplicationException ex)
+ {
+ // Handle the exception, thrown on remote side.
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ return passStrings(arg);
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ Passes and returns the structures.
+ */
+ public returnThis passStructure(passThis in_structure)
+ {
+ InputStream in = null;
+ try
+ {
+ // Get the stream where the parameters must be written.
+ OutputStream out = _request("passStructure", true);
+
+ // Write the structure, using its helper.
+ passThisHelper.write(out, in_structure);
+
+ // Invoke the method.
+ in = _invoke(out);
+
+ // Read the returned structer, using another helper.
+ returnThis result = returnThisHelper.read(in);
+ return result;
+ }
+ catch (ApplicationException ex)
+ {
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ return passStructure(in_structure);
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ * Pass and return the tree structure
+ */
+ public void passTree(nodeHolder tree)
+ {
+ InputStream in = null;
+ try
+ {
+ // Get the stream where the parameters must be written.
+ OutputStream out = _request("passTree", true);
+
+ // Write the tree (node with its chilred, grandchildren and so on),
+ // using the appropriate helper.
+ nodeHelper.write(out, tree.value);
+
+ // Call the method.
+ in = _invoke(out);
+
+ // Read the returned tree.
+ tree.value = nodeHelper.read(in);
+ }
+ catch (ApplicationException ex)
+ {
+ // Handle eception on remote side.
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ passTree(tree);
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ * One way call of the remote method.
+ */
+ public void sayHello()
+ {
+ InputStream in = null;
+ try
+ {
+ // As we do not expect any response, the second
+ // parameter is 'false'.
+ OutputStream out = _request("sayHello", false);
+ in = _invoke(out);
+ }
+ catch (ApplicationException ex)
+ {
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ sayHello();
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ * Get the field value.
+ */
+ public int theField()
+ {
+ InputStream in = null;
+ try
+ {
+ // The special name of operation instructs just to get
+ // the field value rather than calling the method.
+ OutputStream out = _request("_get_theField", true);
+ in = _invoke(out);
+
+ int result = in.read_long();
+ return result;
+ }
+ catch (ApplicationException ex)
+ {
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ return theField();
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ * Set the field value.
+ */
+ public void theField(int newTheField)
+ {
+ InputStream in = null;
+ try
+ {
+ // The special name of operation instructs just to set
+ // the field value rather than calling the method.
+ OutputStream out = _request("_set_theField", true);
+ out.write_long(newTheField);
+ in = _invoke(out);
+ }
+ catch (ApplicationException ex)
+ {
+ in = ex.getInputStream();
+ throw new MARSHAL(ex.getId());
+ }
+ catch (RemarshalException _rm)
+ {
+ theField(newTheField);
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+
+ /**
+ * The server side exception tests.
+ *
+ * @param parameter the server throws the user exception in the case
+ * of the positive value of this argument, and system
+ * exception otherwise.
+ *
+ * @throws ourUserException
+ */
+ public void throwException(int parameter)
+ throws ourUserException
+ {
+ InputStream in = null;
+ try
+ {
+ // Get stream.
+ OutputStream out = _request("throwException", true);
+
+ // Write parameter.
+ out.write_long(parameter);
+
+ // Call method.
+ in = _invoke(out);
+ }
+ catch (ApplicationException ex)
+ {
+ in = ex.getInputStream();
+
+ // Get the exception id.
+ String id = ex.getId();
+
+ // If this is the user exception we expect to catch, read and throw
+ // it here. The system exception, if thrown, is handled by _invoke.
+ if (id.equals("IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException:1.0")
+ )
+ throw ourUserExceptionHelper.read(in);
+ else
+ throw new MARSHAL(id);
+ }
+ catch (RemarshalException _rm)
+ {
+ throwException(parameter);
+ }
+ finally
+ {
+ _releaseReply(in);
+ }
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comServant.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comServant.java
new file mode 100644
index 0000000..08d1759
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comServant.java
@@ -0,0 +1,236 @@
+/* comServant.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.ByteHolder;
+import org.omg.CORBA.CompletionStatus;
+import org.omg.CORBA.DoubleHolder;
+import org.omg.CORBA.ShortHolder;
+import org.omg.CORBA.StringHolder;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.PrintStream;
+
+/**
+ * This class handles the actual server functionality in this test
+ * application. When the client calls the remote method, this
+ * finally results calling the method of this class.
+ *
+ * The parameters, passed to the server only, are just parameters of the
+ * java methods. The parameters that shuld be returned to client
+ * are wrapped into holder classes.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class comServant
+ extends _comTesterImplBase
+{
+ /**
+ * The field, that can be set and checked by remote client.
+ */
+ private int m_theField = 17;
+
+ /**
+ * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
+ * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
+ * encodings. Returs they generalization as a wide string.
+ */
+ public String passCharacters(String wide, String narrow)
+ {
+ System.out.println("SERVER: **** Wide and narrow string test.");
+ System.out.println("SERVER: Received '" + narrow + "' and '" + wide +
+ "'"
+ );
+
+ return "return '" + narrow + "' and '" + wide + "'";
+ }
+
+ /**
+ * Accept and return parameters, having various types.
+ */
+ public int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
+ StringHolder a_string, DoubleHolder a_double
+ )
+ {
+ System.out.println("SERVER: ***** Test passing multiple parameters");
+ System.out.println("SERVER: Received:");
+ System.out.println("SERVER: octet " + an_octet.value);
+ System.out.println("SERVER: short " + a_short.value);
+ System.out.println("SERVER: string " + a_string.value);
+
+ // Returning incremented values.
+ an_octet.value++;
+ a_short.value++;
+
+ // OUT parameter, return only.
+ a_double.value = 1;
+ a_string.value += " [return]";
+ return 452572;
+ }
+
+ /**
+ * Accept and return the string arrays.
+ */
+ public String[] passStrings(String[] args)
+ {
+ System.out.println("SERVER: ***** Transferring string arrays");
+
+ String[] rt = new String[ args.length ];
+ for (int i = 0; i < args.length; i++)
+ {
+ System.out.println("SERVER: " + args [ i ]);
+
+ // Returning the changed content.
+ rt [ i ] = args [ i ] + ":" + args [ i ];
+ }
+ return rt;
+ }
+
+ /**
+ * Accept and return the structures.
+ */
+ public returnThis passStructure(passThis in_structure)
+ {
+ System.out.println("SERVER: ***** Transferring structures");
+ System.out.println("SERVER: Received " + in_structure.a + ":" +
+ in_structure.b
+ );
+
+ // Create and send back the returned structure.
+ returnThis r = new returnThis();
+ r.c = in_structure.a + in_structure.b;
+ r.n = 555;
+ r.arra = new int[] { 11, 22, 33 };
+ return r;
+ }
+
+ /**
+ * Pass and return the tree structure
+ */
+ public void passTree(nodeHolder tree)
+ {
+ System.out.println("SERVER: ***** Transferring tree");
+
+ StringBuffer b = new StringBuffer();
+
+ // This both creates the tree string representation
+ // and changes the node names.
+ getImage(b, tree.value);
+ System.out.println("SERVER: The tree was: " + b + ", returning changed.");
+ }
+
+ /**
+ * Just prints the hello message.
+ */
+ public void sayHello()
+ {
+ System.out.println("SERVER: ***** Hello, world!");
+ }
+
+ /**
+ * Get the value of our field.
+ */
+ public int theField()
+ {
+ System.out.println("SERVER: ***** Getting the field value, " + m_theField);
+ return m_theField;
+ }
+
+ /**
+ * Set the value of our field.
+ */
+ public void theField(int a_field)
+ {
+ System.out.println("SERVER: ***** Setting the field value to " + a_field);
+ m_theField = a_field;
+ }
+
+ /**
+ * Throw an exception.
+ *
+ * @param parameter specifies which exception will be thrown.
+ *
+ * @throws ourUserException for the non negative parameter.
+ * @throws BAD_OPERATION for the negative parameter.
+ */
+ public void throwException(int parameter)
+ throws ourUserException
+ {
+ System.out.println("SERVER: ***** Testing exceptions");
+ if (parameter > 0)
+ {
+ System.out.println("SERVER: Throwing the user exception, " +
+ "specific field = "+parameter
+ );
+ throw new ourUserException(parameter);
+ }
+ else
+ {
+ System.out.println("SERVER: Throwing " +
+ "the BAD_OPERATION, minor 456, completed"
+ );
+ throw new BAD_OPERATION(456, CompletionStatus.COMPLETED_YES);
+ }
+ }
+
+ /**
+ * Visit all tree nodes, getting the string representation
+ * and adding '++' to the node names.
+ *
+ * @param b the buffer to collect the string representation.
+ * @param n the rott tree node.
+ */
+ private void getImage(StringBuffer b, node n)
+ {
+ b.append(n.name);
+ n.name = n.name + "++";
+ b.append(": (");
+
+ for (int i = 0; i < n.children.length; i++)
+ {
+ getImage(b, n.children [ i ]);
+ b.append(' ');
+ }
+ b.append(") ");
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester.java
new file mode 100644
index 0000000..495807e
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/comTester.java
@@ -0,0 +1,111 @@
+/* comTester.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.ByteHolder;
+import org.omg.CORBA.DoubleHolder;
+import org.omg.CORBA.ShortHolder;
+import org.omg.CORBA.StringHolder;
+
+/**
+ * The interface of our remote object. Some IDL compiles split it
+ * into "comTester" and "comTesterOperations", but we do not see
+ * much sense in doing this here.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public interface comTester
+{
+ /**
+ * Passes wide (UTF-16) string and narrow (ISO8859_1) string.
+ * Both types are mapped into java String.
+ *
+ * @see gnu.CORBA.GIOP.CharSets_OSF for supported and default
+ * encodings.
+ */
+ String passCharacters(String wide, String narrow);
+
+ /**
+ * Passes various parameters in both directions.
+ * The parameters that must return the value are wrapped in holders.
+ */
+ int passSimple(ByteHolder an_octet, int a_long, ShortHolder a_short,
+ StringHolder a_string, DoubleHolder a_double
+ );
+
+ /**
+ * Passes and returns the string sequence (flexible length).
+ */
+ String[] passStrings(String[] arg);
+
+ /**
+ * Passes and returns the structures.
+ */
+ returnThis passStructure(passThis in_structure);
+
+ /**
+ * Pass and return the tree structure
+ *
+ * @param tree the root node of the tree.
+ */
+ void passTree(nodeHolder tree);
+
+ /**
+ * Just prints the "Hello" message.
+ */
+ void sayHello();
+
+ /**
+ * Gets the value of the field in our object.
+ */
+ int theField();
+
+ /**
+ * Sets the value for the field in our object.
+ */
+ void theField(int newTheField);
+
+ /**
+ * Throws either 'ourUserException' with the 'ourField' field
+ * initialised to the passed positive value
+ * or system exception (if the parameter is zero or negative).
+ */
+ void throwException(int parameter)
+ throws ourUserException;
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/node.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/node.java
new file mode 100644
index 0000000..527d02d
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/node.java
@@ -0,0 +1,55 @@
+/* node.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+/**
+ * The support for the tree structure, used in the test of
+ * ability to pass and return the tree structure.
+ *
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class node
+ implements org.omg.CORBA.portable.IDLEntity
+{
+ /** The node name */
+ public String name = null;
+
+ /** The node children. */
+ public node[] children = null;
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHelper.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHelper.java
new file mode 100644
index 0000000..8d4121c
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHelper.java
@@ -0,0 +1,160 @@
+/* nodeHelper.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * This class is used for various helper operations around the
+ * tree {@link} structure.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public abstract class nodeHelper
+{
+ /**
+ * The node repository id, used to identify the structure.
+ */
+ private static String _id =
+ "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/node:1.0";
+
+ /**
+ * Caches the typecode, allowing to compute it only once.
+ */
+ private static TypeCode typeCode;
+
+ /**
+ * This is used to handle the recursive object references in
+ * CORBA - supported way. The tree node definition is recursive,
+ * as the node contains the sequence of the nodes as its field.
+ */
+ private static boolean active;
+
+ /**
+ * Extract the tree node from the unversal CORBA wrapper, Any.
+ */
+ public static node extract(Any a)
+ {
+ return read(a.create_input_stream());
+ }
+
+ /**
+ * Get the node string identifer.
+ */
+ public static String id()
+ {
+ return _id;
+ }
+
+ /**
+ * Insert the node into the universal CORBA wrapper, Any.
+ */
+ public static void insert(Any a, node that)
+ {
+ OutputStream out = a.create_output_stream();
+ a.type(type());
+ write(out, that);
+ a.read_value(out.create_input_stream(), type());
+ }
+
+ /**
+ * Read the node from the common data reprentation (CDR) stream.
+ */
+ public static node read(InputStream istream)
+ {
+ node value = new node();
+ value.name = istream.read_string();
+
+ int _len0 = istream.read_long();
+ value.children = new node[ _len0 ];
+ for (int i = 0; i < value.children.length; ++i)
+ value.children [ i ] = nodeHelper.read(istream);
+ return value;
+ }
+
+ /**
+ * Get the node type code definition.
+ */
+ public static synchronized TypeCode type()
+ {
+ // Compute the type code only once.
+ if (typeCode == null)
+ {
+ synchronized (TypeCode.class)
+ {
+ if (typeCode == null)
+ {
+ // To avoid the infinite recursion loop, the
+ // recursive reference is handled in specific way.
+ if (active)
+ return ORB.init().create_recursive_tc(_id);
+ active = true;
+
+ // List all memebers of the node structure.
+ StructMember[] members = new StructMember[ 2 ];
+ TypeCode memberType;
+ memberType = ORB.init().create_string_tc(0);
+ members [ 0 ] = new StructMember("name", memberType, null);
+ memberType = ORB.init().create_recursive_tc("");
+ members [ 1 ] = new StructMember("children", memberType, null);
+ typeCode =
+ ORB.init().create_struct_tc(nodeHelper.id(), "node", members);
+ active = false;
+ }
+ }
+ }
+ return typeCode;
+ }
+
+ /**
+ * Write the node into the common data reprentation (CDR) stream.
+ */
+ public static void write(OutputStream ostream, node value)
+ {
+ ostream.write_string(value.name);
+ ostream.write_long(value.children.length);
+ for (int i = 0; i < value.children.length; ++i)
+ nodeHelper.write(ostream, value.children [ i ]);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHolder.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHolder.java
new file mode 100644
index 0000000..8e49139
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/nodeHolder.java
@@ -0,0 +1,100 @@
+/* nodeHolder.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.Streamable;
+
+/**
+ * The node holder is a wrapper about the node data structure. It
+ * can be used where the node must be passed both to and from
+ * the method being called. The same structure holds the tree,
+ * as it can be represented as a root node with children.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class nodeHolder
+ implements Streamable
+{
+ /**
+ * Stores the node value.
+ */
+ public node value;
+
+ /**
+ * Creates the node holder with the null initial value.
+ */
+ public nodeHolder()
+ {
+ }
+
+ /**
+ * Creates the node holder with the given initial value.
+ */
+ public nodeHolder(node initialValue)
+ {
+ value = initialValue;
+ }
+
+ /**
+ * Reads the node value from the common data representation (CDR)
+ * stream.
+ */
+ public void _read(InputStream in)
+ {
+ value = nodeHelper.read(in);
+ }
+
+ /**
+ * Writes the node value into common data representation (CDR)
+ * stream.
+ * @return
+ */
+ public TypeCode _type()
+ {
+ return nodeHelper.type();
+ }
+
+ public void _write(OutputStream out)
+ {
+ nodeHelper.write(out, value);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException.java
new file mode 100644
index 0000000..51ea5f2
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException.java
@@ -0,0 +1,70 @@
+/* ourUserException.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.UserException;
+import org.omg.CORBA.portable.IDLEntity;
+
+/**
+ * Our user exception, thrown in the tests of handling the exceptions,
+ * thrown on remote side. The exception contains the user - defined
+ * data field that is transferred from client to the server when the
+ * exception is thrown.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class ourUserException
+ extends UserException
+ implements IDLEntity
+{
+ /**
+ * Our specific field, transferred to client.
+ */
+ public int ourField;
+
+ /**
+ * Create the exception.
+ *
+ * @param _ourField the value of our specific field.
+ */
+ public ourUserException(int _ourField)
+ {
+ ourField = _ourField;
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserExceptionHelper.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserExceptionHelper.java
new file mode 100644
index 0000000..8c499df
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserExceptionHelper.java
@@ -0,0 +1,116 @@
+/* ourUserExceptionHelper.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+
+/**
+ * The class, providing various helper operations with our user
+ * exception.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public abstract class ourUserExceptionHelper
+{
+ /**
+ * The exception repository id. This name is also used to find the
+ * mapping local CORBA class.
+ */
+ private static String _id =
+ "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/ourUserException:1.0";
+
+ /**
+ * Get the exception repository id.
+ */
+ public static String id()
+ {
+ return _id;
+ }
+
+ /**
+ * Extract the exception from the given Any where it might be
+ * wrapped.
+ */
+ public static ourUserException extract(Any a)
+ {
+ return read(a.create_input_stream());
+ }
+
+ /**
+ * Read the exception from the CDR stream.
+ */
+ public static ourUserException read(org.omg.CORBA.portable.InputStream istream)
+ {
+ ourUserException value = new ourUserException(0);
+
+ // The repository ID is not used
+ istream.read_string();
+ value.ourField = istream.read_long();
+ return value;
+ }
+
+ /**
+ * Create the type code of this exception.
+ */
+ public static synchronized TypeCode type()
+ {
+ StructMember[] members = new StructMember[ 1 ];
+ TypeCode member = null;
+ member = ORB.init().get_primitive_tc(TCKind.tk_long);
+ members [ 0 ] = new StructMember("ourField", member, null);
+ return ORB.init().create_struct_tc(ourUserExceptionHelper.id(),
+ "ourUserException", members
+ );
+ }
+
+ /**
+ * Write the exception into the CDR stream.
+ */
+ public static void write(org.omg.CORBA.portable.OutputStream ostream,
+ ourUserException value
+ )
+ {
+ ostream.write_string(id());
+ ostream.write_long(value.ourField);
+ }
+} \ No newline at end of file
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThis.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThis.java
new file mode 100644
index 0000000..2a680b9
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThis.java
@@ -0,0 +1,61 @@
+/* passThis.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+
+/**
+ * The data structure, passed from to the server from client in our tests.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class passThis
+ implements org.omg.CORBA.portable.IDLEntity
+{
+ /**
+ * The first string, stored in this structure (defined as
+ * "narrow string").
+ */
+ public String a;
+
+ /**
+ * The second string, stored in this structure (define as
+ * "wide" (usually Unicode) string.
+ */
+ public String b;
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHelper.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHelper.java
new file mode 100644
index 0000000..6b9f4ce
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHelper.java
@@ -0,0 +1,102 @@
+/* passThisHelper.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * The helper operations for the {@link passThis}.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public abstract class passThisHelper
+{
+ /**
+ * The repository ID of the {@link passThis}.
+ */
+ private static String id =
+ "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThis:1.0";
+
+ /**
+ * Get the repository id.
+ */
+ public static String id()
+ {
+ return id;
+ }
+
+ /**
+ * Read the structure from the CDR stram.
+ */
+ public static passThis read(InputStream istream)
+ {
+ passThis value = new passThis();
+ value.a = istream.read_string();
+ value.b = istream.read_wstring();
+ return value;
+ }
+
+ /**
+ * Get the type code of this structure.
+ */
+ public static synchronized TypeCode type()
+ {
+ StructMember[] members = new StructMember[ 2 ];
+ TypeCode member = null;
+ member = ORB.init().create_string_tc(0);
+ members [ 0 ] = new StructMember("a", member, null);
+ member = ORB.init().create_string_tc(0);
+ members [ 1 ] = new StructMember("b", member, null);
+ return ORB.init().create_struct_tc(passThisHelper.id(), "passThis", members);
+ }
+
+ /**
+ * Write the structure into the CDR stream.
+ */
+ public static void write(OutputStream ostream, passThis value)
+ {
+ ostream.write_string(value.a);
+ ostream.write_wstring(value.b);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHolder.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHolder.java
new file mode 100644
index 0000000..0d93cba
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/passThisHolder.java
@@ -0,0 +1,37 @@
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.Streamable;
+
+public final class passThisHolder
+ implements Streamable
+{
+ public passThis value;
+
+ public passThisHolder()
+ {
+ }
+
+ public passThisHolder(passThis initialValue)
+ {
+ value = initialValue;
+ }
+
+ public void _read(InputStream i)
+ {
+ value = passThisHelper.read(i);
+ }
+
+ public org.omg.CORBA.TypeCode _type()
+ {
+ return passThisHelper.type();
+ }
+
+ public void _write(OutputStream o)
+ {
+ passThisHelper.write(o, value);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThis.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThis.java
new file mode 100644
index 0000000..b7c3923
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThis.java
@@ -0,0 +1,66 @@
+/* returnThis.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.portable.IDLEntity;
+
+/**
+ * This data structure is returned from the server to client in our tests.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public class returnThis
+ implements IDLEntity
+{
+ /**
+ * The string field.
+ */
+ public String c;
+
+ /**
+ * The CORBA array field. This field is handled as the fixed
+ * size CORBA array, but structures can also have the variable
+ * size CORBA sequences.
+ */
+ public int[] arra = new int[3];
+
+ /**
+ * The int (CORBA long) field.
+ */
+ public int n;
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHelper.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHelper.java
new file mode 100644
index 0000000..79838d7
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHelper.java
@@ -0,0 +1,115 @@
+/* returnThisHelper.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.Any;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.StructMember;
+import org.omg.CORBA.TCKind;
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+
+/**
+ * This class defines the helper operations for {@link returnThis}.
+ *
+ * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org)
+ */
+public abstract class returnThisHelper
+{
+ /**
+ * The repository id.
+ */
+ private static String _id =
+ "IDL:gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThis:1.0";
+
+ /**
+ * Return the repository id.
+ */
+ public static String id()
+ {
+ return _id;
+ }
+
+ /**
+ * Read the structure from the CDR stream.
+ */
+ public static returnThis read(InputStream istream)
+ {
+ returnThis value = new returnThis();
+ value.n = istream.read_long();
+ value.c = istream.read_wstring();
+ value.arra = new int[ 3 ];
+
+ // Read the fixed size array.
+ for (int i = 0; i < 3; i++)
+ value.arra [ i ] = istream.read_long();
+ return value;
+ }
+
+ /**
+ * Create the typecode.
+ */
+ public static synchronized TypeCode type()
+ {
+ StructMember[] members = new StructMember[ 3 ];
+ TypeCode member = ORB.init().get_primitive_tc(TCKind.tk_long);
+ members [ 0 ] = new StructMember("n", member, null);
+ member = ORB.init().create_string_tc(0);
+ members [ 1 ] = new StructMember("c", member, null);
+ member = ORB.init().get_primitive_tc(TCKind.tk_long);
+ member = ORB.init().create_array_tc(3, member);
+ members [ 2 ] = new StructMember("arra", member, null);
+ return ORB.init().create_struct_tc(returnThisHelper.id(), "returnThis",
+ members
+ );
+ }
+
+ /**
+ * Write the structure to the CDR stream.
+ */
+ public static void write(OutputStream ostream, returnThis value)
+ {
+ ostream.write_long(value.n);
+ ostream.write_wstring(value.c);
+
+ // Write the fixed size array.
+ for (int i = 0; i < 3; i++)
+ ostream.write_long(value.arra [ i ]);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHolder.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHolder.java
new file mode 100644
index 0000000..294e37a
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/returnThisHolder.java
@@ -0,0 +1,60 @@
+
+
+package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import org.omg.CORBA.TypeCode;
+import org.omg.CORBA.portable.InputStream;
+import org.omg.CORBA.portable.OutputStream;
+import org.omg.CORBA.portable.Streamable;
+
+/**
+ * The holder for the structure, returned from the server.
+ */
+public final class returnThisHolder
+ implements Streamable
+{
+ /**
+ * The enclosed structure.
+ */
+ public returnThis value = null;
+
+ /**
+ * Create the empty holder.
+ */
+ public returnThisHolder()
+ {
+ }
+
+ /**
+ * Crate the holder with the defined initial value.
+ */
+ public returnThisHolder(returnThis initialValue)
+ {
+ value = initialValue;
+ }
+
+ /**
+ * Read the value from the CDR stream.
+ */
+ public void _read(InputStream in)
+ {
+ value = returnThisHelper.read(in);
+ }
+
+ /**
+ * Get the typecode of this structure.
+ */
+ public TypeCode _type()
+ {
+ return returnThisHelper.type();
+ }
+
+ /**
+ * Write the value from the CDR stream.
+ * @param out
+ */
+ public void _write(OutputStream out)
+ {
+ returnThisHelper.write(out, value);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/awt/Demo.java b/libjava/classpath/examples/gnu/classpath/examples/awt/Demo.java
new file mode 100644
index 0000000..dbb6600
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/awt/Demo.java
@@ -0,0 +1,867 @@
+/* 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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);
+
+ Menu helpMenu = new Menu("Help");
+ helpMenu.add(new MenuItem("About"));
+ mb.add(helpMenu);
+ mb.setHelpMenu(helpMenu);
+
+ 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;
+ 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/libjava/classpath/examples/gnu/classpath/examples/html/Demo.java b/libjava/classpath/examples/gnu/classpath/examples/html/Demo.java
new file mode 100644
index 0000000..34dd73b
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/html/Demo.java
@@ -0,0 +1,131 @@
+/* Demo.java --
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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. */
+
+package gnu.classpath.examples.html;
+
+import gnu.javax.swing.text.html.parser.HTML_401F;
+
+import gnu.xml.dom.html2.DomHTMLParser;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.StringReader;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.html2.HTMLDocument;
+
+/**
+ * This example demonstrates how to parse HTML input into
+ * org.w3c.dom.html2 document model.
+ * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
+ */
+public class Demo
+{
+ /**
+ * The sample HTML to parse.
+ */
+ static String input = "<!--2-->a<b iD=1>x</b>y<b><i>c</b>d</i>e";
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ // Create a parser, using our DTD.
+ DomHTMLParser p = new DomHTMLParser(HTML_401F.getInstance());
+ HTMLDocument d = p.parseDocument(new StringReader(input));
+
+ // Print the input HTML.
+ System.out.println(input);
+
+ // Print the parsed data structure.
+ print(System.out, d, 0);
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ /**
+ * Print the parsed data structure.
+ *
+ * @param stream the output
+ * @param node the node
+ * @param ident the identation
+ */
+ static void print(PrintStream stream, Node node, int ident)
+ {
+ if (node == null)
+ return;
+
+ StringBuffer tab = new StringBuffer();
+ stream.println();
+ for (int i = 0; i < ident; i++)
+ {
+ tab.append(' ');
+ }
+
+ stream.print(tab + node.getNodeName());
+ if (node.getNodeValue() != null)
+ {
+ stream.println();
+ stream.print(tab + " '" + node.getNodeValue() + "'");
+ }
+
+ NamedNodeMap attributes = node.getAttributes();
+ if (attributes != null && attributes.getLength() != 0)
+ {
+ stream.print(' ');
+ for (int i = 0; i < attributes.getLength(); i++)
+ {
+ Node a = attributes.item(i);
+ stream.print(a.getNodeName() + "='" + a.getNodeValue() + "'");
+ }
+ }
+
+ ident += 2;
+
+ NodeList childs = node.getChildNodes();
+ if (childs != null)
+ for (int i = 0; i < childs.getLength(); i++)
+ {
+ print(stream, childs.item(i), ident);
+ }
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/big-fullscreen.png b/libjava/classpath/examples/gnu/classpath/examples/icons/big-fullscreen.png
new file mode 100644
index 0000000..12ca146
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/big-fullscreen.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/big-home.png b/libjava/classpath/examples/gnu/classpath/examples/icons/big-home.png
new file mode 100644
index 0000000..3a8f055
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/big-home.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/big-warning.png b/libjava/classpath/examples/gnu/classpath/examples/icons/big-warning.png
new file mode 100644
index 0000000..dc8c8a4
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/big-warning.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-copy.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-copy.png
new file mode 100644
index 0000000..f2f83e3
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-copy.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-cut.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-cut.png
new file mode 100644
index 0000000..f887e15
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-cut.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-back.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-back.png
new file mode 100644
index 0000000..bd5607c
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-back.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-down.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-down.png
new file mode 100644
index 0000000..c8f54fb
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-down.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-forward.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-forward.png
new file mode 100644
index 0000000..bc5bcc5
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-go-forward.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-mic.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-mic.png
new file mode 100644
index 0000000..62fc914
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-mic.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-new.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-new.png
new file mode 100644
index 0000000..db8b087
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-new.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-open.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-open.png
new file mode 100644
index 0000000..b1b22e5
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-open.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-paste.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-paste.png
new file mode 100644
index 0000000..35f67d6
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-paste.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-quit.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-quit.png
new file mode 100644
index 0000000..60a6e40
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-quit.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-save-as.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-save-as.png
new file mode 100644
index 0000000..9d7f9a4
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-save-as.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-save.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-save.png
new file mode 100644
index 0000000..0bc44ab
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-save.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/icons/stock-spell-check.png b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-spell-check.png
new file mode 100644
index 0000000..6f154fd
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/icons/stock-spell-check.png
Binary files differ
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/Demo.java b/libjava/classpath/examples/gnu/classpath/examples/swing/Demo.java
new file mode 100644
index 0000000..4471be1
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/Demo.java
@@ -0,0 +1,1074 @@
+/* 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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.plaf.metal.MetalLookAndFeel;
+import javax.swing.tree.*;
+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
+ {
+ try
+ {
+ if (System.getProperty("swing.defaultlaf") == null)
+ {
+ StringBuffer text = new StringBuffer();
+ text.append("\tYou may change the Look and Feel of this\n");
+ text.append("\tDemo by setting the system property\n");
+ text.append("\t-Dswing.defaultlaf=<LAFClassName>\n\n");
+ text.append("\tPossible values for <LAFClassName> are:\n");
+ text.append("\t * javax.swing.plaf.metal.MetalLookAndFeel\n");
+ text.append("\t\tthe default Java L&F\n");
+ text.append("\t * gnu.classpath.examples.swing.GNULookAndFeel\n");
+ text.append("\tthe GNU Look and Feel\n");
+ text.append("\t(derived from javax.swing.plaf.basic.BasicLookAndFeel\n\n");
+ text.append("\tthe default is gnu.classpath.examples.swing.GNULookAndFeel\n");
+ JEditorPane textPane = new JEditorPane();
+ // temporary hack, preferred size should be computed by the
+ // component
+ textPane.setPreferredSize(new Dimension(400, 300));
+ textPane.setText(text.toString());
+ JOptionPane.showMessageDialog(null, textPane,
+ "Look and Feel notice",
+ JOptionPane.INFORMATION_MESSAGE);
+
+ 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);
+
+ JMenu examples = new JMenu("Examples");
+ new PopUpAction("Buttons",
+ mkPanel(new JComponent[]
+ {mkBigButton("mango"),
+ mkBigButton("guava"),
+ mkBigButton("lemon")}),
+ examples);
+
+ new PopUpAction("Toggles",
+ mkToggle("cool and refreshing"),
+ examples);
+
+ new PopUpAction("Checkbox",
+ mkCheckbox("ice cold"),
+ examples);
+
+ new PopUpAction("Radio",
+ mkRadio("delicious"),
+ examples);
+
+ new PopUpAction("Slider",
+ mkSliders(),
+ examples);
+
+ new PopUpAction("List",
+ mkListPanel(new String[] { "hello",
+ "this",
+ "is",
+ "a",
+ "list",
+ "that",
+ "wraps",
+ "over"}),
+ examples);
+
+ new PopUpAction("Scrollbar",
+ mkScrollBar(),
+ examples);
+
+ new PopUpAction("Viewport",
+ mkViewportBox(mkBigButton("View Me!")),
+ examples);
+
+ new PopUpAction("ScrollPane",
+ mkScrollPane(mkBigButton("Scroll Me!")),
+ examples);
+
+ new PopUpAction("TabPane",
+ mkTabs(new String[] {"happy",
+ "sad",
+ "indifferent"}),
+ examples);
+
+ new PopUpAction("Spinner",
+ mkSpinner(),
+ examples);
+
+ new PopUpAction("TextField",
+ mkTextField("Hello, World!"),
+ examples);
+
+ new PopUpAction("ColorChooser",
+ mkColorChooser(),
+ examples);
+
+ new PopUpAction("ComboBox",
+ mkComboBox(new String[] {"Stop",
+ "Software",
+ "Hoarders",
+ "Support",
+ "GNU!"}),
+ examples);
+
+ new PopUpAction("Editor",
+ mkEditorPane(),
+ examples);
+
+ new PopUpAction("Tree",
+ mkTree(),
+ examples);
+
+ new PopUpAction("Table",
+ mkTable(),
+ examples);
+
+ 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(examples);
+ 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;
+ }
+
+ private static JPanel mkTreeWorld()
+ {
+ // non-leafs
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("Exotic Subsistence");
+ DefaultMutableTreeNode fruit = new DefaultMutableTreeNode("Interesting Fruit");
+ DefaultMutableTreeNode veg = new DefaultMutableTreeNode("Extraordinary Vegetables");
+ DefaultMutableTreeNode liq = new DefaultMutableTreeNode("Peculiar Liquids");
+
+ // leafs
+ DefaultMutableTreeNode f1 = new DefaultMutableTreeNode("Abiu");
+ DefaultMutableTreeNode f2 = new DefaultMutableTreeNode("Bamboo Shoots");
+ DefaultMutableTreeNode f3 = new DefaultMutableTreeNode("Breadfruit");
+ DefaultMutableTreeNode f4 = new DefaultMutableTreeNode("Canistel");
+ DefaultMutableTreeNode f5 = new DefaultMutableTreeNode("Duku");
+ DefaultMutableTreeNode f6 = new DefaultMutableTreeNode("Guava");
+ DefaultMutableTreeNode f7 = new DefaultMutableTreeNode("Jakfruit");
+ DefaultMutableTreeNode f8 = new DefaultMutableTreeNode("Quaribea");
+
+ DefaultMutableTreeNode v1 = new DefaultMutableTreeNode("Amaranth");
+ DefaultMutableTreeNode v2 = new DefaultMutableTreeNode("Kiwano");
+ DefaultMutableTreeNode v3 = new DefaultMutableTreeNode("Leeks");
+ DefaultMutableTreeNode v4 = new DefaultMutableTreeNode("Luffa");
+ DefaultMutableTreeNode v5 = new DefaultMutableTreeNode("Chayote");
+ DefaultMutableTreeNode v6 = new DefaultMutableTreeNode("Jicama");
+ DefaultMutableTreeNode v7 = new DefaultMutableTreeNode("Okra");
+
+ DefaultMutableTreeNode l1 = new DefaultMutableTreeNode("Alcoholic");
+ DefaultMutableTreeNode l11 = new DefaultMutableTreeNode("Caipirinha");
+ DefaultMutableTreeNode l21 = new DefaultMutableTreeNode("Mojito");
+ DefaultMutableTreeNode l31 = new DefaultMutableTreeNode("Margarita");
+ DefaultMutableTreeNode l41 = new DefaultMutableTreeNode("Martini");
+ DefaultMutableTreeNode l5 = new DefaultMutableTreeNode("Non Alcoholic");
+ DefaultMutableTreeNode l55 = new DefaultMutableTreeNode("Babaji");
+ DefaultMutableTreeNode l65 = new DefaultMutableTreeNode("Chikita");
+
+ root.add(fruit);
+ root.add(veg);
+ root.add(liq);
+ fruit.add(f1);
+ fruit.add(f2);
+ fruit.add(f3);
+ fruit.add(f4);
+ fruit.add(f5);
+ fruit.add(f6);
+ fruit.add(f7);
+ fruit.add(f8);
+ veg.add(v1);
+ veg.add(v2);
+ veg.add(v3);
+ veg.add(v4);
+ veg.add(v5);
+ veg.add(v6);
+ veg.add(v7);
+ liq.add(l1);
+ l1.add(l11);
+ l1.add(l21);
+ l1.add(l31);
+ l1.add(l41);
+ liq.add(l5);
+ l5.add(l55);
+ l5.add(l65);
+
+ final JTree tree = new JTree(root);
+ tree.setLargeModel(true);
+ DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
+ dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setSelectionModel(dtsm);
+
+ // buttons to add and delete
+ JButton add = mkButton("add element");
+ add.addActionListener(new ActionListener()
+ {
+ int i = 0;
+ public void actionPerformed(ActionEvent e)
+ {
+ for (int i = 0; i < tree.getRowCount(); i++)
+ {
+ if (tree.isRowSelected(i))
+ {
+ TreePath p = tree.getPathForRow(i);
+ DefaultMutableTreeNode n = (DefaultMutableTreeNode) p.
+ getLastPathComponent();
+ n.add(new DefaultMutableTreeNode("New Element"));
+ tree.repaint();
+ break;
+ }
+ }
+ }
+ });
+
+
+ JPanel p1 = new JPanel();
+ p1.setLayout(new BorderLayout());
+
+ JPanel p2 = new JPanel();
+ p2.add(add);
+
+ p1.add(p2, BorderLayout.NORTH);
+ p1.add(mkScrollPane(tree), BorderLayout.CENTER);
+
+ return p1;
+ }
+
+ 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);
+ f.setVisible(true);
+ 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());
+ tabs.add("Tree world!", mkTreeWorld());
+ 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);
+ JPanel main = new JPanel();
+ main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
+ main.add(mkTabbedPane());
+ main.add(mkButtonBar());
+ component.add(main, BorderLayout.CENTER);
+ 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 JComboBox mkComboBox(String[] names)
+ {
+ JComboBox box = new JComboBox(names);
+ return box;
+ }
+
+ public static JSpinner mkSpinner()
+ {
+ JSpinner spinner = new JSpinner();
+ return spinner;
+ }
+
+ 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);
+ list1.setLayoutOrientation(JList.VERTICAL_WRAP);
+ list1.setVisibleRowCount(4);
+ final JList list2 = new JList(mod);
+ list2.setLayoutOrientation(JList.VERTICAL_WRAP);
+ list2.setVisibleRowCount(4);
+
+ 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;
+ }
+
+ public static JColorChooser mkColorChooser()
+ {
+ return new JColorChooser();
+ }
+
+ private static class PopUpAction
+ implements ActionListener
+ {
+ private JComponent inner;
+ private String name;
+
+ PopUpAction(String n, JComponent i, JMenu m)
+ {
+ name = n;
+ inner = i;
+
+ JMenuItem item = new JMenuItem(name);
+ item.addActionListener(this);
+ m.add(item);
+ }
+
+ 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 static JEditorPane mkEditorPane()
+ {
+ JEditorPane editorPane = new JEditorPane();
+ editorPane.setEditable(true);
+ return editorPane;
+ }
+
+ private static JTree mkTree()
+ {
+ DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root node");
+ DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child node 1");
+ DefaultMutableTreeNode child11 =
+ new DefaultMutableTreeNode("Child node 1.1");
+ DefaultMutableTreeNode child12 =
+ new DefaultMutableTreeNode("Child node 1.2");
+ DefaultMutableTreeNode child13 =
+ new DefaultMutableTreeNode("Child node 1.3");
+ DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child node 2");
+ DefaultMutableTreeNode child21 =
+ new DefaultMutableTreeNode("Child node 2.1");
+ DefaultMutableTreeNode child22 =
+ new DefaultMutableTreeNode("Child node 2.2");
+ DefaultMutableTreeNode child23 =
+ new DefaultMutableTreeNode("Child node 2.3");
+ DefaultMutableTreeNode child24 =
+ new DefaultMutableTreeNode("Child node 2.4");
+
+ DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child node 3");
+ root.add(child1);
+ root.add(child2);
+ root.add(child3);
+ child1.add(child11);
+ child1.add(child12);
+ child1.add(child13);
+ child2.add(child21);
+ child2.add(child22);
+ child2.add(child23);
+ child2.add(child24);
+
+ JTree tree = new JTree(root);
+ tree.setLargeModel(true);
+ DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel();
+ dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
+ tree.setSelectionModel(dtsm);
+
+ return tree;
+ }
+
+ private static JTable mkTable()
+ {
+ Object[][] tableData = new Object[][] {
+ {
+ "Field 1", "Field 2" , "Field 3"
+ },
+ {
+ "Field 4", "Field 5" , "Field 6"
+ },
+ {
+ "Field 7", "Field 8" , "Field 9"
+ },
+ {
+ "Field 10", "Field 11" , "Field 12"
+ }
+ };
+ Object[] columnNames = new Object[] {"Column 1", "Column 2", "Column 3"};
+
+ JTable table = new JTable(tableData, columnNames);
+ return table;
+ }
+
+ 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",
+ "that",
+ "wraps",
+ "over"}),
+ 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);
+
+ new PopUpAction("Spinner",
+ mkSpinner(),
+ panel);
+
+ new PopUpAction("TextField",
+ mkTextField("Hello, World!"),
+ panel);
+
+ new PopUpAction("ColorChooser",
+ mkColorChooser(),
+ panel);
+
+ new PopUpAction("ComboBox",
+ mkComboBox(new String[] {"Stop",
+ "Software",
+ "Hoarders",
+ "Support",
+ "GNU!"}),
+ panel);
+
+ new PopUpAction("Editor",
+ mkEditorPane(),
+ panel);
+
+ new PopUpAction("Tree",
+ mkTree(),
+ panel);
+
+ new PopUpAction("Table",
+ mkTable(),
+ panel);
+
+ JButton exitDisposer = mkDisposerButton(frame);
+ panel.add(exitDisposer);
+
+ return panel;
+ }
+
+ public static JTextField mkTextField(String sometext)
+ {
+ return new JTextField(sometext, 40);
+ }
+}
diff --git a/libjava/classpath/examples/gnu/classpath/examples/swing/GNULookAndFeel.java b/libjava/classpath/examples/gnu/classpath/examples/swing/GNULookAndFeel.java
new file mode 100644
index 0000000..97e91a8
--- /dev/null
+++ b/libjava/classpath/examples/gnu/classpath/examples/swing/GNULookAndFeel.java
@@ -0,0 +1,85 @@
+/* GNULookAndFeel.java -- An example of using the javax.swing UI.
+ Copyright (C) 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+*/
+
+package gnu.classpath.examples.swing;
+
+import java.awt.Color;
+
+import javax.swing.ImageIcon;
+import javax.swing.UIDefaults;
+import javax.swing.plaf.ColorUIResource;
+import javax.swing.plaf.IconUIResource;
+import javax.swing.plaf.basic.BasicLookAndFeel;
+
+public class GNULookAndFeel extends BasicLookAndFeel
+{
+
+ static Color blueGray = new Color(0xdc, 0xda, 0xd5);
+
+ 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;
+
+ private final static String iconspath = "/gnu/javax/swing/plaf/gtk/icons/";
+
+ 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),
+
+ "Tree.closedIcon",
+ new IconUIResource(new ImageIcon
+ (getClass().getResource
+ (iconspath + "TreeClosed.png"))),
+ "Tree.leafIcon",
+ new IconUIResource(new ImageIcon
+ (getClass().getResource
+ (iconspath + "TreeLeaf.png"))),
+ "Tree.openIcon",
+ new IconUIResource(new ImageIcon
+ (getClass().getResource
+ (iconspath + "TreeOpen.png"))),
+ };
+ LAF_defaults.putDefaults(myDefaults);
+ }
+ return LAF_defaults;
+ }
+}