[Schmitzm-commits] r953 - in trunk: doc src/schmitzm/jfree src/schmitzm/jfree/chart/style src/schmitzm/xml src_junit/schmitzm/jfree/feature/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Jul 28 21:23:56 CEST 2010
Author: mojays
Date: 2010-07-28 21:23:54 +0200 (Wed, 28 Jul 2010)
New Revision: 953
Modified:
trunk/doc/Chart style XML structure.pdf
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
trunk/src/schmitzm/xml/XMLUtil.java
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
Log:
New chartstyle features added to XML.
Modified: trunk/doc/Chart style XML structure.pdf
===================================================================
(Binary files differ)
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-07-28 17:50:19 UTC (rev 952)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-07-28 19:23:54 UTC (rev 953)
@@ -966,7 +966,21 @@
// TODO Ich will einen schönen Tooltip für die Regressionslinine in der Legende
}
+
/**
+ * Creates a basic stroke by only some basic attributes
+ * @param lineWidth line width
+ * @param dashAttr defines the dashing
+ * @return
+ */
+ public static Stroke createDefaultStroke(float lineWidth, Float[] dashAttr) {
+ float[] floats = new float[dashAttr.length];
+ for (int i=0; i<floats.length; i++)
+ floats[i] = dashAttr[i];
+ return createDefaultStroke(lineWidth, floats);
+ }
+
+ /**
* Creates a basic stroke by only some basic attributes
* @param lineWidth line width
* @param dashAttr defines the dashing
Modified: trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2010-07-28 17:50:19 UTC (rev 952)
+++ trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2010-07-28 19:23:54 UTC (rev 953)
@@ -91,7 +91,7 @@
/** Holds the dash attributes a series graph is painted with (for all series this property
* is not set explicitly).
* @see BasicStroke */
- protected float[] defaultDashAttr = null;
+ protected Float[] defaultDashAttr = null;
/** Holds whether the shape of a series is visible (for all series this property
* is not set explicitly). */
protected Boolean defaultShapesVisible = null;
@@ -116,7 +116,7 @@
protected Map<Integer, Integer> seriesWidth = new HashMap<Integer, Integer>();
/** Holds the dash attributes a series graph is painted with.
* @see BasicStroke */
- protected Map<Integer,float[]> seriesDashAttr = new HashMap<Integer,float[]>();
+ protected Map<Integer,Float[]> seriesDashAttr = new HashMap<Integer,Float[]>();
/** Holds whether the shape of a series is visible. */
protected Map<Integer, Boolean> seriesShapesVisible = new HashMap<Integer, Boolean>();
/** Holds whether the series is visible in the legend. */
@@ -309,7 +309,7 @@
* @return {@code null} if no specific dashing is set for the series
* @see BasicStroke
*/
- public float[] getSeriesLineDashAttibutes(int series) {
+ public Float[] getSeriesLineDashAttibutes(int series) {
return seriesDashAttr.get(series);
}
@@ -319,7 +319,7 @@
* @param width dash attributes for the series (can be {@code null} to reset
* to a continuous line)
*/
- public void setSeriesLineDashAttributes(int series, float... dashAttr) {
+ public void setSeriesLineDashAttributes(int series, Float... dashAttr) {
if ( dashAttr.length == 0 )
dashAttr = null;
seriesDashAttr.put(series,dashAttr);
@@ -470,7 +470,7 @@
* @return {@code null} if no specific dashing is set for the series
* @see BasicStroke
*/
- public float[] getDefaultLineDashAttibutes() {
+ public Float[] getDefaultLineDashAttibutes() {
return defaultDashAttr;
}
@@ -480,7 +480,7 @@
* @param width dash attributes for the series (can be {@code null} to reset
* to a continuous line)
*/
- public void setDefaultLineDashAttributes(float... dashAttr) {
+ public void setDefaultLineDashAttributes(Float... dashAttr) {
if ( dashAttr.length == 0 )
dashAttr = null;
defaultDashAttr = dashAttr;
@@ -694,7 +694,7 @@
renderer.setSeriesPaint(series, getDefaultPaint(), false);
if ( getDefaultLineWidth() != null || getDefaultLineDashAttibutes() != null ) {
float width = getDefaultLineWidth() == null ? 1.0f : getDefaultLineWidth();
- float[] dashAttr = getDefaultLineDashAttibutes();
+ Float[] dashAttr = getDefaultLineDashAttibutes();
Stroke stroke = JFreeChartUtil.createDefaultStroke(width, dashAttr);
renderer.setSeriesStroke(series, stroke, false);
}
@@ -734,7 +734,7 @@
// Apply rendering stroke (line width)
if ( getSeriesLineWidth(series) != null || getSeriesLineDashAttibutes(series) != null ) {
float width = getDefaultLineWidth() == null ? 1.0f : getDefaultLineWidth();
- float[] dashAttr = getDefaultLineDashAttibutes();
+ Float[] dashAttr = getDefaultLineDashAttibutes();
if ( getSeriesLineWidth(series) != null )
width = getSeriesLineWidth(series);
if ( getSeriesLineDashAttibutes(series) != null )
Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2010-07-28 17:50:19 UTC (rev 952)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2010-07-28 19:23:54 UTC (rev 953)
@@ -286,6 +286,12 @@
if ( defaultLineWidth != null )
style.setDefaultLineWidth(defaultLineWidth);
+ // series line dash attributes
+ Object[] defaultLineDashAttrObj = XMLUtil.getArrayAttribute(element, "lineDash");
+ Float[] defaultLineDashAttr = XMLUtil.convertObjectToFloat(defaultLineDashAttrObj);
+ if ( defaultLineDashAttr != null )
+ style.setDefaultLineDashAttributes(defaultLineDashAttr);
+
// item label visibility
Boolean defaultLabelsVisible = XMLUtil.getBooleanAttribute(element, "itemLabelsVisible");
if ( defaultLabelsVisible != null )
@@ -331,6 +337,12 @@
if ( seriesLineWidth != null )
style.setSeriesLineWidth(i, seriesLineWidth);
+ // series line dash attributes
+ Object[] seriesLineDashAttrObj = XMLUtil.getArrayAttribute(seriesElement, "lineDash");
+ Float[] seriesLineDashAttr = XMLUtil.convertObjectToFloat(seriesLineDashAttrObj);
+ if ( seriesLineDashAttr != null )
+ style.setSeriesLineDashAttributes(i, seriesLineDashAttr);
+
// item label visibility
Boolean labelsVisible = XMLUtil.getBooleanAttribute(seriesElement, "itemLabelsVisible");
if ( labelsVisible != null )
@@ -680,6 +692,7 @@
// Attributes for default series properties
XMLUtil.setNotNullAttribute(rendererElem, "paint", rendererStyle.getDefaultPaint());
XMLUtil.setNotNullAttribute(rendererElem, "lineWidth", rendererStyle.getDefaultLineWidth());
+ XMLUtil.setNotNullAttribute(rendererElem, "lineDash", XMLUtil.convertArrayToSeparatedString(rendererStyle.getDefaultLineDashAttibutes()));
XMLUtil.setNotNullAttribute(rendererElem, "itemLabelsVisible", rendererStyle.isDefaultItemLabelsVisible());
XMLUtil.setNotNullAttribute(rendererElem, "shapesVisible", rendererStyle.isDefaultShapesVisible());
XMLUtil.setNotNullAttribute(rendererElem, "legendVisible", rendererStyle.isDefaultLegendVisible());
@@ -694,6 +707,7 @@
XMLUtil.setNotNullAttribute(seriesElem, "seriesKey", rendererStyle.getSeriesKey(i));
XMLUtil.setNotNullAttribute(seriesElem, "paint", rendererStyle.getSeriesPaint(i));
XMLUtil.setNotNullAttribute(seriesElem, "lineWidth", rendererStyle.getSeriesLineWidth(i));
+ XMLUtil.setNotNullAttribute(seriesElem, "lineDash", XMLUtil.convertArrayToSeparatedString(rendererStyle.getSeriesLineDashAttibutes(i)));
XMLUtil.setNotNullAttribute(seriesElem, "itemLabelsVisible", rendererStyle.isSeriesItemLabelsVisible(i));
XMLUtil.setNotNullAttribute(seriesElem, "shapesVisible", rendererStyle.isSeriesShapesVisible(i));
XMLUtil.setNotNullAttribute(seriesElem, "legendVisible", rendererStyle.isSeriesLegendVisible(i));
Modified: trunk/src/schmitzm/xml/XMLUtil.java
===================================================================
--- trunk/src/schmitzm/xml/XMLUtil.java 2010-07-28 17:50:19 UTC (rev 952)
+++ trunk/src/schmitzm/xml/XMLUtil.java 2010-07-28 19:23:54 UTC (rev 953)
@@ -33,6 +33,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.Vector;
import org.apache.log4j.Logger;
import org.jdom.Element;
@@ -58,7 +59,8 @@
public static final JAXPDOMAdapter JDOM_TO_JAX = new JAXPDOMAdapter();
/** Writes XML element to file. */
public static final XMLOutputter XML_OUTPUTTER = new XMLOutputter( Format.getPrettyFormat() );
-
+ /** Delimiter to encode lists in an XML attribute. */
+ public static final String LIST_DELIMITER = ";";
/**
* Gets the attribute value from element.
* @param element element where the attribute is determined from
@@ -162,7 +164,7 @@
}
/**
- * Gets a string-separated attribute value from element as {@code Set<String>}.
+ * Gets a semicolon-separated attribute value from element as {@code Set<String>}.
* @param element element where the attribute is determined from
* @param attrName name of the attribute
* @param defValue optional default value returned if attribute is not found (or empty)
@@ -179,14 +181,32 @@
}
/**
+ * Gets a semicolon-separated attribute value from element as {@code Object[]}.
+ * @param element element where the attribute is determined from
+ * @param attrName name of the attribute
+ * @param defValue optional default values returned if attribute is not found (or empty)
+ * @return {@code null} if {@code element} is {@code null} or attribute is not
+ * specified in element
+ */
+ public static Object[] getArrayAttribute(Element element, String attrName, Object... defValue) {
+ String value = getAttribute(element, attrName);
+ if ( value != null )
+ return convertSeparatedStringToArray(value);
+ if ( defValue.length > 0 )
+ return defValue;
+ return null;
+ }
+
+ /**
* Parses a semicolon-separated string and stores its elements in
* a set.
* @param objectString the semicolon-separated string of objects
* @return an empty set if the string is empty
+ * @see #LIST_DELIMITER
*/
public static Set<Object> convertSeparatedStringToSet(String objectString) {
Set<Object> objects = new HashSet<Object>();
- StringTokenizer st = new StringTokenizer(objectString,";\n");
+ StringTokenizer st = new StringTokenizer(objectString,LIST_DELIMITER+"\n");
for (;st.hasMoreTokens();)
objects.add( st.nextToken() );
return objects;
@@ -197,15 +217,59 @@
* @param objects the objects which are transformed to string and
* concatenated
* @return {@code null} if the set is empty or {@code null}
+ * @see #LIST_DELIMITER
*/
public static String convertSetToSeparatedString(Set<Object> objects) {
if ( objects == null || objects.isEmpty() )
return null;
- return LangUtil.stringConcatWithSep(";", objects.toArray());
+ return LangUtil.stringConcatWithSep(LIST_DELIMITER, objects.toArray());
}
+ /**
+ * Parses a semicolon-separated string and stores its elements in
+ * an {@link Object}-array.
+ * @param objectString the semicolon-separated string of objects
+ * @return an empty array if the string is empty
+ * @see #LIST_DELIMITER
+ */
+ public static Object[] convertSeparatedStringToArray(String objectString) {
+ Vector<Object> objects = new Vector<Object>();
+ StringTokenizer st = new StringTokenizer(objectString,LIST_DELIMITER+"\n");
+ for (;st.hasMoreTokens();)
+ objects.add( st.nextToken() );
+ return objects.toArray( new Object[0] );
+ }
/**
+ * Creates a semicolon-separated string of the elements of an array.
+ * @param objects the objects which are transformed to string and
+ * concatenated
+ * @return {@code null} if the set is empty or {@code null}
+ * @see #LIST_DELIMITER
+ */
+ public static String convertArrayToSeparatedString(Object[] objects) {
+ if ( objects == null || objects.length == 0 )
+ return null;
+ return LangUtil.stringConcatWithSep(LIST_DELIMITER, objects);
+ }
+
+ /**
+ * Converts an {@link Object}-array to {@code Float[]}.
+ * @param objects objects
+ * @return {@code null} if the input array is null
+ */
+ public static Float[] convertObjectToFloat(Object[] objects) {
+ if ( objects == null )
+ return null;
+
+ Float[] floatValues = new Float[objects.length];
+ for (int i=0; i<objects.length; i++)
+ floatValues[i] = Float.parseFloat( objects[i].toString() );
+
+ return floatValues;
+ }
+
+ /**
* Sets an attribute value. The {@code .toString()} method is used
* to convert the object value to string.<br>
* Exceptions:
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-07-28 17:50:19 UTC (rev 952)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-07-28 19:23:54 UTC (rev 953)
@@ -119,6 +119,8 @@
// secondary axis.
ChartRendererStyle chartRendererStyle2 = new ChartRendererStyle();
chartRendererStyle2.setDefaultLineDashAttributes(5.0f,5.0f);
+ chartRendererStyle2.setSeriesLineWidth(1, 10);
+ chartRendererStyle2.setSeriesLineDashAttributes(1, 10f,10f);
lineChartStyle.setRendererStyle(1, chartRendererStyle2);
@@ -153,9 +155,12 @@
File testFile2 = File.createTempFile("testDoubleLineChart", ".xml");
xmlFactory.writeStyleToFile(lineChartAUsXMLgelesen, "testDoubleLineChart",
testFile2);
+ String readXML = IOUtil.readFileAsString(testFile2);
+ System.out.println(writtenXML);
+ System.out.println(readXML);
assertEquals(
"Nachdem das Style geschrieben, gelesen und wieder geschrieben wurde ist das XML nicht gleich!",
- writtenXML, IOUtil.readFileAsString(testFile2));
+ writtenXML, readXML);
}
More information about the Schmitzm-commits
mailing list