Hi Curtis,
That solved the problem. Thank you!
-Michelle
Michelle Kam (408) 742-2881
Lockheed Martin Space Systems Co. SSM/ATC/MSIS
B/153 O/L922
1111 Lockheed Martin Way, Sunnyvale, CA 94089
-----Original Message-----
From: Curtis Rueden [mailto:curtis@xxxxxxxxxxxxx]
Sent: Monday, June 16, 2003 10:47 AM
To: Kam, Michelle C
Subject: RE: setMaps()?
Hi Michelle,
>Busy waiting for a data change didn't quite seem to work. I'm still seeing
>small.v5d loaded without any mappings at all.
Busy waiting will not work, because that's not how Java's event
architecture works. Each event triggers a separate call to the
event handling method (in this case, ssCellChanged). Thus, your
code can simply ignore any calls to this method that do not have
the requisite parameters (in this case, e.getChangeType() =
SSCellChangeEvent.DATA_CHANGE).
>And you're right. I did have that other method in SpreadSheet.java called
>"myAutoDetect()" which I now removed since I wasn't using it. So your
>version of my SpreadSheet.java should be most up to date. Attached is my
>updated VisadAPI.java as well as SSCellListener since I had to import a
>couple packages in that class to have it compile. Do you know what could be
>causing this?
You have ssCellChanged declared as throwing VisADException and
RemoteException, but the interface method does not. Thus, your
implementation should not either. Instead of changing
SSCellListener.java, change your method so that it does not
declare itself throwing those exceptions. You are catching them
in a try block anyway, so it doesn't matter.
Also, your loadMyDataSet method in SpreadSheet.java will not
work properly, because you are constructing a new BasicSSCell
within it. Here is a version that will work:
----
/**
* Calls loadMyDataSet in VisadAPI.java where file is loaded.
*/
public void loadMyDataSet() {
try {
VisadAPI mine = new VisadAPI(this, DisplayCells[0][0]);
mine.loadMyDataSet();
}
catch (VisADException exc) { exc.printStackTrace(); }
catch (RemoteException exc) { exc.printStackTrace(); }
}
----
Here is a working version of VisadAPI.java:
----
//Imports small.v5d and sets up specified mappings.
package visad.ss;
import java.rmi.RemoteException;
import visad.*;
public class VisadAPI implements SSCellListener {
public static SpreadSheet mySS;
public static BasicSSCell myBasicSS;
public VisadAPI(SpreadSheet ss, BasicSSCell basic) {
mySS = ss;
myBasicSS = basic;
myBasicSS.addSSCellListener(this);
}
/**
* loads small.v5d into top left spreadsheet cell,
* called from SpreadSheet.java
*/
public static void loadMyDataSet() throws VisADException, RemoteException
{
try {
mySS.setAutoDetect(false);
if (mySS != null) {
//LOAD IN FILE
mySS.DisplayCells[0][0].addDataSource("C:\\java\\data\\small.v5d",
BasicSSCell.URL_SOURCE);
}
}
catch (VisADException exc) { exc.printStackTrace(); }
catch (RemoteException exc) { exc.printStackTrace(); }
}
/** sets up default mappings when image is first loaded in. */
public static void setMappings() throws VisADException, RemoteException {
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);
myBasicSS.setMaps(new ScalarMap[] {
Alt_rad, Alt_green, Lat_blue, Long_red
});
}
catch (VisADException exc) { exc.printStackTrace(); }
catch (RemoteException exc) { exc.printStackTrace(); }
}
/** called each time myBasicSS changes */
public void ssCellChanged(SSCellChangeEvent e) {
if (e.getChangeType() != SSCellChangeEvent.DATA_CHANGE) return;
if (e.getSSCell() != myBasicSS) return;
String source = myBasicSS.getDataSource("A1d1");
if (source == null || !source.endsWith("small.v5d")) return;
try {
setMappings();
}
catch (VisADException exc) { exc.printStackTrace(); }
catch (RemoteException exc) { exc.printStackTrace(); }
}
}
----
You had a bunch of unneeded imports. I took those out.
You were not calling addSSCellListener on myBasicSS (and thus,
SsCellChangeEvents were not reported to your ssCellChanged
method. I added that in the constructor.
I changed your exception catching blocks to call
exc.printStackTrace(), because that gives you a full report of
where things went wrong. More useful than a println statement.
I removed the busy wait from your ssCellChanged method, since
it would only result in deadlock if a non-DATA_CHANGE were to
get reported. Instead, I added code to ignore data changes
that you aren't interested in. That is, it ignores any data
change that wasn't the result of calling
addDataSource("small.v5d").
Lastly, I'm not sure the mappings you are using are what you
are after. Don't you want mappings from RealType.Latitude to
Display.Latitude, and from RealType.Longitude to
Display.Longitude as well?
-Curtis