// ChangeLine:


// To change the line style for needle lines:
//   1) Define a MarkerStyle for the plot markers
//   2) Get the RiskMapPlotModel and call its setInterpolationEnabled()
//      method to enable interpolation
//   3) Call the MarkerStyle's setInterpolation() method to set
//      the interpolation type
//   4) Define a LineStyle and call the RiskMapPlotModel's
//      setNeedleLineStyle() method to set the interpolation type

import com.sas.graphics.components.riskmapplot.RiskMapPlotModel;
import com.sas.graphics.components.MarkerStyle;
import com.sas.graphics.components.LineStyle;
import com.sas.measures.BaseLength;
import com.sas.graphics.components.GraphConstants;
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 ChangeLine extends JPanel {
  private ChangeLine  theApp;
  public ChangeLine () {
      setLayout(new BorderLayout());

     Data dataTable = new Data();  // defined below

     RiskMapPlotTableDataModel dataModel=
       new RiskMapPlotTableDataModel(dataTable);
     dataModel.setXVariable(new PlotVariable("Systolic Blood Pressure"));
     dataModel.setYVariable(new PlotVariable("Blood Sugar"));

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

     RiskMapPlot riskMapPlot = new RiskMapPlot(dataModel);
     RiskMapPlotModel graphModel=riskMapPlot.getGraphModel();
     graphModel.setRiskMap(simpleRiskMap);


//   1) Define a MarkerStyle for the plot markers
        MarkerStyle[] markerStyle=new MarkerStyle[] {
              new MarkerStyle(MarkerStyle.SYMBOL_SQUARE_FILLED)};
        graphModel.getDataElementStyles().setMarkerStyles(markerStyle);

//   2) Call setInterpolationEnabled() to enable interpolation
        graphModel.setInterpolationEnabled(true);

//   3) Call the MarkerStyle's setInterpolation() method to set the interpolation type
        markerStyle[0].setInterpolation(MarkerStyle.INTERPOLATION_VERTICAL_NEEDLES);

//   4) Define a LineStyle and call setNeedleLineStyle() to set the interpolation type
        LineStyle lineStyle = new LineStyle(
          Color.gray,
          new BaseLength(3, "pt"),
          GraphConstants.TRUE);
        graphModel.setNeedleLineStyle(lineStyle);

     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());
     ChangeLine  bipGraphSample = new ChangeLine();

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