sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1564260 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt: Colors.java ElementKind.java Formatter.java
Date Tue, 04 Feb 2014 12:00:29 GMT
Author: desruisseaux
Date: Tue Feb  4 12:00:28 2014
New Revision: 1564260

URL: http://svn.apache.org/r1564260
Log:
Syntax colors for SCOPE, EXTENT and REMARKS elements.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Colors.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/ElementKind.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Colors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Colors.java?rev=1564260&r1=1564259&r2=1564260&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Colors.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Colors.java
[UTF-8] Tue Feb  4 12:00:28 2014
@@ -67,6 +67,9 @@ public class Colors implements Cloneable
         map.put(ElementKind.METHOD,     X364.FOREGROUND_GREEN);
         map.put(ElementKind.DATUM,      X364.FOREGROUND_GREEN);
         map.put(ElementKind.ERROR,      X364.BACKGROUND_RED);
+        map.put(ElementKind.SCOPE,      X364.BACKGROUND_GRAY);
+        map.put(ElementKind.EXTENT,     X364.BACKGROUND_GRAY);
+        map.put(ElementKind.REMARKS,    X364.BACKGROUND_GRAY);
         CONSOLE.isImmutable = true;
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/ElementKind.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/ElementKind.java?rev=1564260&r1=1564259&r2=1564260&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/ElementKind.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/ElementKind.java
[UTF-8] Tue Feb  4 12:00:28 2014
@@ -52,7 +52,7 @@ public enum ElementKind {
     UNIT,
 
     /**
-     * {@linkplain org.opengis.referencing.cs.CoordinateSystemAxis Axes},
+     * {@linkplain org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis Coordinate system
axes},
      * often represented by {@code AXIS[…]} elements.
      */
     AXIS,
@@ -63,24 +63,42 @@ public enum ElementKind {
     CODE_LIST,
 
     /**
-     * {@linkplain org.opengis.parameter.ParameterValue Parameter values},
+     * {@linkplain org.apache.sis.parameter.DefaultParameterValue Parameter values},
      * often represented by {@code PARAMETER[…]} elements.
      */
     PARAMETER,
 
     /**
-     * {@linkplain org.opengis.referencing.operation.OperationMethod Operation methods},
+     * {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod Operation
methods},
      * often represented by {@code PROJECTION[…]} elements.
      */
     METHOD,
 
     /**
-     * {@linkplain org.opengis.referencing.datum.Datum Datum},
+     * {@linkplain org.apache.sis.referencing.datum.AbstractDatum Datum},
      * often represented by {@code DATUM[…]} elements.
      */
     DATUM,
 
     /**
+     * CRS, datum or operation {@linkplain org.apache.sis.referencing.AbstractReferenceSystem#getScope()
scope},
+     * often represented by {@code SCOPE[…]} elements.
+     */
+    SCOPE,
+
+    /**
+     * CRS, datum or operation {@linkplain org.apache.sis.referencing.AbstractReferenceSystem#getDomainOfValidity()
+     * domain of validity}, often represented by {@code AREA[…]} or {@code BBOX[…]} elements.
+     */
+    EXTENT,
+
+    /**
+     * {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getRemarks() Remarks},
+     * often represented by {@code REMARKS[…]} elements.
+     */
+    REMARKS,
+
+    /**
      * Unformattable elements.
      */
     ERROR;

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1564260&r1=1564259&r2=1564260&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Tue Feb  4 12:00:28 2014
@@ -188,6 +188,12 @@ public class Formatter {
     private int bufferBase;
 
     /**
+     * Incremented when {@link #setColor(ElementKind)} is invoked, and decremented when {@link
#resetColor()}
+     * is invoked. Used in order to prevent child elements to overwrite the colors decided
by enclosing elements.
+     */
+    private int colorApplied;
+
+    /**
      * The amount of spaces to use in indentation, or {@value org.apache.sis.io.wkt.WKTFormat#SINGLE_LINE}
      * if indentation is disabled.
      *
@@ -372,10 +378,14 @@ public class Formatter {
      */
     private void setColor(final ElementKind type) {
         if (colors != null) {
-            final String color = colors.getAnsiSequence(type);
-            if (color != null) {
+            if (colorApplied == 0) {
+                final String color = colors.getAnsiSequence(type);
+                if (color == null) {
+                    return; // Do not increment 'colorApplied' for giving a chance to children
to apply their colors.
+                }
                 buffer.append(color);
             }
+            colorApplied++;
         }
     }
 
@@ -384,7 +394,8 @@ public class Formatter {
      * This method does nothing unless syntax coloring has been explicitly enabled.
      */
     private void resetColor() {
-        if (colors != null) {
+        if (colors != null && --colorApplied <= 0) {
+            colorApplied = 0;
             buffer.append(FOREGROUND_DEFAULT);
         }
     }
@@ -552,7 +563,7 @@ public class Formatter {
          * Format remarks if any, and close the element.
          */
         if (info != null) {
-            append("REMARKS", info.getRemarks());
+            append("REMARKS", info.getRemarks(), ElementKind.REMARKS);
         }
         buffer.appendCodePoint(symbols.getClosingBracket(0));
         requestNewLine = true;
@@ -578,16 +589,18 @@ public class Formatter {
         } else {
             return;
         }
-        append("SCOPE", scope);
+        append("SCOPE", scope, ElementKind.SCOPE);
         if (area != null) {
-            append("AREA", area.getDescription());
+            append("AREA", area.getDescription(), ElementKind.EXTENT);
             append(Extents.getGeographicBoundingBox(area), 2);
             final MeasurementRange<Double> range = Extents.getVerticalRange(area);
             if (range != null) {
                 openElement("VERTICALEXTENT");
+                setColor(ElementKind.EXTENT);
                 append(range.getMinDouble());
                 append(range.getMaxDouble());
                 append(range.unit());
+                resetColor();
                 closeElement();
             }
         }
@@ -625,6 +638,7 @@ public class Formatter {
     public void append(final GeographicBoundingBox bbox, final int fractionDigits) {
         if (bbox != null) {
             openElement("BBOX");
+            setColor(ElementKind.EXTENT);
             numberFormat.setMinimumFractionDigits(fractionDigits);
             numberFormat.setMaximumFractionDigits(fractionDigits);
             numberFormat.setRoundingMode(RoundingMode.FLOOR);
@@ -633,6 +647,7 @@ public class Formatter {
             numberFormat.setRoundingMode(RoundingMode.CEILING);
             appendPreset(bbox.getNorthBoundLatitude());
             appendPreset(bbox.getEastBoundLongitude());
+            resetColor();
             closeElement();
         }
     }
@@ -840,13 +855,15 @@ public class Formatter {
      * @param keyword The keyword. Example: {@code "SCOPE"}, {@code "AREA"} or {@code "REMARKS"}.
      * @param text The text, or {@code null} if none.
      */
-    private void append(final String keyword, final InternationalString text) {
+    private void append(final String keyword, final InternationalString text, final ElementKind
type) {
         if (text != null) {
             final String localized = CharSequences.trimWhitespaces(text.toString(locale));
             if (localized != null && !localized.isEmpty()) {
                 requestNewLine = true;
                 openElement(keyword);
+                setColor(type);
                 quote(localized);
+                resetColor();
                 closeElement();
             }
         }



Mime
View raw message