summaryrefslogtreecommitdiff
path: root/examples/gnu/classpath/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gnu/classpath/examples')
-rw-r--r--examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToPassHelper.java15
-rw-r--r--examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToReturnHelper.java25
-rw-r--r--examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/TreeNodeHelper.java11
-rw-r--r--examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/WeThrowThisExceptionHelper.java6
-rw-r--r--examples/gnu/classpath/examples/awt/Demo.java201
-rw-r--r--examples/gnu/classpath/examples/java2d/bench.c606
-rw-r--r--examples/gnu/classpath/examples/java2d/bench.h64
-rw-r--r--examples/gnu/classpath/examples/management/TestBeans.java55
-rw-r--r--examples/gnu/classpath/examples/swing/Demo.java40
-rw-r--r--examples/gnu/classpath/examples/swing/HtmlDemo.java133
10 files changed, 1128 insertions, 28 deletions
diff --git a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToPassHelper.java b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToPassHelper.java
index c41ebe237..652ee53cc 100644
--- a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToPassHelper.java
+++ b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToPassHelper.java
@@ -38,6 +38,8 @@ exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+import gnu.CORBA.OrbRestricted;
+
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
import org.omg.CORBA.TypeCode;
@@ -81,13 +83,14 @@ public abstract class StructureToPassHelper
*/
public static synchronized TypeCode type()
{
- StructMember[] members = new StructMember[ 2 ];
+ 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(StructureToPassHelper.id(), "StructureToPass", members);
+ member = OrbRestricted.Singleton.create_string_tc(0);
+ members[0] = new StructMember("a", member, null);
+ member = OrbRestricted.Singleton.create_string_tc(0);
+ members[1] = new StructMember("b", member, null);
+ return OrbRestricted.Singleton.create_struct_tc(StructureToPassHelper.id(),
+ "StructureToPass", members);
}
/**
diff --git a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToReturnHelper.java b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToReturnHelper.java
index 42fb7a574..2ac03a895 100644
--- a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToReturnHelper.java
+++ b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/StructureToReturnHelper.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+import gnu.CORBA.OrbRestricted;
+
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
import org.omg.CORBA.TCKind;
@@ -86,17 +88,18 @@ public abstract class StructureToReturnHelper
*/
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(StructureToReturnHelper.id(), "StructureToReturn",
- members
- );
+ StructMember[] members = new StructMember[3];
+ TypeCode member = OrbRestricted.Singleton.get_primitive_tc(TCKind.tk_long);
+ members[0] = new StructMember("n", member, null);
+ member = OrbRestricted.Singleton.create_string_tc(0);
+ members[1] = new StructMember("c", member, null);
+ member = OrbRestricted.Singleton.get_primitive_tc(TCKind.tk_long);
+ member = OrbRestricted.Singleton.create_array_tc(3, member);
+ members[2] = new StructMember("arra", member, null);
+ return OrbRestricted.Singleton.create_struct_tc(
+ StructureToReturnHelper.id(),
+ "StructureToReturn",
+ members);
}
/**
diff --git a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/TreeNodeHelper.java b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/TreeNodeHelper.java
index f111d0eac..ccf792da8 100644
--- a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/TreeNodeHelper.java
+++ b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/TreeNodeHelper.java
@@ -38,6 +38,9 @@ exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+
+import gnu.CORBA.OrbRestricted;
+
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
@@ -128,18 +131,18 @@ public abstract class TreeNodeHelper
// To avoid the infinite recursion loop, the
// recursive reference is handled in specific way.
if (active)
- return ORB.init().create_recursive_tc(_id);
+ return OrbRestricted.Singleton.create_recursive_tc(_id);
active = true;
// List all memebers of the TreeNode structure.
StructMember[] members = new StructMember[ 2 ];
TypeCode memberType;
- memberType = ORB.init().create_string_tc(0);
+ memberType = OrbRestricted.Singleton.create_string_tc(0);
members [ 0 ] = new StructMember("name", memberType, null);
- memberType = ORB.init().create_recursive_tc("");
+ memberType = OrbRestricted.Singleton.create_recursive_tc("");
members [ 1 ] = new StructMember("children", memberType, null);
typeCode =
- ORB.init().create_struct_tc(TreeNodeHelper.id(), "TreeNode", members);
+ OrbRestricted.Singleton.create_struct_tc(TreeNodeHelper.id(), "TreeNode", members);
active = false;
}
}
diff --git a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/WeThrowThisExceptionHelper.java b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/WeThrowThisExceptionHelper.java
index 4d5eee74b..6ad13a9bb 100644
--- a/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/WeThrowThisExceptionHelper.java
+++ b/examples/gnu/classpath/examples/CORBA/SimpleCommunication/communication/WeThrowThisExceptionHelper.java
@@ -38,6 +38,8 @@ exception statement from your version. */
package gnu.classpath.examples.CORBA.SimpleCommunication.communication;
+import gnu.CORBA.OrbRestricted;
+
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.StructMember;
@@ -96,9 +98,9 @@ public abstract class WeThrowThisExceptionHelper
{
StructMember[] members = new StructMember[ 1 ];
TypeCode member = null;
- member = ORB.init().get_primitive_tc(TCKind.tk_long);
+ member = OrbRestricted.Singleton.get_primitive_tc(TCKind.tk_long);
members [ 0 ] = new StructMember("ourField", member, null);
- return ORB.init().create_struct_tc(WeThrowThisExceptionHelper.id(),
+ return OrbRestricted.Singleton.create_struct_tc(WeThrowThisExceptionHelper.id(),
"WeThrowThisException", members
);
}
diff --git a/examples/gnu/classpath/examples/awt/Demo.java b/examples/gnu/classpath/examples/awt/Demo.java
index 5e668dde6..bd5e755cb 100644
--- a/examples/gnu/classpath/examples/awt/Demo.java
+++ b/examples/gnu/classpath/examples/awt/Demo.java
@@ -20,11 +20,70 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
package gnu.classpath.examples.awt;
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Canvas;
+import java.awt.Checkbox;
+import java.awt.CheckboxGroup;
+import java.awt.CheckboxMenuItem;
+import java.awt.Choice;
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.DisplayMode;
+import java.awt.FileDialog;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.Graphics;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.Label;
import java.awt.List;
-import java.awt.event.*;
+import java.awt.Menu;
+import java.awt.MenuBar;
+import java.awt.MenuItem;
+import java.awt.MenuShortcut;
+import java.awt.Panel;
+import java.awt.ScrollPane;
+import java.awt.TextField;
+import java.awt.Toolkit;
+import java.awt.Window;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragSource;
+import java.awt.dnd.DragSourceContext;
+import java.awt.dnd.DragSourceDragEvent;
+import java.awt.dnd.DragSourceDropEvent;
+import java.awt.dnd.DragSourceEvent;
+import java.awt.dnd.DragSourceListener;
+import java.awt.dnd.DropTarget;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
+import java.awt.dnd.InvalidDnDOperationException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.net.URL;
-import java.util.*;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
class Demo
{
@@ -156,6 +215,7 @@ class Demo
addSubWindow ("Animation", new AnimationWindow ());
addSubWindow ("Resolution", new ResolutionWindow ());
addSubWindow ("Fullscreen", new FullscreenWindow ());
+ addSubWindow ("Drag n' Drop", new DragDropWindow ());
Panel sp = new Panel();
PrettyPanel p = new PrettyPanel();
@@ -799,6 +859,141 @@ class Demo
}
}
+ static class DragDropWindow
+ extends SubFrame
+ implements ActionListener, DropTargetListener
+ {
+ DragLabel source = new DragLabel("Drag and drop me to the following Button",
+ Label.CENTER);
+
+ Button target = new Button();
+
+ public void init()
+ {
+ source.setForeground(Color.red);
+ add(source, BorderLayout.NORTH);
+
+ target.addActionListener(this);
+ add(target, BorderLayout.SOUTH);
+
+ new DropTarget(target, DnDConstants.ACTION_COPY_OR_MOVE, this);
+
+ setSize(205, 100);
+
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ Button b = (Button) e.getSource();
+ b.setLabel("");
+ }
+
+ public void dragEnter(DropTargetDragEvent e)
+ {
+ }
+
+ public void dragExit(DropTargetEvent e)
+ {
+ }
+
+ public void dragOver(DropTargetDragEvent e)
+ {
+ }
+
+ public void drop(DropTargetDropEvent e)
+ {
+ try
+ {
+ Transferable t = e.getTransferable();
+
+ if (e.isDataFlavorSupported(DataFlavor.stringFlavor))
+ {
+ e.acceptDrop(e.getDropAction());
+
+ String s;
+ s = (String) t.getTransferData(DataFlavor.stringFlavor);
+
+ target.setLabel(s);
+
+ e.dropComplete(true);
+ }
+ else
+ e.rejectDrop();
+ }
+ catch (java.io.IOException e2)
+ {
+ }
+ catch (UnsupportedFlavorException e2)
+ {
+ }
+ }
+
+ public void dropActionChanged(DropTargetDragEvent e)
+ {
+ }
+
+ class DragLabel
+ extends Label
+ implements DragGestureListener, DragSourceListener
+ {
+ private DragSource ds = DragSource.getDefaultDragSource();
+
+ public DragLabel(String s, int alignment)
+ {
+ super(s, alignment);
+ int action = DnDConstants.ACTION_COPY_OR_MOVE;
+ ds.createDefaultDragGestureRecognizer(this, action, this);
+ }
+
+ public void dragGestureRecognized(DragGestureEvent e)
+ {
+ try
+ {
+ Transferable t = new StringSelection(getText());
+ e.startDrag(DragSource.DefaultCopyNoDrop, t, this);
+ }
+ catch (InvalidDnDOperationException e2)
+ {
+ System.out.println(e2);
+ }
+ }
+
+ public void dragDropEnd(DragSourceDropEvent e)
+ {
+ if (e.getDropSuccess() == false)
+ return;
+
+ int action = e.getDropAction();
+ if ((action & DnDConstants.ACTION_MOVE) != 0)
+ setText("");
+ }
+
+ public void dragEnter(DragSourceDragEvent e)
+ {
+ DragSourceContext ctx = e.getDragSourceContext();
+
+ int action = e.getDropAction();
+ if ((action & DnDConstants.ACTION_COPY) != 0)
+ ctx.setCursor(DragSource.DefaultCopyDrop);
+ else
+ ctx.setCursor(DragSource.DefaultCopyNoDrop);
+ }
+
+ public void dragExit(DragSourceEvent e)
+ {
+ }
+
+ public void dragOver(DragSourceDragEvent e)
+ {
+ }
+
+ public void dropActionChanged(DragSourceDragEvent e)
+ {
+ }
+ }
+ }
+
static class FullscreenWindow extends SubFrame
{
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
diff --git a/examples/gnu/classpath/examples/java2d/bench.c b/examples/gnu/classpath/examples/java2d/bench.c
new file mode 100644
index 000000000..e5b45aa1c
--- /dev/null
+++ b/examples/gnu/classpath/examples/java2d/bench.c
@@ -0,0 +1,606 @@
+/* bench.c -- native benchmark for Cairo library (meant to test java2d)
+ Copyright (C) 2006 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 "bench.h"
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include <sys/timeb.h>
+
+G_DEFINE_TYPE (Benchmark, benchmark, GTK_TYPE_DRAWING_AREA);
+
+// Needed for the gtk widget, but not used:
+static void
+benchmark_class_init (BenchmarkClass *klass)
+{
+}
+
+static void
+benchmark_init (Benchmark *obj)
+{
+}
+
+// The Arc2D's PathIterator uses some transforms, so we condense the required
+// functionality of AffineTransform
+static void
+doTransform (double rx, double ry, double theta, double *cvec)
+{
+ // Define identity matrix (corresponds to new AffineTransform())
+ double m00 = 1;
+ double m10 = 0;
+ double m01 = 0;
+ double m11 = 1;
+ double m02 = 0;
+ double m12 = 0;
+
+ // AffineTransform.scale(rx, ry)
+ m00 = m00 * rx;
+ m01 = m01 * ry;
+ m10 = m10 * rx;
+ m11 = m11 * ry;
+
+ // AffineTransform.rotate(theta)
+ double c = cos(theta);
+ double s = sin(theta);
+ double n00 = m00 * c + m01 * s;
+ double n01 = m00 * -s + m01 * c;
+ double n10 = m10 * c + m11 * s;
+ double n11 = m10 * -s + m11 * c;
+
+ m00 = n00;
+ m01 = n01;
+ m10 = n10;
+ m11 = n11;
+
+ // AffineTransform.transform(cvec, 0, cvec, 0, 1)
+ double dstPts[2];
+ dstPts[0] = (float) (m00 * cvec[0] + m01 * cvec[1] + m02);
+ dstPts[1] = (float) (m10 * cvec[0] + m11 * cvec[1] + m12);
+ cvec[0] = dstPts[0];
+ cvec[1] = dstPts[1];
+}
+
+// Place an arc on the cairo path, simulating java2d's Arc2D
+static void
+setupArc(cairo_t *cr, GtkWidget *bench, int shift)
+{
+ double x, y;
+
+ // Normally passed into the Arc2D constructor
+ x = bench->allocation.x + (rand() % (bench->allocation.width - minSize + 1));
+ y = bench->allocation.y + (rand() % (bench->allocation.height - minSize + 1));
+
+ int angle = rand() % 360;
+ int length = (rand() % 360) - angle;
+ int width = rand() % (int)((bench->allocation.width - x - 10) + 10);
+ int height = rand() % (int)((bench->allocation.height - y - 10) + 10);
+
+ // This is from the ArcPath iterator
+ double start = angle * (M_PI / 180);
+ double extent = length * (M_PI / 180);
+
+ if (extent < 0)
+ {
+ extent = -extent;
+ start = 2 * M_PI - extent + start;
+ }
+
+ int limit;
+ if (width < 0 || height < 0) // We assume type == 0; ie, Arc2D.OPEN
+ limit = -1;
+ else if (extent == 0)
+ limit = 0;
+ else if (extent <= M_PI / 2.0)
+ limit = 1;
+ else if (extent <= M_PI)
+ limit = 2;
+ else if (extent <= 3.0 * (M_PI / 2.0))
+ limit = 3;
+ else
+ limit = 4;
+
+ // This is from CairoGraphics2D.walkPath
+ double xnew = 0;
+ double ynew = 0;
+ double coords[6];
+
+ cairo_fill_rule_t cfillrule = CAIRO_FILL_RULE_WINDING;
+ cairo_set_fill_rule(cr, cfillrule);
+
+ // First iteration will move to the starting point
+ double rx = width / 2;
+ double ry = height / 2;
+ double xmid = x + rx;
+ double ymid = y + ry;
+ coords[0] = xmid + rx * cos(start);
+ coords[1] = ymid - ry * sin(start);
+
+ if (shift == 1)
+ {
+ xnew = floor(coords[0]) + 0.5;
+ ynew = floor(coords[1]) + 0.5;
+ }
+ else
+ {
+ xnew = coords[0];
+ ynew = coords[1];
+ }
+
+ cairo_move_to(cr, xnew, ynew);
+
+ // Iterate through segments of the arc
+ int current;
+ for (current = 1; current <= limit; current++)
+ {
+ // Back to the ArcPath iterator's getCurrent
+ double kappa = (sqrt(2.0) - 1.0) * (4.0 / 3.0);
+ double quad = (M_PI / 2.0);
+
+ double curr_begin = start + (current - 1) * quad;
+ double curr_extent;
+
+ if (start + extent - curr_begin < quad)
+ curr_extent = (start + extent) - curr_begin;
+ else
+ curr_extent = quad;
+
+ double portion_of_a_quadrant = curr_extent / quad;
+
+ double x0 = xmid + rx * cos(curr_begin);
+ double y0 = ymid - ry * sin(curr_begin);
+
+ double x1 = xmid + rx * cos(curr_begin + curr_extent);
+ double y1 = ymid - ry * sin(curr_begin + curr_extent);
+
+ double cvec[2];
+ double len = kappa * portion_of_a_quadrant;
+ double angle = curr_begin;
+
+ cvec[0] = 0;
+ cvec[1] = len;
+ doTransform(rx, ry, angle, cvec);
+ coords[0] = x0 + cvec[0];
+ coords[1] = y0 - cvec[1];
+
+ cvec[0] = 0;
+ cvec[1] = -len;
+ doTransform(rx, ry, angle, cvec);
+ doTransform(1, 1, curr_extent, cvec);
+ coords[2] = x1 + cvec[0];
+ coords[3] = y1 - cvec[1];
+
+ coords[4] = x1;
+ coords[5] = y1;
+
+ // draw it, from CairoGraphics2D.walkPath
+ if (shift == 1)
+ {
+ xnew = floor(coords[4]) + 0.5;
+ ynew = floor(coords[5]) + 0.5;
+ cairo_curve_to(cr, floor(coords[0]) + 0.5, floor(coords[1]) + 0.5,
+ floor(coords[2]) + 0.5, floor(coords[3]) + 0.5,
+ xnew, ynew);
+ }
+ else
+ {
+ xnew = coords[4];
+ ynew = coords[5];
+ cairo_curve_to(cr, coords[0], coords[1], coords[2],
+ coords[3], xnew, ynew);
+ }
+ }
+
+ // Randomize the colour, just for asthetics =)
+ cairo_set_source_rgb(cr, (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100));
+
+}
+
+// Place a beizer curve on the cairo path, simulating java2d's CubicCurve2D
+static void
+setupCurve(cairo_t *cr, GtkWidget *bench, int shift)
+{
+ // These are options when creating a new curve
+ int x1 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int y1 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+ int xc1 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int yc1 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+ int xc2 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int yc2 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+ int x2 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int y2 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+
+ // From CairoGraphics2D.walkPath
+ double xnew = 0;
+ double ynew = 0;
+ double coords[6];
+
+ cairo_fill_rule_t cfillrule = CAIRO_FILL_RULE_WINDING;
+ cairo_set_fill_rule(cr, cfillrule);
+
+ // And into CubicCurve's PathIterator...
+ // start by moving to the starting coordinate
+ coords[0] = (float) x1;
+ coords[1] = (float) y1;
+
+ if (shift == 1)
+ {
+ xnew = floor(coords[0]) + 0.5;
+ ynew = floor(coords[1]) + 0.5;
+ }
+ else
+ {
+ xnew = coords[0];
+ ynew = coords[1];
+ }
+
+ cairo_move_to(cr, xnew, ynew);
+
+ // Now the curve itself
+ coords[0] = (float) xc1;
+ coords[1] = (float) yc1;
+ coords[2] = (float) xc2;
+ coords[3] = (float) yc2;
+ coords[4] = (float) x2;
+ coords[5] = (float) y2;
+
+ if (shift == 1)
+ {
+ xnew = floor(coords[4]) + 0.5;
+ ynew = floor(coords[5]) + 0.5;
+ cairo_curve_to(cr, floor(coords[0]) + 0.5, floor(coords[1]) + 0.5,
+ floor(coords[2]) + 0.5, floor(coords[3]) + 0.5,
+ xnew, ynew);
+ }
+ else
+ {
+ xnew = coords[4];
+ ynew = coords[5];
+ cairo_curve_to(cr, coords[0], coords[1], coords[2],
+ coords[3], xnew, ynew);
+ }
+
+ // Randomize colour for asthetics
+ cairo_set_source_rgb(cr, (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100));
+}
+
+// Place a line on the cairo path, simulating java2d's Line2D
+static void
+setupLine(cairo_t *cr, GtkWidget *bench, int shift)
+{
+ // These are set when you create a line
+ int x1 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int y1 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+ int x2 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int y2 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+
+ // This is from CairoGraphics2D.walkPath
+ double xnew = 0;
+ double ynew = 0;
+ double coords[6];
+
+ cairo_fill_rule_t cfillrule = CAIRO_FILL_RULE_WINDING;
+ cairo_set_fill_rule(cr, cfillrule);
+
+ // And into Line2D's PathIterator
+ coords[0] = (float) x1;
+ coords[1] = (float) y1;
+
+ if (shift == 1)
+ {
+ xnew = floor(coords[0]) + 0.5;
+ ynew = floor(coords[1]) + 0.5;
+ }
+ else
+ {
+ xnew = coords[0];
+ ynew = coords[1];
+ }
+
+ cairo_move_to(cr, xnew, ynew);
+
+ coords[0] = (float) x2;
+ coords[1] = (float) y2;
+
+ if (shift == 1)
+ {
+ xnew = floor(coords[0]) + 0.5;
+ ynew = floor(coords[1]) + 0.5;
+ }
+ else
+ {
+ xnew = coords[0];
+ ynew = coords[1];
+ }
+
+ cairo_line_to(cr, xnew, ynew);
+
+ // Randomize colour for asthetics
+ cairo_set_source_rgb(cr, (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100));
+}
+
+// Place a rectangle on the cairo path, simulating java2d's Rectangle2D
+static void
+setupRect(cairo_t *cr, GtkWidget *bench, int shift)
+{
+ // These are set when you create a rectangle
+ int x1 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int y1 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+ int x2 = bench->allocation.x + (rand() % (bench->allocation.width - minSize));
+ int y2 = bench->allocation.y + (rand() % (bench->allocation.height - minSize));
+
+ // draw() and fill() have been optimized to ignore the PathIterator.
+ // We do the same here.
+ double xnew = 0;
+ double ynew = 0;
+
+ if (shift == 1)
+ {
+ xnew = floor(x1) + 0.5;
+ ynew = floor(y1) + 0.5;
+ }
+ else
+ {
+ xnew = x1;
+ ynew = y1;
+ }
+
+ cairo_rectangle(cr, x1, y1, x2, y2);
+
+ // Randomize colour for asthetics
+ cairo_set_source_rgb(cr, (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100),
+ (rand() % 100 / (float)100));
+}
+
+// The real work gets done here: this function is called when the widget
+// is drawn on screen.
+static void
+draw (GtkWidget *bench, cairo_t *cr)
+{
+ // Setup
+ struct timeb t1, t2;
+ int i, timeElapsed;
+
+ cairo_set_line_width(cr, lineWidth);
+
+ if (antialias == 0)
+ cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+ else
+ cairo_set_antialias(cr, CAIRO_ANTIALIAS_GRAY);
+
+ // Tell the user what's going on
+ printf("Testing native cairo drawing..\n");
+ printf(" Screen size is %d x %d \n", screenWidth, screenHeight);
+ printf(" Line width is %d\n", lineWidth);
+ printf(" Test size: %d\n", testSize);
+
+ if (antialias == 0)
+ printf(" Anti-alias is off\n");
+ else
+ printf(" Anti-alias is on\n");
+
+ printf("\n");
+ fflush(stdout);
+
+ // Draw & fill Arc
+ if (arcTest == 1)
+ {
+ // Draw
+ ftime(&t1);
+ for (i = 0; i < testSize; i++)
+ {
+ setupArc(cr, bench, 1);
+ cairo_stroke (cr);
+ }
+
+ ftime(&t2);
+ timeElapsed = 1000 * (t2.time - t1.time) + (t2.millitm - t1.millitm);
+ printf("Draw arc: %d ms\n", timeElapsed);
+ fflush(stdout);
+
+ // Fill
+ ftime(&t1);
+ for (i = 0; i < testSize; i++)
+ {
+ setupArc(cr, bench, 0);
+ cairo_fill (cr);
+ }
+
+ ftime(&t2);
+ timeElapsed = 1000 * (t2.time - t1.time) + (t2.millitm - t1.millitm);
+ printf("Fill arc: %d ms\n", timeElapsed);
+ }
+
+ // Draw cubic curve
+ if (curveTest == 1)
+ {
+ ftime(&t1);
+ for (i = 0; i < testSize; i++)
+ {
+ setupCurve(cr, bench, 1);
+ cairo_stroke (cr);
+ }
+
+ ftime(&t2);
+ timeElapsed = 1000 * (t2.time - t1.time) + (t2.millitm - t1.millitm);
+ printf("Draw cubic curve: %d ms\n", timeElapsed);
+ }
+
+ // Ellipse: skip; this is just a special case of arc
+ // General path: skip; this doesn't even work in java2d
+
+ // Draw Line
+ if (lineTest == 1)
+ {
+ ftime(&t1);
+ for (i = 0; i < testSize; i++)
+ {
+ setupLine(cr, bench, 1);
+ cairo_stroke (cr);
+ }
+
+ ftime(&t2);
+ timeElapsed = 1000 * (t2.time - t1.time) + (t2.millitm - t1.millitm);
+ printf("Draw line: %d ms\n", timeElapsed);
+ }
+
+ // Draw & fill Rectangle
+ if (rectTest == 1)
+ {
+ // Draw
+ ftime(&t1);
+ for (i = 0; i < testSize; i++)
+ {
+ setupRect(cr, bench, 1);
+ cairo_stroke (cr);
+ }
+
+ ftime(&t2);
+ timeElapsed = 1000 * (t2.time - t1.time) + (t2.millitm - t1.millitm);
+ printf("Draw rectangle: %d ms\n", timeElapsed);
+
+ // Fill
+ ftime(&t1);
+ for (i = 0; i < testSize; i++)
+ {
+ setupRect(cr, bench, 0);
+ cairo_fill (cr);
+ }
+
+ ftime(&t2);
+ timeElapsed = 1000 * (t2.time - t1.time) + (t2.millitm - t1.millitm);
+ printf("Fill rectangle: %d ms\n", timeElapsed);
+ }
+
+ // Round rectangle: skip, it's just a combination of lines and curves
+ // Image: skip?
+
+ printf("\n");
+}
+
+GtkWidget *
+benchmark_new (void)
+{
+ return g_object_new (BENCHMARK_TYPE, NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+ // Set defaults
+ minSize = 10;
+ arcTest = 0;
+ curveTest = 0;
+ lineTest = 0;
+ rectTest = 0;
+ screenWidth = 320;
+ screenHeight = 240;
+ testSize = 1000;
+ antialias = 0;
+ lineWidth = 1;
+
+ // Process any command-line user options
+ int i;
+ for (i = 1; i < argc; i++)
+ {
+ // Process options first
+ if (!strcmp(argv[i], "-a"))
+ antialias = 1;
+ else if (!strcmp(argv[i], "-h"))
+ screenHeight = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-l"))
+ lineWidth = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-t"))
+ testSize = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-w"))
+ screenWidth = atoi(argv[++i]);
+ else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--h")
+ || !strcmp(argv[i], "-help") || !strcmp(argv[i], "--help"))
+ {
+ printf("Cairo benchmarker, meant to measure JNI overhead\n");
+ printf("Usage: bench [-a] [-h height] [-t test size] [-w width] [tests...]\n");
+ printf("\n");
+ printf(" Valid options: -a turn on anti-aliasing (default off)\n");
+ printf(" -h set screen height (default 240)\n");
+ printf(" -l set stroke line width (default 1)\n");
+ printf(" -t set test size (default 1000)\n");
+ printf(" -w set screen width (default 320)\n");
+ printf(" -h | --help\n");
+ printf(" Valid tests: arc\n");
+ printf(" curve\n");
+ printf(" line\n");
+ printf(" rect\n");
+ printf(" (default: run all)\n");
+ exit (0);
+ }
+
+ // Process tests
+ else if (!strcmp(argv[i], "arc"))
+ arcTest = 1;
+ else if (!strcmp(argv[i], "curve"))
+ curveTest = 1;
+ else if (!strcmp(argv[i], "line"))
+ lineTest = 1;
+ else if (!strcmp(argv[i], "rect"))
+ rectTest = 1;
+ }
+
+ // If no tests were specified, we default to running all of them
+ if (arcTest == 0 && curveTest == 0 && lineTest == 0 && rectTest == 0)
+ {
+ arcTest = 1;
+ curveTest = 1;
+ lineTest = 1;
+ rectTest = 1;
+ }
+
+ // Set up gtk widget
+ GtkWidget *window, *bench;
+ gtk_init (&argc, &argv);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_resize(GTK_WINDOW(window), screenWidth, screenHeight);
+ gtk_window_set_title(GTK_WINDOW(window), "cairo benchmark");
+
+ // Set up benchmkar and cairo surface
+ bench = benchmark_new ();
+ gtk_container_add (GTK_CONTAINER (window), bench);
+ gtk_widget_show_all (window);
+
+ cairo_t *cr;
+ cr = gdk_cairo_create (bench->window);
+
+ // Run tests
+ draw (bench, cr);
+
+ // Hold output on screen until user exits.
+ printf("Press any key to exit.\n");
+ getchar();
+ exit(0);
+gtk_main();
+}
diff --git a/examples/gnu/classpath/examples/java2d/bench.h b/examples/gnu/classpath/examples/java2d/bench.h
new file mode 100644
index 000000000..aebd50a67
--- /dev/null
+++ b/examples/gnu/classpath/examples/java2d/bench.h
@@ -0,0 +1,64 @@
+/* bench.h -- native benchmark for Cairo library (meant to test java2d)
+ Copyright (C) 2006 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. */
+
+#ifndef __BENCH_H__
+#define __BENCH_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BENCHMARK_TYPE (benchmark_get_type())
+#define BENCHMARK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj, BENCHMARK_TYPE, Benchmark)
+#define BENCHMARK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BENCHMARK_TYPE, BenchmarkClass);
+#define IS_BENCHMARK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BENCHMARK_TYPE))
+#define IS_BENCHMARK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BENCHMARK_TYPE))
+#define BENCHMARK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BENCHMARK_TYPE, BenchmarkClass))
+
+typedef struct _Benchmark Benchmark;
+typedef struct _BenchmarkClass BenchmarkClass;
+
+struct _Benchmark {
+ GtkDrawingArea parent;
+
+};
+
+struct _BenchmarkClass {
+ GtkDrawingAreaClass parent_class;
+};
+
+GType benchmark_get_type (void);
+GtkWidget *benchmark_new (void);
+
+static int minSize;
+static int antialias;
+static int arcTest;
+static int curveTest;
+static int lineTest;
+static int rectTest;
+
+static int screenHeight;
+static int screenWidth;
+static int testSize;
+static int lineWidth;
+
+G_END_DECLS
+
+#endif
diff --git a/examples/gnu/classpath/examples/management/TestBeans.java b/examples/gnu/classpath/examples/management/TestBeans.java
new file mode 100644
index 000000000..ad8234555
--- /dev/null
+++ b/examples/gnu/classpath/examples/management/TestBeans.java
@@ -0,0 +1,55 @@
+/* TestBeans.java -- Tests the dynamic interface of the beans.
+ Copyright (C) 2006 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.management;
+
+import java.lang.management.ManagementFactory;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.DynamicMBean;
+
+public class TestBeans
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ List beans = new ArrayList();
+ /* FIXME: When there's a server, this will be easier... :) */
+ beans.add(ManagementFactory.getOperatingSystemMXBean());
+ beans.add(ManagementFactory.getRuntimeMXBean());
+ beans.add(ManagementFactory.getThreadMXBean());
+ beans.add(ManagementFactory.getCompilationMXBean());
+ beans.add(ManagementFactory.getClassLoadingMXBean());
+ beans.add(ManagementFactory.getMemoryMXBean());
+ beans.addAll(ManagementFactory.getMemoryPoolMXBeans());
+ beans.addAll(ManagementFactory.getMemoryManagerMXBeans());
+ beans.addAll(ManagementFactory.getGarbageCollectorMXBeans());
+ Iterator it = beans.iterator();
+ while (it.hasNext())
+ {
+ DynamicMBean bean = (DynamicMBean) it.next();
+ if (bean != null)
+ System.out.println(bean.getMBeanInfo());
+ }
+ }
+}
diff --git a/examples/gnu/classpath/examples/swing/Demo.java b/examples/gnu/classpath/examples/swing/Demo.java
index ad20fec7e..19bc27c1d 100644
--- a/examples/gnu/classpath/examples/swing/Demo.java
+++ b/examples/gnu/classpath/examples/swing/Demo.java
@@ -30,6 +30,7 @@ import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
+import javax.swing.plaf.basic.BasicLookAndFeel;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.MetalTheme;
@@ -192,6 +193,10 @@ public class Demo
}
});
+ // Installs the BasicLookAndFeel.
+ UIManager.installLookAndFeel("(Basic Look And Feel)",
+ InstantiableBasicLookAndFeel.class.getName());
+
// Create L&F menu.
JMenu lafMenu = new JMenu("Look and Feel");
ButtonGroup lafGroup = new ButtonGroup();
@@ -662,10 +667,45 @@ public class Demo
{
ex.printStackTrace();
}
+
SwingUtilities.updateComponentTreeUI(frame);
themesMenu.setEnabled(laf.getClassName()
.equals("javax.swing.plaf.metal.MetalLookAndFeel"));
}
+ }
+ /**
+ * An implementation of BasicLookAndFeel which can be instantiated.
+ *
+ * @author Robert Schuster (robertschuster@fsfe.org)
+ *
+ */
+ public static class InstantiableBasicLookAndFeel extends BasicLookAndFeel
+ {
+ public String getDescription()
+ {
+ return "An instantiable implementation of BasicLookAndFeel";
+ }
+
+ public String getID()
+ {
+ return "instantiableBasicLookAndFeel";
+ }
+
+ public String getName()
+ {
+ return "Instantiable Basic Look And Feel";
+ }
+
+ public boolean isNativeLookAndFeel()
+ {
+ return false;
+ }
+
+ public boolean isSupportedLookAndFeel()
+ {
+ return true;
+ }
}
+
}
diff --git a/examples/gnu/classpath/examples/swing/HtmlDemo.java b/examples/gnu/classpath/examples/swing/HtmlDemo.java
index 988b0bd0e..223ee07cd 100644
--- a/examples/gnu/classpath/examples/swing/HtmlDemo.java
+++ b/examples/gnu/classpath/examples/swing/HtmlDemo.java
@@ -52,6 +52,8 @@ import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
+import javax.swing.text.Element;
+import javax.swing.text.html.HTMLDocument;
/**
* Parses and displays HTML content.
@@ -63,14 +65,17 @@ public class HtmlDemo extends JPanel
JTextPane html = new JTextPane();
- JTextArea text = new JTextArea("<html><body><p>" +
+ JTextArea text = new JTextArea("<html><body>" +
"123456789HR!<hr>987654321"+
"123456789BR!<br>987654321"+
+ "<p id='insertHere'>Insertion target</p><p>"+
"<font color=red>ma</font>"+
"<sup>sup</sup>normal<sub>sub</sub>normal</p><p>Table:"+
"<table><tr>a<td>b<td>c<tr>x<td>y<td>z</table></body></html>");
JPanel buttons;
+
+ int n;
public HtmlDemo()
{
@@ -111,7 +116,131 @@ public class HtmlDemo extends JPanel
});
buttons.add(parse);
+
+ JButton insertBeforeEnd = new JButton("before end");
+ insertBeforeEnd.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ HTMLDocument doc = (HTMLDocument) html.getDocument();
+ Element el = doc.getElement("insertHere");
+ System.out.println("Element found:"+el);
+ try
+ {
+ doc.insertBeforeEnd(el,"before end "+(n++));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ JButton insertBeforeStart = new JButton("before start");
+ insertBeforeStart.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ HTMLDocument doc = (HTMLDocument) html.getDocument();
+ Element el = doc.getElement("insertHere");
+ System.out.println("Element found:"+el);
+ try
+ {
+ doc.insertBeforeStart(el,"before start "+(n++));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ JButton insertAfterEnd = new JButton("after end");
+ insertAfterEnd.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ HTMLDocument doc = (HTMLDocument) html.getDocument();
+ Element el = doc.getElement("insertHere");
+ System.out.println("Element found:"+el);
+ try
+ {
+ doc.insertAfterEnd(el,"after end "+(n++));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ JButton insertAfterStart = new JButton("after start");
+ insertAfterStart.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ HTMLDocument doc = (HTMLDocument) html.getDocument();
+ Element el = doc.getElement("insertHere");
+ System.out.println("Element found:"+el);
+ try
+ {
+ doc.insertAfterStart(el,"after start "+(n++));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+
+ JButton setInner = new JButton("inner");
+ setInner.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ HTMLDocument doc = (HTMLDocument) html.getDocument();
+ Element el = doc.getElement("insertHere");
+ System.out.println("Element found:"+el);
+ try
+ {
+ doc.setInnerHTML(el,"inner "+(n++));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ JButton setOuter = new JButton("outer");
+ setOuter.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event)
+ {
+ HTMLDocument doc = (HTMLDocument) html.getDocument();
+ Element el = doc.getElement("insertHere");
+ System.out.println("Element found:"+el);
+ try
+ {
+ doc.setOuterHTML(el,"outer "+(n++));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ buttons.add(insertBeforeStart);
+ buttons.add(insertAfterStart);
+ buttons.add(insertBeforeEnd);
+ buttons.add(insertAfterEnd);
+
+ buttons.add(setInner);
+ buttons.add(setOuter);
+
add(center, BorderLayout.CENTER);
add(buttons, BorderLayout.SOUTH);
}
@@ -144,7 +273,7 @@ public class HtmlDemo extends JPanel
JFrame frame = new JFrame();
frame.getContentPane().add(demo);
- frame.setSize(new Dimension(640, 480));
+ frame.setSize(new Dimension(700, 480));
frame.setVisible(true);
}
});