// Basic Requirements:


// Basic requirements for creating a waterfall chart:
//   1) Create a WaterfallChart instance and a data source 
//   2) Create a data model and attach the data source to it
//   3) Assign the Category variable role, and optionally the
//      Response variable role, to appropriate variable(s)
//   4) Assign the data model to the WaterfallChart
// To set a title or footnote, get the appropriate WaterfallChart
// title or footnote, and then set the returned object's text.

   import com.sas.graphics.components.waterfallchart.WaterfallChart;
   import com.sas.graphics.components.waterfallchart.WaterfallChartTableDataModel;
   import com.sas.graphics.components.AnalysisVariable;
   import com.sas.graphics.components.ClassificationVariable;
   import javax.swing.table.DefaultTableModel;
   import java.awt.BorderLayout;
   import java.awt.Color;
   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 WaterfallChart and a data source 
        WaterfallChart waterfallChart=new WaterfallChart();
        SampleData dataTable=new SampleData();

     // 2) Create a data model and attach the data source
        WaterfallChartTableDataModel dataModel=
                  new WaterfallChartTableDataModel();
        dataModel.setModel(dataTable);

      // 3) Assign the Category variable role, and optionally the
      // Response variable role, to appropriate variable(s).
      // This sample sorts category values in descending order, and
      // it applies the NLMNLUSD format to the response variable so
      // that Transaction amounts in the output are displayed in an
      // internationalized representation of US dollars.
     
         dataModel.setCategoryVariable(
                  new ClassificationVariable("Id"));
         dataModel.setResponseVariable(
                  new AnalysisVariable("Transaction", "nlmnlusd"));

     // 4) Assign the data model to the WaterfallChart
        waterfallChart.setDataModel(dataModel);

     // Set a graph title
        waterfallChart.getTitle1().setText("BIP Waterfall Chart");
        add(waterfallChart, BorderLayout.CENTER);
      }
   // Create the data source
      static private class SampleData extends DefaultTableModel {
        private static Class  columnClass[]={Double.class, String.class};
        private static String columnNames[]={  "Transaction"  ,  "Id"  };
          public SampleData() {
	    super();
            Object data[][] = {
                                  {new Double(  23),"D"}
                                , {new Double(  85),"C"}
                                , {new Double(  27),"A"}
                                , {new Double( -20),"E"}
                                , {new Double( 125),"B"}
                                , {new Double(   3),"F"}
                                , {new Double(   6),"G"}
                                , {new Double( 142),"H"}
                                , {new Double(-117),"I"}
                                , {new Double(  26),"J"}
                                , {new Double(  73),"K"}
                                , {new Double(  16),"L"}
                                , {new Double( -82),"M"}
                                , {new Double(  93),"N"}
                                , {new Double( 126),"O"}
            };
            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);
      }
   }