| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package net.sf.statcvs.charts; |
| 5 | |
|
| 6 | |
import java.awt.BasicStroke; |
| 7 | |
import java.awt.Color; |
| 8 | |
import java.awt.Dimension; |
| 9 | |
import java.awt.Font; |
| 10 | |
import java.awt.Image; |
| 11 | |
import java.net.MalformedURLException; |
| 12 | |
import java.net.URL; |
| 13 | |
|
| 14 | |
import javax.swing.ImageIcon; |
| 15 | |
|
| 16 | |
import net.sf.statcvs.output.ConfigurationOptions; |
| 17 | |
import net.sf.statcvs.util.StringUtils; |
| 18 | |
|
| 19 | |
import org.jfree.chart.JFreeChart; |
| 20 | |
import org.jfree.chart.plot.Plot; |
| 21 | |
import org.jfree.chart.renderer.xy.XYItemRenderer; |
| 22 | |
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
| 23 | |
import org.jfree.chart.title.TextTitle; |
| 24 | |
import org.jfree.data.xy.XYDataset; |
| 25 | |
import org.jfree.ui.Align; |
| 26 | |
import org.jfree.ui.HorizontalAlignment; |
| 27 | 0 | import org.jfree.ui.RectangleEdge; |
| 28 | 0 | |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public final class ChartConfigUtil { |
| 34 | 0 | private ChartConfigUtil() { |
| 35 | 0 | } |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public static Color getBackgroundColor(final String chartName) { |
| 46 | 0 | return ConfigurationOptions.getConfigColorProperty("chart." + chartName + ".backgroundColor", "chart.backgroundColor", ChartImage.BACKGROUND_COLOR); |
| 47 | |
} |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | 0 | |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public static Color getPlotColor(final String chartName) { |
| 58 | 0 | return ConfigurationOptions.getConfigColorProperty("chart." + chartName + ".plotColor", "chart.plotColor", ChartImage.BACKGROUND_COLOR); |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | 0 | |
| 66 | |
|
| 67 | |
|
| 68 | 0 | |
| 69 | |
|
| 70 | |
|
| 71 | 0 | public static Dimension getDimension(final String chartName, final Dimension defaultDimension) { |
| 72 | 0 | final Integer width = ConfigurationOptions |
| 73 | |
.getConfigIntegerProperty("chart." + chartName + ".width", "chart.width", new Integer(defaultDimension.width)); |
| 74 | |
|
| 75 | 0 | final Integer height = ConfigurationOptions.getConfigIntegerProperty("chart." + chartName + ".height", "chart.height", new Integer( |
| 76 | |
defaultDimension.height)); |
| 77 | |
|
| 78 | 0 | return new Dimension(width.intValue(), height.intValue()); |
| 79 | |
} |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | 0 | |
| 84 | 0 | |
| 85 | 0 | |
| 86 | 0 | |
| 87 | |
|
| 88 | |
|
| 89 | 0 | public static void configureStroke(final String chartName, final XYItemRenderer renderer, final XYDataset data) { |
| 90 | 0 | final Float stroke = ConfigurationOptions.getConfigFloatProperty("chart." + chartName + ".lineStroke", "chart.lineStroke", null); |
| 91 | 0 | if (stroke != null) { |
| 92 | 0 | for (int i = 0; i < data.getSeriesCount(); i++) { |
| 93 | 0 | renderer.setSeriesStroke(i, new BasicStroke(stroke.floatValue())); |
| 94 | |
} |
| 95 | |
} |
| 96 | 0 | } |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | 0 | |
| 101 | 0 | |
| 102 | 0 | |
| 103 | |
|
| 104 | |
|
| 105 | 0 | |
| 106 | 0 | public static void configureShapes(final String chartName, final XYItemRenderer renderer) { |
| 107 | 0 | if (renderer instanceof XYLineAndShapeRenderer) { |
| 108 | 0 | final Boolean showShapes = ConfigurationOptions.getConfigBooleanProperty("chart." + chartName + ".showShapes", "chart.showShapes", Boolean.FALSE); |
| 109 | 0 | final Boolean filledShapes = ConfigurationOptions.getConfigBooleanProperty("chart." + chartName + ".filledShapes", "chart.filledShapes", |
| 110 | |
Boolean.FALSE); |
| 111 | |
|
| 112 | 0 | ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(showShapes.booleanValue()); |
| 113 | 0 | ((XYLineAndShapeRenderer) renderer).setBaseShapesFilled(filledShapes.booleanValue()); |
| 114 | |
} |
| 115 | 0 | } |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | 0 | |
| 121 | 0 | |
| 122 | |
|
| 123 | 0 | |
| 124 | 0 | |
| 125 | |
|
| 126 | 0 | |
| 127 | 0 | |
| 128 | 0 | public static void configureChartBackgroungImage(final String chartName, final JFreeChart chart) { |
| 129 | 0 | final String imageLocation = ConfigurationOptions.getConfigStringProperty("chart." + chartName + ".chartBackgroundImage.url", |
| 130 | 0 | "chart.chartBackgroundImage.url", null); |
| 131 | 0 | final Float alpha = ConfigurationOptions.getConfigFloatProperty("chart." + chartName + ".chartBackgroundImage.transparency", |
| 132 | |
"chart.chartBackgroundImage.transparency", new Float(0.35)); |
| 133 | 0 | if (StringUtils.isNotEmpty(imageLocation) && alpha != null) { |
| 134 | 0 | Image image = null; |
| 135 | |
try { |
| 136 | 0 | image = new ImageIcon(new URL(imageLocation)).getImage(); |
| 137 | 0 | } catch (MalformedURLException e) { |
| 138 | 0 | e.printStackTrace(); |
| 139 | 0 | } |
| 140 | 0 | if (image != null) { |
| 141 | 0 | chart.setBackgroundImageAlpha(alpha.floatValue()); |
| 142 | 0 | chart.setBackgroundImageAlignment(Align.BOTTOM_LEFT); |
| 143 | 0 | chart.setBackgroundImage(image); |
| 144 | |
} |
| 145 | |
} |
| 146 | 0 | } |
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
public static void configurePlotImage(final String chartName, final JFreeChart chart) { |
| 160 | 0 | final String imageLocation = ConfigurationOptions.getConfigStringProperty("chart." + chartName + ".plotImage.url", "chart.plotImage.url", |
| 161 | |
null); |
| 162 | 0 | final Float alpha = ConfigurationOptions.getConfigFloatProperty("chart." + chartName + ".plotImage.transparency", "chart.plotImage.transparency", |
| 163 | |
new Float(0.35)); |
| 164 | 0 | if (StringUtils.isNotEmpty(imageLocation) && alpha != null) { |
| 165 | 0 | Image image = null; |
| 166 | |
try { |
| 167 | 0 | image = new ImageIcon(new URL(imageLocation)).getImage(); |
| 168 | 0 | } catch (MalformedURLException e) { |
| 169 | 0 | e.printStackTrace(); |
| 170 | 0 | } |
| 171 | 0 | if (image != null) { |
| 172 | 0 | final Plot plot = chart.getPlot(); |
| 173 | 0 | plot.setBackgroundImageAlpha(alpha.floatValue()); |
| 174 | 0 | plot.setBackgroundImage(image); |
| 175 | |
} |
| 176 | |
} |
| 177 | 0 | } |
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public static void configureCopyrightNotice(final String chartName, final JFreeChart chart) { |
| 189 | 0 | final String copyrightTxt = ConfigurationOptions.getConfigStringProperty("chart." + chartName + ".copyright", "chart.copyright", null); |
| 190 | 0 | final Integer copyrightTxtSize = ConfigurationOptions.getConfigIntegerProperty("chart." + chartName + ".copyrightTextSize", "chart.copyrightTextSize", |
| 191 | |
new Integer(9)); |
| 192 | 0 | if (StringUtils.isNotEmpty(copyrightTxt)) { |
| 193 | 0 | final TextTitle copyright = new TextTitle(copyrightTxt, new Font("SansSerif", Font.PLAIN, copyrightTxtSize.intValue())); |
| 194 | |
|
| 195 | 0 | copyright.setPosition(RectangleEdge.BOTTOM); |
| 196 | 0 | copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); |
| 197 | 0 | chart.addSubtitle(copyright); |
| 198 | |
} |
| 199 | 0 | } |
| 200 | |
} |