[cp-patches] Patch: FYI: StyleContext.writeAttributeSet

Tom Tromey tromey at redhat.com
Tue Jun 6 19:52:11 UTC 2006


I'm checking this in.

This implements StyleContext.writeAttributeSet according to
readAttributeSet and my reading of the specs.

Tom

2006-06-06  Tom Tromey  <tromey at redhat.com>

	* javax/swing/text/StyleContext.java (registerStaticAttributeKey):
	Javadoc fix.
	(writeAttributeSet): Implemented.

Index: javax/swing/text/StyleContext.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/StyleContext.java,v
retrieving revision 1.12
diff -u -r1.12 StyleContext.java
--- javax/swing/text/StyleContext.java	16 May 2006 20:39:01 -0000	1.12
+++ javax/swing/text/StyleContext.java	6 Jun 2006 19:55:25 -0000
@@ -38,8 +38,6 @@
 
 package javax.swing.text;
 
-import gnu.classpath.NotImplementedException;
-
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.FontMetrics;
@@ -50,7 +48,6 @@
 import java.io.Serializable;
 import java.util.Enumeration;
 import java.util.EventListener;
-import java.util.HashSet;
 import java.util.Hashtable;
 
 import javax.swing.event.ChangeEvent;
@@ -770,16 +767,29 @@
   }
   
   /**
-   * TODO: DOCUMENT ME!
+   * Serialize an attribute set in a way that is compatible with it
+   * being read in again by {@link #readAttributeSet(ObjectInputStream, MutableAttributeSet)}.
+   * In particular registered static keys are transformed properly.
    * 
    * @param out - stream to write to
    * @param a - the attribute set
    * @throws IOException - any I/O error
    */
   public static void writeAttributeSet(ObjectOutputStream out, AttributeSet a)
-    throws IOException, NotImplementedException
+    throws IOException
   {
-    // FIXME: Not implemented
+    Enumeration e = a.getAttributeNames();
+    while (e.hasMoreElements())
+      {
+        Object oldKey = e.nextElement();
+        Object newKey = getStaticAttribute(oldKey);
+        Object key = (newKey == null) ? oldKey : newKey;
+ 
+        out.writeObject(key);
+        out.writeObject(a.getAttribute(oldKey));
+      }
+    out.writeObject(null);
+    out.writeObject(null);
   }
 
   /**
@@ -813,7 +823,7 @@
 
   /**
    * Registers an attribute key as a well-known keys. When an attribute with
-   * such a key is written to a stream,, a special syntax is used so that it
+   * such a key is written to a stream, a special syntax is used so that it
    * can be recognized when it is read back in. All attribute keys defined
    * in <code>StyleContext</code> are registered as static keys. If you define
    * additional attribute keys that you want to exist as nonreplicated objects,



More information about the Classpath-patches mailing list