[idvdevelopers] color scales class usage??

I am using the idv jar for new application development. I have some contour filled bathy data set up, using the Contour2DDisplayable class.

I want to add a legend, so that the user can tell the depth from the color table I installed. In trying to use the ColorScale class, I never see a scale/legend appear in my jframe. I have no idea what to try next. Attached is the code (it will not compile but should give a hint as to my intentions)

Any help appreciated

Stuart Maclean

package gliderconsortium.glmpc.console.tools.basemaps.idv;

import java.awt.Container;
import java.io.FileInputStream;
import javax.swing.JFrame;

import gliderconsortium.glmpc.console.server.visad.data.dbdbv.YXZAdapter;
import gliderconsortium.glmpc.console.server.visad.data.geodas.XYZAdapter;
import ucar.unidata.geoloc.ProjectionRect;
import ucar.unidata.geoloc.projection.Mercator;
import ucar.unidata.ui.colortable.ColorTableDefaults;
import ucar.unidata.util.ColorTable;
import ucar.unidata.view.geoloc.MapProjectionDisplay;
import ucar.unidata.view.geoloc.MapProjectionDisplayJ2D;
import ucar.unidata.view.geoloc.MapProjectionDisplayJ3D;
import ucar.visad.display.ColorScale;
import ucar.visad.display.Contour2DDisplayable;
import ucar.visad.display.ContourLevels;
import ucar.visad.display.RegularContourLevels;
import visad.FlatField;

public class First {

        // standalone test mode...
        static public void main( String[] args ) throws Exception {

                

                FlatField ff = null;

                if( true && false) {
                        String s = 
"../webapp/config/dev/basemaps/bathy/kauai_26_18_-160_-154.xyz";
                        float missingValue = 999999.0f;
                        FileInputStream fis = new FileInputStream(s);
                        XYZAdapter xyz = new XYZAdapter( fis, missingValue );
                        ff = xyz.getData();
                } else {
                        String s = 
"../webapp/config/local/basemaps/bathy/18N_26N_161W_154W.yxz";
                        float missingValue = -10f;
                        FileInputStream fis = new FileInputStream(s);
                        YXZAdapter yxz = new YXZAdapter( fis, missingValue );
                        ff = yxz.getData();
                }
                        
                        
                Contour2DDisplayable cdd = new Contour2DDisplayable( "bathy" );
                cdd.loadData( ff );
                ContourLevels cl = new RegularContourLevels( 500, 0, 0, 6000 );
                cdd.setContourLevels( cl );

                float[] red = { 1, 0, 0 };
                float[] green = { 0, 1, 0 };
                float[] blue = { 0, 0, 1 };

                float[][] colorTable = ColorTableDefaults.topographyCT( );

                float[][] cyans = {
                        { 0xcc, 0x99, 0x66, 0x33, 0 },
                        { 0xff, 0xcc, 0x99, 0x66, 0x33 },
                        { 0xff, 0xcc, 0x99, 0x66, 0x33 } };
                int len = cyans[0].length;
                for (int n = 0; n < 3; n++) {
            for (int m = 0; m < len; m++) {
                cyans[n][m] = cyans[n][m] / 256.0f;
            }
        }

                
                cdd.setColorFill( true );
                //              cdd.setColorPalette( colorTable );//new 
float[][] { red, green, blue } );
                cdd.setColorPalette( cyans );//new float[][] { red, green, blue 
} );
                
                Mercator m = new Mercator( 40, -105, 0 );
                double ox = -6220;
                double oy = -2800;
                ProjectionRect pr = new ProjectionRect( ox, oy, ox + 512, oy + 
512 );
                m.setDefaultMapArea( pr );

                MapProjectionDisplay mpd = null;

                if( true ) {
                        int mode = MapProjectionDisplay.MODE_2Din3D;
                        mpd = new MapProjectionDisplayJ3D(m,mode );
                } else {
                        mpd = new MapProjectionDisplayJ2D( m );
                }
                mpd.setBoxVisible( true );
                
                mpd.addDisplayable( cdd );

                float cx = ColorScale.getX( ColorScale.HORIZONTAL_ORIENT,
                                                                        
ColorScale.TOP );
                float cy = ColorScale.getY( ColorScale.HORIZONTAL_ORIENT,
                                                                        
ColorScale.TOP );

                System.out.println( cx + " " + cy );
                ColorScale cs = new ColorScale( "", 
ColorScale.HORIZONTAL_ORIENT,
                                                                                
cx, cy, cyans );
                mpd.addDisplayable( cs );
                cs.setRangeForColor( 0, 5000 );
                
                cs.setVisible( true );

                JFrame jf = new JFrame("");
                Container cp = jf.getContentPane();
                cp.add( mpd.getComponent() );
                jf.pack();
                jf.setVisible( true );
                mpd.draw();
        }
}

// eof

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