[Schmitzm-commits] r249 - in trunk/src/schmitzm: jfree/chart/style jfree/feature/style xml
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Jul 31 13:31:55 CEST 2009
Author: mojays
Date: 2009-07-31 13:31:55 +0200 (Fri, 31 Jul 2009)
New Revision: 249
Modified:
trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
trunk/src/schmitzm/xml/XMLUtil.java
Log:
XMLUtil: setAttribute(..) parameter "ignoreNull" changed to "inclNullAttr"
ChartStyleXMLFactory: write plot definition to XML
FeatureChartStyleXMLFactory: bug fixed
Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2009-07-31 10:54:46 UTC (rev 248)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2009-07-31 11:31:55 UTC (rev 249)
@@ -30,12 +30,9 @@
package schmitzm.jfree.chart.style;
import java.awt.Color;
-import java.awt.Paint;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.Format;
@@ -400,19 +397,16 @@
root.setAttribute("orientation", "vertical" );
// Element for background
- if ( style.getBackground() != null )
- addChildToElement(root, "background", "paint", style.getBackground() );
+ addChildToElement(root, "background", false, "paint", style.getBackground() );
// Element for border
- addChildToElement(root, "border", "visible", style.isBorderVisible() );
+ addChildToElement(root, "border", false, "visible", style.isBorderVisible() );
// Chart title
- if ( style.getTitleStyle() != null )
- addLabelChildToElement(root, "title", style.getTitleStyle() );
+ addLabelChildToElement(root, "title", style.getTitleStyle() );
// Chart description
- if ( style.getDescStyle() != null )
- addLabelChildToElement(root, "desc", style.getDescStyle() );
+ addLabelChildToElement(root, "desc", style.getDescStyle() );
// Axis
if ( style.getAxisCount() > 0 )
@@ -427,11 +421,33 @@
addRendererChildToElement(root, style.getRendererStyle(i));
// Plot
- Element plotElem = addChildToElement(root, "plot");
-
+ if ( style.getPlotStyle() != null ) {
+ Element plotElem = addChildToElement(root, "plot");
+ ChartPlotStyle plotStyle = style.getPlotStyle();
+ addChildToElement(plotElem, "foreground", false,
+ "alpha", plotStyle.getForegroundAlpha()
+ );
+ addChildToElement(plotElem, "background", false,
+ "alpha", plotStyle.getBackgroundAlpha(),
+ "paint", plotStyle.getBackgroundPaint()
+ );
+ if ( plotStyle.getInsets() != null )
+ addChildToElement(plotElem, "insets", false,
+ "top", plotStyle.getInsets().getTop(),
+ "bottom", plotStyle.getInsets().getBottom(),
+ "left", plotStyle.getInsets().getLeft(),
+ "right", plotStyle.getInsets().getRight()
+ );
+ addChildToElement(plotElem, "domainGridline", false,
+ "visible", plotStyle.isDomainGridlineVisible(),
+ "paint", plotStyle.getDomainGridlinePaint()
+ );
+ addChildToElement(plotElem, "rangeGridline", false,
+ "visible", plotStyle.isRangeGridlineVisible(),
+ "paint", plotStyle.getRangeGridlinePaint()
+ );
+ }
- // TODO: <renderer> + <plot>
-
// Type specific style properties
if ( style instanceof BasicChartStyle ) {
root.setAttribute("stepped", String.valueOf( ((BasicChartStyle)style).isStepped() ));
@@ -445,25 +461,44 @@
}
/**
+ * Creates an child element with no attributes. 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 childName name of the new child
+ * @return the new child element
+ */
+ public static Element addChildToElement(Element element, String childName) {
+ return addChildToElement(element,childName,true);
+ }
+
+ /**
* Creates an child element and sets some attributes. If an element is given,
- * the new child is automatically added.
+ * the new child is automatically added.
* @param element if not {@code null} the new element is added as child to
* this element
* @param childName name of the new child
+ * @param inclNullAttr if {@code false} attributes with value {@code null}
+ * are not set; if ALL attributes are {@code null} also
+ * the child is not created!
* @param attributes attribute/value pairs for the new child element
* @return the new child element
*/
- public static Element addChildToElement(Element element, String childName, Object... attributes) {
+ public static Element addChildToElement(Element element, String childName, boolean inclNullAttr, Object... attributes) {
// Create child
Element child = new Element(childName,SCHEMA_URI);
// Set child attributes
+ boolean anyAttrSet = false;
for (int i=0; i<attributes.length; i+=2) {
String attrName = attributes[i].toString();
- String attrValue = (attributes[i+1] != null) ? attributes[i+1].toString() : "";
- if ( attributes[i+1] instanceof Color )
- attrValue = Integer.toHexString( ((Color)attributes[i+1]).getRGB() );
- child.setAttribute(attrName, attrValue);
+ Object attrValue = attributes[i+1];
+ anyAttrSet |= XMLUtil.setAttribute(child, attrName, attrValue, inclNullAttr);
}
+ // if null attributes should be ignored and NO attribute is
+ // actually set, also the child is not created!
+ if ( !anyAttrSet && !inclNullAttr )
+ child = null;
+
// If element is given, the child is added
if ( element != null )
element.addContent(child);
@@ -485,7 +520,8 @@
if ( labelStyle == null )
return null;
// Create and add child with paint attribute
- Element labelElem = addChildToElement(element, titleChildName, "paint", labelStyle.getPaint());
+ Element labelElem = addChildToElement(element, titleChildName);
+ XMLUtil.setNotNullAttribute(labelElem, "paint", labelStyle.getPaint());
// Set title to element content
labelElem.setText( labelStyle.getLabelTranslation().toOneLine() );
@@ -506,18 +542,18 @@
return null;
// Create and add child with visible attribute
- Element axisElem = addChildToElement(element, axisChildName, "visible", axisStyle.isVisible());
+ Element axisElem = addChildToElement(element, axisChildName);
+ XMLUtil.setNotNullAttribute(axisElem, "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());
+ XMLUtil.setNotNullAttribute(titleElem, "angle", axisStyle.getLabelAngle());
// Create and add child <valueLabels>
Element valueLabelsElem = addChildToElement(axisElem, "valueLabels");
- if ( axisStyle.getValuesAngle() != null )
- valueLabelsElem.setAttribute("valueAngle", axisStyle.getValuesAngle().toString() );
+ XMLUtil.setNotNullAttribute(valueLabelsElem, "valueAngle", axisStyle.getValuesAngle());
+
Format format = axisStyle.getValuesFormat();
if ( format instanceof DateFormat )
valueLabelsElem.setAttribute("dateFormat", format.toString());
Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java 2009-07-31 10:54:46 UTC (rev 248)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java 2009-07-31 11:31:55 UTC (rev 249)
@@ -125,11 +125,11 @@
// Attribute definition
if ( style.getAttributeCount() > 0 )
- addChildToElement(root, "domainAttr", "name", style.getAttributeName(0));
+ addChildToElement(attrElem, "domainAttr", true, "name", style.getAttributeName(0));
if ( style.getAttributeCount() > 1 )
- addChildToElement(root, "rangeAttr", "name", style.getAttributeName(1));
+ addChildToElement(attrElem, "rangeAttr", true, "name", style.getAttributeName(1));
if ( style.getAttributeCount() > 2 )
- addChildToElement(root, "rangeAttr2", "name", style.getAttributeName(2));
+ addChildToElement(attrElem, "rangeAttr2", true, "name", style.getAttributeName(2));
return root;
}
Modified: trunk/src/schmitzm/xml/XMLUtil.java
===================================================================
--- trunk/src/schmitzm/xml/XMLUtil.java 2009-07-31 10:54:46 UTC (rev 248)
+++ trunk/src/schmitzm/xml/XMLUtil.java 2009-07-31 11:31:55 UTC (rev 249)
@@ -162,15 +162,15 @@
* <ul>
* <li>{@link Color}: the color is converted to hex rgb string</li>
* </ul>
- * @param element element the attribute is set for
- * @param attrName name of the attribute to set
- * @param value attribute value
- * @param ignoreNull if {@code true} and {@code value} is {@code null}
- * the attribute is NOT SET
+ * @param element element the attribute is set for
+ * @param attrName name of the attribute to set
+ * @param value attribute value
+ * @param inclNullAttr if {@code false} and {@code value} is {@code null}
+ * the attribute is NOT SET
* @return {@code true} if the attribute is set
*/
- public static boolean setAttribute(Element element, String attrName, Object value, boolean ignoreNull) {
- if ( value == null && ignoreNull )
+ public static boolean setAttribute(Element element, String attrName, Object value, boolean inclNullAttr) {
+ if ( value == null && !inclNullAttr )
return( false );
if ( value == null )
More information about the Schmitzm-commits
mailing list