// FillAreas:


// When the specification on the data model generates multiple plot lines,
// the areas between the lines can be filled by calling the
// LinePlotModel's setFillAreaEnabled() method with the argument value
// true. Optionally, you can define a fill for the areas and set the
// fill on the DataElementStyles. This sample uses multiple response
// variables to generate multiple plot lines.

   import com.sas.graphics.components.lineplot.LinePlot;
   import com.sas.graphics.components.lineplot.LinePlotTableDataModel;
   import com.sas.graphics.components.ClassificationVariable;
   import com.sas.graphics.components.PlotVariable;
   import com.sas.graphics.components.PlotVariableList;
   import com.sas.graphics.components.lineplot.LinePlotModel;
   import com.sas.graphics.components.DataElementStyles;
   import com.sas.graphics.components.FillStyle;
   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;
   import javax.swing.table.DefaultTableModel;

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

     // Create a LinePlot and a data source 
        LinePlot linePlot=new LinePlot();
        SampleData dataTable=new SampleData();

     // Get the plot's graph model and enable filled areas
        LinePlotModel graphModel=linePlot.getGraphModel();
        graphModel.setFillAreaEnabled(true);

     // Create transparent fills for the filled areas
        FillStyle[] transparencies=new FillStyle[] {
          new FillStyle(new Color(204,0,102,100) ),    // red transparency
          new FillStyle(new Color(102,153,102,100) ),  // green transparency
          new FillStyle(new Color(51,102,255,100) ) }; // blue transparency

     // Set the fills on the plot areas
        graphModel.getDataElementStyles().setFillStyles(transparencies);

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

     // Define multiple X variables
        PlotVariableList multiX=new PlotVariableList(
          new PlotVariable[] {
              new PlotVariable("x1"),
              new PlotVariable("x2"),
              new PlotVariable("x3")
          } );

     // Define multiple Y variables
        PlotVariableList multiY=new PlotVariableList(
          new PlotVariable[] {
              new PlotVariable("y1"),
              new PlotVariable("y2")
          } );
        PlotVariable oneY=new PlotVariable("y3");

     // Assign the X and Y variable roles
        dataModel.setXVariable(multiX);
        dataModel.setYVariable(multiY);
        dataModel.setY2Variable(oneY);

     // Assign the data model to the LinePlot
        linePlot.setDataModel(dataModel);

     // Set a graph title
        linePlot.getTitle1().setText(
          "Fill Plot Areas");

        add(linePlot, BorderLayout.CENTER);
      }
  // Create the data source
     static private class SampleData extends DefaultTableModel {
       private static Class  columnClass[]={ Double.class
                                            , Double.class
                                            , Double.class
                                            , Double.class
                                            , Double.class
                                            , Double.class
                                            };
                                            
        private static String columnNames[]={ "x1"
                                            , "x2"
                                            , "x3"
                                            , "y1"
                                            , "y2"
                                            , "y3"
                                            };

	    public SampleData()
	    {
	        super();
            Object data[][]={ 
                              {new Double( 10),new Double( 20), new Double( 30), new Double(  3),new Double(  5), new Double(  25)}
                            , {new Double( 20),new Double( 30), new Double( 40), new Double(  6),new Double(  10), new Double(  30)}
                            , {new Double( 30),new Double( 40), new Double( 50), new Double(  9),new Double(  15), new Double(  35)}
                            , {new Double( 40),new Double( 50), new Double( 60), new Double(  12),new Double(  20), new Double(  40)}
                            , {new Double( 50),new Double( 60), new Double( 70), new Double(  15),new Double(  25), new Double(  50)}
                            , {new Double( 70),new Double( 80), new Double( 90), new Double(  18),new Double( 20), new Double(  55)}
                            , {new Double( 80),new Double( 90), new Double( 100), new Double(  21),new Double(  15), new Double(  60)}
                            , {new Double( 90),new Double( 100), new Double( 110), new Double(  24),new Double(  10), new Double(  65)}
                            , {new Double( 100),new Double( 110), new Double( 120), new Double(  27),new Double(  5), new Double(  70)}
                            };
            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());
          FillAreas  bipGraphSample = new FillAreas ();

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