Hi,

The following code was too clever for my little brain. I rewrote it and
extracted it into its of static method. Hopefully this also helps others
trying to understand this part of the code.

2005-09-30  Mark Wielaard  <[EMAIL PROTECTED]>

    * gnu/java/awt/peer/gtk/GdkFontMetrics.java (initFont): New static
    method.
    (GdkFontMetrics): Use initFont() in super() call.

Committed,

Mark
Index: gnu/java/awt/peer/gtk/GdkFontMetrics.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkFontMetrics.java,v
retrieving revision 1.14
diff -u -r1.14 GdkFontMetrics.java
--- gnu/java/awt/peer/gtk/GdkFontMetrics.java	28 Sep 2005 13:59:14 -0000	1.14
+++ gnu/java/awt/peer/gtk/GdkFontMetrics.java	30 Sep 2005 09:57:22 -0000
@@ -1,5 +1,5 @@
 /* GdkFontMetrics.java
-   Copyright (C) 1999, 2002, 2004  Free Software Foundation, Inc.
+   Copyright (C) 1999, 2002, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -63,15 +63,27 @@
   static final int TEXT_METRICS_X_ADVANCE = 4;
   static final int TEXT_METRICS_Y_ADVANCE = 5;
   
+  /**
+   * Makes sure to return a Font based on the given Font that has as
+   * peer a GdkFontPeer. Used in the initializer.
+   */
+  private static Font initFont(Font font)
+  {
+    if (font == null)
+      return new Font("Dialog", Font.PLAIN, 12);
+    else if (font.getPeer() instanceof GdkFontPeer)
+      return font;
+    else
+      {
+	ClasspathToolkit toolkit;
+	toolkit = (ClasspathToolkit) Toolkit.getDefaultToolkit();
+	return toolkit.getFont(font.getName(), font.getAttributes());
+      }
+  }
+    
   public GdkFontMetrics (Font font)
   {    
-    super ((font == null) 
-           ? new Font("Dialog", Font.PLAIN, 12) 
-           : font.getPeer() instanceof GdkFontPeer 
-           ? font 
-           : ((ClasspathToolkit)(Toolkit.getDefaultToolkit ()))
-             .getFont (font.getName(), font.getAttributes ()));
-    
+    super(initFont(font));
     peer = (GdkFontPeer) this.font.getPeer();
 
     font_metrics = new int[5];

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to