KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > base > JRBaseChartPlot


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.base;
29
30 import java.awt.Color JavaDoc;
31 import java.io.Serializable JavaDoc;
32 import java.util.SortedSet JavaDoc;
33 import java.util.TreeSet JavaDoc;
34
35 import net.sf.jasperreports.engine.JRChartPlot;
36 import net.sf.jasperreports.engine.JRConstants;
37
38 import org.jfree.chart.plot.PlotOrientation;
39
40
41 /**
42  * @author Teodor Danciu (teodord@users.sourceforge.net)
43  * @version $Id: JRBaseChartPlot.java 1389 2006-09-06 00:36:07 +0300 (Wed, 06 Sep 2006) bklawans $
44  */

45 public abstract class JRBaseChartPlot implements JRChartPlot, Serializable JavaDoc
46 {
47
48
49     /**
50      *
51      */

52     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
53     
54     protected Color JavaDoc backcolor = null;
55     protected PlotOrientation orientation = PlotOrientation.VERTICAL;
56     protected float backgroundAlpha = 1;
57     protected float foregroundAlpha = 1;
58     protected double labelRotation = 0.0;
59     protected SortedSet JavaDoc seriesColors = null;
60
61
62     /**
63      *
64      */

65     protected JRBaseChartPlot(JRChartPlot plot)
66     {
67         if (plot != null) {
68             backcolor = plot.getBackcolor();
69             orientation = plot.getOrientation();
70             backgroundAlpha = plot.getBackgroundAlpha();
71             foregroundAlpha = plot.getForegroundAlpha();
72             labelRotation = plot.getLabelRotation();
73             seriesColors = new TreeSet JavaDoc(plot.getSeriesColors());
74         }
75         else
76         {
77             seriesColors = new TreeSet JavaDoc();
78         }
79     }
80
81
82     /**
83      *
84      */

85     protected JRBaseChartPlot(JRChartPlot plot, JRBaseObjectFactory factory)
86     {
87         factory.put(plot, this);
88
89         backcolor = plot.getBackcolor();
90         orientation = plot.getOrientation();
91         backgroundAlpha = plot.getBackgroundAlpha();
92         foregroundAlpha = plot.getForegroundAlpha();
93         labelRotation = plot.getLabelRotation();
94         seriesColors = new TreeSet JavaDoc(plot.getSeriesColors());
95     }
96
97     
98     /**
99      *
100      */

101     public Color JavaDoc getBackcolor()
102     {
103         return this.backcolor;
104     }
105
106     /**
107      *
108      */

109     public void setBackcolor(Color JavaDoc backcolor)
110     {
111         this.backcolor = backcolor;
112     }
113
114     /**
115      *
116      */

117     public PlotOrientation getOrientation()
118     {
119         return orientation;
120     }
121
122     /**
123      *
124      */

125     public void setOrientation(PlotOrientation orientation)
126     {
127         this.orientation = orientation;
128     }
129
130     /**
131      *
132      */

133     public float getBackgroundAlpha()
134     {
135         return backgroundAlpha;
136     }
137
138     /**
139      *
140      */

141     public void setBackgroundAlpha(float backgroundAlpha)
142     {
143         this.backgroundAlpha = backgroundAlpha;
144     }
145
146     /**
147      *
148      */

149     public float getForegroundAlpha()
150     {
151         return foregroundAlpha;
152     }
153
154     /**
155      *
156      */

157     public void setForegroundAlpha(float foregroundAlpha)
158     {
159         this.foregroundAlpha = foregroundAlpha;
160     }
161
162     /**
163      * Gets the angle in degrees to rotate the data axis labels. The range is -360 to 360. A positive value angles
164      * the label so it reads downwards wile a negative value angles the label so it reads upwards. Only charts that
165      * use a category based axis (such as line or bar charts) support label rotation.
166      */

167     public double getLabelRotation()
168     {
169         return labelRotation;
170     }
171     
172     /**
173      * Sets the angle in degrees to rotate the data axis labels. The range is -360 to 360. A positive value angles
174      * the label so it reads downwards wile a negative value angles the label so it reads upwards. Only charts that
175      * use a category based axis (such as line or bar charts) support label rotation.
176      */

177     public void setLabelRotation(double labelRotation)
178     {
179         this.labelRotation = labelRotation;
180     }
181     
182     
183     /**
184      * Returns a list of all the defined series colors. Every entry in the list is of type JRChartPlot.JRSeriesColor.
185      * If there are no defined series colors this method will return an empty list, not null.
186      */

187     public SortedSet JavaDoc getSeriesColors()
188     {
189         return seriesColors;
190     }
191     
192     /**
193      * Removes all defined series colors.
194      */

195     public void clearSeriesColors()
196     {
197         seriesColors.clear();
198     }
199     
200     /**
201      * Adds the specified series color to the plot.
202      */

203     public void addSeriesColor(JRSeriesColor seriesColor)
204     {
205         seriesColors.add(seriesColor);
206     }
207     
208     public static class JRBaseSeriesColor implements JRChartPlot.JRSeriesColor, Serializable JavaDoc, Comparable JavaDoc
209     {
210         /**
211          *
212          */

213         private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
214         
215         protected int seriesOrder = -1;
216         protected Color JavaDoc color = null;
217         
218         public JRBaseSeriesColor(int seriesOrder, Color JavaDoc color)
219         {
220             this.seriesOrder = seriesOrder;
221             this.color = color;
222         }
223         
224         /**
225          * Returns the series number (0 based) that this color applies to.
226          */

227         public int getSeriesOrder()
228         {
229             return seriesOrder;
230         }
231         
232         /**
233          * Returns the color to use for this series.
234          */

235         public Color JavaDoc getColor()
236         {
237             return color;
238         }
239
240         public int compareTo(Object JavaDoc obj) {
241             if (obj == null)
242             {
243                 throw new NullPointerException JavaDoc();
244             }
245             
246             return seriesOrder - ((JRBaseSeriesColor)obj).getSeriesOrder();
247         }
248     }
249 }
250
Popular Tags