[Schmitzm-commits] r235 - in trunk: doc src/schmitzm/jfree/chart/style src/schmitzm/jfree/feature/style

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Jul 19 13:53:06 CEST 2009


Author: mojays
Date: 2009-07-19 13:53:01 +0200 (Sun, 19 Jul 2009)
New Revision: 235

Modified:
   trunk/doc/Chart style XML structure.pdf
   trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
   trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
   trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
Log:
chart style documentation v1.2
methods in (Feature)ChartStyleXMLFactory to write style to XML

Modified: trunk/doc/Chart style XML structure.pdf
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2009-07-19 10:39:30 UTC (rev 234)
+++ trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java	2009-07-19 11:53:01 UTC (rev 235)
@@ -99,7 +99,7 @@
   /**
    * Returns the angle (in degrees) the axis values are rotated by.
    */
-  public double getValuesAngle() {
+  public Double getValuesAngle() {
     return valuesAngleDegr;
   }
 
@@ -114,7 +114,7 @@
    * Sets the angle (in degrees) the label text is rotated by.
    * @param color Color for the label text
    */
-  public void setValuesAngle(double angel) {
+  public void setValuesAngle(Double angel) {
     this.valuesAngleDegr = angel;
   }
 

Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-19 10:39:30 UTC (rev 234)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java	2009-07-19 11:53:01 UTC (rev 235)
@@ -18,7 +18,10 @@
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.text.DateFormat;
 import java.text.DecimalFormat;
+import java.text.Format;
+import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.util.List;
 import java.util.Random;
@@ -172,8 +175,7 @@
    * Reads the {@link ChartLabelStyle} properties from an XML element.
    * <ul>
    *   <li>Attribute "paint": color of the label</li>
-   *   <li>Attribute "angle": angle of the label</li>
-   *   <li>Child element "label": the label content</li>
+   *   <li>Element content: the label title</li>
    * </ul>
    * @param element
    * @param style
@@ -184,10 +186,9 @@
     if ( color != null )
       style.setPaint( color );
     
-    // label in child element <label>
-    Element labelElem = element.getChild("label");
-    if ( labelElem != null )
-      style.setLabel( labelElem.getTextTrim() ); 
+    // label in element data
+    String label = element.getTextTrim();
+    style.setLabel( label != null ? label : "" ); 
   }
   
   /**
@@ -210,16 +211,16 @@
   public ChartAxisStyle createAxisStyleFromXML(Element element) {
     ChartAxisStyle style = new ChartAxisStyle();
     
-    // read the common ChartLabelStyle properties
-    applyLabelStyleFromXML(element,style);
-    
     // read "visible" property from attribute
     Boolean visible = XMLUtil.getBooleanAttribute(element, "visible");
     if ( visible != null )
       style.setVisible( visible );
 
-    // read label angle in attribute
-    Double labelAngle = XMLUtil.getDoubleAttribute(element, "angle");
+    // read the axis title from child <title>
+    Element axisTitleElem = element.getChild("title");
+    applyLabelStyleFromXML(axisTitleElem,style);
+    // read the axis title angle from child <title>
+    Double labelAngle = XMLUtil.getDoubleAttribute(axisTitleElem, "angle");
     if ( labelAngle != null )
       style.setLabelAngle( labelAngle );
 
@@ -344,7 +345,7 @@
    *                        used)
    * @param documentUrl     URL to store the style to
    */
-  public static void writeStyleToURL(ChartStyle style, String rootElementName, URL documentUrl) throws IOException, URISyntaxException {
+  public void writeStyleToURL(E style, String rootElementName, URL documentUrl) throws IOException, URISyntaxException {
     final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );
     // Create XML-Document
     XMLUtil.XML_OUTPUTTER.output(
@@ -362,7 +363,7 @@
    * @param rootElementName name for the root element (if {@code null} "ChartType" is 
    *                        used)
    */
-  public static Element createElementFromStyle(ChartStyle style, String rootElementName) {
+  public Element createElementFromStyle(E style, String rootElementName) {
     if ( rootElementName == null )
       rootElementName = "ChartStyle";
     Element root = new Element(rootElementName,SCHEMA_URI);
@@ -386,8 +387,33 @@
     // Element for border
     addChildToElement(root, "border", "visible", style.isBorderVisible() );
     
-    // T.B.C.
+    // Chart title
+    if ( style.getTitleStyle() != null )
+      addLabelChildToElement(root, "title", style.getTitleStyle() );
+
+    // Chart description
+    if ( style.getDescStyle() != null )
+      addLabelChildToElement(root, "desc", style.getDescStyle() );
+    
+    // Axis
+    if ( style.getAxisCount() > 0 )
+      addAxisChildToElement(root, "domainAxis", style.getAxisStyle(0) );
+    if ( style.getAxisCount() > 1 )
+      addAxisChildToElement(root, "rangeAxis", style.getAxisStyle(1) );
+    if ( style.getAxisCount() > 2 )
+      addAxisChildToElement(root, "rangeAxis2", style.getAxisStyle(2) );
+    
+    // TODO: <renderer> + <plot>
+    
+    // Type specific style properties
+    if ( style instanceof BasicChartStyle ) {
+      root.setAttribute("stepped", String.valueOf( ((BasicChartStyle)style).isStepped() ));
+      root.setAttribute("stacked", String.valueOf( ((BasicChartStyle)style).isStacked() ));
+    }
+    if ( style instanceof ScatterChartStyle )
+      root.setAttribute("regrLineVisible", String.valueOf( ((ScatterChartStyle)style).isRegressionLineVisible() ));
       
+    
     return root;
   }
   
@@ -417,4 +443,61 @@
 
     return child;
   }
+
+  /**
+   * Creates an child element for a {@link ChartLabelStyle}. Besides the attributes
+   * the label title is set as element content. If an element is given, the new child
+   * is automatically added. 
+   * @param element    if not {@code null} the new element is added as child to
+   *                   this element
+   * @param titleChildName  name of the new child
+   * @param labelStyle the label style to create the element for
+   * @return the new child element; {@code null} if {@code labelStyle} is {@code null}
+   */
+  private static Element addLabelChildToElement(Element element, String titleChildName, ChartLabelStyle labelStyle) {
+    if ( labelStyle == null )
+      return null;
+    // Create and add child with paint attribute
+    Element labelElem = addChildToElement(element, titleChildName, "paint", labelStyle.getPaint());
+    // Set title to element content
+    labelElem.setText( labelStyle.getLabelTranslation().toOneLine() );
+
+    return labelElem;
+  }
+
+  /**
+   * Creates an child element for a {@link ChartAxisStyle}.
+   * If an element is given, the new child is automatically added. 
+   * @param element    if not {@code null} the new element is added as child to
+   *                   this element
+   * @param axisChildName  name of the new child
+   * @param labelStyle the label style to create the element for
+   * @return the new child element; {@code null} if {@code labelStyle} is {@code null}
+   */
+  private static Element addAxisChildToElement(Element element, String axisChildName, ChartAxisStyle axisStyle) {
+    if ( axisStyle == null )
+      return null;
+    
+    // Create and add child with visible attribute
+    Element axisElem = addChildToElement(element, axisChildName, "visible", axisStyle.isVisible()); 
+    
+    // Create and add child <title>
+    Element titleElem = addLabelChildToElement(axisElem, "title", axisStyle);
+    // Add angle attribute to <title> element
+    if ( axisStyle.getLabelAngle() != null )
+      titleElem.setAttribute("angle", axisStyle.getLabelAngle().toString());
+    
+    // Create and add child <valueLabels>
+    Element valueLabelsElem = addChildToElement(axisElem, "valueLabels");
+    if ( axisStyle.getValuesAngle() != null )
+      valueLabelsElem.setAttribute("valueAngle", axisStyle.getValuesAngle().toString() );
+    Format format = axisStyle.getValuesFormat();
+    if ( format instanceof DateFormat )
+      valueLabelsElem.setAttribute("dateFormat", format.toString());
+    if ( format instanceof NumberFormat )
+      valueLabelsElem.setAttribute("numberFormat", format.toString());
+    
+    return axisElem;
+  }
+
 }

Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2009-07-19 10:39:30 UTC (rev 234)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2009-07-19 11:53:01 UTC (rev 235)
@@ -16,6 +16,7 @@
 import org.geotools.feature.FeatureCollection;
 import org.jdom.Element;
 
+import schmitzm.jfree.chart.style.ChartLabelStyle;
 import schmitzm.jfree.chart.style.ChartStyle;
 import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
 import schmitzm.jfree.chart.style.ChartType;
@@ -89,4 +90,31 @@
     }
     throw new UnsupportedOperationException("Style for this chart type not yet supported for features: "+type);
   }
+
+
+  /**
+   * Creates a XML {@link Element} representing the {@link FeatureChartStylee}.
+   * @param style           style to create an element for
+   * @param rootElementName name for the root element (if {@code null} "ChartType" is 
+   *                        used)
+   */
+  @Override
+  public Element createElementFromStyle(FeatureChartStyle style, String rootElementName) {
+    Element root = super.createElementFromStyle(style, rootElementName);
+    
+    // Create and add element <featureAttributes>
+    Element attrElem = addChildToElement(root, "featureAttributes");
+    
+    // Attribute definition
+    if ( style.getAttributeCount() > 0 )
+      addChildToElement(root, "domainAttr", "name", style.getAttributeName(0));
+    if ( style.getAttributeCount() > 1 )
+      addChildToElement(root, "rangeAttr", "name", style.getAttributeName(1));
+    if ( style.getAttributeCount() > 2 )
+      addChildToElement(root, "rangeAttr2", "name", style.getAttributeName(2));
+
+    return root;
+  }
+
+
 }



More information about the Schmitzm-commits mailing list