[cp-patches] FYI: Reentrant GDK lock

2007-04-03 Thread Roman Kennke
This patch makes the GDK lock reentrant. Basically it replaces the
portableNativeSync functionality by a simple new implementation. As of
GTK 2.4 (according to the docs), there is a function
gdk_threads_set_lock_functions() which allows to define a pair of
functions for locking and unlocking. I implemented it so that it uses
JNI MonitorEnter() and MonitorExit() on a global object in GtkToolkit.
It can be activated by setting the system property
gnu.classpath.awt.gtk.portable.native.sync to true. It completely
obsoletes a whole bunch of code, I'll remove that later.

This has a couple of advantages:
- The gdk_threads_enter() and gdk_threads_leave() are reentrant with
this enabled, by making use of the VM's locking impl.
- It is possible to easily lock on the Java side by using
synchronized(GtkToolkit.GTK_LOCK) now. ComponentGraphics says hi! Should
boost performance even.
- It should allow to cleanup a lot of workarounds.

For now this is not enabled by default. I propose to thouroughly test
this and make it default when things turn out to work. I tested the
Swing, AWT and Java2D demo as well as some JOGL pieces (which originally
caused problems with the JAWT Lock/Unlock functions) and those seem to
work well with this. Maybe turn on default after the release and weed
out issues in the following cycle.

Cheers, Roman

-- 
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-0

USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
Index: include/gnu_java_awt_peer_gtk_GtkToolkit.h
===
RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_GtkToolkit.h,v
retrieving revision 1.15
diff -u -1 -5 -r1.15 gnu_java_awt_peer_gtk_GtkToolkit.h
--- include/gnu_java_awt_peer_gtk_GtkToolkit.h	3 Jan 2007 22:51:07 -	1.15
+++ include/gnu_java_awt_peer_gtk_GtkToolkit.h	3 Apr 2007 13:38:54 -
@@ -1,28 +1,28 @@
 /* DO NOT EDIT THIS FILE - it is machine generated */
 
 #ifndef __gnu_java_awt_peer_gtk_GtkToolkit__
 #define __gnu_java_awt_peer_gtk_GtkToolkit__
 
 #include jni.h
 
 #ifdef __cplusplus
 extern C
 {
 #endif
 
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env, jclass, jint);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env, jclass, jint, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain (JNIEnv *env, jclass);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit (JNIEnv *env, jclass);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_beep (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenSizeDimensions (JNIEnv *env, jobject, jintArray);
 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_sync (JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors (JNIEnv *env, jobject, jintArray);
 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getLockState (JNIEnv *env, jobject, jint);
 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons (JNIEnv *env, jobject);
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* __gnu_java_awt_peer_gtk_GtkToolkit__ */
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
===
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c,v
retrieving revision 1.33
diff -u -1 -5 -r1.33 gnu_java_awt_peer_gtk_GtkToolkit.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c	29 Mar 2007 20:24:51 -	1.33
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c	3 Apr 2007 13:38:54 -
@@ -1,15 +1,16 @@
+
 /* gtktoolkit.c -- Native portion of GtkToolkit
Copyright (C) 1998, 1999, 2005, 2007  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.
 
@@ -76,104 +77,112 @@
 #define VK_SHIFT 16
 #define VK_CONTROL 17
 #define VK_ALT 18
 #define VK_CAPS_LOCK 20
 #define VK_META 157
 
 struct state_table *cp_gtk_native_state_table;
 struct state_table *cp_gtk_native_global_ref_table;
 
 static jclass gtkgenericpeer;
 static jclass gtktoolkit;
 static JavaVM *java_vm;
 static jmethodID printCurrentThreadID;
 static jmethodID 

[cp-patches] [RFA] Add ArrayValue for JDWP

2007-04-03 Thread Kyle Galloway
JDWP needs to distinguish between and Object and an Array to properly 
get and set values, so this patch adds the ArrayValue type, which is 
used for this purpose.  It is very similar to ObjectValue, but with a 
different tag value.


ChangeLog
2007-04-03  Kyle Galloway  [EMAIL PROTECTED]

   * gnu/classpath/jdwp/value/ArrayValue.java: New file.

Questions/comments/concerns?

Thanks,
Kyle



Re: [cp-patches] [RFA] Add ArrayValue for JDWP

2007-04-03 Thread Kyle Galloway

Sometimes, it helps to attach a patch :-).

Kyle Galloway wrote:
JDWP needs to distinguish between and Object and an Array to properly 
get and set values, so this patch adds the ArrayValue type, which is 
used for this purpose.  It is very similar to ObjectValue, but with a 
different tag value.


ChangeLog
2007-04-03  Kyle Galloway  [EMAIL PROTECTED]

   * gnu/classpath/jdwp/value/ArrayValue.java: New file.

Questions/comments/concerns?

Thanks,
Kyle



### Eclipse Workspace Patch 1.0
#P GNU Classpath
Index: gnu/classpath/jdwp/value/ArrayValue.java
===
RCS file: gnu/classpath/jdwp/value/ArrayValue.java
diff -N gnu/classpath/jdwp/value/ArrayValue.java
--- /dev/null	1 Jan 1970 00:00:00 -
+++ gnu/classpath/jdwp/value/ArrayValue.java	1 Jan 1970 00:00:00 -
@@ -0,0 +1,92 @@
+/* ObjectValue.java -- JDWP wrapper class for an Object value
+   Copyright (C) 2007 Free Software Foundation
+
+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.jdwp.value;
+
+import gnu.classpath.jdwp.JdwpConstants;
+import gnu.classpath.jdwp.VMIdManager;
+import gnu.classpath.jdwp.id.ObjectId;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+/**
+ * Wrapper for an Array value.
+ * 
+ * @author Kyle Galloway [EMAIL PROTECTED]
+ */
+public class ArrayValue
+extends Value
+{
+  // The Array wrapped by this class represented as a Object
+  Object _value;
+
+  /**
+   * Create a new ArrayValue from an Object
+   * 
+   * @param value the Object to wrap
+   */
+  public ArrayValue(Object value)
+  {
+super(JdwpConstants.Tag.ARRAY);
+_value = value;
+  }
+  
+  /**
+   * Return an object representing this type
+   * 
+   * @return an Object represntation of this value
+   */
+  @Override
+  protected Object getObject()
+  {
+return _value;
+  }
+
+  /**
+   * Write the wrapped object to the given DataOutputStream.
+   * 
+   * @param os the output stream to write to
+   */
+  @Override
+  protected void write(DataOutputStream os)
+throws IOException
+  {
+ObjectId oid = VMIdManager.getDefault().getObjectId(_value);
+oid.write(os);
+  }
+}


Re: [cp-patches] FYI: Reentrant GDK lock

2007-04-03 Thread Thomas Fitzsimmons

Hi Roman,

Roman Kennke wrote:

This patch makes the GDK lock reentrant. Basically it replaces the
portableNativeSync functionality by a simple new implementation. As of
GTK 2.4 (according to the docs), there is a function
gdk_threads_set_lock_functions() which allows to define a pair of
functions for locking and unlocking. I implemented it so that it uses
JNI MonitorEnter() and MonitorExit() on a global object in GtkToolkit.
It can be activated by setting the system property
gnu.classpath.awt.gtk.portable.native.sync to true. It completely
obsoletes a whole bunch of code, I'll remove that later.

This has a couple of advantages:
- The gdk_threads_enter() and gdk_threads_leave() are reentrant with
this enabled, by making use of the VM's locking impl.
- It is possible to easily lock on the Java side by using
synchronized(GtkToolkit.GTK_LOCK) now. ComponentGraphics says hi! Should
boost performance even.
- It should allow to cleanup a lot of workarounds.

For now this is not enabled by default. I propose to thouroughly test
this and make it default when things turn out to work.


This may make sense for portableNativeSync -- have you talked to the JikesRVM 
developers about this change?  I don't think making it the default is a good 
idea though, for two reasons:


1) It eliminates the possibility of using the GTK AWT peers in the same process
   as another GTK-using toolkit.  We've already hit this problem because SWT
   does something similar to what you're proposing:

   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25375
   https://bugs.eclipse.org/bugs/show_bug.cgi?id=139468

2) Most GDK-using applications use the default non-reentrant lock, which means
   that reentrant code paths through GDK won't have been as well-tested.  If all
   AWT apps start using these code paths then this opens up the possibility of
   more subtle race conditions being exposed (we've had to track down many over
   the years, in our GTK peers and in components of GNOME).

If we really want a reentrant GDK lock then I think we should propose the change 
to GDK itself.  SWT would likely adopt the result (resolving those bug reports) 
and the GDK maintainers could help audit the current GDK/GTK code to eliminate 
reentrancy problems.  Once that work has landed in GDK we'll be able to simplify 
our peer code.


Tom


I tested the
Swing, AWT and Java2D demo as well as some JOGL pieces (which originally
caused problems with the JAWT Lock/Unlock functions) and those seem to
work well with this.  Maybe turn on default after the release and weed
out issues in the following cycle.

Cheers, Roman





Index: include/gnu_java_awt_peer_gtk_GtkToolkit.h
===
RCS file: 
/cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_GtkToolkit.h,v
retrieving revision 1.15
diff -u -1 -5 -r1.15 gnu_java_awt_peer_gtk_GtkToolkit.h
--- include/gnu_java_awt_peer_gtk_GtkToolkit.h  3 Jan 2007 22:51:07 -   
1.15
+++ include/gnu_java_awt_peer_gtk_GtkToolkit.h  3 Apr 2007 13:38:54 -
@@ -1,28 +1,28 @@
 /* DO NOT EDIT THIS FILE - it is machine generated */
 
 #ifndef __gnu_java_awt_peer_gtk_GtkToolkit__

 #define __gnu_java_awt_peer_gtk_GtkToolkit__
 
 #include jni.h
 
 #ifdef __cplusplus

 extern C
 {
 #endif
 
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env, jclass, jint);

+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv 
*env, jclass, jint, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkMain (JNIEnv 
*env, jclass);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkQuit (JNIEnv 
*env, jclass);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_beep (JNIEnv 
*env, jobject);
 JNIEXPORT void JNICALL 
Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenSizeDimensions (JNIEnv *env, 
jobject, jintArray);
 JNIEXPORT jint JNICALL 
Java_gnu_java_awt_peer_gtk_GtkToolkit_getScreenResolution (JNIEnv *env, 
jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_sync (JNIEnv 
*env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_loadSystemColors 
(JNIEnv *env, jobject, jintArray);
 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_gtk_GtkToolkit_getLockState 
(JNIEnv *env, jobject, jint);
 JNIEXPORT jint JNICALL 
Java_gnu_java_awt_peer_gtk_GtkToolkit_getMouseNumberOfButtons (JNIEnv *env, 
jobject);
 
 #ifdef __cplusplus

 }
 #endif
 
 #endif /* __gnu_java_awt_peer_gtk_GtkToolkit__ */

Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
===
RCS file: 
/cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c,v
retrieving revision 1.33
diff -u -1 -5 -r1.33 gnu_java_awt_peer_gtk_GtkToolkit.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c  29 Mar 2007 
20:24:51 -   

Re: [cp-patches] [RFA] Add ArrayValue for JDWP

2007-04-03 Thread Keith Seitz

Kyle Galloway wrote:


ChangeLog
2007-04-03  Kyle Galloway  [EMAIL PROTECTED]

   * gnu/classpath/jdwp/value/ArrayValue.java: New file.

Questions/comments/concerns?


Looks good. Please commit.

Keith



Re: [cp-patches] [RFA] Add ArrayValue for JDWP

2007-04-03 Thread Kyle Galloway

Keith Seitz wrote:

Kyle Galloway wrote:


ChangeLog
2007-04-03  Kyle Galloway  [EMAIL PROTECTED]

   * gnu/classpath/jdwp/value/ArrayValue.java: New file.

Questions/comments/concerns?


Looks good. Please commit. 

Committed, thanks.

Kyle




Re: [cp-patches] FYI: Font substitution

2007-04-03 Thread Francis Kung
I've run through a number of tests and have not noticed any 
regressions in performance or functionality, but please let me know if 
there are any problems.


That didn't take long.  This patch clears up a null pointer exception 
introduced by the last patch.




One last one, a tiny fix for people with --enable-regen-headers

Francis


2007-04-03  Francis Kung  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(getGlyphs(int[], int[], long[])): Return void.

Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.18
diff -u -r1.18 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	2 Apr 2007 21:28:58 -	1.18
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	3 Apr 2007 19:30:10 -
@@ -234,7 +234,7 @@
   /**
* Returns the glyph code within the font for a given character
*/
-  public native int[] getGlyphs(int[] codepoints, int[] glyphs, long[] fonts);
+  public native void getGlyphs(int[] codepoints, int[] glyphs, long[] fonts);
 
   /**
* Returns the kerning of a glyph pair


Re: [cp-patches] FYI: Reentrant GDK lock

2007-04-03 Thread Roman Kennke
Hi Thomas,

 For now this is not enabled by default. I propose to thouroughly test
  this and make it default when things turn out to work.
 
 This may make sense for portableNativeSync -- have you talked to the JikesRVM 
 developers about this change?  I don't think making it the default is a good 
 idea though, for two reasons:
 
 1) It eliminates the possibility of using the GTK AWT peers in the same 
 process
 as another GTK-using toolkit.  We've already hit this problem because SWT
 does something similar to what you're proposing:
 
 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25375
 https://bugs.eclipse.org/bugs/show_bug.cgi?id=139468
 
 2) Most GDK-using applications use the default non-reentrant lock, which means
 that reentrant code paths through GDK won't have been as well-tested.  If 
 all
 AWT apps start using these code paths then this opens up the possibility 
 of
 more subtle race conditions being exposed (we've had to track down many 
 over
 the years, in our GTK peers and in components of GNOME).
 
 If we really want a reentrant GDK lock then I think we should propose the 
 change 
 to GDK itself.  SWT would likely adopt the result (resolving those bug 
 reports) 
 and the GDK maintainers could help audit the current GDK/GTK code to 
 eliminate 
 reentrancy problems.  Once that work has landed in GDK we'll be able to 
 simplify 
 our peer code.

I agree with that. I've filed a bugreport for GDK. Let's see how it
works out.

http://bugzilla.gnome.org/show_bug.cgi?id=425995

/Roman
-- 
http://kennke.org/blog/




[cp-patches] FYI: Some cvsignores

2007-04-03 Thread Roman Kennke
There were some .cvsignores missing. Here they are.

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* native/target/.cvsignore,
* native/target/Linux/.cvsignore,
* native/target/generic/.cvsignore: Some new ignores.

/Roman

-- 
http://kennke.org/blog/
Index: native/target/.cvsignore
===
RCS file: native/target/.cvsignore
diff -N native/target/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -
+++ native/target/.cvsignore	3 Apr 2007 20:17:47 -
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: native/target/Linux/.cvsignore
===
RCS file: native/target/Linux/.cvsignore
diff -N native/target/Linux/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -
+++ native/target/Linux/.cvsignore	3 Apr 2007 20:17:47 -
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: native/target/generic/.cvsignore
===
RCS file: native/target/generic/.cvsignore
diff -N native/target/generic/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -
+++ native/target/generic/.cvsignore	3 Apr 2007 20:17:47 -
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in


[cp-patches] FYI: Metal fixlets

2007-04-03 Thread Roman Kennke
Ok, I've got to flush some older patches. These are a small bunch of
minor fixes for the Metal LF.

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/plaf/metal/MetalButtonUI.java
(paintButtonPressed): Fill the whole button not only visibleRect.
* javax/swing/plaf/metal/MetalLookAndFeel.java
(LAF_defaults): Removed.
(getDefaults): Always fetch super's defaults.
* javax/swing/plaf/metal/MetalMenuBarUI.java
(update): Don't leave 2 pixel gap.

/Roman

-- 
http://kennke.org/blog/
Index: javax/swing/plaf/metal/MetalButtonUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalButtonUI.java,v
retrieving revision 1.20
diff -u -1 -5 -r1.20 MetalButtonUI.java
--- javax/swing/plaf/metal/MetalButtonUI.java	22 Aug 2006 11:23:58 -	1.20
+++ javax/swing/plaf/metal/MetalButtonUI.java	3 Apr 2007 20:26:19 -
@@ -162,33 +162,32 @@
 // This is overridden to be public, for whatever reason.
 super.uninstallDefaults(button);
   }
 
   /**
* Paints the background of the button to indicate that it is in the
* pressed state.
* 
* @param g  the graphics context.
* @param b  the button.
*/
   protected void paintButtonPressed(Graphics g, AbstractButton b) 
   { 
 if (b.isContentAreaFilled())
 {
-  Rectangle area = b.getVisibleRect();
   g.setColor(getSelectColor());
-  g.fillRect(area.x, area.y, area.width, area.height);
+  g.fillRect(0, 0, b.getWidth(), b.getHeight());
 }
   }
 
   /** 
* Paints the focus rectangle around the button text and/or icon.
* 
* @param g  the graphics context.
* @param b  the button.
* @param viewRect  the button bounds.
* @param textRect  the text bounds.
* @param iconRect  the icon bounds.
*/
   protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
   Rectangle textRect, Rectangle iconRect) 
   {
Index: javax/swing/plaf/metal/MetalLookAndFeel.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java,v
retrieving revision 1.88
diff -u -1 -5 -r1.88 MetalLookAndFeel.java
--- javax/swing/plaf/metal/MetalLookAndFeel.java	10 Dec 2006 20:25:48 -	1.88
+++ javax/swing/plaf/metal/MetalLookAndFeel.java	3 Apr 2007 20:26:19 -
@@ -63,33 +63,30 @@
  * {
  * nbsp;nbsp;UIManager.setLookAndFeel(new MetalLookAndFeel());
  * }
  * catch (UnsupportedLookAndFeelException e)
  * {
  * nbsp;nbsp;e.printStackTrace();
  * }/pre
  */
 public class MetalLookAndFeel extends BasicLookAndFeel
 {  
   private static final long serialVersionUID = 6680646159193457980L;
   
   /** The current theme. */
   private static MetalTheme theme;
   
-  /** The look and feel defaults. */
-  private UIDefaults LAF_defaults;
-
   /**
* Creates a new instance of the Metal look and feel.
*/
   public MetalLookAndFeel()
   {
 // Nothing to do here.
   }
 
   /**
* Sets the current theme to a new instance of [EMAIL PROTECTED] DefaultMetalTheme}.
*/
   protected void createDefaultTheme()
   {
 getCurrentTheme();
   }
@@ -139,41 +136,34 @@
   }
 
   /**
* Returns the look and feel name.
* 
* @return MetalLookAndFeel.
*/
   public String getName()
   {
 return Metal;
   }
 
   public UIDefaults getDefaults()
   {
 createDefaultTheme();
-if (LAF_defaults == null)
-  {
-LAF_defaults = super.getDefaults();
+UIDefaults def = super.getDefaults();
 
-// add custom theme entries to the table
-if (theme != null)
-  theme.addCustomEntriesToTable(LAF_defaults);
-  }
-
-// Returns the default values for this look and feel. 
-return LAF_defaults;
+theme.addCustomEntriesToTable(def);
+return def;
   }
 
   /**
* Returns the accelerator foreground color from the installed theme.
* 
* @return The accelerator foreground color.
*/
   public static ColorUIResource getAcceleratorForeground()
   {
 if (theme != null)
   return theme.getAcceleratorForeground();
 return null;
   }
 
   /**
Index: javax/swing/plaf/metal/MetalMenuBarUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java,v
retrieving revision 1.3
diff -u -1 -5 -r1.3 MetalMenuBarUI.java
--- javax/swing/plaf/metal/MetalMenuBarUI.java	3 Aug 2006 22:29:09 -	1.3
+++ javax/swing/plaf/metal/MetalMenuBarUI.java	3 Apr 2007 20:26:19 -
@@ -70,25 +70,25 @@
 
 
   /**
* If the property codeMenuBar.gradient/code is set, then a gradient
* is painted as background, otherwise the normal superclass behaviour is
* called.
*/
   public void update(Graphics g, JComponent c)
   {
 int height = c.getHeight();
 if (c.isOpaque()
  UIManager.get(MenuBar.gradient) 

[cp-patches] FYI: BasicLabelUI

2007-04-03 Thread Roman Kennke
This improves the BasicLabelUI:
- It caches the Insets instance.
- It makes the font metrics fetching more fail-safe.
- It removes the graphics color restoring, this is already performed by
Swing's painting mechanism.

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicLabelUI.java
(cachedInsets): New field. Used for reusing the insets instance.
(getFontMetrics): New helper method for fetching a suitable
FontMetrics object.
(getPreferredSize): Use new helper method for font metrics.
(paint): Only do something if we have an icon or text.
Use cached Insets instance and new font metrics helper.
(paintDisabledText): Don't restore the graphics' color.
(paintEnabledText): Don't restore the graphics' color.

/Roman

-- 
http://kennke.org/blog/
Index: javax/swing/plaf/basic/BasicLabelUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicLabelUI.java,v
retrieving revision 1.25
diff -u -1 -5 -r1.25 BasicLabelUI.java
--- javax/swing/plaf/basic/BasicLabelUI.java	17 Aug 2006 14:45:46 -	1.25
+++ javax/swing/plaf/basic/BasicLabelUI.java	3 Apr 2007 20:33:19 -
@@ -25,73 +25,80 @@
 
  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 javax.swing.plaf.basic;
 
-import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Rectangle;
+import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
 import javax.swing.AbstractAction;
 import javax.swing.ActionMap;
 import javax.swing.Icon;
 import javax.swing.InputMap;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.KeyStroke;
 import javax.swing.LookAndFeel;
 import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.LabelUI;
 import javax.swing.text.View;
 
 /**
  * This is the Basic Look and Feel class for the JLabel.  One BasicLabelUI
  * object is used to paint all JLabels that utilize the Basic Look and Feel.
  */
 public class BasicLabelUI extends LabelUI implements PropertyChangeListener
 {
   /** The labelUI that is shared by all labels. */
   protected static BasicLabelUI labelUI;
 
   /**
* These fields hold the rectangles for the whole label,
* the icon and the text.
*/
   private Rectangle vr;
   private Rectangle ir;
   private Rectangle tr;
 
   /**
+   * A cached Insets object for reuse in the label layout methods.
+   */
+  private Insets cachedInsets;
+
+  /**
* Creates a new BasicLabelUI object.
*/
   public BasicLabelUI()
   {
 super();
 vr = new Rectangle();
 ir = new Rectangle();
 tr = new Rectangle();
   }
 
   /**
* Creates and returns a UI for the label. Since one UI is shared by  all
* labels, this means creating only if necessary and returning the  shared
* UI.
*
@@ -119,31 +126,31 @@
   {
 JLabel lab = (JLabel) c;
 Insets insets = lab.getInsets();
 int insetsX = insets.left + insets.right;
 int insetsY = insets.top + insets.bottom;
 Icon icon = lab.getIcon();
 String text = lab.getText();
 Dimension ret;
 if (icon == null  text == null)
   ret = new Dimension(insetsX, insetsY);
 else if (icon != null  text == null)
   ret = new Dimension(icon.getIconWidth() + insetsX,
   icon.getIconHeight() + insetsY);
 else
   {
-FontMetrics fm = lab.getFontMetrics(lab.getFont());
+FontMetrics fm = getFontMetrics(lab);
 ir.x = 0;
 ir.y = 0;
 ir.width = 0;
 ir.height = 0;
 tr.x = 0;
 tr.y = 0;
 tr.width = 0;
 tr.height = 0;
 vr.x = 0;
 vr.y = 0;
 vr.width = Short.MAX_VALUE;
 vr.height = Short.MAX_VALUE;
 layoutCL(lab, fm, text, icon, vr, ir, tr);
 Rectangle cr = SwingUtilities.computeUnion(tr.x, tr.y, tr.width,
tr.height, ir);
@@ -177,67 

[cp-patches] FYI: BasicTreeUI fix

2007-04-03 Thread Roman Kennke
This fixes BasicTreeUI.getPathBounds() to also consider the tree's
insets, plus it adds a bunch of null checks for safety (all of this
stuff is public API and can thus be overridden to return null, so...).

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicTreeUI.java
(getPathBounds): Consider the tree's insets. Added a bunch of
null checks.

/Roman

-- 
http://kennke.org/blog/
Index: javax/swing/plaf/basic/BasicTreeUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.156
diff -u -1 -5 -r1.156 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	10 Dec 2006 20:25:48 -	1.156
+++ javax/swing/plaf/basic/BasicTreeUI.java	3 Apr 2007 20:40:32 -
@@ -104,31 +104,31 @@
 import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 import javax.swing.tree.TreeSelectionModel;
 import javax.swing.tree.VariableHeightLayoutCache;
 
 /**
  * A delegate providing the user interface for codeJTree/code according to
  * the Basic look and feel.
  * 
  * @see javax.swing.JTree
  * @author Lillian Angel ([EMAIL PROTECTED])
  * @author Sascha Brawer ([EMAIL PROTECTED])
  * @author Audrius Meskauskas ([EMAIL PROTECTED])
  */
 public class BasicTreeUI
-extends TreeUI
+  extends TreeUI
 {
   /**
* The tree cell editing may be started by the single mouse click on the
* selected cell. To separate it from the double mouse click, the editing
* session starts after this time (in ms) after that single click, and only no
* other clicks were performed during that time.
*/
   static int WAIT_TILL_EDITING = 900;
 
   /** Collapse Icon for the tree. */
   protected transient Icon collapsedIcon;
 
   /** Expanded Icon for the tree. */
   protected transient Icon expandedIcon;
 
@@ -644,31 +644,42 @@
 return treeSelectionModel;
   }
 
   /**
* Returns the Rectangle enclosing the label portion that the last item in
* path will be drawn to. Will return null if any component in path is
* currently valid.
* 
* @param tree is the current tree the path will be drawn to.
* @param path is the current path the tree to draw to.
* @return the Rectangle enclosing the label portion that the last item in the
* path will be drawn to.
*/
   public Rectangle getPathBounds(JTree tree, TreePath path)
   {
-return treeState.getBounds(path, new Rectangle());
+Rectangle bounds = null;
+if (tree != null  treeState != null)
+  {
+bounds = treeState.getBounds(path, null);
+Insets i = tree.getInsets();
+if (bounds != null  i != null)
+  {
+bounds.x += i.left;
+bounds.y += i.top;
+  }
+  }
+return bounds;
   }
 
   /**
* Returns the max height of all the nodes in the tree.
* 
* @param tree - the current tree
* @return the max height.
*/
   int getMaxHeight(JTree tree)
   {
 if (maxHeight != 0)
   return maxHeight;
 
 Icon e = UIManager.getIcon(Tree.openIcon);
 Icon c = UIManager.getIcon(Tree.closedIcon);
@@ -1549,31 +1560,30 @@
 int rows = treeState.getRowCount();
 
 if (rows == 0)
   // There is nothing to do if the tree is empty.
   return;
 
 Rectangle clip = g.getClipBounds();
 
 Insets insets = tree.getInsets();
 
 if (clip != null  treeModel != null)
   {
 int startIndex = tree.getClosestRowForLocation(clip.x, clip.y);
 int endIndex = tree.getClosestRowForLocation(clip.x + clip.width,
  clip.y + clip.height);
-
 // Also paint dashes to the invisible nodes below.
 // These should be painted first, otherwise they may cover
 // the control icons.
 if (endIndex  rows)
   for (int i = endIndex + 1; i  rows; i++)
 {
   TreePath path = treeState.getPathForRow(i);
   if (isLastChild(path))
 paintVerticalPartOfLeg(g, clip, insets, path);
 }
 
 // The two loops are required to ensure that the lines are not
 // painted over the other tree components.
 
 int n = endIndex - startIndex + 1;


Re: [cp-patches] FYI: Avoid possible NPE ByteOrder

2007-04-03 Thread Roman Kennke
Hi,

 This avoids a possible NPE when the byteorder system property is not
 set.

Some people argued (on IRC IIRC) that we should rather let this fail if
the property is not setup correcly. I think I agree and revert that like
attached.

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* java/nio/ByteOrder.java
(nativeByteOrder): Let this fail when the corresponding
property is not set properly.
/Roman

-- 
http://kennke.org/blog/
Index: java/nio/ByteOrder.java
===
RCS file: /cvsroot/classpath/classpath/java/nio/ByteOrder.java,v
retrieving revision 1.12
diff -u -1 -5 -r1.12 ByteOrder.java
--- java/nio/ByteOrder.java	15 Feb 2007 10:38:30 -	1.12
+++ java/nio/ByteOrder.java	3 Apr 2007 20:56:25 -
@@ -49,31 +49,33 @@
*/
   public static final ByteOrder BIG_ENDIAN = new ByteOrder();
 
   /**
* Constant indicating little endian byte order.
*/
   public static final ByteOrder LITTLE_ENDIAN = new ByteOrder();
 
   /**
* Returns the native byte order of the platform currently running.
*
* @return the native byte order
*/
   public static ByteOrder nativeOrder()
   {
-return (big.equals(System.getProperty(gnu.cpu.endian))
+// Let this fail with an NPE when the property is not set correctly.
+// Otherwise we risk that NIO is silently working wrong.
+return (System.getProperty(gnu.cpu.endian).equals(big)
 ? BIG_ENDIAN : LITTLE_ENDIAN);
   }
 
   /**
* Returns a string representation of the byte order.
*
* @return the string
*/
   public String toString()
   {
 return this == BIG_ENDIAN ? BIG_ENDIAN : LITTLE_ENDIAN;
   }
 
   // This class can only be instantiated here.
   private ByteOrder()


[cp-patches] FYI: inheritedChannel() support

2007-04-03 Thread Roman Kennke
This has been lying around for a long time here. It implements the basic
inheritedChannel() infrastructure. The default implementation can't do
much more than return null (which is OK, and actually what the JDK does
for me). If a VM can do something more useful here, it would have to
provide its own SelectorProvider. I didn't feel like introducing some
kind of VMXYZ method here, because we already have a fine abstraction
via the SPI.

2007-04-03  Roman Kennke  [EMAIL PROTECTED]

* java/lang/System.java
(inheritedChannel): New method, wraps
SelectorProvider.inheritedChannel().
* java/nio/channels/spi/SelectorProvider.java
(inheritedChannel): New abstract method.
* gnu/java/nio/SelectorProviderImpl.java
(inheritedChannel): New method, return null as default.


-- 
http://kennke.org/blog/
Index: java/lang/System.java
===
RCS file: /cvsroot/classpath/classpath/java/lang/System.java,v
retrieving revision 1.60
diff -u -1 -5 -r1.60 System.java
--- java/lang/System.java	23 Feb 2007 15:50:04 -	1.60
+++ java/lang/System.java	3 Apr 2007 21:26:17 -
@@ -30,32 +30,35 @@
 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 java.lang;
 
 import gnu.classpath.SystemProperties;
 import gnu.classpath.VMStackWalker;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.channels.Channel;
+import java.nio.channels.spi.SelectorProvider;
 import java.util.AbstractCollection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.Properties;
 import java.util.PropertyPermission;
 
 /**
  * System represents system-wide resources; things that represent the
  * general environment.  As such, all methods are static.
  *
@@ -660,30 +663,49 @@
   VMStackWalker.getCallingClassLoader());
   }
 
   /**
* Convert a library name to its platform-specific variant.
*
* @param libname the library name, as used in codeloadLibrary/code
* @return the platform-specific mangling of the name
* @since 1.2
*/
   public static String mapLibraryName(String libname)
   {
 return VMRuntime.mapLibraryName(libname);
   }
 
+  /**
+   * Returns the inherited channel of the VM.
+   *
+   * This wraps the inheritedChannel() call of the system's default
+   * [EMAIL PROTECTED] SelectorProvider}.
+   *
+   * @return the inherited channel of the VM
+   *
+   * @throws IOException If an I/O error occurs
+   * @throws SecurityException If an installed security manager denies access
+   * to RuntimePermission(inheritedChannel)
+   *
+   * @since 1.5
+   */
+  public static Channel inheritedChannel()
+throws IOException
+  {
+return SelectorProvider.provider().inheritedChannel();
+  }
 
   /**
* This is a specialised codeCollection/code, providing
* the necessary provisions for the collections used by the
* environment variable map.  Namely, it prevents
* querying anything but codeString/codes.
*
* @author Andrew John Hughes ([EMAIL PROTECTED])
*/
   private static class EnvironmentCollection
 extends AbstractCollectionString
   {
 
 /**
  * The wrapped collection.
Index: java/nio/channels/spi/SelectorProvider.java
===
RCS file: /cvsroot/classpath/classpath/java/nio/channels/spi/SelectorProvider.java,v
retrieving revision 1.11
diff -u -1 -5 -r1.11 SelectorProvider.java
--- java/nio/channels/spi/SelectorProvider.java	2 Jul 2005 20:32:40 -	1.11
+++ java/nio/channels/spi/SelectorProvider.java	3 Apr 2007 21:26:17 -
@@ -28,30 +28,31 @@
 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 java.nio.channels.spi;
 
 import gnu.java.nio.SelectorProviderImpl;
 
 import java.io.IOException;
+import