1:
46:
47: package ;
48:
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59:
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65:
66:
69: public class WaferMapRenderer extends AbstractRenderer {
70:
71:
72: private Map paintIndex;
73:
74:
75: private WaferMapPlot plot;
76:
77:
78: private int paintLimit;
79:
80:
81: private static final int DEFAULT_PAINT_LIMIT = 35;
82:
83:
84: public static final int POSITION_INDEX = 0;
85:
86:
87: public static final int VALUE_INDEX = 1;
88:
89:
90: private int paintIndexMethod;
91:
92:
95: public WaferMapRenderer() {
96: this(null, null);
97: }
98:
99:
105: public WaferMapRenderer(int paintLimit, int paintIndexMethod) {
106: this(new Integer(paintLimit), new Integer(paintIndexMethod));
107: }
108:
109:
115: public WaferMapRenderer(Integer paintLimit, Integer paintIndexMethod) {
116:
117: super();
118: this.paintIndex = new HashMap();
119:
120: if (paintLimit == null) {
121: this.paintLimit = DEFAULT_PAINT_LIMIT;
122: }
123: else {
124: this.paintLimit = paintLimit.intValue();
125: }
126:
127: this.paintIndexMethod = VALUE_INDEX;
128: if (paintIndexMethod != null) {
129: if (isMethodValid(paintIndexMethod.intValue())) {
130: this.paintIndexMethod = paintIndexMethod.intValue();
131: }
132: }
133: }
134:
135:
142: private boolean isMethodValid(int method) {
143: switch (method) {
144: case POSITION_INDEX: return true;
145: case VALUE_INDEX: return true;
146: default: return false;
147: }
148: }
149:
150:
155: public DrawingSupplier getDrawingSupplier() {
156: DrawingSupplier result = null;
157: WaferMapPlot p = getPlot();
158: if (p != null) {
159: result = p.getDrawingSupplier();
160: }
161: return result;
162: }
163:
164:
169: public WaferMapPlot getPlot() {
170: return this.plot;
171: }
172:
173:
178: public void setPlot(WaferMapPlot plot) {
179: this.plot = plot;
180: makePaintIndex();
181: }
182:
183:
190: public Paint getChipColor(Number value) {
191: return getSeriesPaint(getPaintIndex(value));
192: }
193:
194:
201: private int getPaintIndex(Number value) {
202: return ((Integer) this.paintIndex.get(value)).intValue();
203: }
204:
205:
209: private void makePaintIndex() {
210: if (this.plot == null) {
211: return;
212: }
213: WaferMapDataset data = this.plot.getDataset();
214: Number dataMin = data.getMinValue();
215: Number dataMax = data.getMaxValue();
216: Set uniqueValues = data.getUniqueValues();
217: if (uniqueValues.size() <= this.paintLimit) {
218: int count = 0;
219: for (Iterator i = uniqueValues.iterator(); i.hasNext();) {
220: this.paintIndex.put(i.next(), new Integer(count++));
221: }
222: }
223: else {
224:
225:
226: switch (this.paintIndexMethod) {
227: case POSITION_INDEX:
228: makePositionIndex(uniqueValues);
229: break;
230: case VALUE_INDEX:
231: makeValueIndex(dataMax, dataMin, uniqueValues);
232: break;
233: default:
234: break;
235: }
236: }
237: }
238:
239:
245: private void makePositionIndex(Set uniqueValues) {
246: int valuesPerColor = (int) Math.ceil(
247: (double) uniqueValues.size() / this.paintLimit
248: );
249: int count = 0;
250: int paint = 0;
251: for (Iterator i = uniqueValues.iterator(); i.hasNext();) {
252: this.paintIndex.put(i.next(), new Integer(paint));
253: if (++count % valuesPerColor == 0) {
254: paint++;
255: }
256: if (paint > this.paintLimit) {
257: paint = this.paintLimit;
258: }
259: }
260: }
261:
262:
270: private void makeValueIndex(Number max, Number min, Set uniqueValues) {
271: double valueRange = max.doubleValue() - min.doubleValue();
272: double valueStep = valueRange / this.paintLimit;
273: int paint = 0;
274: double cutPoint = min.doubleValue() + valueStep;
275: for (Iterator i = uniqueValues.iterator(); i.hasNext();) {
276: Number value = (Number) i.next();
277: while (value.doubleValue() > cutPoint) {
278: cutPoint += valueStep;
279: paint++;
280: if (paint > this.paintLimit) {
281: paint = this.paintLimit;
282: }
283: }
284: this.paintIndex.put(value, new Integer(paint));
285: }
286: }
287:
288:
294: public LegendItemCollection getLegendCollection() {
295: LegendItemCollection result = new LegendItemCollection();
296: if (this.paintIndex != null && this.paintIndex.size() > 0) {
297: if (this.paintIndex.size() <= this.paintLimit) {
298: for (Iterator i = this.paintIndex.entrySet().iterator();
299: i.hasNext();) {
300:
301: Map.Entry entry = (Map.Entry) i.next();
302: String label = entry.getKey().toString();
303: String description = label;
304: Shape shape = new Rectangle2D.Double(1d, 1d, 1d, 1d);
305: Paint paint = getSeriesPaint(
306: ((Integer) entry.getValue()).intValue()
307: );
308: Paint outlinePaint = Color.black;
309: Stroke outlineStroke = DEFAULT_STROKE;
310:
311: result.add(new LegendItem(label, description, null,
312: null, shape, paint, outlineStroke, outlinePaint));
313:
314: }
315: }
316: else {
317:
318: Set unique = new HashSet();
319: for (Iterator i = this.paintIndex.entrySet().iterator();
320: i.hasNext();) {
321: Map.Entry entry = (Map.Entry) i.next();
322: if (unique.add(entry.getValue())) {
323: String label = getMinPaintValue(
324: (Integer) entry.getValue()).toString()
325: + " - " + getMaxPaintValue(
326: (Integer) entry.getValue()).toString();
327: String description = label;
328: Shape shape = new Rectangle2D.Double(1d, 1d, 1d, 1d);
329: Paint paint = getSeriesPaint(
330: ((Integer) entry.getValue()).intValue()
331: );
332: Paint outlinePaint = Color.black;
333: Stroke outlineStroke = DEFAULT_STROKE;
334:
335: result.add(new LegendItem(label, description,
336: null, null, shape, paint, outlineStroke,
337: outlinePaint));
338: }
339: }
340: }
341: }
342: return result;
343: }
344:
345:
353: private Number getMinPaintValue(Integer index) {
354: double minValue = Double.POSITIVE_INFINITY;
355: for (Iterator i = this.paintIndex.entrySet().iterator(); i.hasNext();) {
356: Map.Entry entry = (Map.Entry) i.next();
357: if (((Integer) entry.getValue()).equals(index)) {
358: if (((Number) entry.getKey()).doubleValue() < minValue) {
359: minValue = ((Number) entry.getKey()).doubleValue();
360: }
361: }
362: }
363: return new Double(minValue);
364: }
365:
366:
374: private Number getMaxPaintValue(Integer index) {
375: double maxValue = Double.NEGATIVE_INFINITY;
376: for (Iterator i = this.paintIndex.entrySet().iterator(); i.hasNext();) {
377: Map.Entry entry = (Map.Entry) i.next();
378: if (((Integer) entry.getValue()).equals(index)) {
379: if (((Number) entry.getKey()).doubleValue() > maxValue) {
380: maxValue = ((Number) entry.getKey()).doubleValue();
381: }
382: }
383: }
384: return new Double(maxValue);
385: }
386:
387:
388: }