001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.nonAxisChart;
034:
035: import org.krysalis.jcharts.types.PieLabelType;
036: import org.krysalis.jcharts.chartText.NumericTagGroup;
037: import org.krysalis.jcharts.chartText.TextTagGroup;
038: import org.krysalis.jcharts.chartText.TextTag;
039: import org.krysalis.jcharts.properties.PieChart2DProperties;
040: import org.krysalis.jcharts.chartData.interfaces.IPieChartDataSet;
041:
042: import java.awt.font.FontRenderContext;
043:
044: /*************************************************************************************
045: * Package private Class used to hold values for the Pie Chart Labels
046: *
047: * @author Nathaniel Auvil
048: * @version $Id: PieLabels.java,v 1.1 2003/05/18 20:28:35 nathaniel_auvil Exp $
049: ************************************************************************************/
050: class PieLabels {
051: private TextTagGroup textTagGroup;
052:
053: private float widestLabel;
054: private float widestLabelTimesTwo;
055: private float tallestLabel;
056: private float tallestLabelTimesTwo;
057:
058: /***********************************************************************************
059: *
060: * @param properties
061: * @param iPieChartDataSet
062: * @param fontRenderContext
063: **********************************************************************************/
064: PieLabels(PieChart2DProperties properties,
065: IPieChartDataSet iPieChartDataSet,
066: FontRenderContext fontRenderContext) {
067: //---if we want to display value labels on the chart need to determine the width this will take
068: if (!properties.getPieLabelType()
069: .equals(PieLabelType.NO_LABELS)) {
070: if (properties.getPieLabelType().equals(
071: PieLabelType.VALUE_LABELS)) {
072: this .textTagGroup = new NumericTagGroup(properties
073: .getValueLabelFont(), fontRenderContext,
074: properties.showValueLabelCurrency(), false,
075: properties.showValueLabelGrouping(), properties
076: .getValueLabelRoundingPowerOfTen());
077:
078: for (int i = 0; i < iPieChartDataSet
079: .getNumberOfDataItems(); i++) {
080: ((NumericTagGroup) this .textTagGroup)
081: .addLabel(iPieChartDataSet.getValue(i));
082: }
083: }
084: //---PieLabelType.LEGEND_LABELS
085: else {
086: this .textTagGroup = new TextTagGroup(properties
087: .getValueLabelFont(), fontRenderContext);
088: for (int i = 0; i < iPieChartDataSet
089: .getNumberOfLegendLabels(); i++) {
090: this .textTagGroup.addLabel(iPieChartDataSet
091: .getLegendLabel(i));
092: }
093: }
094:
095: widestLabel = this .textTagGroup.getWidestLabel();
096: widestLabelTimesTwo = widestLabel * 2;
097: tallestLabel = this .textTagGroup.getTallestLabel();
098: tallestLabelTimesTwo = tallestLabel * 2;
099: }
100:
101: }
102:
103: public TextTag getTextTag(int index) {
104: return this .textTagGroup.getTextTag(index);
105: }
106:
107: public float getWidestLabelTimesTwo() {
108: return widestLabelTimesTwo;
109: }
110:
111: public float getWidestLabel() {
112: return widestLabel;
113: }
114:
115: public float getTallestLabel() {
116: return tallestLabel;
117: }
118:
119: public float getTallestLabelTimesTwo() {
120: return tallestLabelTimesTwo;
121: }
122:
123: }
|