classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] JAWT example


From: Thomas Fitzsimmons
Subject: [cp-patches] JAWT example
Date: Fri, 12 Aug 2005 01:36:56 -0400

Hi,

I committed this.  It's an example program that demonstrates use of the
AWT Native Interface.

Tom

2005-08-12  Thomas Fitzsimmons  <address@hidden>

        * examples/gnu/classpath/examples/jawt/DemoJAWT.c: New file.
        * examples/gnu/classpath/examples/jawt/DemoJAWT.java: Likewise.
        * examples/gnu/classpath/examples/jawt/Makefile: Likewise.

Index: examples/gnu/classpath/examples/jawt/DemoJAWT.c
===================================================================
RCS file: examples/gnu/classpath/examples/jawt/DemoJAWT.c
diff -N examples/gnu/classpath/examples/jawt/DemoJAWT.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/jawt/DemoJAWT.c     12 Aug 2005 05:35:44 
-0000
@@ -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);
+}
Index: examples/gnu/classpath/examples/jawt/DemoJAWT.java
===================================================================
RCS file: examples/gnu/classpath/examples/jawt/DemoJAWT.java
diff -N examples/gnu/classpath/examples/jawt/DemoJAWT.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/jawt/DemoJAWT.java  12 Aug 2005 05:35:44 
-0000
@@ -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 ();
+  }
+}
Index: examples/gnu/classpath/examples/jawt/Makefile
===================================================================
RCS file: examples/gnu/classpath/examples/jawt/Makefile
diff -N examples/gnu/classpath/examples/jawt/Makefile
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ examples/gnu/classpath/examples/jawt/Makefile       12 Aug 2005 05:35:44 
-0000
@@ -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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]