[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] make non-standard Font constructor package-private
From: |
Thomas Fitzsimmons |
Subject: |
[cp-patches] make non-standard Font constructor package-private |
Date: |
Thu, 18 Aug 2005 22:18:39 -0400 |
Hi,
I made this non-standard Font constructor package-private and modified
ClasspathToolkit to access it through reflection.
Tom
2005-08-18 Thomas Fitzsimmons <address@hidden>
* java/awt/Font.java (Font(String,Map)): Make package private.
* gnu/java/awt/ClasspathToolkit.java (getFont): Access
package-private Font.Font(String,Map) constructor using
reflection.
Index: gnu/java/awt/ClasspathToolkit.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/ClasspathToolkit.java,v
retrieving revision 1.15
diff -u -r1.15 ClasspathToolkit.java
--- gnu/java/awt/ClasspathToolkit.java 19 Aug 2005 01:29:26 -0000 1.15
+++ gnu/java/awt/ClasspathToolkit.java 19 Aug 2005 02:06:12 -0000
@@ -42,8 +42,10 @@
import gnu.java.awt.peer.ClasspathFontPeer;
import gnu.java.awt.peer.EmbeddedWindowPeer;
import gnu.java.awt.peer.ClasspathTextLayoutPeer;
+import gnu.java.security.action.SetAccessibleAction;
import java.awt.AWTException;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Font;
@@ -58,11 +60,14 @@
import java.awt.peer.RobotPeer;
import java.io.File;
import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.AttributedString;
import java.util.HashMap;
import java.util.Map;
+import java.security.AccessController;
import javax.imageio.spi.IIORegistry;
@@ -129,8 +134,35 @@
*/
public Font getFont (String name, Map attrs)
{
- // FIXME: use reflection to get at this non-standard constructor.
- return new Font (name, attrs);
+ Font f = null;
+
+ // Circumvent the package-privateness of the
+ // java.awt.Font.Font(String,Map) constructor.
+ try
+ {
+ Constructor fontConstructor = Component.class.getConstructor
+ (new Class[] { String.class, Map.class });
+ AccessController.doPrivileged
+ (new SetAccessibleAction(fontConstructor));
+ f = (Font) fontConstructor.newInstance(new Object[] { name, attrs });
+ }
+ catch (IllegalAccessException e)
+ {
+ // This should never happen.
+ }
+ catch (NoSuchMethodException e)
+ {
+ // This should never happen.
+ }
+ catch (InstantiationException e)
+ {
+ // This should never happen.
+ }
+ catch (InvocationTargetException e)
+ {
+ // This should never happen.
+ }
+ return f;
}
/**
Index: java/awt/Font.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Font.java,v
retrieving revision 1.28
diff -u -r1.28 Font.java
--- java/awt/Font.java 19 Aug 2005 01:29:26 -0000 1.28
+++ java/awt/Font.java 19 Aug 2005 02:06:13 -0000
@@ -353,11 +353,11 @@
this(null, attrs);
}
- /* This extra constructor is here to permit ClasspathToolkit and to build
- a font with a "logical name" as well as attrs. */
- // FIXME: make this package-private and use reflection in
- // ClasspathToolkit to get at it.
- public Font (String name, Map attrs)
+ /* This extra constructor is here to permit ClasspathToolkit and to
+ build a font with a "logical name" as well as attrs.
+ ClasspathToolkit.getFont(String,Map) uses reflection to call this
+ package-private constructor. */
+ Font (String name, Map attrs)
{
// If attrs is null, setting it to an empty HashMap will give this
// Font default attributes.
- [cp-patches] make non-standard Font constructor package-private,
Thomas Fitzsimmons <=