/**********************************************************************
# Copyright (c) EWA Systems Inc. 1998 - 2005 All Rights Reserved
#               No part of this program may be photocopied, reproduced,
#               or translated to another programming language without
#               the prior written consent of EWA Systems.
**********************************************************************/

package com.ewasystems.chart.test;

import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Random;
import com.ewasystems.chart.Chart;
import com.ewasystems.chart.JFrameChart;
import com.ewasystems.chart.waferplot.AxesWafer;
import com.ewasystems.chart.waferplot.WaferDefect;
import com.ewasystems.chart.waferplot.WaferDie;

/**
 * <p>Title: Sample Wafer Plot</p>
 * <p>Copyright: (c) 1998 - 2005</p>
 * <p>Company: EWA Systems, Inc.</p>
 * @author Lincoln Evans-Beauchamp
 * @version 1.0
 */

public class SampleWaferPlot extends JFrameChart
{
  public SampleWaferPlot()
  {
    Chart chart = getChart();

    AxesWafer wafer = new AxesWafer(chart);
    wafer.radius = 215d;

    Random r = new Random();
    ArrayList[] bins = new ArrayList[5];
    bins[0] = new ArrayList();
    bins[1] = new ArrayList();
    bins[2] = new ArrayList();
    bins[3] = new ArrayList();
    bins[4] = new ArrayList();

    for (int x=-7; x<8; x++)
    {
      for (int y=-7; y<8; y++)
      {
        if ((Math.abs(y) > 6) && (Math.abs(x) > 3)) continue;
        if ((Math.abs(y) > 5) && (Math.abs(x) > 5)) continue;
        if ((Math.abs(y) > 4) && (Math.abs(x) > 6)) continue;
        if ((Math.abs(y) > 3) && (Math.abs(x) > 6)) continue;
        bins[r.nextInt(5)].add(new int[] {x , y});
      }
    }

    for (int i=0; i<5; i++)
    {
      int[] x = new int[bins[i].size()];
      int[] y = new int[bins[i].size()];
      for (int j=0; j<bins[i].size(); j++)
      {
        int[] index = (int[])bins[i].get(j);
        x[j] = index[0];
        y[j] = index[1];
      }
      WaferDie die = wafer.addWaferDie(x, y, "Bin#"+i);
      die.setDieSize(new double[] {22d, 22d});
      die.setDieStep(new double[] {25d, 25d});
      die.setDieOrigin(new double[] {-11d, -11d});

      if (i == 0) die.setFillColor(Color.green);
      if (i == 1) die.setFillColor(Color.yellow);
      if (i == 2) die.setFillColor(Color.blue);
      if (i == 3) die.setFillColor(Color.red);
      if (i == 4) die.setFillColor(Color.orange);
    }

    double[] defectX = new double[100];
    double[] defectY = new double[100];
    for (int i=0; i<defectX.length; i++)
    {
      defectX[i] = (r.nextDouble()-.5d)*300d;
      defectY[i] = (r.nextDouble()-.5d)*300d;
    }
    WaferDefect defect = wafer.addWaferDefect(defectX, defectY);

    //chart.getChartLegend().setPaint(true);

    chart.setSize(new Dimension(600, 600));
    this.setSize(650, 650);
  }

  public static void main(String argv[])
  {
    new SampleWaferPlot().setVisible(true);
  }

  public String toString()
    {return "Sample Wafer Plot";}
}
