classpath-patches
[Top][All Lists]
Advanced

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

[cp-patches] FYI: Adding default style to the style table in the StyleCo


From: Meskauskas Audrius
Subject: [cp-patches] FYI: Adding default style to the style table in the StyleContext (fixes 13617)
Date: Tue, 05 Jul 2005 13:46:07 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

This should fix the recently submitted bug #13617:
(https://savannah.gnu.org/bugs/?func=detailitem&item_id=13617)

The reason of throwing that exception is that DefaultStyledDocument
constructor tries to set the default style of the newly created
StyledContext as its logical style. To get that style, it calls
StyledContext.getStyle(StyleContext.DEFAULT_STYLE) and receives
null in return. The attempt to add that null to the table raises an
exception.

Sun's implementation returns non-null value of the default style. This
adds the default style to the styleTable, resulting the same behaviour.
It also fixes another (unnoticed) incompatibility, related to the
contents of the enumerator, returned by getStyleNames.

2005-07-05  Audrius Meskauskas  <address@hidden>

* javax/swing/text/StyleContext.java
(defaultStyle): New field.
(constructor): Add defaultStyle to the styleTable.
(DEFAULT_STYLE, getStyle, getStyleNames): Documented.

Index: javax/swing/text/StyleContext.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/StyleContext.java,v
retrieving revision 1.4
diff -u -r1.4 StyleContext.java
--- javax/swing/text/StyleContext.java  2 Jul 2005 20:32:51 -0000       1.4
+++ javax/swing/text/StyleContext.java  5 Jul 2005 11:28:06 -0000
@@ -380,9 +380,17 @@
   // FIXME: also not sure if these tables ought to be static (singletons),
   // shared across all StyleContexts. I think so, but it's not clear in
   // docs. revert to non-shared if you think it matters.
-
+  
+  /**
+   * The name of the default style.
+   */
   public static final String DEFAULT_STYLE = "default";
   
+  /**
+   * The default style for this style context.
+   */
+  NamedStyle defaultStyle = new NamedStyle(DEFAULT_STYLE, null);
+  
   static Hashtable sharedAttributeSets = new Hashtable();
   static Hashtable sharedFonts = new Hashtable();
 
@@ -392,10 +400,15 @@
   EventListenerList listenerList;
   Hashtable styleTable;
   
+  /**
+   * Creates a new instance of the style context. Add the default style
+   * to the style table.
+   */
   public StyleContext()
   {
     listenerList = new EventListenerList();
     styleTable = new Hashtable();
+    styleTable.put(DEFAULT_STYLE, defaultStyle);
   }
 
   protected SmallAttributeSet createSmallAttributeSet(AttributeSet a)
@@ -436,11 +449,25 @@
     styleTable.remove(name);
   }
 
+  /**
+   * Get the style from the style table. If the passed name
+   * matches address@hidden #DEFAULT_STYLE}, returns the address@hidden 
#getDefaultStyle()}.
+   * Otherwise returns the previously defined style of
+   * <code>null</code> if the style with the given name is not defined.
+   *
+   * @param name the name of the style.
+   *
+   * @return the style with the given name or null if no such defined.
+   */
   public Style getStyle(String name)
   {
     return (Style) styleTable.get(name);
   }
-
+  
+  /**
+   * Get the names of the style. The returned enumeration always
+   * contains at least one member, the default style.
+   */
   public Enumeration getStyleNames()
   {
     return styleTable.keys();

reply via email to

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