summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorThomas Fitzsimmons <fitzsim@redhat.com>2005-08-12 05:37:25 +0000
committerThomas Fitzsimmons <fitzsim@redhat.com>2005-08-12 05:37:25 +0000
commit13ea3ff77eda237c6bc604cb358999054fb243d1 (patch)
tree987b034036aada8ec16a4072f4e98c00e06d7bd3 /examples
parenta3e17e05b9cb5b7f0c7d8ff319687cf880b8894a (diff)
downloadclasspath-13ea3ff77eda237c6bc604cb358999054fb243d1.tar.gz
2005-08-12 Thomas Fitzsimmons <fitzsim@redhat.com>
* examples/gnu/classpath/examples/jawt/DemoJAWT.c: New file. * examples/gnu/classpath/examples/jawt/DemoJAWT.java: Likewise. * examples/gnu/classpath/examples/jawt/Makefile: Likewise.
Diffstat (limited to 'examples')
-rw-r--r--examples/gnu/classpath/examples/jawt/DemoJAWT.c147
-rw-r--r--examples/gnu/classpath/examples/jawt/DemoJAWT.java53
-rw-r--r--examples/gnu/classpath/examples/jawt/Makefile20
3 files changed, 220 insertions, 0 deletions
diff --git a/examples/gnu/classpath/examples/jawt/DemoJAWT.c b/examples/gnu/classpath/examples/jawt/DemoJAWT.c
new file mode 100644
index 000000000..990e1c438
--- /dev/null
+++ b/examples/gnu/classpath/examples/jawt/DemoJAWT.c
@@ -0,0 +1,147 @@
+/* DemoJAWT.c -- native portion of AWT Native Interface demo
+ 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. */
+
+#include "DemoJAWT.h"
+#include "jawt_md.h"
+#include <string.h>
+
+JNIEXPORT void JNICALL
+Java_DemoJAWT_paint (JNIEnv* env, jobject canvas, jobject graphics)
+{
+ JAWT awt;
+ JAWT_DrawingSurface* surface;
+ JAWT_DrawingSurfaceInfo* surface_info;
+ JAWT_X11DrawingSurfaceInfo* surface_info_x11;
+ jint lock;
+ GC gc;
+ int c;
+ char* test_string = "JAWT";
+ XColor orange;
+ XColor yellow;
+ XColor blue;
+ Display* display;
+ Drawable drawable;
+ Status status;
+
+ awt.version = JAWT_VERSION_1_3;
+ if (JAWT_GetAWT (env, &awt) == JNI_FALSE)
+ {
+ printf ("couldn't find AWT\n");
+ return;
+ }
+
+ surface = awt.GetDrawingSurface (env, canvas);
+ if (surface == NULL)
+ {
+ printf ("drawing surface is NULL\n");
+ return;
+ }
+
+ lock = surface->Lock (surface);
+ if ((lock & JAWT_LOCK_ERROR) != 0)
+ {
+ printf ("couldn't lock drawing surface\n");
+ awt.FreeDrawingSurface (surface);
+ return;
+ }
+
+ surface_info = surface->GetDrawingSurfaceInfo (surface);
+ if (surface_info == NULL)
+ {
+ printf ("couldn't get surface information\n");
+ surface->Unlock (surface);
+ awt.FreeDrawingSurface (surface);
+ return;
+ }
+
+ surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
+
+ display = surface_info_x11->display;
+ drawable = surface_info_x11->drawable;
+
+ gc = XCreateGC (display, drawable, 0, 0);
+ XSetBackground (display, gc, 0);
+
+ orange.red = 254 * 65535 / 255;
+ orange.green = 90 * 65535 / 255;
+ orange.blue = 16 * 65535 / 255;
+
+ /* assume color lookups succeed */
+ status = XAllocColor (display, DefaultColormap (display,
+ DefaultScreen (display)),
+ &orange);
+
+ if (!status)
+ {
+ printf ("color allocation failed\n");
+ goto cleanup;
+ }
+
+ yellow.red = 255 * 65535 / 255;
+ yellow.green = 255 * 65535 / 255;
+ yellow.blue = 0 * 65535 / 255;
+
+ XAllocColor (display, DefaultColormap (display,
+ DefaultScreen (display)),
+ &yellow);
+
+ if (!status)
+ {
+ printf ("color allocation failed\n");
+ goto cleanup;
+ }
+
+ blue.red = 16 * 65535 / 255;
+ blue.green = 30 * 65535 / 255;
+ blue.blue = 137 * 65535 / 255;
+
+ XAllocColor (display, DefaultColormap (display,
+ DefaultScreen (display)),
+ &blue);
+
+ if (!status)
+ {
+ printf ("color allocation failed\n");
+ goto cleanup;
+ }
+
+ for (c = 5; c >= 0; c--)
+ {
+ if (c % 2)
+ XSetForeground (display, gc, yellow.pixel);
+ else
+ XSetForeground (display, gc, orange.pixel);
+
+ XFillArc (display, drawable, gc, 140 - c * 15, 140 - c * 15, c * 30, c * 30, 0, 360 * 64);
+ }
+
+ XSetForeground (display, gc, blue.pixel);
+ XDrawString (display, drawable,
+ gc, 129, 145, test_string, strlen (test_string));
+
+ cleanup:
+ XFreeGC (display, gc);
+
+ surface->FreeDrawingSurfaceInfo (surface_info);
+
+ surface->Unlock (surface);
+
+ awt.FreeDrawingSurface (surface);
+}
diff --git a/examples/gnu/classpath/examples/jawt/DemoJAWT.java b/examples/gnu/classpath/examples/jawt/DemoJAWT.java
new file mode 100644
index 000000000..4f55442fe
--- /dev/null
+++ b/examples/gnu/classpath/examples/jawt/DemoJAWT.java
@@ -0,0 +1,53 @@
+/* DemoJAWT.java -- AWT Native Interface demo
+ 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. */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class DemoJAWT extends Canvas
+{
+ static
+ {
+ System.loadLibrary ("DemoJAWT");
+ }
+
+ public native void paint (Graphics g);
+
+ public static void main (String[] args)
+ {
+ Frame f = new Frame ();
+
+ f.setBounds (0, 0, 300, 300);
+
+ f.setResizable (false);
+
+ f.add (new DemoJAWT ());
+
+ f.addWindowListener (new WindowAdapter ()
+ {
+ public void windowClosing (WindowEvent evt)
+ {
+ System.exit (0);
+ }
+ });
+
+ f.show ();
+ }
+}
diff --git a/examples/gnu/classpath/examples/jawt/Makefile b/examples/gnu/classpath/examples/jawt/Makefile
new file mode 100644
index 000000000..974a2f487
--- /dev/null
+++ b/examples/gnu/classpath/examples/jawt/Makefile
@@ -0,0 +1,20 @@
+all: \
+ DemoJAWT.h DemoJAWT.class libDemoJAWT.so
+
+%.class: %.java
+ gcj -C $<
+
+%.h: %.class
+ gcjh -jni $(basename $< .class)
+
+DemoJAWT: DemoJAWT.java
+ gcj -g --main=DemoJAWT -fjni -o DemoJAWT DemoJAWT.java
+
+libDemoJAWT.so: DemoJAWT.c
+ gcc -g -O0 -Wall -I. -I/usr/X11R6/include -shared -o $@ DemoJAWT.c -L. -ljawt -L/usr/X11R6/lib -lX11
+
+run:
+ LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:. jamvm DemoJAWT
+
+clean:
+ rm -f DemoJAWT.h DemoJAWT.class DemoJAWT\$$1.class libDemoJAWT.so