NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

visad.TypeException


Hi,

I am trying to write an application using visad which reads a datafile
and displays it in a JInternalFrame. The first time display works fine
but when I clear the internal frame and try to display a second time 
I get the following exception:

visad.TypeException: ScalarType: name already used

Any help would be appreciated. The source files are attached.

Thanks,

Nash'at


import visad.*;

import visad.util.*;

import visad.java2d.DisplayImplJ2D;

import java.rmi.RemoteException;



import javax.swing.*;

import javax.swing.event.*;

import javax.accessibility.*;

import javax.swing.border.*;



import java.awt.*;

import java.awt.event.*;

import java.net.*;

import java.beans.*;



   public class OmegaWindowManager extends JPanel implements 

                                                      ActionListener {

// ...................................................................

// . <CLASS>                                                         .

// ...................................................................

// ===================================================================

    OmegaClient omega;

    private TerrainView terrView;

    private int icase = 0; 



// define variables

    JButton closButton, terrButton;

    JLayeredPane lc;

    JInternalFrame setCase;



// *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*



   public OmegaWindowManager(OmegaClient omega) throws VisADException, 

                                                     RemoteException {

// ...................................................................

// . <CONSTRUCTOR>                                                   .

// ...................................................................

// ===================================================================

   super();

   this.omega = omega;

   setLayout(new BorderLayout());

   lc = new JDesktopPane();

   lc.setOpaque(false);

   setCase = CaseSetupFrame();

   lc.add(setCase, JLayeredPane.PALETTE_LAYER); 

   add("Center", lc);



   }

// *******************************************************************



   public JInternalFrame CaseSetupFrame() {

// ...................................................................

// . <METHOD>                                                        .

// ...................................................................

// ===================================================================

    JInternalFrame w;

    JPanel tp, bp;

    Container contentPane;



    w = new JInternalFrame("Case Setup");

    contentPane = w.getContentPane();

    contentPane.setLayout(new BorderLayout());



// button panel

    bp = new JPanel();

    bp.setLayout(new GridLayout(2, 1));



    terrButton = new JButton("Terrain");

    terrButton.addActionListener(this);

    bp.add(terrButton);    



    closButton = new JButton("Clear");

    closButton.addActionListener(this);

    bp.add(closButton);



    contentPane.add(bp, BorderLayout.CENTER);



    w.setLocation(10,10);

    w.setSize(160,80);

    w.setResizable(true);

    w.setIconifiable(true);

    return w;

   }

// *******************************************************************

    

   public void actionPerformed(ActionEvent e) {

// ...................................................................

// . <METHOD>                                                        .

// ...................................................................

// ===================================================================



// clear the desktop

    if ( e.getSource() == closButton ) {

         lc.removeAll();

         lc.add(setCase);

         lc.repaint();

         icase = 0;

    } 



// read the terrain data

    else if ( e.getSource() == terrButton && icase == 0 ) {



    try {

      terrView = new TerrainView();

      lc.add(terrView, JLayeredPane.PALETTE_LAYER); 

    }

    catch (VisADException  vise) {System.out.println(vise);}

    catch (RemoteException rexp) {System.out.println(rexp);}



     icase = 1;



    } // end elseif terrButton



   }                           // end action method

// *******************************************************************



   }  // end class OmegaWindowManager

// *******************************************************************



import visad.*;

import visad.util.*;

import visad.java2d.DisplayImplJ2D;

import java.rmi.RemoteException;



import javax.swing.*;

import javax.swing.event.*;

import javax.accessibility.*;



import java.awt.*;

import java.awt.event.*;

import java.net.*;

import java.beans.*;



   class TerrainView extends JInternalFrame {

// ...................................................................

// . <CLASS>                                                         .

// ...................................................................

// ===================================================================

    String fname;



// define variables

    int ntx, nty;



    private RealType longitude, latitude;

    private RealType altitude;

    private RealTupleType domain_tuple;

    private FunctionType func_domain_temp;

    private Set domain_set;

    private FlatField vals_ff;

    private float[][] flat_altitude;

    private float altmin, altmax;

    private float latmin, latmax, lonmin, lonmax;



// The DataReference from data to display

    private DataReferenceImpl data_ref;



// The 2D display, and its the maps

    private DisplayImpl display;

    private ScalarMap latMap, lonMap;

    private ScalarMap altRGBMap;



// A GraphicsModeControlWidget

    private GMCWidget gmcWidget;

    private LabeledColorWidget labelCW;



// *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*



   public TerrainView() throws VisADException, RemoteException {

// ...................................................................

// . <CONSTRUCTOR>                                                   .

// ...................................................................

// ===================================================================



// Create the quantities => RealType(String name)

    latitude     = new RealType("latitude");

    longitude    = new RealType("longitude");

    domain_tuple = new RealTupleType(latitude, longitude);

    altitude     = new RealType("altitude", SI.meter, null);



    ntx = 6; nty = 6;



    float[][] flat_altitude = new float[1][ntx*nty];

    flat_altitude = openTerFile();



    lonmin = latmin = 0.0f; lonmax = latmax = 1.0f;



// Create a FunctionType (domain_tuple -> altitude )

// Use FunctionType(MathType domain, MathType range)

    func_domain_temp    = new FunctionType( domain_tuple, altitude);



// Create the domain Set

    domain_set = new Linear2DSet(domain_tuple, latmin, latmax, ntx,

                                               lonmin, lonmax, nty);



// Get the Set samples to facilitate the calculations

    float[][] set_samples = domain_set.getSamples( true );



// Create the FlatFields => FlatField(FunctionType type, Set domain_set)

    vals_ff     = new FlatField( func_domain_temp, domain_set); // image

    vals_ff.setSamples( flat_altitude , false );



// Create Display and its maps (a 2D display)

    display = new DisplayImplJ2D("display1");



// Get display's graphics mode control and draw scales

    GraphicsModeControl dispGMC = 
(GraphicsModeControl)display.getGraphicsModeControl();

    dispGMC.setScaleEnable(true);



// Create a GMCWidget with the GraphicsModeControl above

    gmcWidget = new GMCWidget( dispGMC );



// Create the ScalarMaps: latitude to YAxis, longitude to XAxis and alt. to RGB

// Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)

    latMap     = new ScalarMap( latitude,  Display.YAxis );

    lonMap     = new ScalarMap( longitude, Display.XAxis );

    altRGBMap  = new ScalarMap( altitude,  Display.RGB );



// Add maps to display

    display.addMap( latMap );

    display.addMap( lonMap );

    display.addMap( altRGBMap );

    labelCW = new LabeledColorWidget( altRGBMap );



// Create data references and set the FlatField as our data

    data_ref     = new DataReferenceImpl("data_ref");

    data_ref.setData( vals_ff );



// Add references to display: first the colored image's reference

    display.addReference( data_ref );



// internal frame

    this.setSize(400,400);

    this.setResizable(true);

    this.setIconifiable(true);

    this.setClosable(true);

    this.setMaximizable(true);

    String title = "Terrain";

    this.setTitle(title);

    this.getContentPane().add(display.getComponent());

    try { this.setSelected(true); } 

    catch (java.beans.PropertyVetoException e2) {}



   }     

// *******************************************************************



   float[][] openTerFile() {

// ...................................................................

// . <METHOD>                                                        .

// ...................................................................

// ===================================================================

// for now define a 2D field

    float[][] faltitude = new float[1][ntx*nty];

    altmin = 10000000000.0f; altmax = -10000000000.0f;

    for(int c = 0; c < ntx; c++) {

      for(int r = 0; r < nty; r++) {

        faltitude[0][ c * nty + r ] = (float)c * (float)r;

      }

    }



    return faltitude;

   

   }

// *******************************************************************



   }  // end class TerrainView

// *******************************************************************



import visad.*;

import visad.util.*;

import visad.java2d.DisplayImplJ2D;

import java.rmi.RemoteException;



import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;



   public class OmegaClient extends JFrame implements ActionListener {

// ...................................................................

// . <CLASS>                                                         .

// ...................................................................

// ===================================================================



   OmegaClient omega;

   private OmegaWindowManager wp;

   private JTabbedPane dPane;

   Container contentPane = null;



// Menu bar

   private JMenuBar menuBar = new JMenuBar();      // Window menu bar



// File menu items

   private JMenuItem exitItem, printItem;



// JFrame

   JFrame theFrame;



// Panels within the frame and the stuff that goes on them

   JPanel centerPanel;



// ===================================================================



// Constructor

   public OmegaClient(String title) {

    super(title);

    Toolkit theKit = getToolkit();                       // Get the window 
toolkit

    Dimension wndSize = theKit.getScreenSize();          // Get screen size

    setBounds(wndSize.width/4, wndSize.height/4,         // Position

                                              800, 600); // Size



// content pane

    contentPane = this.getContentPane();



// menubar

    setJMenuBar(menuBar);       // Add the menu bar to the window



    JMenu fileMenu  = new JMenu("File");      // Create File menu

    fileMenu.setMnemonic('F');                // Create shortcut



    exitItem = new JMenuItem("Exit");

    exitItem.setToolTipText("exit OmegaClient");

    exitItem.setAccelerator(KeyStroke.getKeyStroke('Q',Event.CTRL_MASK ));

    exitItem.addActionListener(new ActionListener() {

         public void actionPerformed(ActionEvent e)

         { 

          dispose();              // Release the window resources

          System.exit(0);         // End the application

         } } );

    fileMenu.add(exitItem);



    menuBar.add(fileMenu);     // Add the file menu



// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



    JPanel dbPanel = new JPanel( new BorderLayout() );

    dPane = new JTabbedPane(JTabbedPane.TOP);



    JPanel advPanel = new JPanel( new BorderLayout() );

    try { wp = new OmegaWindowManager(omega); }

    catch (VisADException  vise) {System.out.println(vise);}

    catch (RemoteException rexp) {System.out.println(rexp);}

    if ( wp !=null ) {

    advPanel.add(wp, BorderLayout.CENTER);

    dPane.addTab("Display", advPanel); }



// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+



    contentPane.setLayout(new BorderLayout());

    contentPane.add(dPane, BorderLayout.CENTER);



    addWindowListener(new WindowHandler());

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    setVisible(true);



    theFrame = this;



// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

   }

// *******************************************************************



   public void actionPerformed(ActionEvent e) {

// ...................................................................

// . <METHOD>                                                        .

// ...................................................................

// ===================================================================

   }

// *******************************************************************



    private class WindowHandler extends WindowAdapter

// ...................................................................

// . <CLASS>                                                         .

// . adapter "convenience" class to handle non-trapped window events .

// ...................................................................

// ===================================================================

   {

// Handler for window closing event

      public void windowClosing(WindowEvent e)

      {

        dispose();                   // Release the window resources

        System.exit(0);              // End the application

      }

   }

// *******************************************************************



   public static void main(String[] args) throws VisADException,

                                                 RemoteException

// ...................................................................

// . <METHOD>                                                        .

// ...................................................................

// ===================================================================

   { new OmegaClient("OMEGA - v0.1"); }

// *******************************************************************



}

// *******************************************************************

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