[Schmitzm-commits] r989 - in trunk: src/schmitzm/jfree src/schmitzm/jfree/chart/style src/schmitzm/jfree/feature/style src/schmitzm/jfree/table/style src/schmitzm/swing src_junit/schmitzm/jfree/feature/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Aug 26 13:03:39 CEST 2010
Author: mojays
Date: 2010-08-26 13:03:37 +0200 (Thu, 26 Aug 2010)
New Revision: 989
Modified:
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
trunk/src/schmitzm/jfree/table/style/TableChartStyle.java
trunk/src/schmitzm/swing/SwingUtil.java
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
Log:
- Legend splitting moved to JFreeChartUtil.
- setting font for axis labels and values
- "ignoreNullRangeValues" integrated in TableChartStyle.copyTo(.)
- DEFAULT_FONT in SwingUtil
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -39,9 +39,14 @@
import org.apache.log4j.Logger;
import org.jfree.chart.JFreeChart;
+import org.jfree.chart.LegendItemSource;
import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.block.BlockBorder;
+import org.jfree.chart.block.BlockContainer;
+import org.jfree.chart.block.BorderArrangement;
+import org.jfree.chart.block.EmptyBlock;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.event.PlotChangeListener;
import org.jfree.chart.event.RendererChangeEvent;
@@ -72,6 +77,7 @@
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.renderer.xy.XYStepAreaRenderer;
import org.jfree.chart.renderer.xy.XYStepRenderer;
+import org.jfree.chart.title.CompositeTitle;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.Title;
import org.jfree.chart.urls.StandardXYURLGenerator;
@@ -89,7 +95,10 @@
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.ui.RectangleEdge;
+import org.jfree.ui.RectangleInsets;
+import schmitzm.jfree.chart.FilteredLegendItemSource;
import schmitzm.jfree.chart.renderer.SelectionRenderer;
import schmitzm.jfree.chart.selection.DatasetSelectionModel;
import schmitzm.jfree.chart.style.BasicChartStyle;
@@ -159,6 +168,46 @@
}
/**
+ * Splits the legend of a chart in two pieces for each range
+ * axis.<br>
+ * Does nothing if chart has only 1 range axis.
+ */
+ public static void splitLegend(JFreeChart chart) {
+ if ( getRangeAxisCountFromPlot(chart.getPlot()) < 2 )
+ return;
+
+ // remove old legend
+ chart.removeLegend();
+
+ // create left legend for first dataset legend items
+ LegendItemSource lis1 = new FilteredLegendItemSource(
+ (LegendItemSource)getRendererForDataset(chart.getPlot(), 0)
+ );
+ LegendTitle legend1 = new LegendTitle(lis1);
+ legend1.setMargin(new RectangleInsets(2, 2, 2, 2));
+ legend1.setFrame(new BlockBorder());
+
+ // create right legend for second dataset legend items
+ LegendItemSource lis2 = new FilteredLegendItemSource(
+ (LegendItemSource)JFreeChartUtil.getRendererForDataset(chart.getPlot(), 1)
+ );
+ LegendTitle legend2 = new LegendTitle(lis2);
+ legend2.setMargin(new RectangleInsets(2, 2, 2, 2));
+ legend2.setFrame(new BlockBorder());
+
+ // combine the legends in a block
+ BlockContainer container = new BlockContainer(new BorderArrangement());
+ container.add(legend1, RectangleEdge.LEFT);
+ container.add(legend2, RectangleEdge.RIGHT);
+ container.add(new EmptyBlock(2000, 0));
+
+ // create the new legend
+ CompositeTitle legends = new CompositeTitle(container);
+ legends.setPosition(RectangleEdge.BOTTOM);
+ chart.addSubtitle(legends);
+ }
+
+ /**
* Fires a change event to all {@link PlotChangeListener} connected to the
* plot.
*
Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -603,32 +603,8 @@
}
// Split the legend when multiple range axis are used
- if ( JFreeChartUtil.getRangeAxisCountFromPlot(chart.getPlot()) > 1 ) {
- chart.removeLegend();
- LegendItemSource lis1 = new FilteredLegendItemSource(
- (LegendItemSource)JFreeChartUtil.getRendererForDataset(chart.getPlot(), 0)
- );
- LegendTitle legend1 = new LegendTitle(lis1);
- legend1.setWidth(100);
- legend1.setMargin(new RectangleInsets(2, 2, 2, 2));
- legend1.setFrame(new BlockBorder());
-
- LegendItemSource lis2 = new FilteredLegendItemSource(
- (LegendItemSource)JFreeChartUtil.getRendererForDataset(chart.getPlot(), 1)
- );
- LegendTitle legend2 = new LegendTitle(lis2);
- legend2.setMargin(new RectangleInsets(2, 2, 2, 2));
- legend2.setFrame(new BlockBorder());
-
- BlockContainer container = new BlockContainer(new BorderArrangement());
- container.add(legend1, RectangleEdge.LEFT);
- container.add(legend2, RectangleEdge.RIGHT);
- container.add(new EmptyBlock(2000, 0));
- CompositeTitle legends = new CompositeTitle(container);
- legends.setPosition(RectangleEdge.BOTTOM);
- chart.addSubtitle(legends);
- }
-
+ if ( JFreeChartUtil.getRangeAxisCountFromPlot(chart.getPlot()) > 1 )
+ JFreeChartUtil.splitLegend(chart);
}
/**
Modified: trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src/schmitzm/jfree/chart/style/ChartAxisStyle.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -30,6 +30,7 @@
package schmitzm.jfree.chart.style;
import java.awt.Color;
+import java.awt.Font;
import java.text.DateFormat;
import java.text.Format;
import java.text.NumberFormat;
@@ -51,16 +52,21 @@
public class ChartAxisStyle extends ChartLabelStyle {
/** Holds the angle (in degrees) the label is rotated by. */
protected Double angleDegr = 0.0;
+ /** Holds the font the label is formated with. */
+ protected Font font = null;
/** Holds the angle (in degrees) the axis values are rotated by. */
protected Double valuesAngleDegr = 0.0;
/** Holds whether the axis is visible. */
protected boolean visible = true;
/** Holds the number format to display the axis values. */
protected Format valuesFormat = null;
+ /** Holds the font the axis values are formated with. */
+ protected Font valuesFont = null;
/** Holds a String that reflects the values units */
protected String unitString = null;
/** Indicates whether the unit is visible in axis label (Default is {@code true}). */
protected boolean unitStringVisible = true;
+
/**
* Creates a new style with default values (empty label, color black, angle 0).
@@ -114,7 +120,9 @@
dest = (ChartAxisStyle)copyTo((ChartLabelStyle)dest);
// copy this classes properties
dest.setLabelAngle( getLabelAngle() );
+ dest.setLabelFont( getLabelFont() );
dest.setValuesAngle( getValuesAngle() );
+ dest.setValuesFont( getValuesFont() );
dest.setVisible( isVisible() );
dest.setValuesFormat( getValuesFormat() );
dest.setUnitString( getUnitString() );
@@ -145,6 +153,21 @@
}
/**
+ * Returns the {@link Font} the axis label is formated with.
+ */
+ public Font getLabelFont() {
+ return font;
+ }
+
+ /**
+ * Sets the {@link Font} the axis label is formated with.
+ * @param font Font for the axis label
+ */
+ public void setLabelFont(Font font) {
+ this.font = font;
+ }
+
+ /**
* Returns the angle (in degrees) the axis values are rotated by.
*/
public Double getValuesAngle() {
@@ -181,6 +204,21 @@
}
/**
+ * Returns the {@link Font} the axis values are formated with.
+ */
+ public Font getValuesFont() {
+ return valuesFont;
+ }
+
+ /**
+ * Sets the {@link Font} the axis values are formated with.
+ * @param font Font for the axis values
+ */
+ public void setValuesFont(Font font) {
+ this.valuesFont = font;
+ }
+
+ /**
* Returns the (number) format for the axis values.
*/
public Format getValuesFormat() {
@@ -217,8 +255,13 @@
axis.setLabelPaint( getPaint() );
if (getLabelAngle() != null)
axis.setLabelAngle( getLabelAngle() );
+ if (getLabelFont() != null)
+ axis.setLabelFont( getLabelFont() );
+ if (getValuesFont() != null)
+ axis.setTickLabelFont( getValuesFont() );
axis.setVisible( isVisible() );
-
+
+
// Apply values format and angel according to the specific axis type
if (axis instanceof CategoryAxis)
applyToCategoryAxis((CategoryAxis)axis);
Modified: trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src/schmitzm/jfree/feature/style/FeatureChartUtil.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -1060,6 +1060,7 @@
}
+
/**
* After loading from XML, a {@link FeatureChartStyle} contains whatever is
* written in the XML. But the DBF Schema can change quickly by accident! This
Modified: trunk/src/schmitzm/jfree/table/style/TableChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/table/style/TableChartStyle.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src/schmitzm/jfree/table/style/TableChartStyle.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -608,6 +608,7 @@
TableChartStyle destFCS = (TableChartStyle) dest;
destFCS.setSortDomainAxis(isSortDomainAxis());
destFCS.setForceCategories(isForceCategories());
+ destFCS.setIgnoreNoDataRangeValues(isIgnoreNoDataRangeValues());
// Clear the attribute names, normalization, aggregation,
// etc.
Modified: trunk/src/schmitzm/swing/SwingUtil.java
===================================================================
--- trunk/src/schmitzm/swing/SwingUtil.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src/schmitzm/swing/SwingUtil.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -35,6 +35,7 @@
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
+import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
@@ -120,6 +121,9 @@
/** Auswahl "Immer ueberschreiben". */
OVERWRITE_ALL
}
+
+ /** A default font. */
+ public static final Font DEFAULT_FONT = new Font(Font.DIALOG,Font.PLAIN,12);
// ****************************************************************************
// Diese Icons sind auf Basis der Icons von Gimp erstellt
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-08-26 09:43:12 UTC (rev 988)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-08-26 11:03:37 UTC (rev 989)
@@ -6,6 +6,7 @@
import static org.junit.Assert.assertTrue;
import java.awt.Color;
+import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.geom.Rectangle2D;
@@ -49,6 +50,7 @@
import schmitzm.jfree.chart.style.ChartStyleXMLFactory;
import schmitzm.jfree.chart.style.ChartType;
import schmitzm.jfree.table.AggregationFunction;
+import schmitzm.swing.SwingUtil;
public class FeatureChartStyleTest {
private static Logger log = Logger.getLogger(FeatureChartStyleTest.class);
@@ -314,6 +316,8 @@
ChartAxisStyle xAxisStyle = new ChartAxisStyle();
ChartAxisStyle yAxisStyle = new ChartAxisStyle();
ChartAxisStyle yAxisStyle2 = new ChartAxisStyle();
+ yAxisStyle.setValuesFont( SwingUtil.DEFAULT_FONT );
+ yAxisStyle2.setValuesFont( SwingUtil.DEFAULT_FONT );
FeatureBasicChartStyle chartStyle = new FeatureBasicChartStyle(
"keckBarChart", ChartType.BAR);
More information about the Schmitzm-commits
mailing list