summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/text/StyleContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/text/StyleContext.java')
-rw-r--r--libjava/classpath/javax/swing/text/StyleContext.java119
1 files changed, 97 insertions, 22 deletions
diff --git a/libjava/classpath/javax/swing/text/StyleContext.java b/libjava/classpath/javax/swing/text/StyleContext.java
index 8ef34400d29..63df3df6a91 100644
--- a/libjava/classpath/javax/swing/text/StyleContext.java
+++ b/libjava/classpath/javax/swing/text/StyleContext.java
@@ -38,8 +38,6 @@ exception statement from your version. */
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.ObjectOutputStream;
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;
@@ -413,7 +410,7 @@ public class StyleContext
/**
* These attribute keys are handled specially in serialization.
*/
- private static HashSet staticAttributeKeys = new HashSet();
+ private static Hashtable staticAttributeKeys = new Hashtable();
EventListenerList listenerList;
Hashtable styleTable;
@@ -708,49 +705,125 @@ public class StyleContext
}
}
-
- // FIXME: there's some sort of quasi-serialization stuff in here which I
- // have left incomplete; I'm not sure I understand the intent properly.
-
+ /**
+ * Gets the object previously registered with registerStaticAttributeKey.
+ *
+ * @param key - the key that was registered.
+ * @return the object previously registered with registerStaticAttributeKey.
+ */
public static Object getStaticAttribute(Object key)
- throws NotImplementedException
{
- throw new InternalError("not implemented");
+ if (key == null)
+ return null;
+ return staticAttributeKeys.get(key);
}
+ /**
+ * Returns the String that key will be registered with
+ * registerStaticAttributeKey.
+ *
+ * @param key - the key that will be registered.
+ * @return the string the key will be registered with.
+ */
public static Object getStaticAttributeKey(Object key)
- throws NotImplementedException
{
- throw new InternalError("not implemented");
+ return key.getClass().getName() + "." + key.toString();
}
+ /**
+ * Reads a set of attributes from the given object input stream. This will
+ * attempt to restore keys that were static objects by considering only the
+ * keys that have were registered with registerStaticAttributeKey. The
+ * attributes retrieved will be placed into the given set.
+ *
+ * @param in - the stream to read from
+ * @param a - the set of attributes
+ * @throws ClassNotFoundException - may be encountered when reading from
+ * stream
+ * @throws IOException - any I/O error
+ */
public static void readAttributeSet(ObjectInputStream in, MutableAttributeSet a)
- throws ClassNotFoundException, IOException, NotImplementedException
+ throws ClassNotFoundException, IOException
{
- throw new InternalError("not implemented");
+ if (in == null || a == null)
+ return;
+
+ Object key = in.readObject();
+ Object val = in.readObject();
+ while (key != null && val != null)
+ {
+ Object staticKey = staticAttributeKeys.get(key);
+ Object staticVal = staticAttributeKeys.get(val);
+
+ if (staticKey != null)
+ key = staticKey;
+ if (staticVal != null)
+ val = staticVal;
+
+ a.addAttribute(key, val);
+ key = in.readObject();
+ val = in.readObject();
+ }
}
+ /**
+ * 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
{
- throw new InternalError("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);
}
+ /**
+ * Handles reading in the attributes.
+ * @see #readAttributeSet(ObjectInputStream, MutableAttributeSet)
+ *
+ * @param in - the stream to read from
+ * @param a - the set of attributes
+ * @throws ClassNotFoundException - may be encountered when reading from stream
+ * @throws IOException - any I/O error
+ */
public void readAttributes(ObjectInputStream in, MutableAttributeSet a)
- throws ClassNotFoundException, IOException, NotImplementedException
+ throws ClassNotFoundException, IOException
{
- throw new InternalError("not implemented");
+ readAttributeSet(in, a);
}
+ /**
+ * Handles writing of the given attributes.
+ * @see #writeAttributeSet(ObjectOutputStream, AttributeSet)
+ *
+ * @param out - stream to write to
+ * @param a - the attribute set
+ * @throws IOException - any I/O error
+ */
public void writeAttributes(ObjectOutputStream out, AttributeSet a)
- throws IOException, NotImplementedException
+ throws IOException
{
- throw new InternalError("not implemented");
+ writeAttributeSet(out, a);
}
/**
* 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,
@@ -760,6 +833,8 @@ public class StyleContext
*/
public static void registerStaticAttributeKey(Object key)
{
- staticAttributeKeys.add(key);
+ if (key != null)
+ staticAttributeKeys.put(key.getClass().getName() + "." + key.toString(),
+ key);
}
}
OpenPOWER on IntegriCloud