Reload the visad applet of html but can't show

S Santos s.santos at uea.ac.uk
Tue Dec 19 03:51:05 MST 2006


Hi Monica,

Maybe you can implement the method destroy or stop of the applet and
clean there the current information displayed, so all is clear at the
moment of reloading the data.

Regards,

Santi

  ----- Original Message ----- 
  From: monica 
  To: visad 
  Sent: Tuesday, December 19, 2006 9:29 AM
  Subject: Reload the visad applet of html but can't show 


  Hello ~
      I have some trouble to reload the visad applet html.

      First step : I open the html which has visad applet. The picture
like no problem and show "Relative humidity(%)" data is correct.(like
p1.jpg)

      Second step : But when I press "Reload" button in html, the
"Relative humidity(%)" data is hidden. The scales seem right, and 
          I still can get data in visad.(Although data can't show, like
p2.jpg) 

      Third step : I try again "Reload" the html, but terrible thing has
happen. Not only the "Relative humidity(%)" data is hidden, 
          but also other scales disappear.(like p3.jpg)

      I sort the email visad-list email, I find many ways, but just the
"open java plugin Console and perss 'x' -- clear classloader cache"  way
          can solve my problem. Is other way to solve the problem
somebody know?Please tell me....
      (I try to code "clear classloader cache" in stop() method, but I
don't know to use which class control it ? and nobody seem not do..)

      help me please, thanks a lot ~~
                                                                        
                                                                        
              monica

  [code]

  package auto3DVisad;

  import java.applet.Applet;
  import java.awt.*;
  import java.net.URL;
  import java.util.*;
  import javax.swing.*;
  import visad.*;
  import ucar.*;

  public class Auto3DVisad extends Applet 
  {    
      DataImpl image_sequence = null;
      DisplayImpl display = null;
      BaseMapAdapter baseMapAdapter;
      NetcdfFile nc_File;
      String url = "";
      String varname = "";
      String mapFile = "";
   
      public void init()// throws VisADException, RemoteException,
IOException
      {
          System.out.println("Auto3DVisad.java Replaced on 2006/12/15");
          
          try
          {
              url = getParameter("HTTPNetcdfFile");
              varname = getParameter("VariableName");
              mapFile = getParameter("OUTLFile");                     
         
          }
          catch(Exception ex)
          {
              System.out.println(ex);
          }
      }
      
      public void start()
      {
          getData();
          drawData();
       }
      
      public void getData()
      {                
          try
          {
              Plain plain = new Plain(); 
              
              // open netcdf file
              if (url.indexOf("://") > 0)
                  image_sequence = plain.open(new URL(url));
              else
                  image_sequence = plain.open(url);
              
              // open OUTL* file
              if (mapFile.indexOf("://") > 0)            
                  baseMapAdapter = new BaseMapAdapter(new
URL(mapFile));            
              else
                  baseMapAdapter = new BaseMapAdapter(mapFile);
              
              if(image_sequence == null)
                  System.out.println("image_sequence is null");
              
              if(baseMapAdapter == null)
                  System.out.println("baseMapAdapter is null");
          }
          catch(Exception ex)
          {
              System.out.println(ex);
          }                       
      }
      
      public void drawData()
      {
          try
          {
              debugMap(display);
              
              // create a Display using Java3D
              display =
MyDataUtility.makeSimpleDisplay(image_sequence);
              GraphicsModeControl dispGMC = (GraphicsModeControl)
display.getGraphicsModeControl();            
              dispGMC.setScaleEnable(true);                        
              
              // create reference
              DataReference image_ref = new
DataReferenceImpl("NetcdfData");
              image_ref.setData(image_sequence);
              display.addReference(image_ref);
              display.reDisplayAll();

              ScalarMap latMap = null, lonMap = null, varMap =
null, altMap = null;
              Vector mapList = display.getMapVector();
              for(int idx = 0 ; idx < mapList.size() ; idx++)
              {
                  ScalarMap tempMap = (ScalarMap)mapList.get(idx);
                  
                  if(tempMap.getScalarName().equals("Latitude"))
                      latMap = tempMap;
                  else if(tempMap.getScalarName().equals("Longitude"))
                      lonMap = tempMap;
                  else if(tempMap.getScalarName().equals(varname))
                      varMap = tempMap;
                  else if(tempMap.getDisplayScalar() ==
Display.ZAxis)
                      altMap = tempMap;
                  else if(tempMap.getScalarName().indexOf("_") != -1) 
                      display.removeMap(tempMap);//because ScalarMap
name not support "_"(ex.level_200)
              }
              
              // we reset range : Latitude : -90 ~ 90, Longitude : 0.0 ~
357.5
              double lonRange[] = new double[2];
              double latRange[] = new double[2];
              FieldImpl temp_field = (FieldImpl) image_sequence;
              FlatField image_field =
(FlatField)temp_field.getSample(0);
              Gridded3DSet set = (Gridded3DSet)
image_field.getDomainSet();            
              float[] hi = set.getHi();
              float[] low = set.getLow();                             
       
              lonRange[0] = low[0];
              lonRange[1] = hi[0];
              latRange[0] = low[1];
              latRange[1] = hi[1];
              
              lonMap.setRange(lonRange[0], lonRange[1]);
              latMap.setRange(latRange[0], latRange[1]);
              
              if(altMap != null)
              {
                  float[][] altSamples = set.getSamples();            
   
                  for(int idx = 2 ; idx < altSamples.length ; idx++)
                  {
                      for(int jdx = 1 ; jdx < altSamples[idx].length ;
jdx++)
                      {
                          if(altSamples[idx][jdx -1] >
altSamples[idx][jdx])
                          {
                              double altRange[] = altMap.getRange();
                              altMap.setRange(altRange[1], altRange[0]);
                              
                              break;
                          }
                      }
                  }                
              }                                   
                
              // link OUTL* file data to display with a data reference
              // set the attributes of the map lines (color, location)
              DataReference maplinesRef = new
DataReferenceImpl("MapLines");            
              enableClipping(display, dispGMC, true);
              maplinesRef.setData(baseMapAdapter.getData());
              
              ConstantMap[] maplinesConstantMap = new ConstantMap[5];
              maplinesConstantMap[0] = new ConstantMap(1.,
Display.Blue);
              maplinesConstantMap[1] = new ConstantMap(1.,
Display.Red);
              maplinesConstantMap[2] = new ConstantMap(1.,
Display.Green);
              maplinesConstantMap[3] = new ConstantMap(1.001,
Display.Radius); // just above the image
              maplinesConstantMap[4] = new ConstantMap(-0.999f,
Display.ZAxis);
              display.addReference(maplinesRef, maplinesConstantMap); 
              display.reDisplayAll();
              
              // change Display.XAxis and Display.YAxis ratio
              ProjectionControl projCont =
display.getProjectionControl();
              double[] latvalue = latMap.getRange();
              double[] lonvalue = lonMap.getRange();
              double latStart = latvalue[0];            
              double latEnd = latvalue[latvalue.length - 1];          

              double lonStart = lonvalue[0];
              double lonEnd = lonvalue[lonvalue.length - 1];          

              
              if(!Double.isNaN(latStart) && !Double.isNaN(latEnd) &&
!Double.isNaN(lonStart) && !Double.isNaN(lonEnd))
              {
                  if(latStart != Double.NaN && latEnd != Double.NaN
&& lonStart != Double.NaN &&lonEnd != Double.NaN)
                  {
                      if((latEnd - latStart) <= (lonEnd - lonStart))
                      {
                          double[] aspect = new double[]{1, (latEnd -
latStart) / (lonEnd - lonStart), 1};                
                          projCont.setAspect(aspect);
                      }
                      else
                      {                
                          double[] aspect = new double[]{(lonEnd -
lonStart) / (latEnd - latStart), 1, 1};
                          projCont.setAspect(aspect);
                      }
                  }
              }
              
              // init ContourWidget
              ContourWidget contourWid = null;
              if(varMap.getDisplayScalar() == Display.IsoContour)
                  contourWid = new ContourWidget(varMap);
              
              // start animation
              final AnimationControl animationControl =
(AnimationControl) display.getControl(AnimationControl.class);
              
              // Create Button control Animation
              JPanel northPanel = new JPanel();
              JPanel btnPanel = new JPanel();
              northPanel.setLayout(new BorderLayout());
              btnPanel.setLayout(new FlowLayout());
                         
              //Title
              if (url.indexOf("://") > 0)            
                  nc_File = new NetcdfFile(new URL(url));            
              else
                  nc_File = new NetcdfFile(url, true);            
              
              Variable nc_var = nc_File.get(varname);     
              JLabel titleLabel = new
JLabel((nc_var.getAttribute("long_name")).getStringValue(),
SwingConstants.CENTER);
              titleLabel.setFont(new Font("Times New Roman", Font.BOLD,
18));
              JPanel titlePanel = new JPanel();
              titlePanel.add(titleLabel);
              
              northPanel.add(titlePanel, BorderLayout.WEST);
              northPanel.add(btnPanel, BorderLayout.CENTER);
              
              debugMap(display);
              
              //Button
              JButton btnPlay = new JButton("  Play   ");            
              btnPlay.addActionListener(new ActionListener() {  
                  public void actionPerformed(ActionEvent e) {
                      try
                      {
                          animationControl.setOn(true);                 
      
                      }
                      catch(Exception ex)
                      {                    
                      }
                  }
              });
              btnPanel.add(btnPlay);           
                      
              JButton btnStop = new JButton("  Stop   ");        
              btnStop.addActionListener(new ActionListener() {  
                  public void actionPerformed(ActionEvent e) {
                      try
                      {                       
                          animationControl.setOn(false);                
       
                      }
                      catch(Exception ex)
                      {                    
                      }
                  }
              });
              btnPanel.add(btnStop);
                      
              JButton btnNext = new JButton("  Next   ");//previous
              btnNext.addActionListener(new ActionListener() {  
                  public void actionPerformed(ActionEvent e) {
                      try
                      {
                          if(animationControl.getOn())
                              animationControl.setOn(false);
                          
                         
animationControl.setCurrent(animationControl.getCurrent() + 1);         
              
                      }
                      catch(Exception ex)
                      {                    
                      }
                  }
              });
              btnPanel.add(btnNext);
              
              JButton btnPrevious = new JButton("Previous");
              btnPrevious.addActionListener(new ActionListener() {  
                  public void actionPerformed(ActionEvent e) {
                      try
                      {
                          if(animationControl.getOn())
                              animationControl.setOn(false);
                          
                         
animationControl.setCurrent(animationControl.getCurrent() - 1);         
              
                      }
                      catch(Exception ex)
                      {                    
                      }
                  }
              });
              btnPanel.add(btnPrevious);
              
              setLayout(new BorderLayout());            
              add(display.getComponent(), BorderLayout.CENTER);         
  
              add(northPanel, BorderLayout.NORTH);            
              if(varMap.getDisplayScalar() == Display.IsoContour)
                 add(contourWid, BorderLayout.SOUTH);
          }
          catch(Exception ex)
          {
              System.out.println(ex);
          }
      }
      
      public void enableClipping(DisplayImpl display,
GraphicsModeControl dispGMC, boolean clip) 
      {     
          DisplayRendererJ3D dr = (DisplayRendererJ3D)
display.getDisplayRenderer();
          
          try 
          {
              dr.setClip(0, clip,  1.0f,  0.0f,  0.0f, -1.001f);
              dr.setClip(1, clip, -1.0f,  0.0f,  0.0f, -1.001f);
              dr.setClip(2, clip,  0.0f,  1.0f,  0.0f, -1.001f);
              dr.setClip(3, clip,  0.0f, -1.0f,  0.0f, -1.001f);        
      
          }
          catch (Exception e) 
          {
              System.err.println("Couldn't set clipping " + e);    
          }        
      }
              
      public void stop()
      {        
          Vector mapList = display.getMapVector();
          
          try
          {
              display.removeAllReferences();               

              for(int idx = 0 ; idx < mapList.size() ; idx++)
              {    
                  ScalarMap tempMap = (ScalarMap)mapList.get(idx);    
       
                  display.removeMap(tempMap); 
              }
          }
          catch(Exception ex)
          {            
          }
      }
  }

  [/code]


More information about the visad mailing list