Re: Refreshing DisplayImplJ2D after loading a new file

Hi Tolga-

> Tolga Sakman wrote:
> My application creates a DisplayImplJ2D, reads a simple grid from a
> default file and displays it. What it is is basically a square with
> axes labeled "X" and "Y", used as a placeholder for the grid that will
> be loaded.
> 
> Then I use my custom container's (a swing gui) controls to select a
> file and feed it into my visaddisplay. What I want is the old display
> to disappear, and the new one show up. Apparently, just changing the
> dataset won't cut it; there are complications. Here's a stack trace:
> 
> It gives a "visad.TypeException: ScalarType: name already used"
> stemming from ScalarType.java:186. Apparently it did not like the fact
> that I am trying to use the same row and column with the same names
> such as:
>      row = new RealType("X", SI.meter, null);
>      column = new RealType("Y", SI.meter, null);
> I presume the name "X" is where it cracks.

RealTypes must be unique in VisAD. If you try to create a new RealType
of the same name, you will get the exception.  One way around this is to
use the static RealType.getRealType() method which will return the
existing RealType or create a new one if there is not one yet defined.
If your data will always end up with RealTypes of row and column, then
you only need to create them once in the constructor as you did.
 
> Then I try to "null"ify these objects if they != null, it does not
> work.
> 
> Then I take these into the initial constructor so that they are not
> called when a new file is loaded. This does not throw exceptions, but
> does not display my new grid either. row and column still have their
> old ways, so does myDisplay (the DisplayImplJ2D reference).
> 
> I try to myDisplay.destroy() if myDisplay != null, but it apparently
> never reaches there.

How are you setting the data?  You should just be able to call the
setData method on your DataReference with the new Data object.  In this
case, the display should automatically update.
 
> So after spending 4 hours of my night and bulk of this morning on
> this, my question is: How do you clear the display and show new data
> without killing the reference within the GUI and constructing a new
> one with the new chosen file?

When you select the file, read it in and create a VisAD Data object and
then call setData with that object on your DataReference.  The new data
should automatically appear in the display. 

Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: