harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r544826 - in /harmony/enhanced/classlib/trunk/modules/beans/src: main/java/org/apache/harmony/beans/editors/ColorEditor.java test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
Date Wed, 06 Jun 2007 12:35:15 GMT
Author: tellison
Date: Wed Jun  6 05:35:15 2007
New Revision: 544826

URL: http://svn.apache.org/viewvc?view=rev&rev=544826
Log:
Apply patch HARMONY-4062 ([classlib][beans]org.apache.harmony.beans.editors.ColorEditor lacks
support for setAsText)

Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java?view=diff&rev=544826&r1=544825&r2=544826
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
Wed Jun  6 05:35:15 2007
@@ -67,6 +67,31 @@
             super.setValue(value);
         }
     }
+    
+    @Override
+    public void setAsText(String text) {
+        if (null == text) {
+            throw new NullPointerException();
+        }
+
+        int r = 0;
+        int g = 0;
+        int b = 0;
+
+        try {
+            int index = text.indexOf(",");
+            r = Integer.parseInt(text.substring(0, index));
+            text = text.substring(index + 1);
+            index = text.indexOf(",");
+            g = Integer.parseInt(text.substring(0, index));
+            text = text.substring(index + 1);
+            b = Integer.parseInt(text);
+            setValue(new Color(r, g, b));
+        } catch (Exception e) {
+            throw new IllegalArgumentException(text);
+        }
+    }
+    
 
     @Override
     public boolean isPaintable() {

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java?view=diff&rev=544826&r1=544825&r2=544826
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
Wed Jun  6 05:35:15 2007
@@ -17,6 +17,7 @@
 
 package org.apache.harmony.beans.tests.java.beans;
 
+import java.awt.Color;
 import java.beans.PropertyEditor;
 import java.beans.PropertyEditorManager;
 
@@ -72,5 +73,36 @@
 
         editor.setAsText(text);
         assertEquals(text, editor.getAsText());
+    }
+    
+    // Regression for HARMONY-4062
+    public void testColorEditor() {
+        PropertyEditor propertyEditor = PropertyEditorManager
+                .findEditor(Color.class);
+        propertyEditor.setValue(new Color(0, 0, 0));
+        propertyEditor.setAsText("1,2,3");
+        Color newColor = new Color(1, 2, 3);
+        assertEquals(newColor, propertyEditor.getValue());
+
+        try {
+            propertyEditor.setAsText(null);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected.
+        }
+
+        try {
+            propertyEditor.setAsText("illegalArugment");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected.
+        }
+
+        try {
+            propertyEditor.setAsText("1,2,3,4");
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            //expected.
+        }
     }
 }



Mime
View raw message