1 23 24 package de.progra.charting; 25 26 import de.progra.charting.model.ChartDataModel; 27 import java.util.*; 28 import de.progra.charting.render.AbstractChartRenderer; 29 import de.progra.charting.render.RowColorModel; 30 import java.awt.geom.AffineTransform ; 31 import java.awt.Rectangle ; 32 import java.awt.Graphics2D ; 33 import java.awt.Dimension ; 34 import java.awt.Color ; 35 36 37 41 public class DefaultChart extends AbstractChart { 42 43 public static int LINEAR_X_LINEAR_Y = 0; 44 public static int NO_COORDINATE_SYSTEM = 1; 45 46 47 protected DefaultChart() { 48 } 49 50 55 public DefaultChart(ChartDataModel model, String title) { 56 this(); 57 setChartDataModel(model); 58 setRowColorModel(new RowColorModel(model)); 59 60 setLegend(new Legend(getRowColorModel())); 61 setTitle(new Title(title)); 62 } 63 64 70 public DefaultChart(ChartDataModel model, String title, int coord) { 71 this(model, title); 72 73 if(coord == this.LINEAR_X_LINEAR_Y) 74 this.setCoordSystem(new CoordSystem(model)); 75 } 76 77 85 public DefaultChart(ChartDataModel model, String title, int coord, 86 String xaxis, String yaxis) { 87 this(model, title, coord); 88 89 this.getCoordSystem().setXAxisUnit(xaxis); 90 this.getCoordSystem().setYAxisUnit(yaxis); 91 } 92 93 96 public Dimension getPreferredSize() { 97 return null; 98 } 99 100 104 public void render(Graphics2D g) { 105 106 109 110 int width = (int)getBounds().getWidth(); 111 int height = (int)getBounds().getHeight(); 112 113 Title t = getTitle(); 114 Legend l = getLegend(); 115 CoordSystem c = getCoordSystem(); 116 Collection renderer = getChartRenderer().values(); 117 118 g.setColor(Color.white); 119 g.fillRect(0, 0, width, height); 120 121 g.setColor(Color.black); 122 123 int titleheight = 0; 124 int legendwidth = 0; 125 126 if(t != null) { 127 Dimension title = t.getPreferredSize(); 128 t.setBounds(new Rectangle ((int)(width/2 129 - (int)(title.getWidth()/2)), 130 0, 131 (int)title.getWidth(), 132 (int)title.getHeight())); 133 t.render(g); 134 titleheight = (int)t.getBounds().getHeight(); 135 } 136 if(l != null) { 137 Dimension legend = l.getPreferredSize(); 138 l.setBounds(new Rectangle ((int)(width - legend.getWidth()), 139 (int)(height/2 - legend.getHeight()/2 + titleheight), 140 (int)legend.getWidth(), 141 (int)legend.getHeight())); 142 l.render(g); 143 legendwidth = (int)l.getBounds().getWidth(); 144 } 145 if(c != null) { 146 c.setBounds(new Rectangle (0, (int)titleheight, 147 (int)(width - legendwidth), 148 (int)(height - titleheight))); 149 } 150 if(! renderer.isEmpty()) { 151 Iterator i = renderer.iterator(); 152 while(i.hasNext()) { 153 AbstractChartRenderer cr = (AbstractChartRenderer)i.next(); 154 cr.setBounds(new Rectangle (0, (int)titleheight, 155 (int)(width - legendwidth), 156 (int)(height - titleheight) - 5)); 157 158 160 cr.render(g); 161 } 162 } 163 if(c != null) 164 c.render(g); 165 166 174 } 177 178 } 179 | Popular Tags |