[Schmitzm-commits] r231 - in trunk/src/schmitzm: jfree/chart/style xml
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Jul 18 23:53:16 CEST 2009
Author: mojays
Date: 2009-07-18 23:53:16 +0200 (Sat, 18 Jul 2009)
New Revision: 231
Modified:
trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
trunk/src/schmitzm/xml/XMLUtil.java
Log:
Ups... I forgot the new ChartType.java
Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -71,7 +71,7 @@
/** Holds a long description for the chart. */
protected ChartLabelStyle descStyle = null;
/** Holds the background color for the chart. */
- protected Paint bgPaint = null;
+ protected Color bgPaint = null;
/** Stores whether a border is shown around the whole chart. */
protected boolean borderVisible = false;
/** Holds the styles of the chart axis. */
@@ -207,7 +207,7 @@
/**
* Returns the background color of the chart.
*/
- public Paint getBackground() {
+ public Color getBackground() {
return bgPaint;
}
@@ -215,7 +215,7 @@
* Sets the background color of the chart.
* @param paint the background color for the chart
*/
- public void setBackground(Paint paint) {
+ public void setBackground(Color paint) {
this.bgPaint = paint;
}
Modified: trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -55,7 +55,7 @@
* @param labelAngle angel (in degrees) the axis label is rotated by
* @param valuesAngle angel (in degrees) the axis values are rotated by
*/
- public ChartAxisStyle(String title, Paint color, Double labelAngle, Double valuesAngle) {
+ public ChartAxisStyle(String title, Color color, Double labelAngle, Double valuesAngle) {
super(title,color);
setLabelAngle(labelAngle);
setValuesAngle(valuesAngle);
@@ -68,7 +68,7 @@
* @param labelAngle angel (in degrees) the axis label is rotated by
* @param valuesAngle angel (in degrees) the axis values are rotated by
*/
- public ChartAxisStyle(Translation title, Paint color, Double labelAngle, Double valuesAngle) {
+ public ChartAxisStyle(Translation title, Color color, Double labelAngle, Double valuesAngle) {
super(title,color);
setLabelAngle(labelAngle);
setValuesAngle(valuesAngle);
Modified: trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/ChartLabelStyle.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -36,7 +36,7 @@
/** Holds the label text. */
protected Translation label = null;
/** Holds the text color of the label. */
- protected Paint paint = null;
+ protected Color paint = null;
/**
* Creates a new style with default values (empty label, color black).
@@ -50,7 +50,7 @@
* @param label label text (localized or static label is provided)
* @param color text color
*/
- public ChartLabelStyle(String label, Paint color) {
+ public ChartLabelStyle(String label, Color color) {
this(new Translation(label), color);
}
@@ -59,7 +59,7 @@
* @param label label text (static
* @param color text color
*/
- public ChartLabelStyle(Translation label, Paint color) {
+ public ChartLabelStyle(Translation label, Color color) {
setLabelTranslation(label);
setPaint(color);
}
@@ -98,7 +98,7 @@
/**
* Returns the color for the label text.
*/
- public Paint getPaint() {
+ public Color getPaint() {
return paint;
}
@@ -106,7 +106,7 @@
* Sets the color for the label text.
* @param color Color for the label text
*/
- public void setPaint(Paint color) {
+ public void setPaint(Color color) {
this.paint = color;
}
Modified: trunk/src/schmitzm/jfree/chart/style/ChartPlotStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartPlotStyle.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/ChartPlotStyle.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -63,17 +63,17 @@
/** Holds the foreground transparency. */
protected Float foregroundAlpha = 1.0f;
/** Holds the background color of the plot. */
- protected Paint backgroundPaint = null;
+ protected Color backgroundPaint = null;
/** Holds the background transparency. */
protected Float backgroundAlpha = 1.0f;
/** Holds whether the domain grid line is visible. */
protected Boolean domainGridlineVisible = null;
/** Holds the color of the domain grid line. */
- protected Paint domainGridlinePaint = null;
+ protected Color domainGridlinePaint = null;
/** Holds whether the range grid line is visible. */
protected Boolean rangeGridlineVisible = null;
/** Holds the color of the range grid line. */
- protected Paint rangeGridlinePaint = null;
+ protected Color rangeGridlinePaint = null;
/**
@@ -134,7 +134,7 @@
* Returns the background color of the plot.
* @return {@code null} if no specific color is set
*/
- public Paint getBackgroundPaint() {
+ public Color getBackgroundPaint() {
return backgroundPaint;
}
@@ -143,7 +143,7 @@
* @param color background color for the plot (can be {@code null} to reset
* to a non-specific color)
*/
- public void setBackgroundPaint(Paint color) {
+ public void setBackgroundPaint(Color color) {
this.backgroundPaint = color;
}
@@ -169,7 +169,7 @@
* Returns the color of the plot's domain grid line.
* @return {@code null} if no specific color is set
*/
- public Paint getDomainGridlinePaint() {
+ public Color getDomainGridlinePaint() {
return domainGridlinePaint;
}
@@ -178,7 +178,7 @@
* @param color color for the domain grid line (can be {@code null} to reset
* to a non-specific color)
*/
- public void setDomainGridlinePaint(Paint color) {
+ public void setDomainGridlinePaint(Color color) {
this.domainGridlinePaint = color;
}
@@ -203,7 +203,7 @@
* Returns the color of the plot's range grid line.
* @return {@code null} if no specific color is set
*/
- public Paint getRangeGridlinePaint() {
+ public Color getRangeGridlinePaint() {
return rangeGridlinePaint;
}
@@ -212,7 +212,7 @@
* @param color color for the range grid line (can be {@code null} to reset
* to a non-specific color)
*/
- public void setRangeGridlinePaint(Paint color) {
+ public void setRangeGridlinePaint(Color color) {
this.rangeGridlinePaint = color;
}
Modified: trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/ChartRendererStyle.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -56,7 +56,7 @@
/** Holds whether the item labels are visible for a series. */
protected Map<Integer, Boolean> seriesItemLabelsVisible = new HashMap<Integer, Boolean>();
/** Holds the color a series is painted with. */
- protected Map<Integer, Paint> seriesPaint = new HashMap<Integer, Paint>();
+ protected Map<Integer, Color> seriesPaint = new HashMap<Integer, Color>();
/** Holds whether the shape of a series is visible. */
protected Map<Integer, Boolean> seriesShapesVisible = new HashMap<Integer, Boolean>();
/** Holds the (percentage) margin for the bars. Only applicable for {@link XYBarRenderer}. */
@@ -89,7 +89,7 @@
* @param series series index
* @return {@code null} if no specific color is set for the series
*/
- public Paint getSeriesPaint(int series) {
+ public Color getSeriesPaint(int series) {
return seriesPaint.get(series);
}
@@ -99,7 +99,7 @@
* @param color color for the series (can be {@code null} to reset
* to a non-specific color)
*/
- public void setSeriesPaint(int series, Paint color) {
+ public void setSeriesPaint(int series, Color color) {
seriesPaint.put(series,color);
}
Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyle.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyle.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -11,6 +11,7 @@
package schmitzm.jfree.chart.style;
+import java.awt.Color;
import java.awt.Paint;
@@ -98,13 +99,13 @@
/**
* Returns the background color of the chart.
*/
- public Paint getBackground();
+ public Color getBackground();
/**
* Sets the background color of the chart.
* @param paint the background color for the chart
*/
- public void setBackground(Paint paint);
+ public void setBackground(Color paint);
/**
* Returns whether a border is shown around the whole chart.
Modified: trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/jfree/chart/style/ChartStyleXMLFactory.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -11,7 +11,13 @@
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.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
@@ -29,6 +35,9 @@
* @version 1.0
*/
public class ChartStyleXMLFactory<E extends ChartStyle> {
+ /** URL for XML schema */
+ public static final String SCHEMA_URI = "http://www.wikisquare.de/AtlasML";
+
/**
* Reads a chart definition from XML element. The chart style ID
* is taken from "id" attribute.
@@ -93,7 +102,7 @@
chartStyle.setURLs( XMLUtil.getBooleanAttribute(element,"urls",true) );
// Background color
- Paint color = XMLUtil.getColorAttribute(element.getChild("background"),"paint");
+ Color color = XMLUtil.getColorAttribute(element.getChild("background"),"paint");
if ( color != null )
chartStyle.setBackground( color );
@@ -171,7 +180,7 @@
*/
private void applyLabelStyleFromXML(Element element, ChartLabelStyle style) {
// color in attribute
- Paint color = XMLUtil.getColorAttribute(element, "paint");
+ Color color = XMLUtil.getColorAttribute(element, "paint");
if ( color != null )
style.setPaint( color );
@@ -250,7 +259,7 @@
for (int i=0; i<seriesElements.size(); i++) {
Element seriesElement = seriesElements.get(i);
// series paint
- Paint seriesPaint = XMLUtil.getColorAttribute(seriesElement, "paint");
+ Color seriesPaint = XMLUtil.getColorAttribute(seriesElement, "paint");
if ( seriesPaint != null )
style.setSeriesPaint(i, seriesPaint);
@@ -288,7 +297,7 @@
Float alpha = XMLUtil.getFloatAttribute(backegroundElem, "alpha");
if ( alpha != null )
style.setBackgroundAlpha(alpha);
- Paint color = XMLUtil.getColorAttribute(backegroundElem, "paint");
+ Color color = XMLUtil.getColorAttribute(backegroundElem, "paint");
if ( color != null )
style.setBackgroundPaint(color);
}
@@ -309,7 +318,7 @@
Boolean visible = XMLUtil.getBooleanAttribute(domainGridElem, "visible");
if ( visible != null )
style.setDomainGridlineVisible(visible);
- Paint color = XMLUtil.getColorAttribute(domainGridElem, "paint");
+ Color color = XMLUtil.getColorAttribute(domainGridElem, "paint");
if ( color != null )
style.setDomainGridlinePaint(color);
}
@@ -320,11 +329,94 @@
Boolean visible = XMLUtil.getBooleanAttribute(rangeGridElem, "visible");
if ( visible != null )
style.setRangeGridlineVisible(visible);
- Paint color = XMLUtil.getColorAttribute(rangeGridElem, "paint");
+ Color color = XMLUtil.getColorAttribute(rangeGridElem, "paint");
if ( color != null )
style.setRangeGridlinePaint(color);
}
return style;
}
+
+ /**
+ * Stores a {@link ChartStyle} to an XML file.
+ * @param style style to store
+ * @param rootElementName name for the root element (if {@code null} "ChartType" is
+ * used)
+ * @param documentUrl URL to store the style to
+ */
+ public static void writeStyleToURL(ChartStyle style, String rootElementName, URL documentUrl) throws IOException, URISyntaxException {
+ final FileWriter out = new FileWriter( new File(documentUrl.toURI()) );
+ // Create XML-Document
+ XMLUtil.XML_OUTPUTTER.output(
+ createElementFromStyle(style, rootElementName),
+ out
+ );
+ out.flush();
+ out.close();
+
+ }
+
+ /**
+ * Creates a XML {@link Element} representing the {@link ChartStyle}.
+ * @param style style to create an element for
+ * @param rootElementName name for the root element (if {@code null} "ChartType" is
+ * used)
+ */
+ public static Element createElementFromStyle(ChartStyle style, String rootElementName) {
+ if ( rootElementName == null )
+ rootElementName = "ChartStyle";
+ Element root = new Element(rootElementName,SCHEMA_URI);
+ // write common attributes
+ root.setAttribute("id", style.getID());
+ root.setAttribute("type", style.getType().toString());
+ root.setAttribute("legend", String.valueOf( style.hasLegend() ));
+ root.setAttribute("tooltips", String.valueOf( style.hasTooltips() ));
+ root.setAttribute("urls", String.valueOf( style.hasURLs() ));
+
+ // Attribute for plot orientation
+ if ( PlotOrientation.HORIZONTAL.equals( style.getOrientation() ) )
+ root.setAttribute("orientation", "horizontal" );
+ else if ( PlotOrientation.VERTICAL.equals( style.getOrientation() ) )
+ root.setAttribute("orientation", "vertical" );
+
+ // Element for background
+ if ( style.getBackground() != null )
+ addChildToElement(root, "background", "paint", style.getBackground() );
+
+ // Element for border
+ addChildToElement(root, "border", "visible", style.isBorderVisible() );
+
+ // Element for title
+ addChildToElement(root, "border", "visible", style.isBorderVisible() );
+
+
+ return root;
+ }
+
+ /**
+ * Creates an child element and sets some 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
+ * @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) {
+ // Create child
+ Element child = new Element(childName,SCHEMA_URI);
+ // Set child attributes
+ 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);
+ }
+ // If element is given, the child is added
+ if ( element != null )
+ element.addContent(child);
+
+ return child;
+ }
}
Modified: trunk/src/schmitzm/xml/XMLUtil.java
===================================================================
--- trunk/src/schmitzm/xml/XMLUtil.java 2009-07-18 19:26:43 UTC (rev 230)
+++ trunk/src/schmitzm/xml/XMLUtil.java 2009-07-18 21:53:16 UTC (rev 231)
@@ -5,6 +5,7 @@
import org.apache.log4j.Logger;
import org.jdom.Element;
import org.jdom.adapters.JAXPDOMAdapter;
+import org.jdom.output.XMLOutputter;
import schmitzm.swing.SwingUtil;
@@ -20,6 +21,8 @@
/** Wrapper from JDOM to W3C. */
public static final JAXPDOMAdapter JDOM_TO_JAX = new JAXPDOMAdapter();
+ /** Writes XML element to file. */
+ public static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
/**
* Gets the attribute value from element.
More information about the Schmitzm-commits
mailing list