KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > krysalis > jcharts > nonAxisChart > PieLabels


1 /***********************************************************************************************
2  * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
3  *
4  * Redistribution and use of this software and associated documentation ("Software"), with or
5  * without modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain copyright statements and notices.
8  * Redistributions must also contain a copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
11  * conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
15  * products derived from this Software without prior written permission of Nathaniel G.
16  * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
17  *
18  * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
19  * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
20  * registered trademark of Nathaniel G. Auvil.
21  *
22  * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
23  *
24  * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
25  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
33  ************************************************************************************************/

34
35 package org.krysalis.jcharts.nonAxisChart;
36
37
38 import org.krysalis.jcharts.types.PieLabelType;
39 import org.krysalis.jcharts.chartText.NumericTagGroup;
40 import org.krysalis.jcharts.chartText.TextTagGroup;
41 import org.krysalis.jcharts.chartText.TextTag;
42 import org.krysalis.jcharts.properties.PieChart2DProperties;
43 import org.krysalis.jcharts.chartData.interfaces.IPieChartDataSet;
44
45 import java.awt.font.FontRenderContext JavaDoc;
46
47
48 /*************************************************************************************
49  * Package private Class used to hold values for the Pie Chart Labels
50  *
51  * @author Nathaniel Auvil
52  * @version $Id: PieLabels.java,v 1.1 2003/05/18 20:28:35 nathaniel_auvil Exp $
53  ************************************************************************************/

54 class PieLabels
55 {
56    private TextTagGroup textTagGroup;
57
58     private float widestLabel;
59     private float widestLabelTimesTwo;
60     private float tallestLabel;
61     private float tallestLabelTimesTwo;
62
63
64     /***********************************************************************************
65      *
66      * @param properties
67      * @param iPieChartDataSet
68      * @param fontRenderContext
69      **********************************************************************************/

70     PieLabels( PieChart2DProperties properties,
71                   IPieChartDataSet iPieChartDataSet,
72                   FontRenderContext JavaDoc fontRenderContext )
73     {
74         //---if we want to display value labels on the chart need to determine the width this will take
75
if( !properties.getPieLabelType().equals( PieLabelType.NO_LABELS ) )
76         {
77             if( properties.getPieLabelType().equals( PieLabelType.VALUE_LABELS ) )
78             {
79                 this.textTagGroup = new NumericTagGroup( properties.getValueLabelFont(),
80                                                                       fontRenderContext,
81                                                                       properties.showValueLabelCurrency(),
82                                                                       false,
83                                                                       properties.showValueLabelGrouping(),
84                                                                       properties.getValueLabelRoundingPowerOfTen() );
85
86                 for( int i = 0; i < iPieChartDataSet.getNumberOfDataItems(); i++ )
87                 {
88                     ((NumericTagGroup) this.textTagGroup).addLabel( iPieChartDataSet.getValue( i ) );
89                 }
90             }
91             //---PieLabelType.LEGEND_LABELS
92
else
93             {
94                 this.textTagGroup = new TextTagGroup( properties.getValueLabelFont(), fontRenderContext );
95                 for( int i = 0; i < iPieChartDataSet.getNumberOfLegendLabels(); i++ )
96                 {
97                     this.textTagGroup.addLabel( iPieChartDataSet.getLegendLabel( i ) );
98                 }
99             }
100
101             widestLabel = this.textTagGroup.getWidestLabel();
102             widestLabelTimesTwo = widestLabel * 2;
103             tallestLabel = this.textTagGroup.getTallestLabel();
104             tallestLabelTimesTwo = tallestLabel * 2;
105         }
106
107     }
108
109
110     public TextTag getTextTag( int index )
111     {
112         return this.textTagGroup.getTextTag( index );
113     }
114
115
116     public float getWidestLabelTimesTwo()
117     {
118         return widestLabelTimesTwo;
119     }
120
121
122     public float getWidestLabel()
123     {
124         return widestLabel;
125     }
126
127
128     public float getTallestLabel()
129     {
130         return tallestLabel;
131     }
132
133
134     public float getTallestLabelTimesTwo()
135     {
136         return tallestLabelTimesTwo;
137     }
138
139 }
140
Popular Tags