001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.base;
029:
030: import java.awt.Color;
031: import java.io.Serializable;
032: import java.util.SortedSet;
033: import java.util.TreeSet;
034:
035: import net.sf.jasperreports.engine.JRChart;
036: import net.sf.jasperreports.engine.JRChartPlot;
037: import net.sf.jasperreports.engine.JRConstants;
038: import net.sf.jasperreports.engine.util.JRStyleResolver;
039:
040: import org.jfree.chart.plot.PlotOrientation;
041:
042: /**
043: * @author Teodor Danciu (teodord@users.sourceforge.net)
044: * @version $Id: JRBaseChartPlot.java 1577 2007-02-09 11:25:48Z teodord $
045: */
046: public abstract class JRBaseChartPlot implements JRChartPlot,
047: Serializable {
048:
049: /**
050: *
051: */
052: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
053:
054: protected JRChart chart = null;
055: protected Color backcolor = null;
056: protected PlotOrientation orientation = PlotOrientation.VERTICAL;
057: protected float backgroundAlpha = 1;
058: protected float foregroundAlpha = 1;
059: protected double labelRotation = 0.0;
060: protected SortedSet seriesColors = null;
061:
062: /**
063: *
064: */
065: protected JRBaseChartPlot(JRChartPlot plot, JRChart chart) {
066: this .chart = chart;
067:
068: if (plot != null) {
069: backcolor = plot.getOwnBackcolor();
070: orientation = plot.getOrientation();
071: backgroundAlpha = plot.getBackgroundAlpha();
072: foregroundAlpha = plot.getForegroundAlpha();
073: labelRotation = plot.getLabelRotation();
074: seriesColors = new TreeSet(plot.getSeriesColors());
075: } else {
076: seriesColors = new TreeSet();
077: }
078: }
079:
080: /**
081: *
082: */
083: protected JRBaseChartPlot(JRChartPlot plot,
084: JRBaseObjectFactory factory) {
085: factory.put(plot, this );
086:
087: chart = factory.getChart(plot.getChart());
088:
089: backcolor = plot.getOwnBackcolor();
090: orientation = plot.getOrientation();
091: backgroundAlpha = plot.getBackgroundAlpha();
092: foregroundAlpha = plot.getForegroundAlpha();
093: labelRotation = plot.getLabelRotation();
094: seriesColors = new TreeSet(plot.getSeriesColors());
095: }
096:
097: /**
098: *
099: */
100: public JRChart getChart() {
101: return chart;
102: }
103:
104: /**
105: *
106: */
107: public Color getBackcolor() {
108: return JRStyleResolver.getBackcolor(this );
109: }
110:
111: /**
112: *
113: */
114: public Color getOwnBackcolor() {
115: return this .backcolor;
116: }
117:
118: /**
119: *
120: */
121: public void setBackcolor(Color backcolor) {
122: this .backcolor = backcolor;
123: }
124:
125: /**
126: *
127: */
128: public PlotOrientation getOrientation() {
129: return orientation;
130: }
131:
132: /**
133: *
134: */
135: public void setOrientation(PlotOrientation orientation) {
136: this .orientation = orientation;
137: }
138:
139: /**
140: *
141: */
142: public float getBackgroundAlpha() {
143: return backgroundAlpha;
144: }
145:
146: /**
147: *
148: */
149: public void setBackgroundAlpha(float backgroundAlpha) {
150: this .backgroundAlpha = backgroundAlpha;
151: }
152:
153: /**
154: *
155: */
156: public float getForegroundAlpha() {
157: return foregroundAlpha;
158: }
159:
160: /**
161: *
162: */
163: public void setForegroundAlpha(float foregroundAlpha) {
164: this .foregroundAlpha = foregroundAlpha;
165: }
166:
167: /**
168: * Gets the angle in degrees to rotate the data axis labels. The range is -360 to 360. A positive value angles
169: * the label so it reads downwards wile a negative value angles the label so it reads upwards. Only charts that
170: * use a category based axis (such as line or bar charts) support label rotation.
171: */
172: public double getLabelRotation() {
173: return labelRotation;
174: }
175:
176: /**
177: * Sets the angle in degrees to rotate the data axis labels. The range is -360 to 360. A positive value angles
178: * the label so it reads downwards wile a negative value angles the label so it reads upwards. Only charts that
179: * use a category based axis (such as line or bar charts) support label rotation.
180: */
181: public void setLabelRotation(double labelRotation) {
182: this .labelRotation = labelRotation;
183: }
184:
185: /**
186: * Returns a list of all the defined series colors. Every entry in the list is of type JRChartPlot.JRSeriesColor.
187: * If there are no defined series colors this method will return an empty list, not null.
188: */
189: public SortedSet getSeriesColors() {
190: return seriesColors;
191: }
192:
193: /**
194: * Removes all defined series colors.
195: */
196: public void clearSeriesColors() {
197: seriesColors.clear();
198: }
199:
200: /**
201: * Adds the specified series color to the plot.
202: */
203: public void addSeriesColor(JRSeriesColor seriesColor) {
204: seriesColors.add(seriesColor);
205: }
206:
207: public static class JRBaseSeriesColor implements
208: JRChartPlot.JRSeriesColor, Serializable, Comparable {
209: /**
210: *
211: */
212: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
213:
214: protected int seriesOrder = -1;
215: protected Color color = null;
216:
217: public JRBaseSeriesColor(int seriesOrder, Color color) {
218: this .seriesOrder = seriesOrder;
219: this .color = color;
220: }
221:
222: /**
223: * Returns the series number (0 based) that this color applies to.
224: */
225: public int getSeriesOrder() {
226: return seriesOrder;
227: }
228:
229: /**
230: * Returns the color to use for this series.
231: */
232: public Color getColor() {
233: return color;
234: }
235:
236: public int compareTo(Object obj) {
237: if (obj == null) {
238: throw new NullPointerException();
239: }
240:
241: return seriesOrder
242: - ((JRBaseSeriesColor) obj).getSeriesOrder();
243: }
244: }
245: }
|