[Schmitzm-commits] r992 - in trunk: src/schmitzm/jfree src/schmitzm/jfree/chart/style src_junit/schmitzm/jfree/feature/style
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Aug 26 22:50:21 CEST 2010
Author: mojays
Date: 2010-08-26 22:50:20 +0200 (Thu, 26 Aug 2010)
New Revision: 992
Modified:
trunk/src/schmitzm/jfree/JFreeChartUtil.java
trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
Log:
BugFix: split legend take effect the hastLegend() property
Modified: trunk/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-08-26 17:05:35 UTC (rev 991)
+++ trunk/src/schmitzm/jfree/JFreeChartUtil.java 2010-08-26 20:50:20 UTC (rev 992)
@@ -43,6 +43,7 @@
import org.jfree.chart.axis.Axis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
+import org.jfree.chart.block.Block;
import org.jfree.chart.block.BlockBorder;
import org.jfree.chart.block.BlockContainer;
import org.jfree.chart.block.BorderArrangement;
@@ -162,11 +163,28 @@
* indicates the visible property
*/
public static void setLegendVisible(JFreeChart chart, boolean visible) {
- for (Object title : chart.getSubtitles())
- if (title instanceof LegendTitle)
- ((Title) title).setVisible(visible);
+// for (Object title : chart.getSubtitles())
+// if (title instanceof LegendTitle)
+// ((Title) title).setVisible(visible);
+ for (Object title : chart.getSubtitles()) {
+ if (title instanceof LegendTitle)
+ ((Title) title).setVisible(visible);
+ // If legend is split because of multiple range axis, there
+ // is an CompositeTitle instead of LegendTitle. Setting
+ // (in)visible the LegendTitles inside, does not take effect.
+ // -> So set the whole CompositeTitle (in)visible if one
+ // of the blocks inside is a LegendTitle...
+ if (title instanceof CompositeTitle) {
+ for (Object block : ((CompositeTitle)title).getContainer().getBlocks()) {
+ if ( block instanceof LegendTitle ) {
+ ((CompositeTitle)title).setVisible(visible);
+ break;
+ }
+ }
+ }
+ }
}
-
+
/**
* Splits the legend of a chart in two pieces for each range
* axis.<br>
Modified: trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java
===================================================================
--- trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java 2010-08-26 17:05:35 UTC (rev 991)
+++ trunk/src/schmitzm/jfree/chart/style/AbstractChartStyle.java 2010-08-26 20:50:20 UTC (rev 992)
@@ -526,9 +526,6 @@
if ( getPlotStyle() != null )
getPlotStyle().applyToPlot(chart.getPlot());
- // Style the legend
- JFreeChartUtil.setLegendVisible(chart, hasLegend());
-
// Style the chart title
TextTitle title = chart.getTitle();
if ( title == null && getTitleStyle() != null ) {
@@ -608,6 +605,9 @@
// Split the legend when multiple range axis are used
if ( JFreeChartUtil.getRangeAxisCountFromPlot(chart.getPlot()) > 1 )
JFreeChartUtil.splitLegend(chart);
+ // Style the legend
+ JFreeChartUtil.setLegendVisible(chart, hasLegend());
+
}
/**
Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-08-26 17:05:35 UTC (rev 991)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java 2010-08-26 20:50:20 UTC (rev 992)
@@ -33,6 +33,8 @@
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer;
import org.jfree.chart.renderer.category.BarRenderer;
+import org.jfree.chart.title.CompositeTitle;
+import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RectangleEdge;
@@ -294,7 +296,7 @@
}
@Test
- public void testKRECKbarChart() throws IOException, InterruptedException {
+ public void testKECKbarChart() throws IOException, InterruptedException {
String titleAttName = "jahr";
String xAxisAttName = "title"; //"code";
String yAxisAttName = "dm_u3";
@@ -328,9 +330,9 @@
yAxisStyle2.setValuesFont( SwingUtil.DEFAULT_FONT.deriveFont(8f).deriveFont(Font.BOLD+Font.ITALIC) );
yAxisStyle2.setValuesPaint( Color.BLUE );
- final FeatureBasicChartStyle chartStyle = new FeatureBasicChartStyle(
+ FeatureBasicChartStyle chartStyle = new FeatureBasicChartStyle(
"keckBarChart", ChartType.BAR);
-
+ chartStyle.setLegend(true);
// Domain Axis
chartStyle.setAttributeName(0, xAxisAttName);
chartStyle.setAxisStyle(0, xAxisStyle);
@@ -364,11 +366,9 @@
chartPlotStyle.setRangeGridlinePaint(Color.darkGray);
chartStyle.setPlotStyle(chartPlotStyle);
-// chartStyle.setLegend(false);
-
- final JFreeChart barChart = chartStyle.applyToFeatureCollection(features);
-// ((CategoryPlot)barChart.getPlot()).setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
+ JFreeChart barChart = chartStyle.applyToFeatureCollection(features);
+
// // Maximale Breite der Bars einstellen
// BarRenderer renderer = (BarRenderer) barChart.getCategoryPlot()
// .getRenderer();
More information about the Schmitzm-commits
mailing list