1 41 42 package org.jfree.chart.plot; 43 44 import java.awt.BasicStroke ; 45 import java.awt.Color ; 46 import java.awt.Graphics2D ; 47 import java.awt.Paint ; 48 import java.awt.Shape ; 49 import java.awt.Stroke ; 50 import java.awt.geom.Arc2D ; 51 import java.awt.geom.Ellipse2D ; 52 import java.awt.geom.Point2D ; 53 import java.awt.geom.Rectangle2D ; 54 import java.io.Serializable ; 55 import java.util.ResourceBundle ; 56 57 import org.jfree.chart.LegendItemCollection; 58 import org.jfree.chart.event.PlotChangeEvent; 59 import org.jfree.chart.event.RendererChangeEvent; 60 import org.jfree.chart.event.RendererChangeListener; 61 import org.jfree.chart.renderer.WaferMapRenderer; 62 import org.jfree.data.general.WaferMapDataset; 63 import org.jfree.ui.RectangleInsets; 64 65 68 public class WaferMapPlot extends Plot implements RendererChangeListener, 69 Cloneable , 70 Serializable { 71 72 73 private static final long serialVersionUID = 4668320403707308155L; 74 75 76 public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke (0.5f, 77 BasicStroke.CAP_BUTT, 78 BasicStroke.JOIN_BEVEL, 79 0.0f, 80 new float[] {2.0f, 2.0f}, 81 0.0f); 82 83 84 public static final Paint DEFAULT_GRIDLINE_PAINT = Color.lightGray; 85 86 87 public static final boolean DEFAULT_CROSSHAIR_VISIBLE = false; 88 89 90 public static final Stroke DEFAULT_CROSSHAIR_STROKE 91 = DEFAULT_GRIDLINE_STROKE; 92 93 94 public static final Paint DEFAULT_CROSSHAIR_PAINT = Color.blue; 95 96 97 protected static ResourceBundle localizationResources = 98 ResourceBundle.getBundle("org.jfree.chart.plot.LocalizationBundle"); 99 100 104 private PlotOrientation orientation; 105 106 107 private WaferMapDataset dataset; 108 109 113 private WaferMapRenderer renderer; 114 115 120 public WaferMapPlot(WaferMapDataset dataset) { 121 this(dataset, null); 122 } 123 124 130 public WaferMapPlot(WaferMapDataset dataset, WaferMapRenderer renderer) { 131 132 super(); 133 134 this.orientation = PlotOrientation.VERTICAL; 135 136 this.dataset = dataset; 137 if (dataset != null) { 138 dataset.addChangeListener(this); 139 } 140 141 this.renderer = renderer; 142 if (renderer != null) { 143 renderer.setPlot(this); 144 renderer.addChangeListener(this); 145 } 146 147 } 148 149 154 public String getPlotType() { 155 return ("WMAP_Plot"); 156 } 157 158 165 public void setRenderer(WaferMapRenderer renderer) { 166 167 if (this.renderer != null) { 168 this.renderer.removeChangeListener(this); 169 } 170 171 this.renderer = renderer; 172 if (renderer != null) { 173 renderer.setPlot(this); 174 } 175 176 notifyListeners(new PlotChangeEvent(this)); 177 178 } 179 180 189 public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, 190 PlotState state, 191 PlotRenderingInfo info) { 192 193 boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); 195 boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); 196 if (b1 || b2) { 197 return; 198 } 199 200 if (info != null) { 202 info.setPlotArea(area); 203 } 204 205 RectangleInsets insets = getInsets(); 207 insets.trim(area); 208 209 drawChipGrid(g2, area); 210 drawWaferEdge(g2, area); 211 212 } 213 214 220 private void drawChipGrid(Graphics2D g2, Rectangle2D plotArea) { 221 222 Shape savedClip = g2.getClip(); 223 g2.setClip(getWaferEdge(plotArea)); 224 Rectangle2D chip = new Rectangle2D.Double (); 225 int xchips = 35; 226 int ychips = 20; 227 double space = 1d; 228 if (this.dataset != null) { 229 xchips = this.dataset.getMaxChipX() + 2; 230 ychips = this.dataset.getMaxChipY() + 2; 231 space = this.dataset.getChipSpace(); 232 } 233 double startX = plotArea.getX(); 234 double startY = plotArea.getY(); 235 double chipWidth = 1d; 236 double chipHeight = 1d; 237 if (plotArea.getWidth() != plotArea.getHeight()) { 238 double major = 0d; 239 double minor = 0d; 240 if (plotArea.getWidth() > plotArea.getHeight()) { 241 major = plotArea.getWidth(); 242 minor = plotArea.getHeight(); 243 } 244 else { 245 major = plotArea.getHeight(); 246 minor = plotArea.getWidth(); 247 } 248 if (plotArea.getWidth() == minor) { startY += (major - minor) / 2; 251 chipWidth = (plotArea.getWidth() - (space * xchips - 1)) 252 / xchips; 253 chipHeight = (plotArea.getWidth() - (space * ychips - 1)) 254 / ychips; 255 } 256 else { startX += (major - minor) / 2; 258 chipWidth = (plotArea.getHeight() - (space * xchips - 1)) 259 / xchips; 260 chipHeight = (plotArea.getHeight() - (space * ychips - 1)) 261 / ychips; 262 } 263 } 264 265 for (int x = 1; x <= xchips; x++) { 266 double upperLeftX = (startX - chipWidth) + (chipWidth * x) 267 + (space * (x - 1)); 268 for (int y = 1; y <= ychips; y++) { 269 double upperLeftY = (startY - chipHeight) + (chipHeight * y) 270 + (space * (y - 1)); 271 chip.setFrame(upperLeftX, upperLeftY, chipWidth, chipHeight); 272 g2.setColor(Color.white); 273 if (this.dataset.getChipValue(x - 1, ychips - y - 1) != null) { 274 g2.setPaint( 275 this.renderer.getChipColor( 276 this.dataset.getChipValue(x - 1, ychips - y - 1) 277 ) 278 ); 279 } 280 g2.fill(chip); 281 g2.setColor(Color.lightGray); 282 g2.draw(chip); 283 } 284 } 285 g2.setClip(savedClip); 286 } 287 288 295 private Ellipse2D getWaferEdge(Rectangle2D plotArea) { 296 Ellipse2D edge = new Ellipse2D.Double (); 297 double diameter = plotArea.getWidth(); 298 double upperLeftX = plotArea.getX(); 299 double upperLeftY = plotArea.getY(); 300 if (plotArea.getWidth() != plotArea.getHeight()) { 302 double major = 0d; 303 double minor = 0d; 304 if (plotArea.getWidth() > plotArea.getHeight()) { 305 major = plotArea.getWidth(); 306 minor = plotArea.getHeight(); 307 } 308 else { 309 major = plotArea.getHeight(); 310 minor = plotArea.getWidth(); 311 } 312 diameter = minor; 314 if (plotArea.getWidth() == minor) { upperLeftY = plotArea.getY() + (major - minor) / 2; 317 } 318 else { upperLeftX = plotArea.getX() + (major - minor) / 2; 320 } 321 } 322 edge.setFrame(upperLeftX, upperLeftY, diameter, diameter); 323 return edge; 324 } 325 326 332 private void drawWaferEdge(Graphics2D g2, Rectangle2D plotArea) { 333 Ellipse2D waferEdge = getWaferEdge(plotArea); 335 g2.setColor(Color.black); 336 g2.draw(waferEdge); 337 Arc2D notch = null; 341 Rectangle2D waferFrame = waferEdge.getFrame(); 342 double notchDiameter = waferFrame.getWidth() * 0.04; 343 if (this.orientation == PlotOrientation.HORIZONTAL) { 344 Rectangle2D notchFrame = 345 new Rectangle2D.Double ( 346 waferFrame.getX() + waferFrame.getWidth() 347 - (notchDiameter / 2), waferFrame.getY() 348 + (waferFrame.getHeight() / 2) - (notchDiameter / 2), 349 notchDiameter, notchDiameter 350 ); 351 notch = new Arc2D.Double (notchFrame, 90d, 180d, Arc2D.OPEN); 352 } 353 else { 354 Rectangle2D notchFrame = 355 new Rectangle2D.Double ( 356 waferFrame.getX() + (waferFrame.getWidth() / 2) 357 - (notchDiameter / 2), waferFrame.getY() 358 + waferFrame.getHeight() - (notchDiameter / 2), 359 notchDiameter, notchDiameter 360 ); 361 notch = new Arc2D.Double (notchFrame, 0d, 180d, Arc2D.OPEN); 362 } 363 g2.setColor(Color.white); 364 g2.fill(notch); 365 g2.setColor(Color.black); 366 g2.draw(notch); 367 368 } 369 370 375 public WaferMapDataset getDataset() { 376 return this.dataset; 377 } 378 379 384 public LegendItemCollection getLegendItems() { 385 return this.renderer.getLegendCollection(); 386 } 387 388 393 public void rendererChanged(RendererChangeEvent event) { 394 notifyListeners(new PlotChangeEvent(this)); 395 } 396 397 } 398 | Popular Tags |