// BasicGridRiskMap:


// Basic requirements for creating a GridRiskMap chart:
//   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
//      GridRiskMap class, which requires SegmentedRangeModel
//      values for the X and Y axes, and also colors for those
//      axis values
//   4) Construct a RiskMapPlot that uses the data model and risk map

import com.sas.graphics.components.Variable;
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.GridRiskMap;
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 BasicGridRiskMap extends JPanel {
  private BasicGridRiskMap  theApp;
  public BasicGridRiskMap () {
      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("Completeness of Vision"));
     dataModel.setYVariable(new PlotVariable("Ability to Execute"));
     dataModel.setTopMarkerLabelVariable(new Variable("Company Names"));

  // 3) Set up the desired risk map, in this case, a GridRiskMap
     SegmentedRangeModel xRange = SegmentedRangeModel.
       newSegmentedRangeModel(new double[]{0, 10, 20});
     SegmentedRangeModel yRange = SegmentedRangeModel.
       newSegmentedRangeModel(new double[]{0, 10, 20});

     GridRiskMap gridRiskMap = new GridRiskMap(xRange, yRange,
       new Color[][]{ {Color.RED,Color.YELLOW}, {Color.ORANGE, Color.GREEN} });

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

     add(riskMapPlot, BorderLayout.CENTER);
  }
  private static class Data extends DefaultTableModel
  {
     private Class   columnClass[] = {Double.class, Double.class, String.class, String.class};
     private String  columnNames[] = {"Completeness of Vision" , "Ability to Execute", "Company Names", "Type"};
     private Object  data[][]      = {
       {new Double(11), new Double(9),    "Company A", "Challengers"},
       {new Double(11), new Double(13),   "Company B", "Leaders"},
       {new Double(9),  new Double(11),   "Company C", "Challengers"},
       {new Double(14), new Double(12),   "Company D", "Leaders"},
       {new Double(8),  new Double(10.5), "Company E", "Leaders"},
       {new Double(7),  new Double(9.5),  "Company F", "Leaders"},
       {new Double(8),  new Double(8),    "Company G", "Challengers"},
       {new Double(3),  new Double(8),    "Company H", "Challengers"},
       {new Double(5),  new Double(7),    "Company I", "Leaders"},
       {new Double(4),  new Double(4),    "Company J", "Leaders"},
       {new Double(2),  new Double(4),    "Company K", "Leaders"},
       {new Double(2),  new Double(2),    "Company L", "Challengers"},
       {new Double(9),  new Double(8),    "Company M", "Leaders"},
       {new Double(8),  new Double(6),    "Company N", "Leaders"},
       {new Double(4),  new Double(6),    "Company O", "Leaders"},
       {new Double(5),  new Double(7),    "Company P", "Leaders"},
       {new Double(3),  new Double(7),    "Company Q", "Leaders"}
     };
     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());
     BasicGridRiskMap  bipGraphSample = new BasicGridRiskMap();

     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);
  }
}