1 34 35 package org.krysalis.jcharts.chartText; 36 37 38 import org.krysalis.jcharts.axisChart.axis.scale.ScaleCalculator; 39 import org.krysalis.jcharts.properties.util.ChartFont; 40 41 import java.awt.font.FontRenderContext ; 42 import java.text.NumberFormat ; 43 44 45 50 public class NumericTagGroup extends TextTagGroup 51 { 52 private NumberFormat numberFormat; 53 54 55 64 public NumericTagGroup( ChartFont chartFont, 65 FontRenderContext fontRenderContext, 66 boolean isCurrency, 67 boolean isPercent, 68 boolean showCommas, 69 int roundingPowerOfTen ) 70 { 71 super( chartFont, fontRenderContext ); 72 73 this.numberFormat = getNumberFormatInstance( isCurrency, isPercent, showCommas, roundingPowerOfTen ); 74 } 75 76 77 86 public static final NumberFormat getNumberFormatInstance( boolean isCurrency, 87 boolean isPercent, 88 boolean showCommas, 89 int roundingPowerOfTen ) 90 { 91 NumberFormat numberFormat; 92 93 if( isCurrency ) 95 { 96 numberFormat = NumberFormat.getCurrencyInstance(); 97 } 98 else if( isPercent ) 99 { 100 numberFormat = NumberFormat.getPercentInstance(); 101 } 102 else 103 { 104 numberFormat = NumberFormat.getInstance(); 105 } 106 107 if( showCommas ) 109 { 110 numberFormat.setGroupingUsed( true ); 111 } 112 else 113 { 114 numberFormat.setGroupingUsed( false ); 115 } 116 117 if( roundingPowerOfTen >= 0 ) 119 { 120 numberFormat.setMaximumFractionDigits( 0 ); 121 numberFormat.setMinimumFractionDigits( 0 ); 122 } 123 else 124 { 125 numberFormat.setMaximumFractionDigits( -roundingPowerOfTen ); 126 numberFormat.setMinimumFractionDigits( -roundingPowerOfTen ); 127 } 128 129 return numberFormat; 130 } 131 132 133 137 public void addLabel( double value ) 138 { 139 super.addLabel( this.numberFormat.format( value ) ); 140 } 141 142 143 148 public void createAxisScaleLabels( ScaleCalculator scaleCalculator ) 149 { 150 double value = scaleCalculator.getMinValue(); 151 this.addLabel( value ); 152 153 for( int i = 1; i < scaleCalculator.getNumberOfScaleItems(); i++ ) 154 { 155 value += scaleCalculator.getIncrement(); 156 this.addLabel( value ); 157 } 158 } 159 160 } 161 | Popular Tags |