Changeset 191


Ignore:
Timestamp:
09/12/11 18:11:46 (13 years ago)
Author:
vmipsl
Message:

Servlet _ Contour en cours

Location:
ether_megapoli/trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • ether_megapoli/trunk/applets/src/gov/noaa/pmel/sgt/GridCartesianRenderer.java

    r174 r191  
    1111 */ 
    1212 
    13 package  gov.noaa.pmel.sgt; 
    14  
    15 import gov.noaa.pmel.sgt.dm.SGTGrid; 
    16 import gov.noaa.pmel.sgt.dm.SGTData; 
     13package gov.noaa.pmel.sgt; 
     14 
    1715import gov.noaa.pmel.sgt.contour.Contour; 
    1816import gov.noaa.pmel.sgt.contour.ContourLine; 
    19  
     17import gov.noaa.pmel.sgt.dm.SGTData; 
     18import gov.noaa.pmel.sgt.dm.SGTGrid; 
     19import gov.noaa.pmel.sgt.dm.SimpleGrid; 
     20import gov.noaa.pmel.util.Debug; 
    2021import gov.noaa.pmel.util.GeoDate; 
    2122import gov.noaa.pmel.util.Range2D; 
    22 import gov.noaa.pmel.util.Point2D; 
    23 import gov.noaa.pmel.util.Debug; 
    24  
    25 import java.awt.Graphics; 
    26 import java.awt.Color; 
    27 import java.awt.Rectangle; 
    28 import java.awt.Font; 
    29 import java.awt.Point; 
    30 import java.awt.FontMetrics; 
     23 
     24import java.awt.*; 
     25import java.beans.PropertyChangeEvent; 
    3126import java.util.Enumeration; 
    32 import java.beans.PropertyChangeEvent; 
    3327 
    3428/** 
     
    3933 * @since 1.0 
    4034 */ 
    41 public class GridCartesianRenderer extends CartesianRenderer { 
    42   /**@shapeType AggregationLink 
    43    * @label grid 
    44    * @undirected 
    45    * @supplierCardinality 1*/ 
    46   private SGTGrid grid_; 
    47   /**@shapeType AggregationLink 
    48    * @label attr 
    49    * @undirected 
    50    * @supplierCardinality 1*/ 
    51   private GridAttribute attr_ = null; 
    52  
    53   /** 
    54    * @link aggregationByValue 
    55    * @supplierCardinality 1 
    56    * @label con 
    57    */ 
    58   private Contour con_ = null; 
    59   // 
    60   private void drawRaster(Graphics g) { 
    61     int nT, nX, nY, nZ; 
    62     int[] xp, yp; 
    63     int i, j; 
    64     Color color; 
    65     int xSize, ySize, count; 
    66     double[] xValues, yValues, gValues; 
    67     double val; 
    68     GeoDate[] tValues; 
     35public class GridCartesianRenderer 
     36        extends CartesianRenderer 
     37{ 
     38    /** 
     39     * @shapeType AggregationLink 
     40     * @label grid 
     41     * @undirected 
     42     * @supplierCardinality 1 
     43     */ 
     44    private SGTGrid grid_; 
     45    /** 
     46     * @shapeType AggregationLink 
     47     * @label attr 
     48     * @undirected 
     49     * @supplierCardinality 1 
     50     */ 
     51    private GridAttribute attr_ = null; 
     52 
     53    /** 
     54     * @link aggregationByValue 
     55     * @supplierCardinality 1 
     56     * @label con 
     57     */ 
     58    private Contour con_ = null; 
     59 
    6960    // 
    70     if(grid_.isXTime()) { 
    71       if(grid_.getTimeArray().length <= 2) return; 
    72       if(grid_.hasXEdges()) { 
    73         tValues = grid_.getTimeEdges(); 
    74         xSize = tValues.length; 
    75         xp = new int[xSize]; 
    76         for(count=0; count < xSize; count++) { 
    77           xp[count] = cg_.getXUtoD(tValues[count]); 
    78         } 
    79       } else { 
    80         tValues = grid_.getTimeArray(); 
    81         xSize = tValues.length; 
    82         xp = new int[xSize+1]; 
    83         xp[0] = cg_.getXUtoD(tValues[0].subtract( 
    84                             (tValues[1].subtract(tValues[0])).divide(2.0))); 
    85         for(count=1; count < xSize; count++) { 
    86           xp[count] = cg_.getXUtoD( 
    87                     (tValues[count-1].add(tValues[count])).divide(2.0)); 
    88         } 
    89         xp[xSize] = cg_.getXUtoD(tValues[xSize-1].add( 
    90                     (tValues[xSize-1].subtract(tValues[xSize-2])).divide(2.0))); 
    91       } 
    92     } else { 
    93       if(grid_.getXArray().length <= 2) return; 
    94       if(grid_.hasXEdges()) { 
    95         xValues = grid_.getXEdges(); 
    96         xSize = xValues.length; 
    97         xp = new int[xSize]; 
    98         for(count=0; count < xSize; count++) { 
    99           xp[count] = cg_.getXUtoD(xValues[count]); 
    100         } 
    101       } else { 
    102         xValues = grid_.getXArray(); 
    103         xSize = xValues.length; 
    104         xp = new int[xSize+1]; 
    105         xp[0] = cg_.getXUtoD(xValues[0]-(xValues[1]-xValues[0])*0.5); 
    106         for(count=1; count < xSize; count++) { 
    107           xp[count] = cg_.getXUtoD((xValues[count-1]+xValues[count])*0.5); 
    108         } 
    109         xp[xSize] = cg_.getXUtoD(xValues[xSize-1]+ 
    110                                  (xValues[xSize-1]-xValues[xSize-2])*0.5); 
    111       } 
    112     } 
    113     if(grid_.isYTime()) { 
    114       if(grid_.getTimeArray().length <= 2) return; 
    115       if(grid_.hasYEdges()) { 
    116         tValues = grid_.getTimeEdges(); 
    117         ySize = tValues.length; 
    118         yp = new int[ySize]; 
    119         for(count=0; count < ySize; count++) { 
    120           yp[count] = cg_.getYUtoD(tValues[count]); 
    121         } 
    122       } else { 
    123         tValues = grid_.getTimeArray(); 
    124         ySize = tValues.length; 
    125         yp = new int[ySize+1]; 
    126         yp[0] = cg_.getYUtoD(tValues[0].subtract( 
    127                           (tValues[1].subtract(tValues[0])).divide(2.0))); 
    128         for(count=1; count < ySize; count++) { 
    129           yp[count] = cg_.getYUtoD((tValues[count-1].add( 
    130                                tValues[count])).divide(2.0)); 
    131         } 
    132         yp[ySize] = cg_.getYUtoD(tValues[ySize-1].add( 
    133                      (tValues[ySize-1].subtract(tValues[ySize-2])).divide(2.0))); 
    134       } 
    135     } else { 
    136       if(grid_.getYArray().length <= 2) return; 
    137       if(grid_.hasYEdges()) { 
    138         yValues = grid_.getYEdges(); 
    139         ySize = yValues.length; 
    140         yp = new int[ySize]; 
    141         for(count=0; count < ySize; count++) { 
    142           yp[count] = cg_.getYUtoD(yValues[count]); 
    143         } 
    144       } else { 
    145         yValues = grid_.getYArray(); 
    146         ySize = yValues.length; 
    147         yp = new int[ySize+1]; 
    148         yp[0] = cg_.getYUtoD(yValues[0]-(yValues[1]-yValues[0])*0.5); 
    149         for(count=1; count < ySize; count++) { 
    150           yp[count] = cg_.getYUtoD((yValues[count-1]+yValues[count])*0.5); 
    151         } 
    152         yp[ySize] = cg_.getYUtoD(yValues[ySize-1]+ 
    153                                  (yValues[ySize-1]-yValues[ySize-2])*0.5); 
    154       } 
    155     } 
    156     // 
    157     // draw raster 
    158     // 
    159     gValues = grid_.getZArray(); 
    160     count=0; 
    161     for(i=0; i < xSize; i++) { 
    162       for(j=0; j < ySize; j++) { 
    163         val = gValues[count]; 
    164         if(!Double.isNaN(val)) { 
    165           color = attr_.getColorMap().getColor(val); 
    166           g.setColor(color); 
    167           drawRect(g, xp[i], yp[j], xp[i+1], yp[j+1]); 
    168         } 
    169         count++; 
    170       } 
    171     } 
    172   } 
    173   /** 
    174    * Get the <code>Attribute</code> associated with 
    175    * the <code>SGTGrid</code> data. 
    176    * 
    177    * @return <code>Attribute</code> 
    178    */ 
    179   public Attribute getAttribute() { 
    180     return attr_; 
    181   } 
    182   /** 
    183    * Set the <code>GridAttribute</code> for the renderer. 
    184    * @since 2.0 
    185    */ 
    186   public void setAttribute(GridAttribute attr) { 
    187     if(attr_ != null) attr_.removePropertyChangeListener(this); 
    188     attr_ = attr; 
    189     attr_.addPropertyChangeListener(this); 
    190   } 
    191   private void drawRect(Graphics g,int x1,int y1,int x2,int y2) { 
    192     int x, y, width, height; 
    193     if(x1 < x2) { 
    194       x = x1; 
    195       width = x2 - x1; 
    196     } else { 
    197       x=x2; 
    198       width = x1 - x2; 
    199     } 
    200     if(y1 < y2) { 
    201       y = y1; 
    202       height = y2 - y1; 
    203     } else { 
    204       y = y2; 
    205       height = y1 - y2; 
    206     } 
    207     g.fillRect(x, y, width, height); 
    208   } 
    209   /** 
    210    * Default constructor. The <code>GridCartesianRenderer</code> should 
    211    * be created using the <code>CartesianRenderer.getRenderer</code> 
    212    * method. 
    213    * 
    214    * @see CartesianRenderer#getRenderer 
    215    * @see Graph 
    216    **/ 
    217   public GridCartesianRenderer(CartesianGraph cg) { 
    218     this(cg, null, null); 
    219   } 
    220   /** 
    221    * Construct a <code>GridCartesianRenderer</code>. 
    222    * The <code>GridCartesianRenderer</code> should 
    223    * be created using the <code>CartesianRenderer.getRenderer</code> 
    224    * method. 
    225    * 
    226    * @see CartesianRenderer#getRenderer 
    227    * @see Graph 
    228    **/ 
    229   public GridCartesianRenderer(CartesianGraph cg, SGTGrid data) { 
    230     this(cg, data, null); 
    231   } 
    232   /** 
    233    * Construct a <code>GridCartesianRenderer</code>. 
    234    * The <code>GridCartesianRenderer</code> should 
    235    * be created using the <code>CartesianRenderer.getRenderer</code> 
    236    * method. 
    237    * 
    238    * @see CartesianRenderer#getRenderer 
    239    * @see Graph 
    240    **/ 
    241   public GridCartesianRenderer(CartesianGraph cg, SGTGrid grid, GridAttribute attr) { 
    242     cg_ = cg; 
    243     grid_ = grid; 
    244     attr_ = attr; 
    245     if(attr_ != null) attr_.addPropertyChangeListener(this); 
    246   } 
    247   /** 
    248    * Render the <code>SGTData</code>. This method should not 
    249    * be directly called. 
    250    * 
    251    * @param g graphics context 
    252    * 
    253    * @see Pane#draw 
    254    */ 
    255   public void draw(Graphics g) { 
    256     if(cg_.clipping_) { 
    257       int xmin, xmax, ymin, ymax; 
    258       int x, y, width, height; 
    259       if(cg_.xTransform_.isSpace()) { 
    260         xmin = cg_.getXUtoD(cg_.xClipRange_.start); 
    261         xmax = cg_.getXUtoD(cg_.xClipRange_.end); 
    262       } else { 
    263         xmin = cg_.getXUtoD(cg_.tClipRange_.start); 
    264         xmax = cg_.getXUtoD(cg_.tClipRange_.end); 
    265       } 
    266       if(cg_.yTransform_.isSpace()) { 
    267         ymin = cg_.getYUtoD(cg_.yClipRange_.start); 
    268         ymax = cg_.getYUtoD(cg_.yClipRange_.end); 
    269       } else { 
    270         ymin = cg_.getYUtoD(cg_.tClipRange_.start); 
    271         ymax = cg_.getYUtoD(cg_.tClipRange_.end); 
    272       } 
    273       if(xmin < xmax) { 
    274         x = xmin; 
    275         width = xmax - xmin; 
    276       } else { 
    277         x=xmax; 
    278         width = xmin - xmax; 
    279       } 
    280       if(ymin < ymax) { 
    281         y = ymin; 
    282         height = ymax - ymin; 
    283       } else { 
    284         y = ymax; 
    285         height = ymin - ymax; 
    286       } 
    287       g.setClip(x, y, width, height); 
    288     } 
    289     if(attr_.isRaster()) { 
    290       drawRaster(g); 
    291     } 
    292     if(attr_.isAreaFill()) { 
    293       // 
    294       // This is a temporary method based on the 
    295       // PPLUS area fill algorthim 
    296       // 
    297       // To be replaced by a area fill method that 
    298       // uses the ContourLines 
    299       // 
    300       double[] x = xArrayP(); 
    301       double[] y = yArrayP(); 
    302       double[] z = grid_.getZArray(); 
    303       int i,j; 
    304       int nx = x.length; 
    305       int ny = y.length; 
    306       double[] xt = new double[5]; 
    307       double[] yt = new double[5]; 
    308       double[] zt = new double[5]; 
    309       for(i=0; i < nx-1; i++) { 
    310         for(j=0; j < ny-1; j++) { 
    311           xt[0] = x[i]; 
    312           yt[0] = y[j]; 
    313           zt[0] = z[j + i*ny]; 
    314           // 
    315           xt[1] = x[i+1]; 
    316           yt[1] = y[j]; 
    317           zt[1] = z[j + (i+1)*ny]; 
    318           // 
    319           xt[2] = x[i+1]; 
    320           yt[2] = y[j+1]; 
    321           zt[2] = z[j+1 + (i+1)*ny]; 
    322           // 
    323           xt[3] = xt[0]; 
    324           yt[3] = yt[2]; 
    325           zt[3] = z[j+1 + i*ny]; 
    326           // 
    327           // repeat first point 
    328           // 
    329           xt[4] = xt[0]; 
    330           yt[4] = yt[0]; 
    331           zt[4] = zt[0]; 
    332           // 
    333           fillSquare(g, xt, yt, zt); 
    334         } 
    335       } 
    336     } 
    337     if(attr_.isContour()) { 
    338       double val; 
    339       String label; 
    340       Range2D range = computeRange(10); 
    341       Format format; 
    342       //        con_ = new Contour(cg_, grid_, range); 
    343       con_ = new Contour(cg_, grid_, attr_.getContourLevels()); 
    344       ContourLevels clevels = con_.getContourLevels(); 
    345       DefaultContourLineAttribute attr; 
    346       // 
    347       // set labels 
    348       // 
    349       for(int i=0; i < clevels.size(); i++) { 
    350         try { 
    351           val = clevels.getLevel(i); 
    352           attr = clevels.getDefaultContourLineAttribute(i); 
    353           if(attr.isAutoLabel()) { 
    354             if(attr.getLabelFormat().length() <= 0) { 
    355               format  = new Format(Format.computeFormat(range.start, 
    356                                                         range.end, 
    357                                                         attr.getSignificantDigits())); 
    358             } else { 
    359               format = new Format(attr.getLabelFormat()); 
    360             } 
    361             label = format.form(val); 
    362             attr.setLabelText(label); 
    363           } 
    364         } catch (ContourLevelNotFoundException e) { 
    365           System.out.println(e); 
    366         } 
    367       } 
    368       con_.generateContourLines(); 
    369       con_.generateContourLabels(g); 
    370       Enumeration elem = con_.elements(); 
    371       ContourLine cl; 
    372       while(elem.hasMoreElements()) { 
    373         cl = (ContourLine)elem.nextElement(); 
    374         if(Debug.CONTOUR) { 
    375           System.out.println(" level = " + cl.getLevel() + 
    376                              ", length = " + cl.getKmax() + 
    377                              ", closed = " + cl.isClosed()); 
    378         } 
    379         cl.draw(g); 
    380       } 
    381     } 
    382     // 
    383     // reset clip 
    384     // 
    385     Rectangle rect = cg_.getLayer().getPane().getBounds(); 
    386     g.setClip(rect); 
    387   } 
    388  
    389   private void fillSquare(Graphics g, double[] x, 
    390                           double[] y, double[] z) { 
    391     ContourLevels clevels = attr_.getContourLevels(); 
    392     IndexedColor cmap = (IndexedColor)attr_.getColorMap(); 
    393     int i,j,cindex, npoly, maxindex; 
    394     double zlev, zlevp1, f; 
    395     Color col; 
    396     double[] xpoly = new double[20]; 
    397     double[] ypoly = new double[20]; 
    398     double zmin = Math.min(z[0], z[1]); 
    399     double zmax = Math.max(z[0], z[1]); 
    400     for(i=2; i <= 3; i++) { 
    401       zmin = Math.min(zmin, z[i]); 
    402       zmax = Math.max(zmax, z[i]); 
    403     } 
    404     if(Double.isNaN(zmax)) return; 
    405     maxindex = clevels.getMaximumIndex(); 
    406     for(cindex=-1; cindex <= maxindex; cindex++) { 
    407       try { 
    408         if(cindex == -1) { 
    409           zlev = -Double.MAX_VALUE; 
    410         } else { 
    411           zlev = clevels.getLevel(cindex); 
    412         } 
    413         if(cindex == maxindex) { 
    414           zlevp1 = Double.MAX_VALUE; 
    415         } else { 
    416           zlevp1 = clevels.getLevel(cindex+1); 
    417         } 
    418       } catch (ContourLevelNotFoundException e) { 
    419         System.out.println(e); 
    420         break; 
    421       } 
    422       col = cmap.getColorByIndex(cindex+1); 
    423       if(zmin > zlevp1 || zmax < zlev) continue; 
    424       if(zmin >= zlev && zmax <= zlevp1) { 
    425         fillPolygon(g, col, x, y, 4); 
    426         return; 
    427       } 
    428       npoly = -1; 
    429       for(j=0; j < 4; j++) {  /* sides */ 
    430         if(z[j] < zlev) { 
    431           // 
    432           // z[j] is below 
    433           // 
    434           if(z[j+1] > zlevp1) { 
     61    private void drawRaster( Graphics g ) 
     62    { 
     63        int nT, nX, nY, nZ; 
     64        int[] xp, yp; 
     65        int i, j; 
     66        Color color; 
     67        int xSize, ySize, count; 
     68        double[] xValues, yValues, gValues; 
     69        double val; 
     70        GeoDate[] tValues; 
     71        // 
     72        if( grid_.isXTime() ) 
     73        { 
     74            if( grid_.getTimeArray().length <= 2 ) return; 
     75            if( grid_.hasXEdges() ) 
     76            { 
     77                tValues = grid_.getTimeEdges(); 
     78                xSize = tValues.length; 
     79                xp = new int[xSize]; 
     80                for( count = 0; count < xSize; count++ ) 
     81                { 
     82                    xp[count] = cg_.getXUtoD( tValues[count] ); 
     83                } 
     84            } 
     85            else 
     86            { 
     87                tValues = grid_.getTimeArray(); 
     88                xSize = tValues.length; 
     89                xp = new int[xSize + 1]; 
     90                xp[0] = cg_.getXUtoD( tValues[0].subtract( 
     91                        ( tValues[1].subtract( tValues[0] ) ).divide( 2.0 ) ) ); 
     92                for( count = 1; count < xSize; count++ ) 
     93                { 
     94                    xp[count] = cg_.getXUtoD( 
     95                            ( tValues[count - 1].add( tValues[count] ) ).divide( 2.0 ) ); 
     96                } 
     97                xp[xSize] = cg_.getXUtoD( tValues[xSize - 1].add( 
     98                        ( tValues[xSize - 1].subtract( tValues[xSize - 2] ) ).divide( 2.0 ) ) ); 
     99            } 
     100        } 
     101        else 
     102        { 
     103            if( grid_.getXArray().length <= 2 ) return; 
     104            if( grid_.hasXEdges() ) 
     105            { 
     106                xValues = grid_.getXEdges(); 
     107                xSize = xValues.length; 
     108                xp = new int[xSize]; 
     109                for( count = 0; count < xSize; count++ ) 
     110                { 
     111                    xp[count] = cg_.getXUtoD( xValues[count] ); 
     112                } 
     113            } 
     114            // VMIPSL 
     115            else if( grid_ instanceof SimpleGrid && !( (SimpleGrid) grid_ ).isRealFullGrid() ) 
     116            { 
     117                xValues = grid_.getXArray(); 
     118                xSize = xValues.length; 
     119                xp = new int[xSize]; 
     120                for( count = 0; count < xSize; count++ ) 
     121                    xp[count] = cg_.getXUtoD( xValues[count] ); 
     122            } 
     123            else 
     124            { 
     125                xValues = grid_.getXArray(); 
     126                xSize = xValues.length; 
     127                xp = new int[xSize + 1]; 
     128                xp[0] = cg_.getXUtoD( xValues[0] - ( xValues[1] - xValues[0] ) * 0.5 ); 
     129                for( count = 1; count < xSize; count++ ) 
     130                { 
     131                    xp[count] = cg_.getXUtoD( ( xValues[count - 1] + xValues[count] ) * 0.5 ); 
     132                } 
     133                xp[xSize] = cg_.getXUtoD( xValues[xSize - 1] + 
     134                        ( xValues[xSize - 1] - xValues[xSize - 2] ) * 0.5 ); 
     135            } 
     136        } 
     137        if( grid_.isYTime() ) 
     138        { 
     139            if( grid_.getTimeArray().length <= 2 ) return; 
     140            if( grid_.hasYEdges() ) 
     141            { 
     142                tValues = grid_.getTimeEdges(); 
     143                ySize = tValues.length; 
     144                yp = new int[ySize]; 
     145                for( count = 0; count < ySize; count++ ) 
     146                { 
     147                    yp[count] = cg_.getYUtoD( tValues[count] ); 
     148                } 
     149            } 
     150            else 
     151            { 
     152                tValues = grid_.getTimeArray(); 
     153                ySize = tValues.length; 
     154                yp = new int[ySize + 1]; 
     155                yp[0] = cg_.getYUtoD( tValues[0].subtract( 
     156                        ( tValues[1].subtract( tValues[0] ) ).divide( 2.0 ) ) ); 
     157                for( count = 1; count < ySize; count++ ) 
     158                { 
     159                    yp[count] = cg_.getYUtoD( ( tValues[count - 1].add( 
     160                            tValues[count] ) ).divide( 2.0 ) ); 
     161                } 
     162                yp[ySize] = cg_.getYUtoD( tValues[ySize - 1].add( 
     163                        ( tValues[ySize - 1].subtract( tValues[ySize - 2] ) ).divide( 2.0 ) ) ); 
     164            } 
     165        } 
     166        else 
     167        { 
     168            if( grid_.getYArray().length <= 2 ) return; 
     169            if( grid_.hasYEdges() ) 
     170            { 
     171                yValues = grid_.getYEdges(); 
     172                ySize = yValues.length; 
     173                yp = new int[ySize]; 
     174                for( count = 0; count < ySize; count++ ) 
     175                { 
     176                    yp[count] = cg_.getYUtoD( yValues[count] ); 
     177                } 
     178            } 
     179            else 
     180            { 
     181                yValues = grid_.getYArray(); 
     182                ySize = yValues.length; 
     183                yp = new int[ySize + 1]; 
     184                yp[0] = cg_.getYUtoD( yValues[0] - ( yValues[1] - yValues[0] ) * 0.5 ); 
     185                for( count = 1; count < ySize; count++ ) 
     186                { 
     187                    yp[count] = cg_.getYUtoD( ( yValues[count - 1] + yValues[count] ) * 0.5 ); 
     188                } 
     189                yp[ySize] = cg_.getYUtoD( yValues[ySize - 1] + 
     190                        ( yValues[ySize - 1] - yValues[ySize - 2] ) * 0.5 ); 
     191            } 
     192        } 
     193        // 
     194        // draw raster 
     195        // 
     196        gValues = grid_.getZArray(); 
     197        count = 0; 
     198 
     199        // VMIPSl 
     200        if( grid_ instanceof SimpleGrid && !( (SimpleGrid) grid_ ).isRealFullGrid() ) 
     201        { 
     202            for( i = 0; i < Math.max( xSize, ySize ); i++ ) 
     203            { 
     204                val = gValues[i]; 
     205                if( !Double.isNaN( val ) ) 
     206                { 
     207                    color = attr_.getColorMap().getColor( val ); 
     208                    g.setColor( color ); 
     209                    drawPoint( g, xp[i], yp[i], attr_ ); 
     210                } 
     211            } 
     212        } 
     213        else 
     214        { 
     215            for( i = 0; i < xSize; i++ ) 
     216            { 
     217                for( j = 0; j < ySize; j++ ) 
     218                { 
     219                    val = gValues[count]; 
     220                    if( !Double.isNaN( val ) ) 
     221                    { 
     222                        color = attr_.getColorMap().getColor( val ); 
     223                        g.setColor( color ); 
     224                        drawRect( g, xp[i], yp[j], xp[i + 1], yp[j + 1] ); 
     225                    } 
     226                    count++; 
     227                } 
     228            } 
     229        } 
     230    } 
     231 
     232    /** 
     233     * Get the <code>Attribute</code> associated with 
     234     * the <code>SGTGrid</code> data. 
     235     * 
     236     * @return <code>Attribute</code> 
     237     */ 
     238    public Attribute getAttribute() 
     239    { 
     240        return attr_; 
     241    } 
     242 
     243    /** 
     244     * Set the <code>GridAttribute</code> for the renderer. 
     245     * 
     246     * @since 2.0 
     247     */ 
     248    public void setAttribute( GridAttribute attr ) 
     249    { 
     250        if( attr_ != null ) attr_.removePropertyChangeListener( this ); 
     251        attr_ = attr; 
     252        attr_.addPropertyChangeListener( this ); 
     253    } 
     254 
     255    private void drawRect( Graphics g, int x1, int y1, int x2, int y2 ) 
     256    { 
     257        int x, y, width, height; 
     258        if( x1 < x2 ) 
     259        { 
     260            x = x1; 
     261            width = x2 - x1; 
     262        } 
     263        else 
     264        { 
     265            x = x2; 
     266            width = x1 - x2; 
     267        } 
     268        if( y1 < y2 ) 
     269        { 
     270            y = y1; 
     271            height = y2 - y1; 
     272        } 
     273        else 
     274        { 
     275            y = y2; 
     276            height = y1 - y2; 
     277        } 
     278        g.fillRect( x, y, width, height ); 
     279    } 
     280 
     281    // VMIPSL 
     282    protected void drawPoint( final Graphics g, final int x, final int y, final GridAttribute attr ) 
     283    { 
     284        Layer ly = cg_.getLayer(); 
     285        final PointAttribute pointAttribute = new PointAttribute(); 
     286        PlotMark pm = new PlotMark( pointAttribute ); 
     287        pm.setMarkHeightP( 0.2 ); 
     288 
     289        pm.paintMark( g, ly, x, y ); 
     290    } 
     291 
     292    /** 
     293     * Default constructor. The <code>GridCartesianRenderer</code> should 
     294     * be created using the <code>CartesianRenderer.getRenderer</code> 
     295     * method. 
     296     * 
     297     * @see CartesianRenderer#getRenderer 
     298     * @see Graph 
     299     */ 
     300    public GridCartesianRenderer( CartesianGraph cg ) 
     301    { 
     302        this( cg, null, null ); 
     303    } 
     304 
     305    /** 
     306     * Construct a <code>GridCartesianRenderer</code>. 
     307     * The <code>GridCartesianRenderer</code> should 
     308     * be created using the <code>CartesianRenderer.getRenderer</code> 
     309     * method. 
     310     * 
     311     * @see CartesianRenderer#getRenderer 
     312     * @see Graph 
     313     */ 
     314    public GridCartesianRenderer( CartesianGraph cg, SGTGrid data ) 
     315    { 
     316        this( cg, data, null ); 
     317    } 
     318 
     319    /** 
     320     * Construct a <code>GridCartesianRenderer</code>. 
     321     * The <code>GridCartesianRenderer</code> should 
     322     * be created using the <code>CartesianRenderer.getRenderer</code> 
     323     * method. 
     324     * 
     325     * @see CartesianRenderer#getRenderer 
     326     * @see Graph 
     327     */ 
     328    public GridCartesianRenderer( CartesianGraph cg, SGTGrid grid, GridAttribute attr ) 
     329    { 
     330        cg_ = cg; 
     331        grid_ = grid; 
     332        attr_ = attr; 
     333        if( attr_ != null ) attr_.addPropertyChangeListener( this ); 
     334    } 
     335 
     336    /** 
     337     * Render the <code>SGTData</code>. This method should not 
     338     * be directly called. 
     339     * 
     340     * @param g graphics context 
     341     * @see Pane#draw 
     342     */ 
     343    public void draw( Graphics g ) 
     344    { 
     345        if( cg_.clipping_ ) 
     346        { 
     347            int xmin, xmax, ymin, ymax; 
     348            int x, y, width, height; 
     349            if( cg_.xTransform_.isSpace() ) 
     350            { 
     351                xmin = cg_.getXUtoD( cg_.xClipRange_.start ); 
     352                xmax = cg_.getXUtoD( cg_.xClipRange_.end ); 
     353            } 
     354            else 
     355            { 
     356                xmin = cg_.getXUtoD( cg_.tClipRange_.start ); 
     357                xmax = cg_.getXUtoD( cg_.tClipRange_.end ); 
     358            } 
     359            if( cg_.yTransform_.isSpace() ) 
     360            { 
     361                ymin = cg_.getYUtoD( cg_.yClipRange_.start ); 
     362                ymax = cg_.getYUtoD( cg_.yClipRange_.end ); 
     363            } 
     364            else 
     365            { 
     366                ymin = cg_.getYUtoD( cg_.tClipRange_.start ); 
     367                ymax = cg_.getYUtoD( cg_.tClipRange_.end ); 
     368            } 
     369            if( xmin < xmax ) 
     370            { 
     371                x = xmin; 
     372                width = xmax - xmin; 
     373            } 
     374            else 
     375            { 
     376                x = xmax; 
     377                width = xmin - xmax; 
     378            } 
     379            if( ymin < ymax ) 
     380            { 
     381                y = ymin; 
     382                height = ymax - ymin; 
     383            } 
     384            else 
     385            { 
     386                y = ymax; 
     387                height = ymin - ymax; 
     388            } 
     389            g.setClip( x, y, width, height ); 
     390        } 
     391        if( attr_.isRaster() ) 
     392        { 
     393            drawRaster( g ); 
     394        } 
     395        if( attr_.isAreaFill() ) 
     396        { 
    435397            // 
    436             // z[j+1] is above 
     398            // This is a temporary method based on the 
     399            // PPLUS area fill algorthim 
    437400            // 
    438             npoly=npoly+1; 
    439             f = (z[j]-zlev)/(z[j]-z[j+1]); 
    440             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    441             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
     401            // To be replaced by a area fill method that 
     402            // uses the ContourLines 
    442403            // 
    443             npoly=npoly+1; 
    444             f = (z[j]-zlevp1)/(z[j]-z[j+1]); 
    445             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    446             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    447           } else if(z[j+1] >= zlev && 
    448                     z[j+1] <= zlevp1) { 
     404            double[] x = xArrayP(); 
     405            double[] y = yArrayP(); 
     406            double[] z = grid_.getZArray(); 
     407            int i, j; 
     408            int nx = x.length; 
     409            int ny = y.length; 
     410            double[] xt = new double[5]; 
     411            double[] yt = new double[5]; 
     412            double[] zt = new double[5]; 
     413            for( i = 0; i < nx - 1; i++ ) 
     414            { 
     415                for( j = 0; j < ny - 1; j++ ) 
     416                { 
     417                    xt[0] = x[i]; 
     418                    yt[0] = y[j]; 
     419                    zt[0] = z[j + i * ny]; 
     420                    // 
     421                    xt[1] = x[i + 1]; 
     422                    yt[1] = y[j]; 
     423                    zt[1] = z[j + ( i + 1 ) * ny]; 
     424                    // 
     425                    xt[2] = x[i + 1]; 
     426                    yt[2] = y[j + 1]; 
     427                    zt[2] = z[j + 1 + ( i + 1 ) * ny]; 
     428                    // 
     429                    xt[3] = xt[0]; 
     430                    yt[3] = yt[2]; 
     431                    zt[3] = z[j + 1 + i * ny]; 
     432                    // 
     433                    // repeat first point 
     434                    // 
     435                    xt[4] = xt[0]; 
     436                    yt[4] = yt[0]; 
     437                    zt[4] = zt[0]; 
     438                    // 
     439                    fillSquare( g, xt, yt, zt ); 
     440                } 
     441            } 
     442        } 
     443        if( attr_.isContour() ) 
     444        { 
     445            double val; 
     446            String label; 
     447            Range2D range = computeRange( 10 ); 
     448            Format format; 
     449            //  con_ = new Contour(cg_, grid_, range); 
     450            con_ = new Contour( cg_, grid_, attr_.getContourLevels() ); 
     451            ContourLevels clevels = con_.getContourLevels(); 
     452            DefaultContourLineAttribute attr; 
    449453            // 
    450             // z[j+1] is inside 
     454            // set labels 
    451455            // 
    452             npoly=npoly+1; 
    453             f = (z[j]-zlev)/(z[j]-z[j+1]); 
    454             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    455             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    456             // 
    457             npoly=npoly+1; 
    458             xpoly[npoly] = x[j+1]; 
    459             ypoly[npoly] = y[j+1]; 
    460           } 
    461         } else if(z[j] > zlevp1) { 
    462           // 
    463           // z[j] is above 
    464           // 
    465           if(z[j+1] < zlev) { 
    466             // 
    467             // z[j+1] is below 
    468             // 
    469             npoly=npoly+1; 
    470             f = (z[j]-zlevp1)/(z[j]-z[j+1]); 
    471             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    472             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    473             // 
    474             npoly=npoly+1; 
    475             f = (z[j]-zlev)/(z[j]-z[j+1]); 
    476             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    477             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    478           } else if(z[j+1] >= zlev && z[j+1] <= zlevp1) { 
    479             // 
    480             // z[j+1] is inside 
    481             // 
    482             npoly=npoly+1; 
    483             f = (z[j]-zlevp1)/(z[j]-z[j+1]); 
    484             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    485             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    486             // 
    487             npoly=npoly+1; 
    488             xpoly[npoly] = x[j+1]; 
    489             ypoly[npoly] = y[j+1]; 
    490           } 
    491         } else { 
    492           // 
    493           // x[j] is inside 
    494           // 
    495           if(z[j+1] > zlevp1) { 
    496             // 
    497             // z[j+1] is above 
    498             // 
    499             npoly=npoly+1; 
    500             f = (z[j]-zlevp1)/(z[j]-z[j+1]); 
    501             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    502             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    503           } else if(z[j+1] < zlev) { 
    504             // 
    505             // z[j+1] is below 
    506             // 
    507             npoly=npoly+1; 
    508             f = (z[j]-zlev)/(z[j]-z[j+1]); 
    509             xpoly[npoly] = x[j] - f*(x[j]-x[j+1]); 
    510             ypoly[npoly] = y[j] - f*(y[j]-y[j+1]); 
    511           } else { 
    512             // 
    513             // z[j+1] is inside 
    514             // 
    515             npoly=npoly+1; 
    516             xpoly[npoly] = x[j+1]; 
    517             ypoly[npoly] = y[j+1]; 
    518           } 
    519         } 
    520       } 
    521       fillPolygon(g, col, xpoly, ypoly, npoly+1); 
    522     } 
    523   } 
    524  
    525   private void fillPolygon(Graphics g, Color c, 
    526                            double[] x, double[] y, 
    527                            int npoints) { 
    528     Layer layer = cg_.getLayer(); 
    529     int[] xt = new int[20]; 
    530     int[] yt = new int[20]; 
    531     g.setColor(c); 
    532     for(int i=0; i < npoints; i++) { 
    533       xt[i] = layer.getXPtoD(x[i]); 
    534       yt[i] = layer.getYPtoD(y[i]); 
    535     } 
    536     g.fillPolygon(xt, yt, npoints); 
    537   } 
    538  
    539   private double[] xArrayP() { 
    540     int i; 
    541     double[] p; 
    542     if(grid_.isXTime()) { 
    543       GeoDate[] t = grid_.getTimeArray(); 
    544       p = new double[t.length]; 
    545       for(i=0; i < t.length; i++) { 
    546         p[i] = cg_.getXUtoP(t[i]); 
    547       } 
    548     } else { 
    549       double[] x = grid_.getXArray(); 
    550       p = new double[x.length]; 
    551       for(i=0; i < x.length; i++) { 
    552         p[i] = cg_.getXUtoP(x[i]); 
    553       } 
    554     } 
    555     return p; 
    556   } 
    557  
    558   private double[] yArrayP() { 
    559     int i; 
    560     double[] p; 
    561     if(grid_.isYTime()) { 
    562       GeoDate[] t = grid_.getTimeArray(); 
    563       p = new double[t.length]; 
    564       for(i=0; i < t.length; i++) { 
    565         p[i] = cg_.getYUtoP(t[i]); 
    566       } 
    567     } else { 
    568       double[] y = grid_.getYArray(); 
    569       p = new double[y.length]; 
    570       for(i=0; i < y.length; i++) { 
    571         p[i] = cg_.getYUtoP(y[i]); 
    572       } 
    573     } 
    574     return p; 
    575   } 
    576  
    577   private Range2D computeRange(int levels) { 
    578     Range2D range; 
    579     double zmin = Double.POSITIVE_INFINITY; 
    580     double zmax = Double.NEGATIVE_INFINITY; 
    581     double[] array = grid_.getZArray(); 
    582     for(int i=0; i < array.length; i++) { 
    583       if(!Double.isNaN(array[i])) { 
    584         zmin = Math.min(zmin, array[i]); 
    585         zmax = Math.max(zmax, array[i]); 
    586       } 
    587     } 
    588     range = Graph.computeRange(zmin, zmax, levels); 
    589     return range; 
    590   } 
    591   /** 
    592    * Get the <code>SGTGrid</code>. 
    593    * 
    594    * @return <code>SGTGrid</code> 
    595    */ 
    596   public SGTGrid getGrid() { 
    597     return grid_; 
    598   } 
    599   /** 
    600    * Get the associated <code>CartesianGraph</code> object. 
    601    * @since 2.0 
    602    * @return <code>CartesianGraph</code> 
    603    */ 
    604   public CartesianGraph getCartesianGraph() { 
    605     return cg_; 
    606   } 
    607  
    608   public void propertyChange(PropertyChangeEvent evt) { 
     456            for( int i = 0; i < clevels.size(); i++ ) 
     457            { 
     458                try 
     459                { 
     460                    val = clevels.getLevel( i ); 
     461                    attr = clevels.getDefaultContourLineAttribute( i ); 
     462                    if( attr.isAutoLabel() ) 
     463                    { 
     464                        if( attr.getLabelFormat().length() <= 0 ) 
     465                        { 
     466                            format = new Format( Format.computeFormat( range.start, 
     467                                    range.end, 
     468                                    attr.getSignificantDigits() ) ); 
     469                        } 
     470                        else 
     471                        { 
     472                            format = new Format( attr.getLabelFormat() ); 
     473                        } 
     474                        label = format.form( val ); 
     475                        attr.setLabelText( label ); 
     476                    } 
     477                } 
     478                catch( ContourLevelNotFoundException e ) 
     479                { 
     480                    System.out.println( e ); 
     481                } 
     482            } 
     483            con_.generateContourLines(); 
     484            con_.generateContourLabels( g ); 
     485            Enumeration elem = con_.elements(); 
     486            ContourLine cl; 
     487            while( elem.hasMoreElements() ) 
     488            { 
     489                cl = (ContourLine) elem.nextElement(); 
     490                if( Debug.CONTOUR ) 
     491                { 
     492                    System.out.println( " level = " + cl.getLevel() + 
     493                            ", length = " + cl.getKmax() + 
     494                            ", closed = " + cl.isClosed() ); 
     495                } 
     496                cl.draw( g ); 
     497            } 
     498        } 
     499        // 
     500        // reset clip 
     501        // 
     502        Rectangle rect = cg_.getLayer().getPane().getBounds(); 
     503        g.setClip( rect ); 
     504    } 
     505 
     506    private void fillSquare( Graphics g, double[] x, 
     507                             double[] y, double[] z ) 
     508    { 
     509        ContourLevels clevels = attr_.getContourLevels(); 
     510        IndexedColor cmap = (IndexedColor) attr_.getColorMap(); 
     511        int i, j, cindex, npoly, maxindex; 
     512        double zlev, zlevp1, f; 
     513        Color col; 
     514        double[] xpoly = new double[20]; 
     515        double[] ypoly = new double[20]; 
     516        double zmin = Math.min( z[0], z[1] ); 
     517        double zmax = Math.max( z[0], z[1] ); 
     518        for( i = 2; i <= 3; i++ ) 
     519        { 
     520            zmin = Math.min( zmin, z[i] ); 
     521            zmax = Math.max( zmax, z[i] ); 
     522        } 
     523        if( Double.isNaN( zmax ) ) return; 
     524        maxindex = clevels.getMaximumIndex(); 
     525        for( cindex = -1; cindex <= maxindex; cindex++ ) 
     526        { 
     527            try 
     528            { 
     529                if( cindex == -1 ) 
     530                { 
     531                    zlev = -Double.MAX_VALUE; 
     532                } 
     533                else 
     534                { 
     535                    zlev = clevels.getLevel( cindex ); 
     536                } 
     537                if( cindex == maxindex ) 
     538                { 
     539                    zlevp1 = Double.MAX_VALUE; 
     540                } 
     541                else 
     542                { 
     543                    zlevp1 = clevels.getLevel( cindex + 1 ); 
     544                } 
     545            } 
     546            catch( ContourLevelNotFoundException e ) 
     547            { 
     548                System.out.println( e ); 
     549                break; 
     550            } 
     551            col = cmap.getColorByIndex( cindex + 1 ); 
     552            if( zmin > zlevp1 || zmax < zlev ) continue; 
     553            if( zmin >= zlev && zmax <= zlevp1 ) 
     554            { 
     555                fillPolygon( g, col, x, y, 4 ); 
     556                return; 
     557            } 
     558            npoly = -1; 
     559            for( j = 0; j < 4; j++ ) 
     560            {  /* sides */ 
     561                if( z[j] < zlev ) 
     562                { 
     563                    // 
     564                    // z[j] is below 
     565                    // 
     566                    if( z[j + 1] > zlevp1 ) 
     567                    { 
     568                        // 
     569                        // z[j+1] is above 
     570                        // 
     571                        npoly = npoly + 1; 
     572                        f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); 
     573                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     574                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     575                        // 
     576                        npoly = npoly + 1; 
     577                        f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); 
     578                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     579                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     580                    } 
     581                    else if( z[j + 1] >= zlev && 
     582                            z[j + 1] <= zlevp1 ) 
     583                    { 
     584                        // 
     585                        // z[j+1] is inside 
     586                        // 
     587                        npoly = npoly + 1; 
     588                        f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); 
     589                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     590                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     591                        // 
     592                        npoly = npoly + 1; 
     593                        xpoly[npoly] = x[j + 1]; 
     594                        ypoly[npoly] = y[j + 1]; 
     595                    } 
     596                } 
     597                else if( z[j] > zlevp1 ) 
     598                { 
     599                    // 
     600                    // z[j] is above 
     601                    // 
     602                    if( z[j + 1] < zlev ) 
     603                    { 
     604                        // 
     605                        // z[j+1] is below 
     606                        // 
     607                        npoly = npoly + 1; 
     608                        f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); 
     609                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     610                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     611                        // 
     612                        npoly = npoly + 1; 
     613                        f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); 
     614                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     615                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     616                    } 
     617                    else if( z[j + 1] >= zlev && z[j + 1] <= zlevp1 ) 
     618                    { 
     619                        // 
     620                        // z[j+1] is inside 
     621                        // 
     622                        npoly = npoly + 1; 
     623                        f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); 
     624                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     625                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     626                        // 
     627                        npoly = npoly + 1; 
     628                        xpoly[npoly] = x[j + 1]; 
     629                        ypoly[npoly] = y[j + 1]; 
     630                    } 
     631                } 
     632                else 
     633                { 
     634                    // 
     635                    // x[j] is inside 
     636                    // 
     637                    if( z[j + 1] > zlevp1 ) 
     638                    { 
     639                        // 
     640                        // z[j+1] is above 
     641                        // 
     642                        npoly = npoly + 1; 
     643                        f = ( z[j] - zlevp1 ) / ( z[j] - z[j + 1] ); 
     644                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     645                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     646                    } 
     647                    else if( z[j + 1] < zlev ) 
     648                    { 
     649                        // 
     650                        // z[j+1] is below 
     651                        // 
     652                        npoly = npoly + 1; 
     653                        f = ( z[j] - zlev ) / ( z[j] - z[j + 1] ); 
     654                        xpoly[npoly] = x[j] - f * ( x[j] - x[j + 1] ); 
     655                        ypoly[npoly] = y[j] - f * ( y[j] - y[j + 1] ); 
     656                    } 
     657                    else 
     658                    { 
     659                        // 
     660                        // z[j+1] is inside 
     661                        // 
     662                        npoly = npoly + 1; 
     663                        xpoly[npoly] = x[j + 1]; 
     664                        ypoly[npoly] = y[j + 1]; 
     665                    } 
     666                } 
     667            } 
     668            fillPolygon( g, col, xpoly, ypoly, npoly + 1 ); 
     669        } 
     670    } 
     671 
     672    private void fillPolygon( Graphics g, Color c, 
     673                              double[] x, double[] y, 
     674                              int npoints ) 
     675    { 
     676        Layer layer = cg_.getLayer(); 
     677        int[] xt = new int[20]; 
     678        int[] yt = new int[20]; 
     679        g.setColor( c ); 
     680        for( int i = 0; i < npoints; i++ ) 
     681        { 
     682            xt[i] = layer.getXPtoD( x[i] ); 
     683            yt[i] = layer.getYPtoD( y[i] ); 
     684        } 
     685        g.fillPolygon( xt, yt, npoints ); 
     686    } 
     687 
     688    private double[] xArrayP() 
     689    { 
     690        int i; 
     691        double[] p; 
     692        if( grid_.isXTime() ) 
     693        { 
     694            GeoDate[] t = grid_.getTimeArray(); 
     695            p = new double[t.length]; 
     696            for( i = 0; i < t.length; i++ ) 
     697            { 
     698                p[i] = cg_.getXUtoP( t[i] ); 
     699            } 
     700        } 
     701        else 
     702        { 
     703            double[] x = grid_.getXArray(); 
     704            p = new double[x.length]; 
     705            for( i = 0; i < x.length; i++ ) 
     706            { 
     707                p[i] = cg_.getXUtoP( x[i] ); 
     708            } 
     709        } 
     710        return p; 
     711    } 
     712 
     713    private double[] yArrayP() 
     714    { 
     715        int i; 
     716        double[] p; 
     717        if( grid_.isYTime() ) 
     718        { 
     719            GeoDate[] t = grid_.getTimeArray(); 
     720            p = new double[t.length]; 
     721            for( i = 0; i < t.length; i++ ) 
     722            { 
     723                p[i] = cg_.getYUtoP( t[i] ); 
     724            } 
     725        } 
     726        else 
     727        { 
     728            double[] y = grid_.getYArray(); 
     729            p = new double[y.length]; 
     730            for( i = 0; i < y.length; i++ ) 
     731            { 
     732                p[i] = cg_.getYUtoP( y[i] ); 
     733            } 
     734        } 
     735        return p; 
     736    } 
     737 
     738    private Range2D computeRange( int levels ) 
     739    { 
     740        Range2D range; 
     741        double zmin = Double.POSITIVE_INFINITY; 
     742        double zmax = Double.NEGATIVE_INFINITY; 
     743        double[] array = grid_.getZArray(); 
     744        for( int i = 0; i < array.length; i++ ) 
     745        { 
     746            if( !Double.isNaN( array[i] ) ) 
     747            { 
     748                zmin = Math.min( zmin, array[i] ); 
     749                zmax = Math.max( zmax, array[i] ); 
     750            } 
     751        } 
     752        range = Graph.computeRange( zmin, zmax, levels ); 
     753        return range; 
     754    } 
     755 
     756    /** 
     757     * Get the <code>SGTGrid</code>. 
     758     * 
     759     * @return <code>SGTGrid</code> 
     760     */ 
     761    public SGTGrid getGrid() 
     762    { 
     763        return grid_; 
     764    } 
     765 
     766    /** 
     767     * Get the associated <code>CartesianGraph</code> object. 
     768     * 
     769     * @return <code>CartesianGraph</code> 
     770     * @since 2.0 
     771     */ 
     772    public CartesianGraph getCartesianGraph() 
     773    { 
     774        return cg_; 
     775    } 
     776 
     777    public void propertyChange( PropertyChangeEvent evt ) 
     778    { 
    609779//      if(Debug.EVENT) { 
    610780//        System.out.println("GridCartesianRenderer: " + evt); 
    611781//        System.out.println("                       " + evt.getPropertyName()); 
    612782//      } 
    613     modified("GridCartesianRenderer: propertyChange(" + 
    614              evt.getSource().toString() + "[" + 
    615              evt.getPropertyName() + "]" + ")"); 
    616   } 
    617   /** 
    618    * @since 3.0 
    619    */ 
    620   public SGTData getDataAt(Point pt) { 
    621     return null; 
    622   } 
     783        modified( "GridCartesianRenderer: propertyChange(" + 
     784                evt.getSource().toString() + "[" + 
     785                evt.getPropertyName() + "]" + ")" ); 
     786    } 
     787 
     788    /** 
     789     * @since 3.0 
     790     */ 
     791    public SGTData getDataAt( Point pt ) 
     792    { 
     793        return null; 
     794    } 
    623795} 
  • ether_megapoli/trunk/applets/src/gov/noaa/pmel/sgt/LineAttribute.java

    r174 r191  
    155155       (style_ != attr.getStyle())) return false; 
    156156    if(style_ == MARK || style_ == MARK_LINE) { 
    157       if((mark_ != attr.getMark()) || 
    158          (markHeightP_ != attr.getMarkHeightP())) return false; 
     157      if((mark_ != attr.getMark()) || (markHeightP_ != attr.getMarkHeightP())) 
     158          return false; 
    159159    } 
    160160    if(style_ == HEAVY) { 
  • ether_megapoli/trunk/applets/src/gov/noaa/pmel/sgt/dm/SimpleGrid.java

    r174 r191  
    1919import gov.noaa.pmel.util.SoTRange; 
    2020 
     21import java.beans.PropertyChangeListener; 
    2122import java.beans.PropertyChangeSupport; 
    22 import java.beans.PropertyChangeListener; 
    2323import java.io.Serializable; 
    2424 
     
    2929 * @author Donald Denbo 
    3030 * @version $Revision: 1.19 $, $Date: 2003/08/22 23:02:38 $ 
    31  * @since 1.0 
    3231 * @see SGTGrid 
    3332 * @see Cartesian 
     33 * @since 1.0 
    3434 */ 
    35 public class SimpleGrid implements SGTGrid, Cartesian, Cloneable, Serializable { 
    36   protected double[] xloc_; 
    37   protected double[] yloc_; 
    38 //  protected GeoDate[] tloc_; 
    39   protected GeoDateArray tloc_; 
    40   protected double[] grid_; 
    41   protected double[] xEdges_; 
    42   protected double[] yEdges_; 
    43 //  protected GeoDate[] tEdges_; 
    44   protected GeoDateArray tEdges_; 
    45   protected boolean hasXEdges_; 
    46   protected boolean hasYEdges_; 
    47   protected String title_; 
    48   protected SGLabel keyTitle_ = null; 
    49   protected String id_ = null; 
    50   protected boolean xTime_; 
    51   protected boolean yTime_; 
    52     /**@shapeType AggregationLink 
    53   * @clientRole x*/ 
     35public class SimpleGrid 
     36        implements SGTGrid, Cartesian, Cloneable, Serializable 
     37{ 
     38    /** 
     39     * Default constructor. 
     40     */ 
     41    public SimpleGrid() 
     42    { 
     43        this( null, (double[]) null, (double[]) null, "" ); 
     44    } 
     45 
     46    /** 
     47     * Constructor for X and Y coordinates as double. 
     48     * 
     49     * @param grid  Z values 
     50     * @param xloc  X coordinates 
     51     * @param yloc  Y coordinates 
     52     * @param title the title 
     53     */ 
     54    public SimpleGrid( double[] grid, double[] xloc, 
     55                       double[] yloc, String title ) 
     56    { 
     57        grid_ = grid; 
     58        xloc_ = xloc; 
     59        yloc_ = yloc; 
     60        title_ = title; 
     61        xTime_ = false; 
     62        yTime_ = false; 
     63        hasXEdges_ = false; 
     64        hasYEdges_ = false; 
     65        xRange_ = computeSoTRange( xloc ); 
     66        yRange_ = computeSoTRange( yloc ); 
     67        zRange_ = computeRange2D( grid ); 
     68    } 
     69 
     70    /** 
     71     * Constructor for X time and Y double. 
     72     * 
     73     * @param grid  Z values 
     74     * @param tloc  Time coordinates 
     75     * @param yloc  Y coordinates 
     76     * @param title the title 
     77     */ 
     78    public SimpleGrid( double[] grid, GeoDate[] tloc, 
     79                       double[] yloc, String title ) 
     80    { 
     81        grid_ = grid; 
     82        tloc_ = new GeoDateArray( tloc ); 
     83        yloc_ = yloc; 
     84        title_ = title; 
     85        xTime_ = true; 
     86        yTime_ = false; 
     87        hasXEdges_ = false; 
     88        hasYEdges_ = false; 
     89        xRange_ = computeSoTRange( tloc_ ); 
     90        yRange_ = computeSoTRange( yloc ); 
     91        zRange_ = computeRange2D( grid ); 
     92    } 
     93 
     94    /** 
     95     * Constructor for X double and Y time. 
     96     * 
     97     * @param grid  Z values 
     98     * @param xloc  X coordinates 
     99     * @param tloc  Time coordinates 
     100     * @param title the title 
     101     */ 
     102    public SimpleGrid( double[] grid, double[] xloc, 
     103                       GeoDate[] tloc, String title ) 
     104    { 
     105        grid_ = grid; 
     106        xloc_ = xloc; 
     107        tloc_ = new GeoDateArray( tloc ); 
     108        title_ = title; 
     109        xTime_ = false; 
     110        yTime_ = true; 
     111        hasXEdges_ = false; 
     112        hasYEdges_ = false; 
     113        xRange_ = computeSoTRange( xloc ); 
     114        yRange_ = computeSoTRange( tloc_ ); 
     115        zRange_ = computeRange2D( grid ); 
     116    } 
     117 
     118    public String getTitle() 
     119    { 
     120        return title_; 
     121    } 
     122 
     123    public SGLabel getKeyTitle() 
     124    { 
     125        return keyTitle_; 
     126    } 
     127 
     128    /** 
     129     * Get the unique identifier.  The presence of the identifier 
     130     * is optional, but if it is present it should be unique.  This 
     131     * field is used to search for the layer that contains the data. 
     132     * 
     133     * @return unique identifier 
     134     * @see gov.noaa.pmel.sgt.Pane 
     135     * @see gov.noaa.pmel.sgt.Layer 
     136     * @since 2.0 
     137     */ 
     138    public String getId() 
     139    { 
     140        return id_; 
     141    } 
     142 
     143    /** 
     144     * Create a copy of the grid. 
     145     * 
     146     * @see SGTData 
     147     * @since 2.0 
     148     */ 
     149    public SGTData copy() 
     150    { 
     151        SGTGrid newGrid; 
     152        try 
     153        { 
     154            newGrid = (SGTGrid) clone(); 
     155        } 
     156        catch( CloneNotSupportedException e ) 
     157        { 
     158            newGrid = new SimpleGrid(); 
     159        } 
     160        return (SGTData) newGrid; 
     161    } 
     162 
     163    public boolean isXTime() 
     164    { 
     165        return xTime_; 
     166    } 
     167 
     168    public boolean isYTime() 
     169    { 
     170        return yTime_; 
     171    } 
     172 
     173    public SGTMetaData getXMetaData() 
     174    { 
     175        return xMetaData_; 
     176    } 
     177 
     178    public SGTMetaData getYMetaData() 
     179    { 
     180        return yMetaData_; 
     181    } 
     182 
     183    public SoTRange getXRange() 
     184    { 
     185        return xRange_.copy(); 
     186    } 
     187 
     188    public SoTRange getYRange() 
     189    { 
     190        return yRange_.copy(); 
     191    } 
     192 
     193    public void addPropertyChangeListener( PropertyChangeListener l ) 
     194    { 
     195        changes_.addPropertyChangeListener( l ); 
     196    } 
     197 
     198    public void removePropertyChangeListener( PropertyChangeListener l ) 
     199    { 
     200        changes_.removePropertyChangeListener( l ); 
     201    } 
     202 
     203    public double[] getXArray() 
     204    { 
     205        return xloc_; 
     206    } 
     207 
     208    /** 
     209     * Get the length of the x axis 
     210     * 
     211     * @since 2.0 
     212     */ 
     213    public int getXSize() 
     214    { 
     215        return xloc_.length; 
     216    } 
     217 
     218    public double[] getYArray() 
     219    { 
     220        return yloc_; 
     221    } 
     222 
     223    /** 
     224     * Get the length of the y axis 
     225     * 
     226     * @since 2.0 
     227     */ 
     228    public int getYSize() 
     229    { 
     230        return yloc_.length; 
     231    } 
     232 
     233    public double[] getZArray() 
     234    { 
     235        return grid_; 
     236    } 
     237 
     238    public Range2D getZRange() 
     239    { 
     240        return zRange_; 
     241    } 
     242 
     243    public GeoDate[] getTimeArray() 
     244    { 
     245        return tloc_.getGeoDate(); 
     246    } 
     247 
     248    /** 
     249     * Get the <code>GeoDateArray</code> object. 
     250     * 
     251     * @since 3.0 
     252     */ 
     253    public GeoDateArray getGeoDateArray() 
     254    { 
     255        return tloc_; 
     256    } 
     257 
     258    /** 
     259     * Get the length of the Time axis 
     260     * 
     261     * @since 2.0 
     262     */ 
     263    public int getTSize() 
     264    { 
     265        return tloc_.getLength(); 
     266    } 
     267 
     268    public SGTMetaData getZMetaData() 
     269    { 
     270        return zMetaData_; 
     271    } 
     272 
     273    public SGTGrid getAssociatedData() 
     274    { 
     275        return associatedData_; 
     276    } 
     277 
     278    public boolean hasAssociatedData() 
     279    { 
     280        return ( associatedData_ != null ); 
     281    } 
     282 
     283    public boolean hasXEdges() 
     284    { 
     285        return hasXEdges_; 
     286    } 
     287 
     288    public double[] getXEdges() 
     289    { 
     290        return xEdges_; 
     291    } 
     292 
     293    /** 
     294     * Return the range of the x edges 
     295     * 
     296     * @since 2.0 
     297     */ 
     298    public SoTRange getXEdgesRange() 
     299    { 
     300        return xEdgesRange_; 
     301    } 
     302 
     303    public boolean hasYEdges() 
     304    { 
     305        return hasYEdges_; 
     306    } 
     307 
     308    public double[] getYEdges() 
     309    { 
     310        return yEdges_; 
     311    } 
     312 
     313    /** 
     314     * Return the range of the y edges 
     315     * 
     316     * @since 2.0 
     317     */ 
     318    public SoTRange getYEdgesRange() 
     319    { 
     320        return yEdgesRange_; 
     321    } 
     322 
     323    public GeoDate[] getTimeEdges() 
     324    { 
     325        return tEdges_.getGeoDate(); 
     326    } 
     327 
     328    /** 
     329     * Get the <code>GeoDateArray</code> object. 
     330     * 
     331     * @since 3.0 
     332     */ 
     333    public GeoDateArray getGeoDateArrayEdges() 
     334    { 
     335        return tEdges_; 
     336    } 
     337 
     338    private SoTRange computeSoTRange( double[] array ) 
     339    { 
     340        Range2D range = computeRange2D( array ); 
     341        return new SoTRange.Double( range.start, range.end ); 
     342    } 
     343 
     344    private SoTRange computeSoTRange( GeoDateArray tarray ) 
     345    { 
     346        long start = Long.MAX_VALUE; 
     347        long end = Long.MIN_VALUE; 
     348        long[] tar = tarray.getTime(); 
     349        int count = 0; 
     350        for( int i = 0; i < tar.length; i++ ) 
     351        { 
     352            if( !( tar[i] == Long.MAX_VALUE ) ) 
     353            { 
     354                start = Math.min( start, tar[i] ); 
     355                end = Math.max( end, tar[i] ); 
     356                count++; 
     357            } 
     358        } 
     359        if( count == 0 ) 
     360        { 
     361            return new SoTRange.Time( Long.MAX_VALUE, 
     362                    Long.MAX_VALUE ); 
     363        } 
     364        else 
     365        { 
     366            return new SoTRange.Time( start, end ); 
     367        } 
     368    } 
     369 
     370    private Range2D computeRange2D( double[] array ) 
     371    { 
     372        double start = Double.POSITIVE_INFINITY; 
     373        double end = Double.NEGATIVE_INFINITY; 
     374        int count = 0; 
     375        for( int i = 0; i < array.length; i++ ) 
     376        { 
     377            if( !Double.isNaN( array[i] ) ) 
     378            { 
     379                start = Math.min( start, array[i] ); 
     380                end = Math.max( end, array[i] ); 
     381                count++; 
     382            } 
     383        } 
     384        if( count == 0 ) 
     385        { 
     386            return new Range2D( Double.NaN, Double.NaN ); 
     387        } 
     388        else 
     389        { 
     390            return new Range2D( start, end ); 
     391        } 
     392    } 
     393 
     394    /** 
     395     * Set the associated data grid. 
     396     * <BR><B>Property Change:</B> <code>associatedDataModified</code>. 
     397     * 
     398     * @since 2.0 
     399     */ 
     400    public void setAssociatedData( SGTGrid assoc ) 
     401    { 
     402        associatedData_ = assoc; 
     403        changes_.firePropertyChange( "associatedDataModified", 
     404                null, 
     405                assoc ); 
     406    } 
     407 
     408    /** 
     409     * Set the values for the x grid edges. 
     410     */ 
     411    public void setXEdges( double[] edge ) 
     412    { 
     413        xEdges_ = edge; 
     414        hasXEdges_ = true; 
     415        xEdgesRange_ = computeSoTRange( edge ); 
     416    } 
     417 
     418    /** 
     419     * Set the values for the y grid edges. 
     420     */ 
     421    public void setYEdges( double[] edge ) 
     422    { 
     423        yEdges_ = edge; 
     424        hasYEdges_ = true; 
     425        yEdgesRange_ = computeSoTRange( edge ); 
     426    } 
     427 
     428    /** 
     429     * Set the values for the temporal grid edges. 
     430     */ 
     431    public void setTimeEdges( GeoDate[] edge ) 
     432    { 
     433        setTimeEdges( new GeoDateArray( edge ) ); 
     434    } 
     435 
     436    /** 
     437     * @since 3.0 
     438     */ 
     439    public void setTimeEdges( GeoDateArray tarray ) 
     440    { 
     441        tEdges_ = tarray; 
     442        if( xTime_ ) 
     443        { 
     444            hasXEdges_ = true; 
     445            xEdgesRange_ = computeSoTRange( tarray ); 
     446        } 
     447        else if( yTime_ ) 
     448        { 
     449            hasYEdges_ = true; 
     450            yEdgesRange_ = computeSoTRange( tarray ); 
     451        } 
     452    } 
     453 
     454    /** 
     455     * Set the <code>SGTMetaData</code> associated with the x 
     456     * coordinate. 
     457     */ 
     458    public void setXMetaData( SGTMetaData md ) 
     459    { 
     460        xMetaData_ = md; 
     461    } 
     462 
     463    /** 
     464     * Set the <code>SGTMetaData</code> associated with the y 
     465     * coordinate. 
     466     */ 
     467    public void setYMetaData( SGTMetaData md ) 
     468    { 
     469        yMetaData_ = md; 
     470    } 
     471 
     472    /** 
     473     * Set the <code>SGTMetaData</code> associated with the z 
     474     * coordinate. 
     475     */ 
     476    public void setZMetaData( SGTMetaData md ) 
     477    { 
     478        zMetaData_ = md; 
     479    } 
     480 
     481    /** 
     482     * Set the grid title 
     483     */ 
     484    public void setTitle( String title ) 
     485    { 
     486        title_ = title; 
     487    } 
     488 
     489    /** 
     490     * Set the title formatted for the <code>VectorKey</code>. 
     491     */ 
     492    public void setKeyTitle( SGLabel title ) 
     493    { 
     494        keyTitle_ = title; 
     495    } 
     496 
     497    /** 
     498     * Set the unique identifier. 
     499     */ 
     500    public void setId( String ident ) 
     501    { 
     502        id_ = ident; 
     503    } 
     504 
     505    /** 
     506     * Set the x coordinate grid centers 
     507     * <BR><B>Property Change:</B> <code>dataModified</code>. 
     508     */ 
     509    public void setXArray( double[] xloc ) 
     510    { 
     511        xloc_ = xloc; 
     512        xTime_ = false; 
     513        xRange_ = computeSoTRange( xloc ); 
     514        changes_.firePropertyChange( "dataModified", 
     515                new Integer( 0 ), 
     516                new Integer( xloc.length ) ); 
     517    } 
     518 
     519    /** 
     520     * Set the y coordinate grid centers 
     521     * <BR><B>Property Change:</B> <code>dataModified</code>. 
     522     */ 
     523    public void setYArray( double[] yloc ) 
     524    { 
     525        yloc_ = yloc; 
     526        yTime_ = false; 
     527        yRange_ = computeSoTRange( yloc ); 
     528        changes_.firePropertyChange( "dataModified", 
     529                new Integer( 0 ), 
     530                new Integer( yloc.length ) ); 
     531    } 
     532 
     533    /** 
     534     * Set the z grid values. 
     535     * <BR><B>Property Change:</B> <code>dataModified</code>. 
     536     */ 
     537    public void setZArray( double[] grid ) 
     538    { 
     539        grid_ = grid; 
     540        zRange_ = computeRange2D( grid ); 
     541        changes_.firePropertyChange( "dataModified", 
     542                new Integer( 0 ), 
     543                new Integer( grid.length ) ); 
     544    } 
     545 
     546    /** 
     547     * set the temporal grid centers 
     548     * <BR><B>Property Change:</B> <code>dataModified</code>. 
     549     */ 
     550    public void setTimeArray( GeoDate[] tloc ) 
     551    { 
     552        setTimeArray( new GeoDateArray( tloc ) ); 
     553    } 
     554 
     555    /** 
     556     * @since 3.0 
     557     */ 
     558    public void setTimeArray( GeoDateArray tarray ) 
     559    { 
     560        tloc_ = tarray; 
     561        if( xTime_ ) 
     562        { 
     563            xRange_ = computeSoTRange( tarray ); 
     564        } 
     565        else if( yTime_ ) 
     566        { 
     567            yRange_ = computeSoTRange( tarray ); 
     568        } 
     569        changes_.firePropertyChange( "dataModified", 
     570                new Integer( 0 ), 
     571                new Integer( tarray.getLength() ) ); 
     572    } 
     573 
     574    // VMIPSL 
     575    public boolean isRealFullGrid() 
     576    { 
     577        return _isRealFullGrid; 
     578    } 
     579 
     580    public void setRealFullGrid( final boolean realFullGrid ) 
     581    { 
     582        _isRealFullGrid = realFullGrid; 
     583    } 
     584 
     585    protected double[] xloc_; 
     586    protected double[] yloc_; 
     587    //  protected GeoDate[] tloc_; 
     588    protected GeoDateArray tloc_; 
     589    protected double[] grid_; 
     590    protected double[] xEdges_; 
     591    protected double[] yEdges_; 
     592    //  protected GeoDate[] tEdges_; 
     593    protected GeoDateArray tEdges_; 
     594    protected boolean hasXEdges_; 
     595    protected boolean hasYEdges_; 
     596    protected String title_; 
     597    protected SGLabel keyTitle_ = null; 
     598    protected String id_ = null; 
     599    protected boolean xTime_; 
     600    protected boolean yTime_; 
     601    /** 
     602     * @shapeType AggregationLink 
     603     * @clientRole x 
     604     */ 
    54605    protected SGTMetaData xMetaData_ = null; 
    55     /**@shapeType AggregationLink 
    56   * @clientRole y*/ 
     606    /** 
     607     * @shapeType AggregationLink 
     608     * @clientRole y 
     609     */ 
    57610    protected SGTMetaData yMetaData_ = null; 
    58     /**@shapeType AggregationLink 
    59   * @clientRole z*/ 
     611    /** 
     612     * @shapeType AggregationLink 
     613     * @clientRole z 
     614     */ 
    60615    protected SGTMetaData zMetaData_ = null; 
    61     /**@shapeType AggregationLink 
    62   * @clientRole associated data*/ 
     616    /** 
     617     * @shapeType AggregationLink 
     618     * @clientRole associated data 
     619     */ 
    63620    protected SGTGrid associatedData_; 
    64   private SoTRange xRange_ = null; 
    65   private SoTRange yRange_ = null; 
    66   private SoTRange xEdgesRange_ = null; 
    67   private SoTRange yEdgesRange_ = null; 
    68   private Range2D zRange_ = null; 
    69   private PropertyChangeSupport changes_ = new PropertyChangeSupport(this); 
    70  
    71   /** 
    72    * Default constructor. 
    73    */ 
    74   public SimpleGrid() { 
    75     this(null, (double[])null, (double[])null, ""); 
    76   } 
    77   /** 
    78    * Constructor for X and Y coordinates as double. 
    79    * 
    80    * @param grid Z values 
    81    * @param xloc X coordinates 
    82    * @param yloc Y coordinates 
    83    * @param title the title 
    84    */ 
    85   public SimpleGrid(double[] grid, double[] xloc, 
    86                     double[] yloc, String title) { 
    87     grid_ = grid; 
    88     xloc_ = xloc; 
    89     yloc_ = yloc; 
    90     title_ = title; 
    91     xTime_ = false; 
    92     yTime_ = false; 
    93     hasXEdges_ = false; 
    94     hasYEdges_ = false; 
    95     xRange_ = computeSoTRange(xloc); 
    96     yRange_ = computeSoTRange(yloc); 
    97     zRange_ = computeRange2D(grid); 
    98   } 
    99   /** 
    100    * Constructor for X time and Y double. 
    101    * 
    102    * @param grid Z values 
    103    * @param tloc Time coordinates 
    104    * @param yloc Y coordinates 
    105    * @param title the title 
    106    */ 
    107   public SimpleGrid(double[] grid, GeoDate[] tloc, 
    108                     double[] yloc,String title) { 
    109     grid_ = grid; 
    110     tloc_ = new GeoDateArray(tloc); 
    111     yloc_ = yloc; 
    112     title_ = title; 
    113     xTime_ = true; 
    114     yTime_ = false; 
    115     hasXEdges_ = false; 
    116     hasYEdges_ = false; 
    117     xRange_ = computeSoTRange(tloc_); 
    118     yRange_ = computeSoTRange(yloc); 
    119     zRange_ = computeRange2D(grid); 
    120   } 
    121   /** 
    122    * Constructor for X double and Y time. 
    123    * 
    124    * @param grid Z values 
    125    * @param xloc X coordinates 
    126    * @param tloc Time coordinates 
    127    * @param title the title 
    128    */ 
    129   public SimpleGrid(double[] grid, double[] xloc, 
    130                     GeoDate[] tloc,String title) { 
    131     grid_ = grid; 
    132     xloc_ = xloc; 
    133     tloc_ = new GeoDateArray(tloc); 
    134     title_ = title; 
    135     xTime_ = false; 
    136     yTime_ = true; 
    137     hasXEdges_ = false; 
    138     hasYEdges_ = false; 
    139     xRange_ = computeSoTRange(xloc); 
    140     yRange_ = computeSoTRange(tloc_); 
    141     zRange_ = computeRange2D(grid); 
    142   } 
    143   /** 
    144    * Create a copy of the grid. 
    145    * 
    146    * @since 2.0 
    147    * @see SGTData 
    148    */ 
    149   public SGTData copy() { 
    150     SGTGrid newGrid; 
    151     try { 
    152       newGrid = (SGTGrid)clone(); 
    153     } catch (CloneNotSupportedException e) { 
    154       newGrid = new SimpleGrid(); 
    155     } 
    156     return (SGTData)newGrid; 
    157   } 
    158   public double[] getXArray() { 
    159     return xloc_; 
    160   } 
    161   /** 
    162    * Get the length of the x axis 
    163    * 
    164    * @since 2.0 
    165    */ 
    166   public int getXSize() { 
    167     return xloc_.length; 
    168   } 
    169   public double[] getYArray() { 
    170     return yloc_; 
    171   } 
    172   /** 
    173    * Get the length of the y axis 
    174    * 
    175    * @since 2.0 
    176    */ 
    177   public int getYSize() { 
    178     return yloc_.length; 
    179   } 
    180   public double[] getZArray() { 
    181     return grid_; 
    182   } 
    183   public GeoDate[] getTimeArray() { 
    184     return tloc_.getGeoDate(); 
    185   } 
    186   /** 
    187    * Get the <code>GeoDateArray</code> object. 
    188    * 
    189    * @since 3.0 
    190    */ 
    191   public GeoDateArray getGeoDateArray() { 
    192     return tloc_; 
    193   } 
    194   /** 
    195    * Get the length of the Time axis 
    196    * 
    197    * @since 2.0 
    198    */ 
    199   public int getTSize() { 
    200     return tloc_.getLength(); 
    201   } 
    202   public boolean isXTime() { 
    203     return xTime_; 
    204   } 
    205   public boolean isYTime() { 
    206     return yTime_; 
    207   } 
    208   public SGTMetaData getXMetaData() { 
    209     return xMetaData_; 
    210   } 
    211   public SGTMetaData getYMetaData() { 
    212     return yMetaData_; 
    213   } 
    214   public SGTMetaData getZMetaData() { 
    215     return zMetaData_; 
    216   } 
    217   public String getTitle() { 
    218     return title_; 
    219   } 
    220   /** 
    221    * Set the associated data grid. 
    222    * <BR><B>Property Change:</B> <code>associatedDataModified</code>. 
    223    * 
    224    * @since 2.0 
    225    */ 
    226   public void setAssociatedData(SGTGrid assoc) { 
    227     associatedData_ = assoc; 
    228     changes_.firePropertyChange("associatedDataModified", 
    229                                 null, 
    230                                 assoc); 
    231   } 
    232   public SGTGrid getAssociatedData() { 
    233     return associatedData_; 
    234   } 
    235   public boolean hasAssociatedData() { 
    236     return (associatedData_ != null); 
    237   } 
    238   public boolean hasXEdges() { 
    239     return hasXEdges_; 
    240   } 
    241   public double[] getXEdges() { 
    242     return xEdges_; 
    243   } 
    244   /** 
    245    * Set the values for the x grid edges. 
    246    */ 
    247   public void setXEdges(double[] edge) { 
    248     xEdges_ = edge; 
    249     hasXEdges_ = true; 
    250     xEdgesRange_ = computeSoTRange(edge); 
    251   } 
    252   public boolean hasYEdges() { 
    253     return hasYEdges_; 
    254   } 
    255   public double[] getYEdges() { 
    256     return yEdges_; 
    257   } 
    258   /** 
    259    * Set the values for the y grid edges. 
    260    */ 
    261   public void setYEdges(double[] edge) { 
    262     yEdges_ = edge; 
    263     hasYEdges_ = true; 
    264     yEdgesRange_ = computeSoTRange(edge); 
    265   } 
    266   public GeoDate[] getTimeEdges() { 
    267     return tEdges_.getGeoDate(); 
    268   } 
    269   /** 
    270    * Get the <code>GeoDateArray</code> object. 
    271    * 
    272    * @since 3.0 
    273    */ 
    274   public GeoDateArray getGeoDateArrayEdges() { 
    275     return tEdges_; 
    276   } 
    277   /** 
    278    * Set the values for the temporal grid edges. 
    279    */ 
    280   public void setTimeEdges(GeoDate[] edge) { 
    281     setTimeEdges(new GeoDateArray(edge)); 
    282   } 
    283   /** 
    284    * @since 3.0 
    285    */ 
    286   public void setTimeEdges(GeoDateArray tarray) { 
    287     tEdges_ = tarray; 
    288     if(xTime_) { 
    289       hasXEdges_ = true; 
    290       xEdgesRange_ = computeSoTRange(tarray); 
    291     } else if(yTime_){ 
    292       hasYEdges_ = true; 
    293       yEdgesRange_ = computeSoTRange(tarray); 
    294     } 
    295   } 
    296   /** 
    297    * Set the <code>SGTMetaData</code> associated with the x 
    298    * coordinate. 
    299    */ 
    300   public void setXMetaData(SGTMetaData md) { 
    301     xMetaData_ = md; 
    302   } 
    303   /** 
    304    * Set the <code>SGTMetaData</code> associated with the y 
    305    * coordinate. 
    306    */ 
    307   public void setYMetaData(SGTMetaData md) { 
    308     yMetaData_ = md; 
    309   } 
    310   /** 
    311    * Set the <code>SGTMetaData</code> associated with the z 
    312    * coordinate. 
    313    */ 
    314   public void setZMetaData(SGTMetaData md) { 
    315     zMetaData_ = md; 
    316   } 
    317   /** 
    318    * Set the grid title 
    319    */ 
    320   public void setTitle(String title) { 
    321     title_ = title; 
    322   } 
    323   public SGLabel getKeyTitle() { 
    324     return keyTitle_; 
    325   } 
    326   /** Set the title formatted for the <code>VectorKey</code>. */ 
    327   public void setKeyTitle(SGLabel title) { 
    328     keyTitle_ = title; 
    329   } 
    330   /** 
    331    * Get the unique identifier.  The presence of the identifier 
    332    * is optional, but if it is present it should be unique.  This 
    333    * field is used to search for the layer that contains the data. 
    334    * 
    335    * @since 2.0 
    336    * @return unique identifier 
    337    * @see gov.noaa.pmel.sgt.Pane 
    338    * @see gov.noaa.pmel.sgt.Layer 
    339    */ 
    340   public String getId() { 
    341     return id_; 
    342   } 
    343   /** 
    344    * Set the unique identifier. 
    345    */ 
    346   public void setId(String ident) { 
    347     id_ = ident; 
    348   } 
    349   /** 
    350    * Set the x coordinate grid centers 
    351    * <BR><B>Property Change:</B> <code>dataModified</code>. 
    352    */ 
    353   public void setXArray(double[] xloc) { 
    354     xloc_ = xloc; 
    355     xTime_ = false; 
    356     xRange_ = computeSoTRange(xloc); 
    357     changes_.firePropertyChange("dataModified", 
    358                                 new Integer(0), 
    359                                 new Integer(xloc.length)); 
    360   } 
    361   /** 
    362    * Set the y coordinate grid centers 
    363    * <BR><B>Property Change:</B> <code>dataModified</code>. 
    364    */ 
    365   public void setYArray(double[] yloc) { 
    366     yloc_ = yloc; 
    367     yTime_ = false; 
    368     yRange_ = computeSoTRange(yloc); 
    369     changes_.firePropertyChange("dataModified", 
    370                                 new Integer(0), 
    371                                 new Integer(yloc.length)); 
    372   } 
    373   /** 
    374    * Set the z grid values. 
    375    * <BR><B>Property Change:</B> <code>dataModified</code>. 
    376    */ 
    377   public void setZArray(double[] grid) { 
    378     grid_ = grid; 
    379     zRange_ = computeRange2D(grid); 
    380     changes_.firePropertyChange("dataModified", 
    381                                 new Integer(0), 
    382                                 new Integer(grid.length)); 
    383   } 
    384   /** 
    385    * set the temporal grid centers 
    386    * <BR><B>Property Change:</B> <code>dataModified</code>. 
    387    */ 
    388   public void setTimeArray(GeoDate[] tloc) { 
    389     setTimeArray(new GeoDateArray(tloc)); 
    390   } 
    391   /** 
    392    * @since 3.0 
    393    */ 
    394   public void setTimeArray(GeoDateArray tarray) { 
    395     tloc_ = tarray; 
    396     if(xTime_) { 
    397       xRange_ = computeSoTRange(tarray); 
    398     } else if(yTime_) { 
    399       yRange_ = computeSoTRange(tarray); 
    400     } 
    401     changes_.firePropertyChange("dataModified", 
    402                                 new Integer(0), 
    403                                 new Integer(tarray.getLength())); 
    404   } 
    405   public SoTRange getXRange() { 
    406     return xRange_.copy(); 
    407   } 
    408   public SoTRange getYRange() { 
    409     return yRange_.copy(); 
    410   } 
    411   public Range2D getZRange() { 
    412     return zRange_; 
    413   } 
    414   /** 
    415    * Return the range of the x edges 
    416    * 
    417    * @since 2.0 
    418    */ 
    419   public SoTRange getXEdgesRange() { 
    420     return xEdgesRange_; 
    421   } 
    422   /** 
    423    * Return the range of the y edges 
    424    * 
    425    * @since 2.0 
    426    */ 
    427   public SoTRange getYEdgesRange() { 
    428     return yEdgesRange_; 
    429   } 
    430  
    431   public void addPropertyChangeListener(PropertyChangeListener l) { 
    432     changes_.addPropertyChangeListener(l); 
    433   } 
    434   public void removePropertyChangeListener(PropertyChangeListener l) { 
    435     changes_.removePropertyChangeListener(l); 
    436   } 
    437  
    438   private SoTRange computeSoTRange(double[] array) { 
    439     Range2D range = computeRange2D(array); 
    440     return new SoTRange.Double(range.start, range.end); 
    441   } 
    442   private SoTRange computeSoTRange(GeoDateArray tarray) { 
    443     long start = Long.MAX_VALUE; 
    444     long end = Long.MIN_VALUE; 
    445     long[] tar = tarray.getTime(); 
    446     int count = 0; 
    447     for(int i=0; i < tar.length; i++) { 
    448       if(!(tar[i] == Long.MAX_VALUE)) { 
    449         start = Math.min(start, tar[i]); 
    450         end = Math.max(end, tar[i]); 
    451         count++; 
    452       } 
    453     } 
    454     if(count == 0) { 
    455       return new SoTRange.Time(Long.MAX_VALUE, 
    456                                Long.MAX_VALUE); 
    457     } else { 
    458       return new SoTRange.Time(start, end); 
    459     } 
    460   } 
    461   private Range2D computeRange2D(double[] array) { 
    462     double start = Double.POSITIVE_INFINITY; 
    463     double end = Double.NEGATIVE_INFINITY; 
    464     int count = 0; 
    465     for(int i=0; i < array.length; i++) { 
    466       if(!Double.isNaN(array[i])) { 
    467         start = Math.min(start, array[i]); 
    468         end = Math.max(end, array[i]); 
    469         count++; 
    470       } 
    471     } 
    472     if(count == 0) { 
    473       return new Range2D(Double.NaN, Double.NaN); 
    474     } else { 
    475       return new Range2D(start, end); 
    476     } 
    477   } 
     621    private SoTRange xRange_ = null; 
     622    private SoTRange yRange_ = null; 
     623    private SoTRange xEdgesRange_ = null; 
     624    private SoTRange yEdgesRange_ = null; 
     625    private Range2D zRange_ = null; 
     626    private PropertyChangeSupport changes_ = new PropertyChangeSupport( this ); 
     627    //VMIPSL 
     628    private boolean _isRealFullGrid = true; 
    478629} 
  • ether_megapoli/trunk/common/implementation/com/ether/EtherHelper.java

    r189 r191  
    11package com.ether; 
    22 
     3import org.apache.commons.lang.ArrayUtils; 
    34import org.jetbrains.annotations.NotNull; 
    45 
     
    2829    } 
    2930 
     31    public static double[] convertListDoubleToDoubleArray(@NotNull final List<Double> list) 
     32    { 
     33        Double[] doubleArray = new Double[list.size()]; 
     34        doubleArray = list.toArray( doubleArray ); 
     35        return ArrayUtils.toPrimitive( doubleArray ); 
     36    } 
    3037 
    3138} 
  • ether_megapoli/trunk/persistence/implementation/com/ether/dao/ValueDAOImpl.java

    r185 r191  
    33import com.ether.Data; 
    44import com.ether.PersistenceException; 
     5import com.medias.Nombre; 
    56import com.medias.database.objects.Valeur; 
    67import org.hibernate.criterion.DetachedCriteria; 
     
    1112import org.jetbrains.annotations.Nullable; 
    1213 
     14import java.util.ArrayList; 
    1315import java.util.Date; 
    1416import java.util.List; 
     
    4749 
    4850        final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 
    49         // TODO : remove maxResults to 10 
    50 //        final List<Object[]> objects = selectPage( null, 10, criteria ); 
    5151 
    5252        final double[] values = new double[objects.size()]; 
     
    6565 
    6666    @NotNull 
    67     public <T1, T2, T3> Data<T1[], T2[], T3[]> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     67    public <T1, T2, T3> Data<T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
    6868            throws PersistenceException 
    6969    { 
     
    8989//        final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 
    9090        // TODO : remove maxResults to 10 
    91         final List<Object[]> objects = selectPage( null, 10, criteria ); 
     91        final List<Object[]> objects = selectPage( null, 100, criteria ); 
    9292 
    9393        final double[] latitudeValues = new double[objects.size()]; 
     
    9999        { 
    100100            parameterValues[i] = (Double) value[0]; 
    101             latitudeValues[i] = Double.valueOf( (Integer) value[1] ); 
    102             longitudeValues[i] = Double.valueOf( (Integer) value[2] ); 
     101            latitudeValues[i] = Nombre.latIntToFloat( (Integer) value[1] ); 
     102            longitudeValues[i] = Nombre.latIntToFloat( (Integer) value[2] ); 
     103            i++; 
     104        } 
     105 
     106        return new Data( parameterValues, latitudeValues, longitudeValues ); 
     107    } 
     108 
     109 
     110    @NotNull 
     111    public <T1, T2, T3> Data<List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     112            throws PersistenceException 
     113    { 
     114        final DetachedCriteria criteria = DetachedCriteria.forClass( Valeur.class, "value" ) 
     115                .add( Restrictions.eq( "value.parametre.id", parameterId ) ) 
     116                .createCriteria( "mesure", "measure" ) 
     117                .add( Restrictions.eq( "measure.plateforme.id", plateformId ) ); 
     118 
     119        if( null != dateBegin ) 
     120            criteria.add( Restrictions.ge( "measure.mesureDate", dateBegin ) ); 
     121        if( null != dateEnd ) 
     122            criteria.add( Restrictions.le( "measure.mesureDate", dateEnd ) ); 
     123 
     124        criteria.createCriteria( "localisation", "localisation" ); 
     125 
     126        criteria.setProjection( Projections.distinct( Projections.projectionList() 
     127                .add( Projections.property( "value.valeurVal" ) ) 
     128                .add( Projections.property( "localisation.localisationLat" ) ) 
     129                .add( Projections.property( "localisation.localisationLon" ) ) ) ); 
     130 
     131        criteria.addOrder( Order.asc( "localisation.localisationLon" ) ); 
     132 
     133//        final List<Object[]> objects = selectAllByCriteria( Object[].class, criteria ); 
     134        // TODO : remove maxResults to 10 
     135        final List<Object[]> objects = selectPage( null, 100, criteria ); 
     136 
     137        final List<Double> latitudeValues = new ArrayList<Double>( objects.size() ); 
     138        final List<Double> longitudeValues = new ArrayList<Double>( objects.size() ); 
     139        final List<Double> parameterValues = new ArrayList<Double>( objects.size() ); 
     140 
     141        int i = 0; 
     142        for( final Object[] value : objects ) 
     143        { 
     144            parameterValues.add( (Double) value[0] ); 
     145            latitudeValues.add( Double.valueOf( Nombre.latIntToFloat( (Integer) value[1] ) ) ); 
     146            longitudeValues.add( Double.valueOf( Nombre.latIntToFloat( (Integer) value[2] ) ) ); 
    103147            i++; 
    104148        } 
  • ether_megapoli/trunk/persistence/interface/com/ether/dao/ValueDAO.java

    r185 r191  
    2323 
    2424    @NotNull 
    25     <T1, T2, T3> Data<T1[], T2[], T3[]> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     25    <T1, T2, T3> Data<T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     26            throws PersistenceException; 
     27 
     28    @NotNull 
     29    <T1, T2, T3> Data<List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
    2630            throws PersistenceException; 
    2731 
  • ether_megapoli/trunk/service/implementation/com/ether/BouchonHelper.java

    r190 r191  
    99 
    1010import java.util.ArrayList; 
     11import java.util.Arrays; 
    1112import java.util.Calendar; 
    1213import java.util.Date; 
     
    254255    { 
    255256        if( null == delta ) 
    256             return new Data(new double[0], new Date[0]); 
     257            return new Data( new double[0], new Date[0] ); 
    257258 
    258259        final double[] values = new double[size]; 
     
    289290    public static Data createRealValuesFor2D() 
    290291    { 
    291         final double[] latitudeArray = {488993.0, 489001.0, 488984.0, 489010.0, 490005.0, 490015.0}; 
    292         final double[] longitudeValues = {-1829.0, -1829.0, -1828.0, -1828.0, -1827.0, -1826.0}; 
    293         final double[] parameterValues = {7.029, 0.0, 0.0, 0.0, 8.547, 0.0, 0.0, 0.0, 8.845, 0.0, 0.0, 0.0, 9.248, 0.0, 0.0, 0.0, 9.58, 0.0, 0.0, 0.0, 9.98, 0.0, 0.0, 0.0, 7.98, 0.0, 0.0, 0.0, 6.58, 0.0, 0.0, 0.0, 8.08, 0.0, 0.0, 0.0}; 
    294  
    295         return new Data( parameterValues, latitudeArray, longitudeValues ); 
     292//        final double[] latitudeValues = {488993.0, 489001.0, 488984.0, 489010.0, 490005.0, 490015.0}; 
     293//        final double[] longitudeValues = {-1829.0, -1829.0, -1828.0, -1828.0, -1827.0, -1826.0}; 
     294//        final double[] parameterValues = {7.029, 0.0, 0.0, 0.0, 8.547, 0.0, 0.0, 0.0, 8.845, 0.0, 0.0, 0.0, 9.248, 0.0, 0.0, 0.0, 9.58, 0.0, 0.0, 0.0, 9.98, 0.0, 0.0, 0.0, 7.98, 0.0, 0.0, 0.0, 6.58, 0.0, 0.0, 0.0, 8.08, 0.0, 0.0, 0.0}; 
     295 
     296        final Double[] latitudeArray = new Double[]{48.898, 48.899, 48.900, 49.1001, 49.1002, 49.1003, 49.1004}; 
     297        final Double[] longitudeArray = new Double[]{-0.1832, 2.0368, 2.0369, 2.037, 2.8216, 2.8221, 3.0}; 
     298        final Double[] parameterArray = new Double[]{0.1094, 30.8, 19.0, 12.31, 12.69, 12.06, 6.813}; 
     299 
     300        final List<Double> latitudeValues = Arrays.asList( latitudeArray ); 
     301        final List<Double> longitudeValues = Arrays.asList( longitudeArray ); 
     302        final List<Double> parameterValues = Arrays.asList( parameterArray ); 
     303 
     304        return new Data( parameterValues, latitudeValues, longitudeValues ); 
    296305    } 
    297306 
  • ether_megapoli/trunk/service/implementation/com/ether/EtherPlotContentServiceImpl.java

    r190 r191  
    55import gov.noaa.pmel.sgt.Axis; 
    66import gov.noaa.pmel.sgt.CartesianGraph; 
     7import gov.noaa.pmel.sgt.ColorMap; 
     8import gov.noaa.pmel.sgt.ContourLevels; 
    79import gov.noaa.pmel.sgt.Graph; 
     10import gov.noaa.pmel.sgt.GridAttribute; 
     11import gov.noaa.pmel.sgt.IndexedColorMap; 
    812import gov.noaa.pmel.sgt.JPane; 
    913import gov.noaa.pmel.sgt.Layer; 
     
    1620import gov.noaa.pmel.sgt.StackedLayout; 
    1721import gov.noaa.pmel.sgt.TimeAxis; 
     22import gov.noaa.pmel.sgt.demo.TestData; 
     23import gov.noaa.pmel.sgt.dm.SGTData; 
    1824import gov.noaa.pmel.sgt.dm.SGTMetaData; 
     25import gov.noaa.pmel.sgt.dm.SimpleGrid; 
    1926import gov.noaa.pmel.sgt.dm.SimpleLine; 
     27import gov.noaa.pmel.sgt.swing.JPlotLayout; 
    2028import gov.noaa.pmel.util.Dimension2D; 
    2129import gov.noaa.pmel.util.GeoDateArray; 
     
    3038import java.awt.*; 
    3139import java.util.ArrayList; 
     40import java.util.Collections; 
    3241import java.util.Date; 
    3342import java.util.List; 
     
    7988        final List<Pair> pIdPIdListForSecondAxis = listPairOfPIdPIdForTwoAxes.getSecondValue(); 
    8089 
    81         final List<SimpleLine> allLines = createLines( pIdPIdListForFirstAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), null, locale ); 
    82         final List<SimpleLine> allLinesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 10, locale ); 
     90        final List<SimpleLine> allLines = createLines( pIdPIdListForFirstAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 10, locale ); 
     91        final List<SimpleLine> allLinesForSecondAxis = createLines( pIdPIdListForSecondAxis, megapoliPlot.getBeginDate(), megapoliPlot.getEndDate(), 50, locale ); 
    8392        List<SimpleLine> lines = extractRealLines( allLines ); 
    8493        List<SimpleLine> linesForSecondAxis = extractRealLines( allLinesForSecondAxis ); 
     
    171180    } 
    172181 
     182    @NotNull 
     183    public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight, @Nullable final Locale locale ) 
     184    { 
     185//        final JPane mainPane = new JPane( "2D Pane", new Dimension( plotWidth, plotHeight ) ); 
     186 
     187        final ResourceBundle bundle = WebHelper.getBundle( locale ); 
     188 
     189        final List<Double> parameterValues = (List<Double>) megapoliPlot.getData().getFirstArray(); 
     190        final List<Double> latitudeValues = (List<Double>) megapoliPlot.getData().getSecondArray(); 
     191        final List<Double> longitudeValues = (List<Double>) megapoliPlot.getData().getThirdArray(); 
     192 
     193        SGTData newData; 
     194        TestData td; 
     195 
     196        /* 
     197       * Create a test grid with sinasoidal-ramp data. 
     198        */ 
     199//        Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f ); 
     200//        Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f ); 
     201        Range2D xr = new Range2D( 190.0f, 200.0f, 1.0f ); 
     202        Range2D yr = new Range2D( 0.0f, 4.0f, 1.0f ); 
     203//        newData = testDataa( xr, yr, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f, parameterArray, latitudeArray, longitudeValues ); 
     204 
     205 
     206//            public SGTData testDataa( Range2D range1, Range2D range2, int type, float amp, float off, float per, final double[] parameterArray, final double[] latitudeArray, final double[] longitudeValues ) 
     207        final SimpleGrid simpleGrid; 
     208        final SGTMetaData xMeta; 
     209        final SGTMetaData yMeta; 
     210        final SGTMetaData zMeta; 
     211 
     212        final int num1 = (int) ( ( xr.end - xr.start ) / xr.delta ) + 1; 
     213        final double[] axis1 = new double[num1]; 
     214        final int num2 = (int) ( ( yr.end - yr.start ) / yr.delta ) + 1; 
     215        final double[] axis2 = new double[num2]; 
     216 
     217        for( int count = 0; count < num1; count++ ) 
     218            axis1[count] = xr.start + count * xr.delta; 
     219 
     220        for( int count = 0; count < num2; count++ ) 
     221            axis2[count] = yr.start + count * yr.delta; 
     222 
     223//        final double[] valuesOrigPetites = getValues( axis1, num1, axis2, 2, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 
     224//        final double[] valuesOrigPetites = getValues( longitudeValues, longitudeValues.length, latitudeValues, latitudeValues.length, TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 
     225 
     226//        final double[] valuesOrig = new double[num1 * num2]; 
     227//        for( int count = 0; count < valuesOrigPetites.length; count++ ) 
     228//        { 
     229//            valuesOrig[count] = valuesOrigPetites[count]; 
     230//        } 
     231//        for( int count = valuesOrigPetites.length; count < num1 * num2; count++ ) 
     232//        { 
     233//            valuesOrig[count] = Double.NaN; 
     234//        } 
     235 
     236        final double[] parameterValuesArray = EtherHelper.convertListDoubleToDoubleArray( parameterValues ); 
     237        final double[] parameterValuesMap = new double[latitudeValues.size() * longitudeValues.size()]; 
     238        for( int i = 0; i < parameterValuesArray.length; i++ ) 
     239            parameterValuesMap[i] = parameterValuesArray[i]; 
     240 
     241        for( int i = parameterValuesArray.length; i < latitudeValues.size() * longitudeValues.size(); i++ ) 
     242            parameterValuesMap[i] = Double.NaN; 
     243 
     244        SGLabel keyLabel = new SGLabel( "Key Label", "", new Point2D.Double( 0.0, 0.0 ) ); 
     245        keyLabel.setHeightP( 0.16 ); 
     246        // 
     247        // create SimpleGrid 
     248        // 
     249        zMeta = new SGTMetaData( "ts", "m s-1" ); 
     250        keyLabel.setText( "XY test grid" ); 
     251        xMeta = new SGTMetaData( bundle.getString( "plot.longitude" ), bundle.getString( "plot.degres" ) ); 
     252        yMeta = new SGTMetaData( bundle.getString( "plot.latitude" ), bundle.getString( "plot.degres" ) ); 
     253//        final SimpleGrid sg = new SimpleGrid( valuesOrig, axis1, axis2, "Test Series" ); 
     254//        simpleGrid = new SimpleGrid( parameterValues, longitudeValues, latitudeValues, "Test Series" ); 
     255//        simpleGrid = new SimpleGrid( valuesOrig, longitudeValues, latitudeValues, "Test Series" ); 
     256//        simpleGrid = new SimpleGrid( valuesOrig, axis1, axis2, "Test Series" ); 
     257 
     258        final double[] longitudeValuesArray = EtherHelper.convertListDoubleToDoubleArray( longitudeValues ); 
     259        final double[] latitudeValuesArray = EtherHelper.convertListDoubleToDoubleArray( latitudeValues ); 
     260        simpleGrid = new SimpleGrid( parameterValuesMap, longitudeValuesArray, latitudeValuesArray, "Test Series" ); 
     261 
     262        simpleGrid.setXMetaData( xMeta ); 
     263        simpleGrid.setYMetaData( yMeta ); 
     264        simpleGrid.setZMetaData( zMeta ); 
     265        simpleGrid.setKeyTitle( keyLabel ); 
     266        simpleGrid.setRealFullGrid( false ); 
     267 
     268 
     269        // Create the contour levels and color map 
     270        final Double min = Collections.min( parameterValues ); 
     271        final Double max = Collections.max( parameterValues ); 
     272        final Double delta = ( max - min ) / 64; 
     273        final Range2D datar = new Range2D( min, max, delta ); 
     274//        final Range2D datar = new Range2D( Collections.min( Arrays.asList( parameterValuesMap ) ), 35f, 0.5f ); 
     275        final ContourLevels clevels = ContourLevels.getDefault( datar ); 
     276        final ColorMap cmap = createColorMap( datar ); 
     277 
     278//        final Range2D datarOrig = new Range2D( 5f, 10.0f, 1f ); 
     279//        final ContourLevels clevelsOrig = ContourLevels.getDefault( datarOrig ); 
     280//        final ColorMap cmapOrig = createColorMap( datarOrig ); 
     281//        final GridAttribute gridAttributeOrig = new GridAttribute( clevelsOrig ); 
     282//        gridAttributeOrig.setColorMap( cmapOrig ); 
     283//        gridAttributeOrig.setStyle( GridAttribute.RASTER_CONTOUR ); 
     284 
     285 
     286        // Create a grid for contour data 
     287        final GridAttribute gridAttribute = new GridAttribute( clevels ); 
     288        gridAttribute.setColorMap( cmap ); 
     289        gridAttribute.setStyle( GridAttribute.RASTER ); 
     290 
     291        // Create the plot 
     292        final JPlotLayout jPlotLayout = new JPlotLayout( true, false, false, "JPlotLayout Pane", null, true ); 
     293        jPlotLayout.setEditClasses( false ); 
     294        jPlotLayout.addData( simpleGrid, gridAttribute, "First Data" ); 
     295        jPlotLayout.setTitles( "", "", "" ); 
     296        jPlotLayout.setSize( new Dimension( plotWidth, plotHeight ) ); 
     297 
     298        /* 
     299       * Resize the key Pane, both the device size and the physical 
     300       * size. Set the size of the key in physical units and place 
     301       * the key pane at the "South" of the frame. 
     302        */ 
     303//    rpl.setKeyLayerSizeP(new Dimension2D(6.0, 1.02)); 
     304//    rpl.setKeyBoundsP(new Rectangle2D.Double(0.01, 1.01, 5.98, 1.0)); 
     305 
     306        return jPlotLayout; 
     307//        return mainPane; 
     308    } 
     309 
     310    @NotNull 
     311    protected String formatTitle( @Nullable final String title ) 
     312    { 
     313        if( null == title ) 
     314            return ""; 
     315        else 
     316        { 
     317            final String formatTitle = title.replaceAll( "\\n", "<br>" ); 
     318            return "<html>" + formatTitle + "</html>"; 
     319        } 
     320    } 
     321 
    173322    private List<SimpleLine> createEmptyLinesList( final List<SimpleLine> allLines, final List<SimpleLine> allLinesForSecondAxis, final List<SimpleLine> lines ) 
    174323    { 
     
    211360 
    212361        return lines; 
    213     } 
    214  
    215     @NotNull 
    216     public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight, @Nullable final Locale locale ) 
    217     { 
    218         final JPane mainPane = new JPane( "2D Pane", new Dimension( plotWidth, plotHeight ) ); 
    219  
    220         final ResourceBundle bundle = WebHelper.getBundle( locale ); 
    221  
    222         final Data realValuesFor2D = BouchonHelper.createRealValuesFor2D(); 
    223 //        final double[] parameterValues = (double[]) megapoliPlot.getData().getFirstArray(); 
    224 //        final double[] latitudeValues = (double[]) megapoliPlot.getData().getSecondArray(); 
    225 //        final double[] longitudeValues = (double[]) megapoliPlot.getData().getThirdArray(); 
    226  
    227         final double[] parameterValues = (double[]) realValuesFor2D.getFirstArray(); 
    228         final double[] latitudeValues = (double[]) realValuesFor2D.getSecondArray(); 
    229         final double[] longitudeValues = (double[]) realValuesFor2D.getThirdArray(); 
    230  
    231         return mainPane; 
    232     } 
    233  
    234     @NotNull 
    235     protected String formatTitle( @Nullable final String title ) 
    236     { 
    237         if( null == title ) 
    238             return ""; 
    239         else 
    240         { 
    241             final String formatTitle = title.replaceAll( "\\n", "<br>" ); 
    242             return "<html>" + formatTitle + "</html>"; 
    243         } 
    244362    } 
    245363 
     
    459577    } 
    460578 
     579    private double[] getValues( double[] axis1, int num1, double[] axis2, int num2, 
     580                                int type, float amp, float off, float per ) 
     581    { 
     582        double[] values; 
     583        int count1, count2, count; 
     584        values = new double[num1 * num2]; 
     585        switch( type ) 
     586        { 
     587            default: 
     588            case TestData.RANDOM: 
     589                for( count = 0; count < num1 * num2; count++ ) 
     590                { 
     591                    values[count] = amp * Math.random() + off; 
     592                } 
     593                break; 
     594            case TestData.SINE: 
     595                count = 0; 
     596                for( count1 = 0; count1 < num1; count1++ ) 
     597                { 
     598                    for( count2 = 0; count2 < num2; count2++ ) 
     599                    { 
     600                        values[count] = amp * Math.sin( axis1[count1] / per ) * 
     601                                Math.sin( axis2[count2] / per ) + off; 
     602                        count++; 
     603                    } 
     604                } 
     605                break; 
     606            case TestData.SINE_RAMP: 
     607                count = 0; 
     608                double ax1factr = 0.08 * Math.abs( axis1[0] - axis1[num1 - 1] ) / 
     609                        Math.max( Math.abs( axis1[0] ), Math.abs( axis1[num1 - 1] ) ); 
     610                double ax2factr = 0.08 * Math.abs( axis2[0] - axis2[num2 - 1] ) / 
     611                        Math.max( Math.abs( axis2[0] ), Math.abs( axis2[num2 - 1] ) ); 
     612                for( count1 = 0; count1 < num1; count1++ ) 
     613                { 
     614                    for( count2 = 0; count2 < num2; count2++ ) 
     615                    { 
     616                        values[count] = amp * Math.sin( axis1[count1] / per ) * 
     617                                Math.sin( axis2[count2] / per ) + off + 
     618                                amp * ( ax1factr * count1 - ax2factr * count2 ); 
     619                        count++; 
     620                    } 
     621                } 
     622        } 
     623        return values; 
     624    } 
     625 
     626 
     627    @NotNull 
     628    private ColorMap createColorMap( final Range2D datar ) 
     629    { 
     630        final int[] red = 
     631                {0, 0, 0, 0, 0, 0, 0, 0, 
     632                        0, 0, 0, 0, 0, 0, 0, 0, 
     633                        0, 0, 0, 0, 0, 0, 0, 0, 
     634                        0, 7, 23, 39, 55, 71, 87, 103, 
     635                        119, 135, 151, 167, 183, 199, 215, 231, 
     636                        247, 255, 255, 255, 255, 255, 255, 255, 
     637                        255, 255, 255, 255, 255, 255, 255, 255, 
     638                        255, 246, 228, 211, 193, 175, 158, 140}; 
     639        final int[] green = 
     640                {0, 0, 0, 0, 0, 0, 0, 0, 
     641                        0, 11, 27, 43, 59, 75, 91, 107, 
     642                        123, 139, 155, 171, 187, 203, 219, 235, 
     643                        251, 255, 255, 255, 255, 255, 255, 255, 
     644                        255, 255, 255, 255, 255, 255, 255, 255, 
     645                        255, 247, 231, 215, 199, 183, 167, 151, 
     646                        135, 119, 103, 87, 71, 55, 39, 23, 
     647                        7, 0, 0, 0, 0, 0, 0, 0}; 
     648        final int[] blue = 
     649                {0, 143, 159, 175, 191, 207, 223, 239, 
     650                        255, 255, 255, 255, 255, 255, 255, 255, 
     651                        255, 255, 255, 255, 255, 255, 255, 255, 
     652                        255, 247, 231, 215, 199, 183, 167, 151, 
     653                        135, 119, 103, 87, 71, 55, 39, 23, 
     654                        7, 0, 0, 0, 0, 0, 0, 0, 
     655                        0, 0, 0, 0, 0, 0, 0, 0, 
     656                        0, 0, 0, 0, 0, 0, 0, 0}; 
     657 
     658        final IndexedColorMap cmap = new IndexedColorMap( red, green, blue ); 
     659        cmap.setTransform( new LinearTransform( 0.0, (double) red.length, datar.start, datar.end ) ); 
     660        return cmap; 
     661    } 
    461662 
    462663    public EtherService getEtherService() 
  • ether_megapoli/trunk/service/implementation/com/ether/EtherPlotServiceImpl.java

    r190 r191  
    6868        jPane.add( jPaneTop, BorderLayout.NORTH ); 
    6969 
    70         final Integer valuesNumber = 10; 
    71 //        final Integer valuesNumber = ( null != megapoliPlot.getValuesNumber() ) ? megapoliPlot.getValuesNumber() : getEtherService().getNumberValuesByPlateformByParameterByPeriod( megapoliPlot.getpIdPIdList(), megapoliPlot.getBeginDate(), megapoliPlot.getEndDate() ); 
     70        final Integer valuesNumber = ( null != megapoliPlot.getValuesNumber() ) ? megapoliPlot.getValuesNumber() : getEtherService().getNumberValuesByPlateformByParameterByPeriod( megapoliPlot.getpIdPIdList(), megapoliPlot.getBeginDate(), megapoliPlot.getEndDate() ); 
    7271 
    7372        // Bottom Pane 
  • ether_megapoli/trunk/service/implementation/com/ether/EtherServiceImpl.java

    r185 r191  
    104104    @NotNull 
    105105    @Transactional(readOnly = true) 
    106     public <T1, T2, T3> Data<T1[], T2[], T3[]> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     106    public <T1, T2, T3> Data<List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
    107107            throws ServiceException 
    108108    { 
     
    110110        { 
    111111            return _valueDAO.getListsByPlateformByParameterByPeriodFor2D( plateformId, parameterId, dateBegin, dateEnd ); 
     112        } 
     113        catch( PersistenceException e ) 
     114        { 
     115            throw new ServiceException( ServiceException.ServiceCode.VALUE_NOT_FOUND, e ); 
     116        } 
     117    } 
     118 
     119 
     120    @NotNull 
     121    @Transactional(readOnly = true) 
     122    public <T1, T2, T3> Data<T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     123            throws ServiceException 
     124    { 
     125        try 
     126        { 
     127            return _valueDAO.getArraysByPlateformByParameterByPeriodFor2D( plateformId, parameterId, dateBegin, dateEnd ); 
    112128        } 
    113129        catch( PersistenceException e ) 
  • ether_megapoli/trunk/service/interface/com/ether/EtherService.java

    r185 r191  
    3737 
    3838    @NotNull 
    39     <T1, T2, T3> Data<T1[], T2[], T3[]> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     39    <T1, T2, T3> Data<T1[], T2[], T3[]> getArraysByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
     40            throws ServiceException; 
     41 
     42    @NotNull 
     43    <T1, T2, T3> Data<List<T1>, List<T2>, List<T3>> getListsByPlateformByParameterByPeriodFor2D( @NotNull final Integer plateformId, @NotNull final Integer parameterId, @Nullable final Date dateBegin, @Nullable final Date dateEnd ) 
    4044            throws ServiceException; 
    4145 
  • ether_megapoli/trunk/service/test/com/ether/EtherTest.java

    r134 r191  
    103103    } 
    104104 
    105     @NotNull 
    106     public LineAttribute createLineAttribute( final boolean markPoint ) 
    107     { 
    108         final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red ); 
    109         if( markPoint ) 
    110         { 
    111             lineAttribute.setStyle( LineAttribute.MARK ); 
    112             // int to display cross 
    113             lineAttribute.setMark( 2 ); 
    114         } 
    115         return lineAttribute; 
    116     } 
    117  
    118  
    119105} 
  • ether_megapoli/trunk/service/test/com/ether/OtherTest.java

    r171 r191  
    11package com.ether; 
    22 
     3import org.apache.commons.lang.ArrayUtils; 
    34import org.junit.Assert; 
    45import org.junit.Test; 
     
    100101            Assert.assertEquals( values.getSecondValue()[2], obj3[1] ); 
    101102        } 
     103    } 
    102104 
     105    @Test 
     106    public void testConversionListToArray() 
     107    { 
     108        final List<Double> doubleList = new ArrayList<Double>( 2 ); 
     109        doubleList.add( 1.2 ); 
     110        doubleList.add( 5.6 ); 
     111 
     112        Double[] doubleArray = new Double[doubleList.size()]; 
     113        doubleArray = doubleList.toArray( doubleArray ); 
     114 
     115        final double[] doubles = ArrayUtils.toPrimitive( doubleArray ); 
     116        Assert.assertEquals( doubles[0], (double) doubleList.get( 0 ), 0 ); 
     117        Assert.assertEquals( doubles[1], (double) doubleList.get( 1 ), 0 ); 
     118 
     119        double[] doubles1 = EtherHelper.convertListDoubleToDoubleArray( doubleList ); 
     120        Assert.assertEquals( doubles1[0], (double) doubleList.get( 0 ), 0 ); 
     121        Assert.assertEquals( doubles1[1], (double) doubleList.get( 1 ), 0 ); 
    103122    } 
    104123} 
  • ether_megapoli/trunk/service/test/com/ether/SGTTest.java

    r188 r191  
    863863//    } 
    864864 
     865    @NotNull 
     866    public LineAttribute createLineAttribute( final boolean markPoint ) 
     867    { 
     868        final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red ); 
     869        if( markPoint ) 
     870        { 
     871            lineAttribute.setStyle( LineAttribute.MARK ); 
     872            // int to display cross 
     873            lineAttribute.setMark( 2 ); 
     874        } 
     875        return lineAttribute; 
     876    } 
     877 
     878 
    865879    // Dimensions of the jPanes 
    866880    private static final int MAIN_WIDTH = 1000; 
  • ether_megapoli/trunk/web/src/com/ether/ControllerPlot.java

    r186 r191  
    106106                megapoliPlot.setTimeSerie( true ); 
    107107                megapoliPlot.setLegendToHide( pIdPIdList.size() == 1 ); 
     108                megapoliPlot.setValuesNumber( 10 ); 
    108109            } 
    109110            else 
     
    113114                final Integer parameterId = (Integer) pIdPIdList.get( 0 ).getSecondValue(); 
    114115//                final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodFor2D( plateformId, parameterId, formatedDateBegin, formatedDateEnd ); 
    115 //                megapoliPlot.setData( valuesLists ); 
     116                final Data valuesLists = BouchonHelper.createRealValuesFor2D(); 
     117                megapoliPlot.setData( valuesLists ); 
    116118 
    117119                megapoliPlot.setTimeSerie( false ); 
    118120                megapoliPlot.setLegendToHide( false ); 
    119 //                megapoliPlot.setValuesNumber( ( (double[]) valuesLists.getFirstArray() ).length ); 
     121//                megapoliPlot.setValuesNumber( ( (ArrayList) valuesLists.getFirstArray() ).size() ); 
    120122                megapoliPlot.setValuesNumber( 5 ); 
    121123            } 
Note: See TracChangeset for help on using the changeset viewer.