classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: Make Font really Serializable


From: Mark Wielaard
Subject: [cp-patches] FYI: Make Font really Serializable
Date: Mon, 03 Oct 2005 02:13:30 +0200

Hi,

This makes Font really serializable by making sure the name field is
always set, the peer is transient and gets set when readObject() is
called.

2005-10-02  Mark Wielaard  <address@hidden>

       * java/awt/Font.java (peer): Make field transient.
       (Font(String,int,int)): Explicitly set name field.
       (Font(String,Map)): Likewise.
       (readObject): New private method.

This makes all jcommon tests pass.

Committed,

Mark
Index: java/awt/Font.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Font.java,v
retrieving revision 1.32
diff -u -r1.32 Font.java
--- java/awt/Font.java  28 Sep 2005 13:46:55 -0000      1.32
+++ java/awt/Font.java  3 Oct 2005 00:12:17 -0000
@@ -50,6 +50,7 @@
 import java.awt.peer.FontPeer;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.text.AttributedCharacterIterator;
 import java.text.CharacterIterator;
@@ -191,7 +192,7 @@
 
 
   // The ClasspathToolkit-provided peer which implements this font
-  private ClasspathFontPeer peer;
+  private transient ClasspathFontPeer peer;
 
 
   /**
@@ -335,6 +336,10 @@
     this.peer = getPeerFromToolkit(name, attrs);
     this.size = size;
     this.pointSize = (float) size;
+    if (name != null)
+      this.name = name;
+    else
+      this.name = peer.getName(this);
   }
 
   public Font(Map attrs)
@@ -355,6 +360,10 @@
     peer = getPeerFromToolkit(name, attrs);
     size = (int) peer.getSize(this);
     pointSize = peer.getSize(this);
+    if (name != null)
+      this.name = name;
+    else
+      this.name = peer.getName(this);
   }
 
   /**
@@ -1315,4 +1324,19 @@
     return getLineMetrics(str, 0, str.length() - 1, frc);
   }
 
+  /**
+   * Reads the normal fields from the stream and then constructs the
+   * peer from the style and size through getPeerFromToolkit().
+   */
+  private void readObject(ObjectInputStream ois)
+    throws IOException, ClassNotFoundException
+  {
+    ois.defaultReadObject();
+
+    HashMap attrs = new HashMap();
+    ClasspathFontPeer.copyStyleToAttrs(style, attrs);
+    ClasspathFontPeer.copySizeToAttrs(size, attrs);
+    peer = getPeerFromToolkit(name, attrs);
+
+  }
 }

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


reply via email to

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