Author: desruisseaux
Date: Fri Mar 8 15:57:51 2013
New Revision: 1454438
URL: http://svn.apache.org/r1454438
Log:
IP review for StringConverter.Color.
Added:
sis/ip-review/StringConverter.Color.xhtml (with props)
sis/ip-review/rev/31322/
sis/ip-review/rev/31322/HEADER.html (with props)
sis/ip-review/rev/31322/StringConverter.Color.xhtml (with props)
Added: sis/ip-review/StringConverter.Color.xhtml
URL:
http://svn.apache.org/viewvc/sis/ip-review/StringConverter.Color.xhtml?rev=1454438&view=auto
==============================================================================
--- sis/ip-review/StringConverter.Color.xhtml (added)
+++ sis/ip-review/StringConverter.Color.xhtml Fri Mar 8 15:57:51 2013
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="UTF-8"/>
+ <title>StringConverter.Color history</title>
+ <style type="text/css" media="all">
+ @import url("./reports.css");
+ </style>
+ </head>
+ <body>
+ <div>
+ <h1>StringConverter.Color history</h1>
+ <p>Click on the commit message for inspecting the <code>diff</code> and how
the code has been rewritten.</p>
+<p><b>Command line:</b></p>
+<blockquote><code>svn log -r31996:29615
http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/ColorConverterFactory.java</code></blockquote>
+<table>
+ <tr>
+ <th>Rev.</th>
+ <th>Date</th>
+ <th>Author</th>
+ <th class="last">Message</th>
+ </tr>
+<tr><td class="rev">31322</td><td>2008-08-30</td><td
class="unav">jgarnett</td><td><a
href="rev/31322/StringConverter.Color.xhtml">additional test case for
ColorConvertFactory; fix to SLDStyleFactory for UDIG-1415</a></td></tr>
+<tr><td class="rev">30648</td><td>2008-06-12</td><td>acuster</td><td>Copyright
headers: lib/main, this time with feeling (and the el in Toolkit)</td></tr>
+<tr><td class="rev">30558</td><td>2008-06-06</td><td>acuster</td><td>Copyright
review: update headers on library/main</td></tr>
+<tr><td class="rev">30258</td><td>2008-05-08</td><td>acuster</td><td>Reshuffle
the top level repo: drop uDig, move up trunk, tags, and branches.</td></tr>
+<tr><td class="rev">30257</td><td>2008-05-08</td><td>acuster</td><td>Move
trunk/gt/ directory contents up to trunk/ and drop gt</td></tr>
+<tr><td class="rev">29615</td><td>2008-03-13</td><td
class="unav">jgarnett</td><td><a
href="rev/31322/StringConverter.Color.xhtml">Added ColorConverterFactory so I
could retire hacks from Filters utility class; made the NumberConverterFactory
agree with the needs of the SLD utility class - it was tripping up over parsing
floating point representation into intergers. See GEOT-1726</a></td></tr>
+</table>
+ </div>
+ </body>
+</html>
Propchange: sis/ip-review/StringConverter.Color.xhtml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/ip-review/StringConverter.Color.xhtml
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: sis/ip-review/rev/31322/HEADER.html
URL:
http://svn.apache.org/viewvc/sis/ip-review/rev/31322/HEADER.html?rev=1454438&view=auto
==============================================================================
--- sis/ip-review/rev/31322/HEADER.html (added)
+++ sis/ip-review/rev/31322/HEADER.html Fri Mar 8 15:57:51 2013
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="UTF-8"/>
+ <title>Revision 31322</title>
+ </head>
+ <body>
+ <div>
+ <h1>Revision 31322</h1>
+<table>
+ <tr><td><b>Author:</b></td><td>jgarnett</td></tr>
+ <tr><td><b>Date:</b></td><td>2008-08-30</td></tr>
+ <tr><td><b>Message:</b></td><td>additional test case for
ColorConvertFactory; fix to SLDStyleFactory for UDIG-1415</td></tr>
+</table>
+ </div>
+ </body>
+</html>
Propchange: sis/ip-review/rev/31322/HEADER.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/ip-review/rev/31322/HEADER.html
------------------------------------------------------------------------------
svn:mime-type = text/html
Added: sis/ip-review/rev/31322/StringConverter.Color.xhtml
URL:
http://svn.apache.org/viewvc/sis/ip-review/rev/31322/StringConverter.Color.xhtml?rev=1454438&view=auto
==============================================================================
--- sis/ip-review/rev/31322/StringConverter.Color.xhtml (added)
+++ sis/ip-review/rev/31322/StringConverter.Color.xhtml Fri Mar 8 15:57:51 2013
@@ -0,0 +1,150 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta charset="UTF-8"/>
+ <title>StringConverter.Color at revision 31322</title>
+ <style type="text/css" media="all">
+ @import url("../../reports.css");
+ </style>
+ </head>
+ <body>
+ <div>
+ <h1>StringConverter.Color at revision 31322</h1>
+<p>While the idea to provide a converter from <code>String</code> to
<code>Color</code> was found in GeoTools,
+the code has been rewritten using a different strategy (types are resolved
more accurately when searching for a
+converter, and the various kind of conversions are separated in different
<code>convert(S)</code> methods,
+so there is no sequences of <code>if</code> ⦠<code>else</code> statements).
The only common code is the following
+line (indirectly, through <code>InternalUtilities.parseColor(source)</code>),
inside a <code>try</code> ⦠<code>catch</code> block performing a different
work in case of failure:</p>
+
+<blockquote><pre>return Color.decode(rgba);</pre></blockquote>
+
+<p>There is no reasonable way to write the above line differently.</p>
+
+<p>The code performing bitmask operation on the RGBA value in order to get the
alpha value appears
+also in Geotoolkit.org (<code>NumberConverter.Color</code>).
+But again this is very classical operation found everywhere.</p>
+
+<p>The table below compares the GeoTools code with the Geotoolkit.org one.</p>
+
+<p><b>Command line:</b></p>
+<blockquote><code>svn cat -r31322
http://svn.osgeo.org/geotools/trunk/modules/library/main/src/main/java/org/geotools/util/ColorConverterFactory.java</code></blockquote>
+<table class="changes">
+<tr><th>Revision 31322</th><th>Geotoolkit.org</th></tr>
+<tr><td><pre><span class="add">/*
+ * GeoTools - The Open Source Java GIS Toolkit
+ * http://geotools.org
+ *
+ * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ */
+package org.geotools.util;
+
+import java.awt.Color;
+
+import org.geotools.factory.Hints;
+
+/**
+ * ConverterFactory for handling color conversions.
+ * <p>
+ * Supported conversions:
+ * <ul>
+ * <li>"#FF0000" (String) -> Color.RED
+ * <li>"false" -> Boolean.FALSE
+ * <li>0xFF0000FF (Integer) -> RED with Alpha
+ * </ul>
+ * </p>
+ * <p>
+ * This code was previously part of the SLD utility class, it is being made
+ * available as part of the Converters framework to allow for broader use.
+ * </p>
+ * @author Jody Garnett (Refractions Research)
+ * @since 2.5
+ */
+public class ColorConverterFactory implements ConverterFactory {
+
+ public Converter createConverter(Class source, Class target, Hints hints) {
+ if ( target.equals( Color.class ) ) {
+ // string to color
+ if ( source.equals( String.class ) ) {
+ return new Converter() {
+ public Object convert(Object source, Class target) throws
Exception {
+ String rgba = (String) source;
+ try {
+ return Color.decode(rgba);
+ } catch (NumberFormatException badRGB) {
+ // unavailable
+ return null;
+ }
+ }
+ };
+ }
+
+ // integer to color
+ if ( source.equals( Integer.class ) ) {
+ return new Converter() {
+ public Object convert(Object source, Class target) throws
Exception {
+ Integer rgba = (Integer) source;
+ int alpha = 0xff000000 & rgba;
+ return new Color(rgba, alpha != 0 );
+ }
+ };
+ }
+ }
+ return null;
+ }
+
+}</span></pre></td>
+<td><pre>/**
+ * Converter from {@link java.lang.String} to {@link java.awt.Color}.
+ * If the string begins with a leading {@code '#'} character (as in HTML
codes),
+ * then the remaining is understood as an hexadecimal number.
+ *
+ * @author Justin Deoliveira (TOPP)
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 3.19
+ *
+ * @since 2.4
+ */
+@Immutable
+static final class Color extends StringConverter<java.awt.Color> {
+ private static final long serialVersionUID = 5294622747871370401L;
+ public static final Color INSTANCE = new Color();
+ private Color() {
+ }
+
+ @Override
+ public Class<java.awt.Color> getTargetClass() {
+ return java.awt.Color.class;
+ }
+
+ @Override
+ public java.awt.Color convert(String source) throws
NonconvertibleObjectException {
+ if (source == null) {
+ return null;
+ }
+ source = source.trim();
+ try {
+ return new java.awt.Color(InternalUtilities.parseColor(source),
true);
+ } catch (NumberFormatException e) {
+ throw new NonconvertibleObjectException(e);
+ }
+ }
+
+ /** Returns the singleton instance on deserialization. */
+ protected Object readResolve() throws ObjectStreamException {
+ return INSTANCE;
+ }
+}</pre></td></tr>
+</table>
+ </div>
+ </body>
+</html>
Propchange: sis/ip-review/rev/31322/StringConverter.Color.xhtml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/ip-review/rev/31322/StringConverter.Color.xhtml
------------------------------------------------------------------------------
svn:mime-type = text/html