// ChangeTileLayout:


// To change the chart layout, call the TileChartModel's setLayoutType() method.
// This example specifies LAYOUT_GEOGRAPHIC, which requires positioning variables.
// The positioning variables in this case are the longitude and latitude 
// coordinates of the cities in the data.

   import com.sas.graphics.components.tilechart.TileChart;
   import com.sas.graphics.components.tilechart.TileChartModel;
   import com.sas.graphics.components.tilechart.TileChartTableDataModel;
   import com.sas.graphics.components.AnalysisVariable;
   import com.sas.graphics.components.GraphConstants;
   import com.sas.graphics.components.ClassificationVariable;
   import com.sas.graphics.components.ClassificationVariableList;
   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 ChangeTileLayout extends JPanel  {
     private ChangeTileLayout  theApp;
     public ChangeTileLayout () {
        setLayout(new BorderLayout());

     // Create a TileChart and a data source 
        TileChart tileChart=new TileChart();
        SampleData dataTable=new SampleData();

     // Set the chart layout
        TileChartModel graphModel=tileChart.getGraphModel();
        graphModel.setLayoutType(TileChartModel.LAYOUT_GEOGRAPHIC);

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

     // Define multiple Classification variables
        ClassificationVariableList multiTile=new ClassificationVariableList(
          new ClassificationVariable[] {
              new ClassificationVariable("State", GraphConstants.SORT_DESCENDING),
              new ClassificationVariable("City", GraphConstants.SORT_DESCENDING)
          } );

     // Assign the classification list to the Tile variable role
        dataModel.setTileVariable(multiTile);

     // Assign the Size variable role
        dataModel.setSizeVariable(
                  new AnalysisVariable("Population"));
 
     // Assign the Color variable role
        dataModel.setColorVariable(
                  new AnalysisVariable("Ave July temp."));
  
     // Assign geographic variable roles
        dataModel.setYVariable(
                  new AnalysisVariable("Latitude"));
        dataModel.setXVariable(
                  new AnalysisVariable("Longitude"));

     // Assign the data model to the TileChart
        tileChart.setDataModel(dataModel);

     // Assign a title
        tileChart.getTitle1().setText("Geographic Layout");

        add(tileChart, BorderLayout.CENTER);
      }
   // Create the data source
      static private class SampleData extends DefaultTableModel {
        private static Class  columnClass[]={ String.class, String.class, String.class, Double.class, Double.class, Double.class, Double.class, Double.class};
        private static String columnNames[]={  "State", "City", "Zone", "Latitude", "Longitude", "Population", "Density pop/sq.mi.", "Ave July temp." };

          public SampleData() {
	    super();
            Object data[][] = {
                    {"NY", "New York City", "North", new Double(40), new Double(-73), new Double(8008278), new Double(26404), new Double(76.8) }
                    ,{"CA", "Los Angeles", "North", new Double(34), new Double(-118), new Double(3694820), new Double(7876), new Double(74.3) }
                    ,{"IL", "Chicago", "North", new Double(42), new Double(-88), new Double(2896016), new Double(12752), new Double(75.1) }
                    ,{"TX", "Houston", "North", new Double(30), new Double(-95), new Double(1953631), new Double(3372), new Double(83.5) }
                    ,{"PA", "Philadelphia", "North", new Double(40), new Double(-75), new Double(1517550), new Double(11233), new Double(76.7) }
                    ,{"AZ", "Phoenix", "North", new Double(33), new Double(-112), new Double(1321045), new Double(2782), new Double(93.5) }
                    ,{"CA", "San Diego", "North", new Double(32), new Double(-117), new Double(1223400), new Double(3772), new Double(71.0) }
                    ,{"TX", "Dallas", "North", new Double(33), new Double(-97), new Double(1188580), new Double(3470), new Double(85.9) }
                    ,{"TX", "San Antonio", "North", new Double(29), new Double(-98), new Double(1144646), new Double(2808), new Double(85.0) }
                    ,{"MI", "Detroit", "North", new Double(42), new Double(-83), new Double(951270), new Double(6854), new Double(74.2) }
                    ,{"CA", "San Jose", "North", new Double(37), new Double(-121), new Double(894943), new Double(5117), new Double(69.5) }
                    ,{"IN", "Indianapolis", "North", new Double(40), new Double(-86), new Double(781870), new Double(2163), new Double(75.4) }
                    ,{"CA", "San Francisco", "North", new Double(37), new Double(-122), new Double(776733), new Double(16632), new Double(59.1) }
                    ,{"FL", "Jacksonville", "North", new Double(30), new Double(-82), new Double(735617), new Double(971), new Double(81.6) }
                    ,{"OH", "Columbus", "North", new Double(40), new Double(-83), new Double(711470), new Double(3383), new Double(73.2) }
                    ,{"TX", "Austin", "North", new Double(30), new Double(-98), new Double(656562), new Double(2611), new Double(84.5) }
                    ,{"MD", "Baltimore", "North", new Double(39), new Double(-76), new Double(651154), new Double(8059), new Double(77.0) }
                    ,{"TN", "Memphis", "North", new Double(35), new Double(-90), new Double(650100), new Double(2328), new Double(82.6) }
                    ,{"WI", "Milwaukee", "North", new Double(43), new Double(-88), new Double(596974), new Double(6212), new Double(73.6) }
                    ,{"MA", "Boston", "North", new Double(42), new Double(-71), new Double(589141), new Double(12172), new Double(73.5) }
                    ,{"DC", "Washington", "North", new Double(39), new Double(-77), new Double(572059), new Double(9317), new Double(80.0) }
                    ,{"TX", "El Paso", "North", new Double(32), new Double(-106), new Double(563662), new Double(2263), new Double(82.3) }
                    ,{"WA", "Seattle", "North", new Double(47), new Double(-122), new Double(563374), new Double(6715), new Double(65.2) }
                    ,{"CO", "Denver", "North", new Double(40), new Double(-105), new Double(554636), new Double(3616), new Double(73.5) }
                    ,{"TN", "Nashville", "North", new Double(36), new Double(-87), new Double(545524), new Double(1153), new Double(79.3) }
                    ,{"NC", "Charlotte", "North", new Double(35), new Double(-81), new Double(540828), new Double(2232), new Double(79.3) }
                    ,{"TX", "Ft. Worth", "North", new Double(33), new Double(-97), new Double(534694), new Double(1828), new Double(85.3) }
            };
            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());
          ChangeTileLayout  bipGraphSample = new ChangeTileLayout ();

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