1 55 56 package org.jfree.chart.renderer; 57 58 import java.awt.Graphics2D ; 59 import java.awt.geom.GeneralPath ; 60 import java.awt.geom.Rectangle2D ; 61 import java.io.Serializable ; 62 63 import org.jfree.chart.axis.CategoryAxis; 64 import org.jfree.chart.axis.ValueAxis; 65 import org.jfree.chart.entity.CategoryItemEntity; 66 import org.jfree.chart.entity.EntityCollection; 67 import org.jfree.chart.labels.CategoryItemLabelGenerator; 68 import org.jfree.chart.plot.CategoryPlot; 69 import org.jfree.chart.plot.PlotOrientation; 70 import org.jfree.data.CategoryDataset; 71 import org.jfree.ui.RectangleEdge; 72 import org.jfree.util.PublicCloneable; 73 74 81 public class AreaRenderer extends AbstractCategoryItemRenderer 82 implements Cloneable , PublicCloneable, Serializable { 83 84 87 public AreaRenderer() { 88 super(); 89 } 90 91 104 public void drawItem(Graphics2D g2, 105 CategoryItemRendererState state, 106 Rectangle2D dataArea, 107 CategoryPlot plot, 108 CategoryAxis domainAxis, 109 ValueAxis rangeAxis, 110 CategoryDataset dataset, 111 int row, 112 int column) { 113 114 Number value = dataset.getValue(row, column); 116 if (value != null) { 117 PlotOrientation orientation = plot.getOrientation(); 118 RectangleEdge axisEdge = plot.getDomainAxisEdge(); 119 int count = dataset.getColumnCount(); 120 float x0 = (float) domainAxis.getCategoryStart(column, count, dataArea, axisEdge); 121 float x1 = (float) domainAxis.getCategoryMiddle(column, count, dataArea, axisEdge); 122 float x2 = (float) domainAxis.getCategoryEnd(column, count, dataArea, axisEdge); 123 124 x0 = Math.round(x0); 125 x1 = Math.round(x1); 126 x2 = Math.round(x2); 127 128 double yy1 = value.doubleValue(); 129 130 double yy0 = 0.0; 131 if (column > 0) { 132 Number n0 = dataset.getValue(row, column - 1); 133 if (n0 != null) { 134 yy0 = (n0.doubleValue() + yy1) / 2.0; 135 } 136 } 137 138 double yy2 = 0.0; 139 if (column < dataset.getColumnCount() - 1) { 140 Number n2 = dataset.getValue(row, column + 1); 141 if (n2 != null) { 142 yy2 = (n2.doubleValue() + yy1) / 2.0; 143 } 144 } 145 146 RectangleEdge edge = plot.getRangeAxisEdge(); 147 float y0 = (float) rangeAxis.translateValueToJava2D(yy0, dataArea, edge); 148 float y1 = (float) rangeAxis.translateValueToJava2D(yy1, dataArea, edge); 149 float y2 = (float) rangeAxis.translateValueToJava2D(yy2, dataArea, edge); 150 float yz = (float) rangeAxis.translateValueToJava2D(0.0, dataArea, edge); 151 152 g2.setPaint(getItemPaint(row, column)); 153 g2.setStroke(getItemStroke(row, column)); 154 155 GeneralPath area = new GeneralPath (); 156 157 if (orientation == PlotOrientation.VERTICAL) { 158 area.moveTo(x0, yz); 159 area.lineTo(x0, y0); 160 area.lineTo(x1, y1); 161 area.lineTo(x2, y2); 162 area.lineTo(x2, yz); 163 } 164 else if (orientation == PlotOrientation.HORIZONTAL) { 165 area.moveTo(yz, x0); 166 area.lineTo(y0, x0); 167 area.lineTo(y1, x1); 168 area.lineTo(y2, x2); 169 area.lineTo(yz, x2); 170 } 171 area.closePath(); 172 173 g2.setPaint(getItemPaint(row, column)); 174 g2.fill(area); 175 176 if (isItemLabelVisible(row, column)) { 178 drawItemLabel(g2, orientation, dataset, row, column, x1, y1, 179 (value.doubleValue() < 0.0)); 180 } 181 182 if (state.getInfo() != null) { 184 EntityCollection entities = state.getInfo().getOwner().getEntityCollection(); 185 if (entities != null) { 186 String tip = null; 187 CategoryItemLabelGenerator generator = getBaseItemLabelGenerator(); 188 if (generator != null) { 189 tip = generator.generateToolTip(dataset, row, column); 190 } 191 String url = null; 192 if (getItemURLGenerator(row, column) != null) { 193 url = getItemURLGenerator(row, column).generateURL(dataset, row, column); 194 } 195 Comparable columnKey = dataset.getColumnKey(column); 196 CategoryItemEntity entity = new CategoryItemEntity( 197 area, tip, url, dataset, row, columnKey, column 198 ); 199 entities.addEntity(entity); 200 } 201 } 202 } 203 204 } 205 206 213 public Object clone() throws CloneNotSupportedException { 214 return super.clone(); 215 } 216 217 } 218 | Popular Tags |