1 34 35 package org.krysalis.jcharts.chartText; 36 37 38 import org.krysalis.jcharts.properties.util.ChartFont; 39 import org.krysalis.jcharts.test.HTMLGenerator; 40 import org.krysalis.jcharts.test.HTMLTestable; 41 42 import java.awt.*; 43 import java.awt.font.FontRenderContext ; 44 import java.io.Serializable ; 45 import java.lang.reflect.Field ; 46 import java.util.ArrayList ; 47 48 49 54 public class TextTagGroup implements HTMLTestable, Serializable 55 { 56 private float widestLabel = 0.0f; 57 private float tallestLabel = 0.0f; 58 private float totalLabelWidths = 0.0f; 59 60 private ArrayList textTags; 61 62 private ChartFont chartFont; 63 private FontRenderContext fontRenderContext; 64 65 66 68 73 77 78 84 public TextTagGroup( ChartFont chartFont, FontRenderContext fontRenderContext ) 85 { 86 this.textTags = new ArrayList ( 30 ); 87 88 this.chartFont = chartFont; 89 this.fontRenderContext = fontRenderContext; 90 } 91 92 93 97 public void addLabel( String label ) 98 { 99 TextTag textTag = new TextTag( label, this.chartFont.getFont(), this.fontRenderContext ); 100 this.textTags.add( textTag ); 101 102 this.widestLabel = Math.max( textTag.getWidth(), this.widestLabel ); 103 this.totalLabelWidths += textTag.getWidth(); 104 105 this.tallestLabel = Math.max( textTag.getHeight(), this.tallestLabel ); 106 } 107 108 109 114 public int size() 115 { 116 return this.textTags.size(); 117 } 118 119 120 125 public void reverse() 126 { 127 ArrayList reverse = new ArrayList ( this.textTags.size() ); 128 for( int i = this.textTags.size() - 1; i >= 0; i-- ) 129 { 130 reverse.add( this.textTags.get( i ) ); 131 } 132 133 this.textTags = reverse; 134 } 135 136 137 174 public float getWidestLabel() 175 { 176 return this.widestLabel; 177 } 178 179 180 184 public float getTallestLabel() 185 { 186 return this.tallestLabel; 187 } 188 189 190 194 public float getTotalLabelWidths() 195 { 196 return this.totalLabelWidths; 197 } 198 199 200 205 public TextTag getTextTag( int index ) 206 { 207 return (TextTag) this.textTags.get( index ); 208 } 209 210 211 219 public void render( int index, Graphics2D g2d, float x, float y ) 220 { 221 this.chartFont.setupGraphics2D( g2d ); 222 this.getTextTag( index ).render( g2d, x, y ); 223 } 224 225 226 257 public void toHTML( HTMLGenerator htmlGenerator ) 258 { 259 htmlGenerator.propertiesTableStart( this.getClass().getName() ); 260 261 Field [] fields = this.getClass().getDeclaredFields(); 262 for( int i = 0; i < fields.length; i++ ) 263 { 264 try 265 { 266 htmlGenerator.addField( fields[ i ].getName(), fields[ i ].get( this ) ); 267 } 268 catch( IllegalAccessException illegalAccessException ) 269 { 270 illegalAccessException.printStackTrace(); 271 } 272 } 273 274 htmlGenerator.propertiesTableEnd(); 275 } 276 277 } | Popular Tags |