// BasicRequirements:


// Basic requirements for creating a RiskMapPlot:
//   1) Create a data source, usually a Java TableModel
//   2) Create a data model that uses the data source
//   3) Set up the desired risk map. This example uses the
//      SimpleRiskMap class, which requires SegmentedRangeModel
//      values for the X and Y axes, colors to associate with the
//      axis values, and the type of risk map you want
//   4) Construct a RiskMapPlot that uses the data model and risk map

import com.sas.graphics.components.PlotVariable;
import com.sas.graphics.components.SegmentedRangeModel;
import com.sas.graphics.components.riskmapplot.RiskMapPlot;
import com.sas.graphics.components.riskmapplot.RiskMapPlotTableDataModel;
import com.sas.graphics.components.riskmapplot.SimpleRiskMap;
import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class BasicRequirements extends JPanel {
  private BasicRequirements  theApp;
  public BasicRequirements () {
      setLayout(new BorderLayout());

  // 1) Create a data source, usually a Java TableModel
     Data dataTable = new Data();  // defined below

  // 2) Construct a data model that uses the data source
     RiskMapPlotTableDataModel dataModel=
       new RiskMapPlotTableDataModel(dataTable);
     dataModel.setXVariable(new PlotVariable("Systolic Blood Pressure"));
     dataModel.setYVariable(new PlotVariable("Blood Sugar"));

  // 3) Set up the desired risk map, in this case, a SimpleRiskMap
     SegmentedRangeModel xRange = SegmentedRangeModel.
       newSegmentedRangeModel(new double[]{0, 120, 135, 160, 200});
     SegmentedRangeModel yRange = SegmentedRangeModel.
       newSegmentedRangeModel(new double[]{0, 100, 120, 160, 400});

     SimpleRiskMap simpleRiskMap = new SimpleRiskMap(xRange, yRange,
       new Color[]{Color.GREEN,Color.YELLOW, Color.ORANGE, Color.RED},
       SimpleRiskMap.TYPE_BLOCK);

  // 4) Construct a RiskMapPlot that uses the data model and risk map
     RiskMapPlot riskMapPlot = new RiskMapPlot(dataModel);
     riskMapPlot.getGraphModel().setRiskMap(simpleRiskMap);

     add(riskMapPlot, BorderLayout.CENTER);
  }
  private static class Data extends DefaultTableModel
  {
     private Class   columnClass[] = {Double.class, Double.class};
     private String  columnNames[] = {"Blood Sugar", "Systolic Blood Pressure"};
     private Object  data[][]      = {
       {new Double(140), new Double(95)},
       {new Double(205), new Double(145)},
       {new Double(175), new Double(152)},
       {new Double(300), new Double(142)},
       {new Double(230), new Double(115)},
       {new Double(125), new Double(125)}
     };
     public Data()
     {
       super();
       setDataVector(data, columnNames);
     }
     public Class getColumnClass(int column)
     {
       return columnClass[column];
     }
  }
  public static void main(String[] args) {
     JFrame frame = new JFrame("BIP Graph Sample");
     Container container = frame.getContentPane();
     container.setLayout(new BorderLayout());
     container.setBackground(Color.white);

     JPanel bipPanel = new JPanel();
     bipPanel.setLayout(new BorderLayout());
     BasicRequirements  bipGraphSample = new BasicRequirements();

     bipPanel.add(bipGraphSample, BorderLayout.CENTER);
     container.add(bipPanel, BorderLayout.CENTER);
     frame.setSize(600,450);
     frame.addWindowListener(
       new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
         }
       }
     );
     frame.setVisible(true);
  }
}