You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2007/01/13 11:21:14 UTC

svn commit: r495866 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/StyledEditorKit.java test/api/java/common/javax/swing/JTextPaneTest.java test/api/java/common/javax/swing/text/StyledEditorKitTest.java

Author: hindessm
Date: Sat Jan 13 02:21:13 2007
New Revision: 495866

URL: http://svn.apache.org/viewvc?view=rev&rev=495866
Log:
Applied patches from "[#HARMONY-2513] [classlib][swing] compatibility:
javax.swing.text.StyledEditorKit.getInputAttributes() returns null on Harmony".

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/StyledEditorKit.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTextPaneTest.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/StyledEditorKitTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/StyledEditorKit.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/StyledEditorKit.java?view=diff&rev=495866&r1=495865&r2=495866
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/StyledEditorKit.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/StyledEditorKit.java Sat Jan 13 02:21:13 2007
@@ -14,12 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
-/**
- * @author Evgeniya G. Maenkova
- * @version $Revision$
- */
-
 package javax.swing.text;
 
 import java.awt.Color;
@@ -32,15 +26,27 @@
 
 import org.apache.harmony.awt.text.TextUtils;
 
+/**
+ * <p>
+ * <i>StyledEditorKit</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.
+ * <em>This applies to nested classes as well</em>.</li>
+ * </ul>
+ */
 public class StyledEditorKit extends DefaultEditorKit {
 
-    public static class AlignmentAction extends
-            StyledEditorKit.StyledTextAction {
-        MutableAttributeSet set;
-        Object defaultValue;
-        public AlignmentAction(final String name, final int allignment) {
+    public static class AlignmentAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
+
+        private final Object defaultValue;
+
+        public AlignmentAction(final String name, final int alignment) {
             super(name);
-            defaultValue = new Integer(allignment);
+            defaultValue = new Integer(alignment);
         }
 
         public void actionPerformed(final ActionEvent event) {
@@ -48,8 +54,7 @@
             if (pane == null) {
                 return;
             }
-            MutableAttributeSet attr = (set == null) ? new SimpleAttributeSet()
-                    : set;
+            MutableAttributeSet attr = new SimpleAttributeSet();
             Object newValue = null;
             if (event != null) {
                 try {
@@ -63,21 +68,23 @@
         }
     }
 
-    public static class BoldAction extends StyledEditorKit.StyledTextAction {
-        MutableAttributeSet set;
+    public static class BoldAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
+
         public BoldAction() {
             super("font-bold");
         }
 
         public void actionPerformed(final ActionEvent event) {
-            performAction(event, StyleConstants.Bold, set, null, null, true);
+            performAction(event, StyleConstants.Bold, null, null, null, true);
         }
     }
 
-    public static class FontFamilyAction extends
-            StyledEditorKit.StyledTextAction {
-        MutableAttributeSet set;
-        Object defaultValue;
+    public static class FontFamilyAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
+
+        private final Object defaultValue;
+
         public FontFamilyAction(final String name, final String family) {
             super(name);
             defaultValue = family;
@@ -91,15 +98,16 @@
                 } catch (NumberFormatException e) {
                 }
             }
-            performAction(event, StyleConstants.FontFamily, set, defaultValue,
+            performAction(event, StyleConstants.FontFamily, null, defaultValue,
                           newValue, false);
         }
     }
 
-    public static class FontSizeAction extends StyledEditorKit
-                                                 .StyledTextAction {
-        MutableAttributeSet set;
-        Object defaultValue;
+    public static class FontSizeAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
+
+        private final Object defaultValue;
+
         public FontSizeAction(final String name, final int size) {
             super(name);
             defaultValue = new Integer(size);
@@ -113,16 +121,17 @@
                 } catch (NumberFormatException e) {
                 }
             }
-            performAction(event, StyleConstants.FontSize, set, defaultValue,
+            performAction(event, StyleConstants.FontSize, null, defaultValue,
                           newValue, false);
         }
 
     }
 
-    public static class ForegroundAction extends
-            StyledEditorKit.StyledTextAction {
-        MutableAttributeSet set;
-        Object defaultValue;
+    public static class ForegroundAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
+
+        private final Object defaultValue;
+
         public ForegroundAction(final String name, final Color color) {
             super(name);
             defaultValue = color;
@@ -136,20 +145,20 @@
                 } catch (NumberFormatException e) {
                 }
             }
-            performAction(event, StyleConstants.Foreground, set, defaultValue,
+            performAction(event, StyleConstants.Foreground, null, defaultValue,
                           newValue, false);
         }
     }
 
-    public static class ItalicAction extends StyledEditorKit.StyledTextAction {
-        private MutableAttributeSet set;
+    public static class ItalicAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
 
         public ItalicAction() {
             super("font-italic");
         }
 
         public void actionPerformed(final ActionEvent event) {
-            performAction(event, StyleConstants.Italic, set, null, null, true);
+            performAction(event, StyleConstants.Italic, null, null, null, true);
         }
     }
 
@@ -196,10 +205,10 @@
                                        selectionEnd - selectionStart,
                                        set, replace);
 
-            MutableAttributeSet atts = getStyledEditorKit(c).inputAttributes;
+            MutableAttributeSet atts = getStyledEditorKit(c).getInputAttributes();
             if (replace) {
-                  atts.removeAttributes(atts.getAttributeNames());
-                }
+                atts.removeAttributes(atts.getAttributeNames());
+            }
             atts.addAttributes(set);
         }
 
@@ -269,16 +278,15 @@
 
     }
 
-    public static class UnderlineAction extends
-            StyledEditorKit.StyledTextAction {
-        private MutableAttributeSet set;
+    public static class UnderlineAction extends StyledTextAction {
+        private static final long serialVersionUID = 1L;
 
         public UnderlineAction() {
             super("font-underline");
         }
 
         public void actionPerformed(final ActionEvent event) {
-            performAction(event, StyleConstants.Underline, set, null, null,
+            performAction(event, StyleConstants.Underline, null, null, null,
                           true);
         }
     }
@@ -321,26 +329,29 @@
         }
     }
 
+    private static final long serialVersionUID = 1L;
+
     private static final ViewFactory factory = new ViewFactoryImpl();
 
-    private static Action[]          actions;
+    private static Action[] actions;
 
-    JEditorPane                      editorPane;
+    private JEditorPane editorPane;
 
-    CaretListenerImpl caretListener;
+    private CaretListenerImpl caretListener;
 
-    //  TODO Perhaps, inputAttributes = new ... a lot. I'll think about this one.
-    MutableAttributeSet inputAttributes;
+    private final MutableAttributeSet inputAttributes = new SimpleAttributeSet();
 
 
     public StyledEditorKit() {
         createStaticActions();
     }
 
+    @Override
     public Action[] getActions() {
-        return (Action[])actions.clone();
+        return actions.clone();
     }
 
+    @Override
     public Document createDefaultDocument() {
         return new DefaultStyledDocument();
     }
@@ -363,6 +374,7 @@
         }
     }
 
+    @Override
     public void deinstall(final JEditorPane component) {
         if (component == editorPane) {
             if (editorPane != null && caretListener != null) {
@@ -425,9 +437,6 @@
     }
 
     public MutableAttributeSet getInputAttributes() {
-        if (editorPane == null) {
-            return null;
-        }
         return inputAttributes;
     }
 
@@ -451,10 +460,12 @@
         return elem;
     }
 
+    @Override
     public ViewFactory getViewFactory() {
         return factory;
     }
 
+    @Override
     public void install(final JEditorPane component) {
         editorPane = component;
         if (caretListener == null) {
@@ -467,7 +478,7 @@
     }
 
     private void updateInputAttributes(final int dot) {
-        inputAttributes = new SimpleAttributeSet();
+        inputAttributes.removeAttributes(inputAttributes);
         Element element = getElementByOffset(editorPane.getDocument(), dot);
         createInputAttributes(element, inputAttributes);
     }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTextPaneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTextPaneTest.java?view=diff&rev=495866&r1=495865&r2=495866
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTextPaneTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/JTextPaneTest.java Sat Jan 13 02:21:13 2007
@@ -429,11 +429,7 @@
         attrs = textPane.getInputAttributes();
         assertAttrubutes(attrs, false, false, true, false, false, true);
         textPane.insertComponent(new JButton("Format C:\\>"));
-        if (isHarmony()) {
-            assertAttrubutes(attrs, false, false, true, false, false, true);
-        } else {
-            assertAttrubutes(attrs, false, false, false, false, false, false);
-        }
+        assertAttrubutes(attrs, false, false, false, false, false, false);
         assertNull(StyleConstants.getComponent(attrs));
         attributes = textPane.getStyledDocument().getCharacterElement(1).getAttributes();
         assertAttrubutes(attributes, false, false, false, false, false, false);
@@ -472,11 +468,7 @@
                 return 40;
             }
         });
-        if (isHarmony()) {
-            assertAttrubutes(attrs, false, false, true, false, false, true);
-        } else {
-            assertAttrubutes(attrs, false, false, false, false, false, false);
-        }
+        assertAttrubutes(attrs, false, false, false, false, false, false);
         Element iconElement = textPane.getStyledDocument().getDefaultRootElement()
                 .getElement(0).getElement(1);
         AttributeSet attributes = iconElement.getAttributes();

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/StyledEditorKitTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/StyledEditorKitTest.java?view=diff&rev=495866&r1=495865&r2=495866
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/StyledEditorKitTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/StyledEditorKitTest.java Sat Jan 13 02:21:13 2007
@@ -240,6 +240,12 @@
             }
         }
     }
+    
+    public void testGetInputAttributesNoComponent() throws Exception {
+        final AttributeSet as = kit.getInputAttributes();
+        assertNotNull(as);
+        assertEquals(0, as.getAttributeCount());
+    }
 
     static final Element getElementByOffset(final Document doc, final int offset) {
         int pos = (offset == 0) ? 0 : offset - 1;