Re: Retaining Controls for ScalarMaps

=?iso-8859-1?Q?Mathias_St=FCmpert?= wrote:
> Hi all,
> 
> I use a refresh method for my displays that does the following (in
> Pseudocode):
> 
> display.disableAction();
> display.removeAllReferences();
> display.clearMaps();
> ...
> display.addMaps(allMaps);
> display.addData(allDatas);
> 
> Where allMaps and allDatas are stored externally. The Problem I have is
> that all Controls linked to my ScalarMaps disappeard when I remove the
> corresponding ScalarMap from the display (or when I re-add them?). So if
> I had a good looking colortable in my ColorControl or some good shapes
> in my ShapeControl after the refresh everything is reset. How can I
> prevent this reset? I saw that there is a setControl() in ScalarMap
> which is package private. Is there a way to do something like:
> 
> Controls controls = allMaps.getControls();
> ...the above code...
> allMaps.setControls(controls);
> 
> to reinitialize the Controls?

Each control has a getSaveString() method and a setSaveString()
method associated with it, so you could do something like:

  ArrayList ctlStr = new ArrayList();

  Iterator iter = allMaps.iterator();
  while (iter.hasNext()) {
    ScalarMap map = (ScalarMap )iter.next();
    ctlStr.add(map.getControl().getSaveString());
  }
  ... disable/remove/clear, then readd everything...

  Iterator iter = allMaps.iterator();
  Iterator ctlIter = ctlStr.iterator();
  while (iter.hasNext()) {
    ScalarMap map = (ScalarMap )iter.next();
    map.getControl().setSaveString((String )ctlIter.next());
  }

Keep in mind that I've never compiled this code or even used
the getSaveString/setSaveString methods (though I know
Curtis uses them inside the VisAD spreadsheet), so the above
code could well cause your computer to explode, your hair to
fall out, etc.)