//Imports small.v5d and sets up specified mappings.

package visad.ss;

import java.awt.*;
import java.io.*;
import java.net.*;
import java.rmi.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import visad.*;
import visad.data.*;
import visad.util.*;

import java.awt.event.*;
import java.awt.print.*;

import java.lang.reflect.*;
import java.rmi.registry.*;
import javax.swing.event.*;

import visad.formula.*;
import visad.java3d.*;

public class VisadAPI {
	
	
	public static SpreadSheet mySS;
	public static BasicSSCell myBasicSS;
	
	public VisadAPI(SpreadSheet ss, BasicSSCell basic) {
		
		mySS = ss;
		myBasicSS = basic;
	}

	//loads small.v5d into top left spreadsheet cell, called from SpreadSheet.java
	public static void loadMyDataSet() throws VisADException, RemoteException {

 	try {
 	  System.out.println("In loadMyDataSet() and in try clause"); 
 	  mySS.myAutoDetect(false);  
 	  System.out.println("After false");
 	  if (mySS ==null) {
 	  	System.out.println("mySS is null!!!");
 	  }
else {
	  mySS.DisplayCells[0][0].addDataSource("D:\\visad\\data\\small.v5d", BasicSSCell.URL_SOURCE);
	 }
	  System.out.println("after addDataSource()");
	  setMappings();
	  System.out.println("after SetMappings");
	  myBasicSS.setMaps(mySS.myMappings);
	  System.out.println("after setMaps");
}
	catch (VisADException exc) {
		System.out.println("in loadMyDataSet() and there is a VisadException");
     	System.out.println("VisADException in loadMyDataSet(). Could not load file small.v5d. ");
}
	catch (RemoteException exc) {
		System.out.println("in loadMyDataSet() and there is a RemoteException");
    	System.out.println("RemoteException in loadMyDataSet(). Could not load file small.v5d.");
	}
}

	//sets up default mappings when image is first loaded in.
	public static void setMappings() throws VisADException {

	try {		
	System.out.println("In VisadAPI.java and setMappings()");	  
	  ScalarMap Alt_rad = new ScalarMap(RealType.Altitude, Display.Radius);		
	  ScalarMap Alt_green = new ScalarMap(RealType.Altitude, Display.Green);
	  ScalarMap Lat_blue = new ScalarMap(RealType.Latitude, Display.Blue);
	  ScalarMap Long_red = new ScalarMap(RealType.Longitude, Display.Red);

	System.out.println("after assigning");	
	  mySS.myMappings[0] = Alt_rad;
	  mySS.myMappings[1] = Alt_green;
	  mySS.myMappings[2] = Lat_blue;
	  mySS.myMappings[3] = Long_red;
	  System.out.println("after setting up array");
	 }
	catch (VisADException exc) {
		System.out.println("VisADException in method setMappings in VisadAPI.java");
	}
}

}
