Hi Shinta,
> After test some examples in VISAD class.
> I have question about the VISAD. Can we add a switch or
> eventlistener to change , remove or add the the new
> ScalarMap in program?
>
> example :
>
> If I alreadly have three baisc ScarlarMaps:
>
> dpys[0].addMap(new ScalarMap(RealType.Latitude,
> Display.YAxis));
> dpys[0].addMap(new ScalarMap(RealType.Longitude,
> Display.XAxis));
> dpys[0].addMap(new ScalarMap(RealType.Radius,
> Display.IsoContour));
>
> I want remove the last one after click one button(on UI) .
>
> dpys[0].addMap(new ScalarMap(RealType.Radius,
> Display.IsoContour));
>
> or add new one after click another button.
>
> dpys[0].addMap(new ScalarMap(RealType.Radius,
> Display.Red));
>
> If there is some method to do this, please tell me. Thanks
In order to change the ScalarMaps in a display, you must
first remove all links to data. If you've set up a display
with code like:
DisplayImplJ3D display = ...;
display.addMap(...);
...
display.addMap(...);
display.addReference(...);
...
display.addReference(...);
and then want to change ScalarMaps, do this:
// save the old maps
Vector sMaps = display.getMapVector();
Vector cMaps = display.getConstantMapVector();
// remove links to data
display.removeAllReferences();
// clear ScalarMaps
display.clearMaps();
// add selected maps back to display
//
// add them back, rather simply recreating them, in order
// to preserve any control widgets you constructed for your
// ScalarMaps (thanks to Dave Glowacki's recent work)
if (sMaps != null) {
int len = sMaps.size();
for (int i = 0; i < len; i++) {
ScalarMap map = (ScalarMap )sMaps.elementAt(i);
ScalarType scalar = map.getScalarType(); // probably a RealType
DisplayRealType dreal = getDisplayScalar();
// decide whether to discard certain ScalarMaps based on
// their RealType and DisplayRealType
if (we want to keep this ScalarMap) {
display.addMap(map);
}
}
}
// add any new ScalarMaps to display
display.addMap(...);
...
display.addMap(...);
// add ConstantMaps back
if (cMaps != null) {
int len = cMaps.size();
for (int i = 0; i < len; i++) {
ConstantMap map = (ConstantMap )cMaps.elementAt(i);
newDpy.addMap(map);
}
}
// recreate links to data
display.addReference(...);
...
display.addReference(...);
Good luck,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI 53706
hibbard@xxxxxxxxxxxxxxxxx 608-263-4427 fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html