PageRenderTime 26ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/jasperreports-3.7.4/src/net/sf/jasperreports/engine/base/JRBaseChartPlot.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 461 lines | 259 code | 69 blank | 133 comment | 15 complexity | a296b5123ee7da90f6273ac2d2cb7424 MD5 | raw file
  1. /*
  2. * JasperReports - Free Java Reporting Library.
  3. * Copyright (C) 2001 - 2009 Jaspersoft Corporation. All rights reserved.
  4. * http://www.jaspersoft.com
  5. *
  6. * Unless you have purchased a commercial license agreement from Jaspersoft,
  7. * the following license terms apply:
  8. *
  9. * This program is part of JasperReports.
  10. *
  11. * JasperReports is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * JasperReports is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. package net.sf.jasperreports.engine.base;
  25. import java.awt.Color;
  26. import java.io.IOException;
  27. import java.io.ObjectInputStream;
  28. import java.io.Serializable;
  29. import java.util.Collection;
  30. import java.util.Iterator;
  31. import java.util.SortedSet;
  32. import java.util.TreeSet;
  33. import net.sf.jasperreports.charts.JRCategoryAxisFormat;
  34. import net.sf.jasperreports.engine.JRChart;
  35. import net.sf.jasperreports.engine.JRChartPlot;
  36. import net.sf.jasperreports.engine.JRConstants;
  37. import net.sf.jasperreports.engine.JRRuntimeException;
  38. import net.sf.jasperreports.engine.design.events.JRChangeEventsSupport;
  39. import net.sf.jasperreports.engine.design.events.JRPropertyChangeSupport;
  40. import net.sf.jasperreports.engine.util.JRStyleResolver;
  41. import org.jfree.chart.plot.PlotOrientation;
  42. /**
  43. * @author Teodor Danciu (teodord@users.sourceforge.net)
  44. * @version $Id: JRBaseChartPlot.java 3716 2010-04-08 19:57:14Z teodord $
  45. */
  46. public abstract class JRBaseChartPlot implements JRChartPlot, Serializable, JRChangeEventsSupport
  47. {
  48. /**
  49. *
  50. */
  51. private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
  52. public static final String PROPERTY_BACKCOLOR = "backcolor";
  53. public static final String PROPERTY_BACKGROUND_ALPHA = "backgroundAlpha";
  54. public static final String PROPERTY_FOREGROUND_ALPHA = "foregroundAlpha";
  55. public static final String PROPERTY_LABEL_ROTATION = "labelRotation";
  56. public static final String PROPERTY_ORIENTATION = "orientation";
  57. public static final String PROPERTY_SERIES_COLORS = "seriesColors";
  58. protected JRChart chart = null;
  59. protected Color backcolor = null;
  60. protected PlotOrientation orientation = PlotOrientation.VERTICAL;
  61. protected Float backgroundAlphaFloat = null;
  62. protected Float foregroundAlphaFloat = null;
  63. protected Double labelRotationDouble = null;
  64. protected SortedSet seriesColors = null;
  65. /**
  66. *
  67. */
  68. protected JRBaseChartPlot(JRChartPlot plot, JRChart chart)
  69. {
  70. this.chart = chart;
  71. if (plot != null)
  72. {
  73. backcolor = plot.getOwnBackcolor();
  74. orientation = plot.getOrientation();
  75. backgroundAlphaFloat = plot.getBackgroundAlphaFloat();
  76. foregroundAlphaFloat = plot.getForegroundAlphaFloat();
  77. labelRotationDouble = plot.getLabelRotationDouble();
  78. seriesColors = new TreeSet(plot.getSeriesColors());
  79. }
  80. else
  81. {
  82. seriesColors = new TreeSet();
  83. }
  84. }
  85. /**
  86. *
  87. */
  88. protected JRBaseChartPlot(JRChartPlot plot, JRBaseObjectFactory factory)
  89. {
  90. factory.put(plot, this);
  91. chart = (JRChart)factory.getVisitResult(plot.getChart());
  92. backcolor = plot.getOwnBackcolor();
  93. orientation = plot.getOrientation();
  94. backgroundAlphaFloat = plot.getBackgroundAlphaFloat();
  95. foregroundAlphaFloat = plot.getForegroundAlphaFloat();
  96. labelRotationDouble = plot.getLabelRotationDouble();
  97. seriesColors = new TreeSet(plot.getSeriesColors());
  98. }
  99. /**
  100. *
  101. */
  102. public JRChart getChart()
  103. {
  104. return chart;
  105. }
  106. /**
  107. *
  108. */
  109. public Color getBackcolor()
  110. {
  111. return JRStyleResolver.getBackcolor(this);
  112. }
  113. /**
  114. *
  115. */
  116. public Color getOwnBackcolor()
  117. {
  118. return this.backcolor;
  119. }
  120. /**
  121. *
  122. */
  123. public void setBackcolor(Color backcolor)
  124. {
  125. Object old = this.backcolor;
  126. this.backcolor = backcolor;
  127. getEventSupport().firePropertyChange(PROPERTY_BACKCOLOR, old, this.backcolor);
  128. }
  129. /**
  130. *
  131. */
  132. public PlotOrientation getOrientation()
  133. {
  134. return orientation;
  135. }
  136. /**
  137. *
  138. */
  139. public void setOrientation(PlotOrientation orientation)
  140. {
  141. Object old = this.orientation;
  142. this.orientation = orientation;
  143. getEventSupport().firePropertyChange(PROPERTY_ORIENTATION, old, this.orientation);
  144. }
  145. /**
  146. * @deprecated Replaced by {@link #getBackgroundAlphaFloat()}
  147. */
  148. public float getBackgroundAlpha()
  149. {
  150. return backgroundAlphaFloat == null ? 1f : backgroundAlphaFloat.floatValue();
  151. }
  152. /**
  153. * @deprecated Replaced by {@link #setBackgroundAlpha(Float)}
  154. */
  155. public void setBackgroundAlpha(float backgroundAlpha)
  156. {
  157. setBackgroundAlpha(new Float(backgroundAlpha));
  158. }
  159. /**
  160. * @deprecated Replaced by {@link #getForegroundAlphaFloat()}
  161. */
  162. public float getForegroundAlpha()
  163. {
  164. return foregroundAlphaFloat == null ? 1f : foregroundAlphaFloat.floatValue();
  165. }
  166. /**
  167. * @deprecated Replaced by {@link #setForegroundAlpha(Float)}
  168. */
  169. public void setForegroundAlpha(float foregroundAlpha)
  170. {
  171. setForegroundAlpha(new Float(foregroundAlpha));
  172. }
  173. /**
  174. * @deprecated Replaced by {@link #getLabelRotationDouble()}
  175. */
  176. public double getLabelRotation()
  177. {
  178. return labelRotationDouble == null ? 0d : labelRotationDouble.doubleValue();
  179. }
  180. /**
  181. * @deprecated Replaced by {@link #setLabelRotation(Double)}
  182. */
  183. public void setLabelRotation(double labelRotation)
  184. {
  185. setLabelRotation(new Double(labelRotation));
  186. }
  187. /**
  188. *
  189. */
  190. public Float getBackgroundAlphaFloat()
  191. {
  192. return backgroundAlphaFloat;
  193. }
  194. /**
  195. *
  196. */
  197. public void setBackgroundAlpha(Float backgroundAlpha)
  198. {
  199. Float old = this.backgroundAlphaFloat;
  200. this.backgroundAlphaFloat = backgroundAlpha;
  201. getEventSupport().firePropertyChange(PROPERTY_BACKGROUND_ALPHA, old, this.backgroundAlphaFloat);
  202. }
  203. /**
  204. *
  205. */
  206. public Float getForegroundAlphaFloat()
  207. {
  208. return foregroundAlphaFloat;
  209. }
  210. /**
  211. *
  212. */
  213. public void setForegroundAlpha(Float foregroundAlpha)
  214. {
  215. Float old = this.foregroundAlphaFloat;
  216. this.foregroundAlphaFloat = foregroundAlpha;
  217. getEventSupport().firePropertyChange(PROPERTY_FOREGROUND_ALPHA, old, this.foregroundAlphaFloat);
  218. }
  219. /**
  220. * Gets the angle in degrees to rotate the data axis labels. The range is -360 to 360. A positive value angles
  221. * the label so it reads downwards wile a negative value angles the label so it reads upwards. Only charts that
  222. * use a category based axis (such as line or bar charts) support label rotation.
  223. * @deprecated Replaced by {@link JRCategoryAxisFormat#getCategoryAxisTickLabelRotation()}.
  224. */
  225. public Double getLabelRotationDouble()
  226. {
  227. return labelRotationDouble;
  228. }
  229. /**
  230. * Sets the angle in degrees to rotate the data axis labels. The range is -360 to 360. A positive value angles
  231. * the label so it reads downwards wile a negative value angles the label so it reads upwards. Only charts that
  232. * use a category based axis (such as line or bar charts) support label rotation.
  233. * @deprecated Replaced by {@link JRCategoryAxisFormat#setCategoryAxisTickLabelRotation(Double)}.
  234. */
  235. public void setLabelRotation(Double labelRotation)
  236. {
  237. Double old = this.labelRotationDouble;
  238. this.labelRotationDouble = labelRotation;
  239. getEventSupport().firePropertyChange(PROPERTY_LABEL_ROTATION, old, this.labelRotationDouble);
  240. }
  241. /**
  242. * Returns a list of all the defined series colors. Every entry in the list is of type JRChartPlot.JRSeriesColor.
  243. * If there are no defined series colors this method will return an empty list, not null.
  244. */
  245. public SortedSet getSeriesColors()
  246. {
  247. return seriesColors;
  248. }
  249. /**
  250. * Removes all defined series colors.
  251. */
  252. public void clearSeriesColors()
  253. {
  254. setSeriesColors(null);
  255. }
  256. /**
  257. * Adds the specified series color to the plot.
  258. */
  259. public void addSeriesColor(JRSeriesColor seriesColor)
  260. {
  261. seriesColors.add(seriesColor);
  262. getEventSupport().fireCollectionElementAddedEvent(PROPERTY_SERIES_COLORS,
  263. seriesColor, seriesColors.size() - 1);
  264. }
  265. public void setSeriesColors(Collection colors)
  266. {
  267. Object old = new TreeSet(seriesColors);
  268. seriesColors.clear();
  269. if (colors != null)
  270. {
  271. seriesColors.addAll(colors);
  272. }
  273. getEventSupport().firePropertyChange(PROPERTY_SERIES_COLORS, old, seriesColors);
  274. }
  275. public static class JRBaseSeriesColor implements JRChartPlot.JRSeriesColor, Serializable, Comparable
  276. {
  277. /**
  278. *
  279. */
  280. private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
  281. protected int seriesOrder = -1;
  282. protected Color color = null;
  283. public JRBaseSeriesColor(int seriesOrder, Color color)
  284. {
  285. this.seriesOrder = seriesOrder;
  286. this.color = color;
  287. }
  288. /**
  289. * Returns the series number (0 based) that this color applies to.
  290. */
  291. public int getSeriesOrder()
  292. {
  293. return seriesOrder;
  294. }
  295. /**
  296. * Returns the color to use for this series.
  297. */
  298. public Color getColor()
  299. {
  300. return color;
  301. }
  302. public int compareTo(Object obj) {
  303. if (obj == null)
  304. {
  305. throw new IllegalArgumentException();
  306. }
  307. return seriesOrder - ((JRBaseSeriesColor)obj).getSeriesOrder();
  308. }
  309. public Object clone()
  310. {
  311. try
  312. {
  313. return super.clone();
  314. }
  315. catch (CloneNotSupportedException e)
  316. {
  317. throw new JRRuntimeException(e);
  318. }
  319. }
  320. }
  321. /**
  322. *
  323. */
  324. public Object clone()
  325. {
  326. JRBaseChartPlot clone = null;
  327. try
  328. {
  329. clone = (JRBaseChartPlot)super.clone();
  330. }
  331. catch (CloneNotSupportedException e)
  332. {
  333. throw new JRRuntimeException(e);
  334. }
  335. if (seriesColors != null)
  336. {
  337. clone.seriesColors = new TreeSet();
  338. for(Iterator it = seriesColors.iterator(); it.hasNext();)
  339. {
  340. clone.seriesColors.add(((JRChartPlot.JRSeriesColor)it.next()).clone());
  341. }
  342. }
  343. return clone;
  344. }
  345. /**
  346. *
  347. */
  348. public Object clone(JRChart parentChart)
  349. {
  350. JRBaseChartPlot clone = (JRBaseChartPlot)this.clone();
  351. clone.chart = parentChart;
  352. return clone;
  353. }
  354. private transient JRPropertyChangeSupport eventSupport;
  355. public JRPropertyChangeSupport getEventSupport()
  356. {
  357. synchronized (this)
  358. {
  359. if (eventSupport == null)
  360. {
  361. eventSupport = new JRPropertyChangeSupport(this);
  362. }
  363. }
  364. return eventSupport;
  365. }
  366. /*
  367. * These fields are only for serialization backward compatibility.
  368. */
  369. private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
  370. /**
  371. * @deprecated
  372. */
  373. private float backgroundAlpha = 1;
  374. /**
  375. * @deprecated
  376. */
  377. private float foregroundAlpha = 1;
  378. /**
  379. * @deprecated
  380. */
  381. private double labelRotation = 0.0;
  382. private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
  383. {
  384. in.defaultReadObject();
  385. if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_1_3)
  386. {
  387. backgroundAlphaFloat = new Float(backgroundAlpha);
  388. foregroundAlphaFloat = new Float(foregroundAlpha);
  389. labelRotationDouble = new Double(labelRotation);
  390. }
  391. }
  392. }