Revision: 4316
          http://sourceforge.net/p/jump-pilot/code/4316
Author:   ma15569
Date:     2015-02-07 18:29:23 +0000 (Sat, 07 Feb 2015)
Log Message:
-----------
[2014_01_24] Giuseppe Aruta (ma15569) - RasterQueryPlugIn
        - new plugin icon
                - Extended inspection to multiband raster layers. 
                - Multiple measure are now displayed (and saved) by default. 
                  Press SHIFT to cancel previous and display only last measure. 
                - Moving cursor on image shows raster cell value on lower panel

Modified Paths:
--------------
    core/trunk/ChangeLog
    core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryCursorTool.java
    core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryPlugIn.java

Added Paths:
-----------
    core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_info.png
    core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_save.png

Modified: core/trunk/ChangeLog
===================================================================
--- core/trunk/ChangeLog        2015-02-05 15:19:40 UTC (rev 4315)
+++ core/trunk/ChangeLog        2015-02-07 18:29:23 UTC (rev 4316)
@@ -1,4 +1,11 @@
 # for display continuity sake please use 2 spaces instead of tabs
+
+[2014_01_24] Giuseppe Aruta (ma15569) - RasterQueryPlugIn
+               - Extended inspection to multiband raster layers. 
+               - Multiple measure are now displayed (and saved) by default. 
+                 Press SHIFT to cancel previous and display only last measure. 
+               - Moving cursor on image shows raster cell value on lower panel
+
 2015-02-02 Nicolas Ribot (elnico)
   * removed Oracle spatial stuff due to dependencies problems
 

Added: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_info.png
===================================================================
(Binary files differ)

Index: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_info.png
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_info.png    
2015-02-05 15:19:40 UTC (rev 4315)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_info.png    
2015-02-07 18:29:23 UTC (rev 4316)

Property changes on: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_info.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Added: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_save.png
===================================================================
(Binary files differ)

Index: core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_save.png
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_save.png    
2015-02-05 15:19:40 UTC (rev 4315)
+++ core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_save.png    
2015-02-07 18:29:23 UTC (rev 4316)

Property changes on: 
core/trunk/src/com/vividsolutions/jump/workbench/ui/images/grid_save.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Modified: 
core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryCursorTool.java
===================================================================
--- 
core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryCursorTool.java    
    2015-02-05 15:19:40 UTC (rev 4315)
+++ 
core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryCursorTool.java    
    2015-02-07 18:29:23 UTC (rev 4316)
@@ -33,34 +33,31 @@
 
 package org.openjump.core.ui.plugin.raster;
 
-
 import java.awt.Color;
 import java.awt.Cursor;
 import java.awt.Font;
 import java.awt.Image;
-import java.awt.Shape;
 import java.awt.event.MouseEvent;
 import java.awt.geom.NoninvertibleTransformException;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
+
 import javax.swing.Icon;
-import javax.swing.JOptionPane;
+import javax.swing.JTextPane;
 
 import org.openjump.core.CheckOS;
 import org.openjump.core.apitools.LayerTools;
 import org.openjump.core.rasterimage.RasterImageLayer;
-import org.openjump.core.rasterimage.sextante.OpenJUMPSextanteRasterLayer;
-import org.openjump.core.rasterimage.sextante.rasterWrappers.GridCell;
-import 
org.openjump.core.rasterimage.sextante.rasterWrappers.GridWrapperNotInterpolated;
+import 
org.openjump.core.rasterimage.RasterImageLayer.RasterDataNotFoundException;
+
 import com.vividsolutions.jts.geom.Coordinate;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
 import com.vividsolutions.jts.geom.Point;
 import com.vividsolutions.jump.I18N;
-import com.vividsolutions.jump.feature.FeatureCollection;
 import com.vividsolutions.jump.feature.AttributeType;
 import com.vividsolutions.jump.feature.BasicFeature;
 import com.vividsolutions.jump.feature.Feature;
+import com.vividsolutions.jump.feature.FeatureCollection;
 import com.vividsolutions.jump.feature.FeatureDataset;
 import com.vividsolutions.jump.feature.FeatureSchema;
 import com.vividsolutions.jump.workbench.WorkbenchContext;
@@ -68,335 +65,248 @@
 import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
 import com.vividsolutions.jump.workbench.plugin.EnableCheckFactory;
 import com.vividsolutions.jump.workbench.plugin.MultiEnableCheck;
-import com.vividsolutions.jump.workbench.ui.WorkbenchToolBar;
 import com.vividsolutions.jump.workbench.ui.cursortool.NClickTool;
-import 
com.vividsolutions.jump.workbench.ui.cursortool.editing.FeatureDrawingUtil;
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 import com.vividsolutions.jump.workbench.ui.renderer.style.LabelStyle;
+
 import de.latlon.deejump.plugin.style.CrossVertexStyle;
-import java.io.IOException;
 
-public class RasterQueryCursorTool extends NClickTool 
-{
-       
-       /*
-          * Giuseppe Aruta 
-          * Simple plugin that allows to inspect raster cell value for DTM
-          * ver 0.1 2013_05_27
-          */
-       
-       
-       private FeatureDrawingUtil featureDrawingUtil;
-        public static final String LAYER_NAME 
=I18N.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.values");
-    public static final String LAYER = 
I18N.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.layer");
-        
-        private List<Coordinate> savedCoordinates = new 
ArrayList<Coordinate>();
-    private OpenJUMPSextanteRasterLayer rstLayer = null;
-       private GridWrapperNotInterpolated gwrapper = null;
-    
+public class RasterQueryCursorTool extends NClickTool {
+
+    /*
+     * [2013_05_27] Giuseppe Aruta Simple plugin that allows to inspect raster 
cell value for
+     *  DTM ver 0.1 2013_05_27
+     * 
+     * [2014_01_24] Giuseppe Aruta - Extended inspection to multiband raster
+     *  layers. Now multiple measure are displayed (and saved) by default. 
Press
+     *  SHIFT to display only last measure. Moving cursor on image shows raster
+     *  cell value on lower panel
+     */
+
+    protected Coordinate tentativeCoordinate;
+    public static final String LAYER_NAME = I18N
+            
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.cell.values");
+    public static final String LAYER = I18N
+            
.get("org.openjump.core.ui.plugin.raster.RasterImageLayerPropertiesPlugIn.layer");
+
     private String lastClick = "-";
-    private String previousClick = "-";
-    private Coordinate currCoord;
-    private String VALUE = 
I18N.get("org.openjump.core.ui.plugin.raster.RasterQueryPlugIn.value");
-    private String PREVIOUS_CLICK= 
I18N.get("org.openjump.core.ui.plugin.raster.RasterQueryPlugIn.previous.value");
-   private String INFO = 
I18N.get("org.openjump.core.ui.plugin.raster.RasterQueryPlugIn.info");
+    // protected int width, height; // The dimensions of the image
+
+    private String VALUE = I18N
+            .get("org.openjump.core.ui.plugin.raster.RasterQueryPlugIn.value");
     private String name;
-    
-    
-    
-    WorkbenchToolBar toolBar;
-    
+
     public RasterQueryCursorTool() {
-        //this.allowSnapping();
-        super (1) ;
-              
-    }
+        super(1);
 
-    
-    protected Shape getShape() throws NoninvertibleTransformException {
-               //Don't want anything to show up when the user drags. [Jon 
Aquino]
-               return null;
-       }
-    
-    public Icon getIcon() 
-    {
-         return IconLoader.icon("information_16x16.png");
-           }
-    
-    /* 
-    public Icon getIcon() 
-    {
-        return  IconLoader.icon("Raster_Info.png");
     }
 
-   
-    public Cursor getCursor() 
-    {
-        for (int i = 0; i < savedCoordinates.size(); i++)
-        {
-            add((Coordinate)savedCoordinates.get(i));
-        }
-        return 
createCursor(IconLoader.icon("Raster_Info_cursor.gif").getImage());
-        
+    public Icon getIcon() {
+        return IconLoader.icon("information_16x16.png");
     }
 
-    */
     public Cursor getCursor() {
         // [ede 03.2103] linux currently support only 2 color cursors
-        Image i = !CheckOS.isLinux() ? 
IconLoader.image("information_cursor.png")
-            : IconLoader.image("information_cursor_2color.gif");
+        Image i = !CheckOS.isLinux() ? IconLoader
+                .image("information_cursor.png") : IconLoader
+                .image("information_cursor_2color.gif");
         return createCursor(i);
-      }
+    }
 
-    public void mousePressed(MouseEvent e) 
-    {
-        super.mousePressed(e);
-        savedCoordinates = new ArrayList<Coordinate>(getCoordinates());
-    }
-    
-        
-    
-      protected void gestureFinished() throws NoninvertibleTransformException, 
IOException{
+    RasterImageLayer rLayer = (RasterImageLayer) LayerTools
+            .getSelectedLayerable(this.getWorkbench().getContext(),
+                    RasterImageLayer.class);
+
+    protected void gestureFinished() throws NoninvertibleTransformException,
+            IOException, RasterDataNotFoundException {
         reportNothingToUndoYet();
-        savedCoordinates.clear();
-        
-        //Status bar is cleared before #gestureFinished is called. So redisplay
-        //the length. [Jon Aquino]
-       
+        JTextPane txt = new JTextPane();
 
-        //-- [sstein] now all the raster profile stuff
-        RasterImageLayer rLayer = (RasterImageLayer) 
LayerTools.getSelectedLayerable(this.getWorkbench().getContext(), 
RasterImageLayer.class);        
-        if (rLayer==null){
-            
getPanel().getContext().warnUser(I18N.get("pirol.plugIns.EditAttributeByFormulaPlugIn.no-layer-selected"));
-            return;
+        RasterImageLayer rLayer = (RasterImageLayer) LayerTools
+                .getSelectedLayerable(this.getWorkbench().getContext(),
+                        RasterImageLayer.class);
+        name = rLayer.getName();
+        Coordinate coord = (Coordinate) getCoordinates().get(0);
+        String cellValues = null;
+        if (getPoint().within(rLayer.getWholeImageEnvelopeAsGeometry())) {
+            try {
+                cellValues = "";
+                for (int b = 0; b < rLayer.getNumBands(); b++) {
+                    Double cellValue = rLayer.getCellValue(coord.x, coord.y, 
b);
+                    if (cellValue != null) {
+                        if (rLayer.isNoData(cellValue)) {
+                            cellValues = Double.toString(Double.NaN);
+                        } else {
+                            cellValues = cellValues.concat(Double
+                                    .toString(cellValue));
+                        }
+                    }
+                    cellValues = cellValues.concat("  ");
+                    if (Double.isNaN(cellValue))
+                        this.lastClick = "    ";
+                    else {
+                        this.lastClick = cellValues;
+                    }
+                }
+            } catch (RasterDataNotFoundException ex) {
+                cellValues = "???";
+            }
+            Geometry measureGeometry = null;
+            if (wasShiftPressed()) {
+                pixelLayer().getFeatureCollectionWrapper().clear();
+                pixelLayer().getFeatureCollectionWrapper().add(
+                        toFeature(measureGeometry, pixelLayer()
+                                .getFeatureCollectionWrapper()
+                                .getFeatureSchema()));
+            } else {
+
+                pixelLayer().getFeatureCollectionWrapper().add(
+                        toFeature(measureGeometry, pixelLayer()
+                                .getFeatureCollectionWrapper()
+                                .getFeatureSchema()));
+            }
+            getPanel().getContext().setStatusMessage(
+                    "(" + name + ") " + VALUE + ": " + lastClick);
+        } else {
+            getPanel()
+                    .getContext()
+                    .warnUser(
+                            "Inspection outside the extension of selected 
Raster layer");
         }
-        reportNothingToUndoYet();
-    
-        
-        this.rstLayer = new OpenJUMPSextanteRasterLayer();
-        this.rstLayer.create(rLayer);
-        
+    }
 
-               
-               this.rstLayer.setFullExtent(); // not sure why this needs to be 
done but it seems to 
-                                                                          
this.rstLayer.getWindowGridExtent();
-               //-- create a gridwrapper to access the cells           
-               this.gwrapper = new GridWrapperNotInterpolated(rstLayer, 
rstLayer.getLayerGridExtent());
-        //this.calculateProfile(getCoordinates(), getWorkbench().getContext());
-        //-- this was used for testing
-        double rvalue = 0.0;
-               Coordinate startCoord = (Coordinate)getCoordinates().get(0);
-               GridCell cell = 
rstLayer.getLayerGridExtent().getGridCoordsFromWorldCoords(startCoord.x, 
startCoord.y);
-                rvalue = cell.getValue(); //can't use this, since the value 
will be zero, so I assume the cell 
-                                                                        
//object is just a place holder for the coordinates
-               
-               rvalue = gwrapper.getCellValueAsDouble(cell.getX(), 
cell.getY(), 0); //get value for first band
-       double Value = rvalue;
-       this.name =rLayer.getName();
-                 this.previousClick = this.lastClick;
-             if (Double.isNaN(rvalue))
-               this.lastClick = "    ";
-             else {
-               this.lastClick = (Double.toString(rvalue));
-             }
-                
-             
-            Geometry measureGeometry = null;  
-           if (wasShiftPressed()){
-               
pixelLayer().getFeatureCollectionWrapper().add(toFeature(measureGeometry,
-                               
pixelLayer().getFeatureCollectionWrapper().getFeatureSchema()));
-           }
-                   
-          else
-       {
-                 // In questa maniera l'oggetto precedente  รจ cancellato //
-                pixelLayer().getFeatureCollectionWrapper().clear();            
-                       
pixelLayer().getFeatureCollectionWrapper().add(toFeature(measureGeometry,
-                                       
pixelLayer().getFeatureCollectionWrapper().getFeatureSchema()));
-       }       
-        
-          getPanel().getContext().setStatusMessage("("+name+") "+VALUE+": " + 
lastClick + "   ["+PREVIOUS_CLICK+": " + previousClick + "]");
-               
-               
-               
+    private Feature toFeature(Geometry measureGeometry, FeatureSchema schema)
+            throws NoninvertibleTransformException {
+        Feature feature = new BasicFeature(pixelLayer()
+                .getFeatureCollectionWrapper().getFeatureSchema());
+        feature.setGeometry(measureGeometry);
+        feature.setAttribute("Pixel", lastClick);
+        feature.setAttribute(LAYER, name);
+        feature.setAttribute("X", new Double(getPoint().getCoordinate().x));
+        feature.setAttribute("Y", new Double(getPoint().getCoordinate().y));
+        feature.setAttribute("GEOM", getPoint());
+        return feature;
     }
-       
-      
-      private Feature toFeature(Geometry measureGeometry, FeatureSchema 
schema) throws NoninvertibleTransformException {
-       Feature feature = new 
BasicFeature(pixelLayer().getFeatureCollectionWrapper().getFeatureSchema());
-               feature.setGeometry(measureGeometry);
-          feature.setAttribute("Pixel", lastClick);
-          feature.setAttribute(LAYER, name);
-          feature.setAttribute("X",new Double(getPoint().getCoordinate().x));
-          feature.setAttribute("Y",new Double(getPoint().getCoordinate().y));
-          feature.setAttribute("GEOM", getPoint());
-               return feature;
-               }
-      
-      private Layer pixelLayer() {
-          Layer pixelLayer = getPanel().getLayerManager().getLayer(LAYER_NAME);
-         // azimuthLayer.setSelectable(true);
-         // azimuthLayer.setEditable(true);
-          if (pixelLayer != null) {
-       
-       return pixelLayer;
+
+    private Layer pixelLayer() {
+        Layer pixelLayer = getPanel().getLayerManager().getLayer(LAYER_NAME);
+        if (pixelLayer != null) {
+            return pixelLayer;
+        }
+        FeatureSchema schema = new FeatureSchema();
+        schema.addAttribute("Pixel", AttributeType.DOUBLE);
+        schema.addAttribute("X", AttributeType.DOUBLE);
+        schema.addAttribute("Y", AttributeType.DOUBLE);
+        schema.addAttribute(LAYER, AttributeType.STRING);
+        schema.addAttribute("GEOM", AttributeType.GEOMETRY);
+        new FeatureSchema();
+        new FeatureDataset(schema);
+        FeatureCollection featureCollection = new FeatureDataset(schema);
+        Layer layer;
+        boolean firingEvents = getPanel().getLayerManager().isFiringEvents();
+        getPanel().getLayerManager().setFiringEvents(false);
+        try {
+            layer = new Layer(LAYER_NAME, Color.red, featureCollection,
+                    getPanel().getLayerManager());
+            layer.removeStyle(layer.getVertexStyle());
+            layer.addStyle(new CrossVertexStyle());
+            layer.getBasicStyle().setLineColor(Color.black);
+            layer.getBasicStyle().setFillColor(Color.black);
+            layer.getBasicStyle().setLineWidth(1);
+            layer.getBasicStyle().setAlpha(255);
+            layer.getBasicStyle().setRenderingLine(true);
+            layer.getBasicStyle().setRenderingFill(false);
+            layer.getVertexStyle().setEnabled(false);
+            layer.getVertexStyle().setSize(1);
+            layer.setDrawingLast(true);
+            LabelStyle labelStyle = layer.getLabelStyle();
+            labelStyle.setAttribute("Pixel");
+            labelStyle.setVerticalAlignment(LabelStyle.ABOVE_LINE);
+            labelStyle.setHorizontalPosition(LabelStyle.RIGHT_SIDE);
+            labelStyle.setHorizontalAlignment(LabelStyle.JUSTIFY_RIGHT);
+            labelStyle.setEnabled(true);
+            labelStyle.setColor(Color.black);
+            labelStyle.setHeight(14);
+            labelStyle.setOutlineShowing(true);
+            labelStyle.setOutlineColor((Color.white));
+            labelStyle.setHidingOverlappingLabels(false);
+            labelStyle.setFont(layer.getLabelStyle().getFont()
+                    .deriveFont(Font.BOLD, 16));
+            layer.setDrawingLast(true);
+        } finally {
+            getPanel().getLayerManager().setFiringEvents(firingEvents);
+        }
+        getPanel().getLayerManager().addLayer(StandardCategoryNames.SYSTEM,
+                layer);
+        return layer;
     }
 
-     FeatureSchema schema = new FeatureSchema();
-     schema.addAttribute("Pixel", AttributeType.DOUBLE);
-     schema.addAttribute("X", AttributeType.DOUBLE);
-     schema.addAttribute("Y", AttributeType.DOUBLE);
-     schema.addAttribute(LAYER, AttributeType.STRING);
-     schema.addAttribute("GEOM", AttributeType.GEOMETRY);
-     new FeatureSchema(); 
-     new FeatureDataset(schema);
-              
-              
-              
-             // schema.addAttribute("Points", AttributeType.GEOMETRY);
-      
-          FeatureCollection featureCollection = new FeatureDataset(schema);
-          Layer layer;
-          boolean firingEvents = getPanel().getLayerManager().isFiringEvents();
-          getPanel().getLayerManager().setFiringEvents(false);
-         
-                 try {layer = new Layer(LAYER_NAME, Color.red, 
featureCollection, getPanel().getLayerManager());
-       
-                 
-                 
-                 layer.removeStyle(layer.getVertexStyle());
-                 layer.addStyle(new CrossVertexStyle());
-                  layer.getBasicStyle().setLineColor(Color.black);
-                  layer.getBasicStyle().setFillColor(Color.black);
-                  layer.getBasicStyle().setLineWidth(1);
-                  layer.getBasicStyle().setAlpha(255);
-                  layer.getBasicStyle().setRenderingLine(true);
-                  layer.getBasicStyle().setRenderingFill(false);
-                  layer.getVertexStyle().setEnabled(false);
-                  layer.getVertexStyle().setSize(1);
-                  layer.setDrawingLast(true);
-                  
-                  LabelStyle labelStyle = layer.getLabelStyle();
-                  labelStyle.setAttribute("Pixel");
-                 // labelStyle.setVerticalAlignment(LabelStyle.RIGHT_SIDE);
-                 labelStyle.setVerticalAlignment(LabelStyle.ABOVE_LINE);
-                labelStyle.setHorizontalPosition(LabelStyle.RIGHT_SIDE);
-                  labelStyle.setHorizontalAlignment(LabelStyle.JUSTIFY_RIGHT);
-                  labelStyle.setEnabled(true);
-                   labelStyle.setColor(Color.black);
-                   labelStyle.setHeight(14);
-                  labelStyle.setOutlineShowing(true);
-                  labelStyle.setOutlineColor((Color.white));
-                 //labelStyle.setOutlineWidth(1);
-                   labelStyle.setHidingOverlappingLabels(false);
-                  
labelStyle.setFont(layer.getLabelStyle().getFont().deriveFont(Font.BOLD, 16));
-                   // labelStyle.setHideAtScale(true);
-                    
-                 
-                  layer.setDrawingLast(true);
-                 
-                  
-             } finally {
-                  getPanel().getLayerManager().setFiringEvents(firingEvents);
-              }
-      
-              
getPanel().getLayerManager().addLayer(StandardCategoryNames.SYSTEM,
-                  layer);
-      
-              return layer;
-         }  
-      
-      
-      
-      protected Point getPoint()
-                       throws NoninvertibleTransformException {
-                       return new GeometryFactory().createPoint(
-                               (Coordinate)getCoordinates().get(0));
-               }
-   
-      
-        
-  /*    
-      
-    
-      public void mouseLocationChanged(MouseEvent e) 
-      {
-          try {      if (isShapeOnScreen()) {
-                  ArrayList<Coordinate> currentCoordinates = new 
ArrayList<Coordinate>(getCoordinates());
-                  
currentCoordinates.add(getPanel().getViewport().toModelCoordinate(e.getPoint()));
-                  display(currentCoordinates, getPanel());
-              }
+    protected Point getPoint() throws NoninvertibleTransformException {
+        return new GeometryFactory().createPoint((Coordinate) getCoordinates()
+                .get(0));
+    }
 
-              currCoord = snap(e.getPoint()); 
-              super.mouseLocationChanged(e);
-          } 
-          catch (Throwable t) 
-          {
-              getPanel().getContext().handleThrowable(t);
-          }
-      }
-      
-  
-      
-    
-      
-      public void mouseMoved(MouseEvent e)
-      {
-          mouseLocationChanged(e);
-      }
-      
-      private void display(List<Coordinate> coordinates, LayerViewPanel panel)
-               throws NoninvertibleTransformException 
-           {
-               display(distance(coordinates), panel);
-           }
-           
-           private void display(double distance, LayerViewPanel panel)
-           {
-               DecimalFormat df3 = new DecimalFormat("###,###,##0.0##");
-               String distString = df3.format(distance / 0.3048);
-               panel.getContext().setStatusMessage( 
-                   panel.format(distance)) ;
-           }
+    public MultiEnableCheck createEnableCheck(
+            final WorkbenchContext workbenchContext) {
+        EnableCheckFactory checkFactory = new EnableCheckFactory(
+                workbenchContext);
+        /*
+         * Works only with one selected RasterImageLayer
+         */
+        return new MultiEnableCheck()
+                .add(checkFactory
+                        .createWindowWithLayerNamePanelMustBeActiveCheck())
+                .add(checkFactory
+                        .createWindowWithLayerViewPanelMustBeActiveCheck())
+                .add(checkFactory.createExactlyNLayerablesMustBeSelectedCheck(
+                        1, RasterImageLayer.class));
 
-           
-           private double distance(List<Coordinate> coordinates) 
-           {
-               double distance = 0;
+    }
 
-               RasterImageLayer rLayer = (RasterImageLayer) 
LayerTools.getSelectedLayerable(this.getWorkbench().getContext(), 
RasterImageLayer.class);        
-                
-               reportNothingToUndoYet();
-           
-               
-               this.rstLayer = new OpenJUMPSextanteRasterLayer();
-                       this.rstLayer.create(rLayer);
-                       this.rstLayer.setFullExtent(); // not sure why this 
needs to be done but it seems to 
-                                                                               
   this.rstLayer.getWindowGridExtent();
-                       //-- create a gridwrapper to access the cells           
-                       this.gwrapper = new 
GridWrapperNotInterpolated(rstLayer, rstLayer.getLayerGridExtent());
-               //this.calculateProfile(getCoordinates(), 
getWorkbench().getContext());
-               //-- this was used for testing
-               double rvalue = 0.0;
-                       Coordinate startCoord = 
(Coordinate)getCoordinates().get(0);
-                       GridCell cell = 
rstLayer.getLayerGridExtent().getGridCoordsFromWorldCoords(startCoord.x, 
startCoord.y);
-                        rvalue = cell.getValue(); //can't use this, since the 
value will be zero, so I assume the cell 
-                                                                               
 //object is just a place holder for the coordinates
-                       rvalue = gwrapper.getCellValueAsDouble(cell.getX(), 
cell.getY(), 0); //get value for first band
-               double Value = rvalue;
+    /*
+     * TODO: if user drag on image, measures on lower panel are no more
+     * displayed. Try to find a solution
+     */
+    public void mouseDragged(MouseEvent e) {
+        // mouseLocationChanged(e);
+    }
 
-               return Value;
-           }
-    */
-   public MultiEnableCheck createEnableCheck(
-                   final WorkbenchContext workbenchContext) {
-               EnableCheckFactory checkFactory = new EnableCheckFactory(
-                       workbenchContext);
+    /*
+     * Displays cell values while moving cursor on the raster
+     */
+    public void mouseMoved(MouseEvent me) {
 
-               return new 
MultiEnableCheck().add(checkFactory.createWindowWithLayerNamePanelMustBeActiveCheck())
-                       
.add(checkFactory.createWindowWithLayerViewPanelMustBeActiveCheck())
-                       
.add(checkFactory.createExactlyNLayerablesMustBeSelectedCheck(1, 
RasterImageLayer.class));
-                                              
-           }
-     
+        String cellValues = null;
+        try {
+            cellValues = "";
+            Coordinate tentativeCoordinate = getPanel().getViewport()
+                    .toModelCoordinate(me.getPoint());
+            for (int b = 0; b < rLayer.getNumBands(); b++) {
+                Double cellValue = rLayer.getCellValue(tentativeCoordinate.x,
+                        tentativeCoordinate.y, b);
+                if (cellValue != null) {
+                    if (rLayer.isNoData(cellValue)) {
+                        cellValues = Double.toString(Double.NaN);
+                    } else {
+                        cellValues = cellValues.concat(Double
+                                .toString(cellValue));
+                    }
+                }
+                cellValues = cellValues.concat("  ");
+            }
+
+        } catch (RasterDataNotFoundException ex) {
+            cellValues = "???";
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (NoninvertibleTransformException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        name = rLayer.getName();
+
+        getPanel().getContext().setStatusMessage(
+                "(" + name + ") " + VALUE + ": " + cellValues.toString());
+    }
 }
\ No newline at end of file

Modified: 
core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryPlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryPlugIn.java    
2015-02-05 15:19:40 UTC (rev 4315)
+++ core/trunk/src/org/openjump/core/ui/plugin/raster/RasterQueryPlugIn.java    
2015-02-07 18:29:23 UTC (rev 4316)
@@ -1,4 +1,3 @@
-
 /*
  * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI 
  * for visualizing and manipulating spatial features with geometry and 
attributes.
@@ -33,11 +32,10 @@
  * www.ashs.isa.com
  */
 
-
 package org.openjump.core.ui.plugin.raster;
 
+import javax.swing.Icon;
 
-import javax.swing.Icon;
 import org.openjump.core.rasterimage.RasterImageLayer;
 
 import com.vividsolutions.jump.I18N;
@@ -49,67 +47,66 @@
 import com.vividsolutions.jump.workbench.ui.MenuNames;
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 
-public class RasterQueryPlugIn extends AbstractPlugIn
-{
-       
-       /*
-          * Giuseppe Aruta 
-          * Simple plugin that allows to inspect raster cell value for DTM
-          * ver 0.1 2013_05_27
-          */
-       
-   
-    private final static String sErrorSeeOutputWindow= 
I18N.get("org.openjump.core.ui.plugin.tools.MeasureM_FPlugIn.Error-see-output-window");
-   
-    
-    public void initialize(PlugInContext context) throws Exception
-    {    
-      
-          context.getFeatureInstaller().addMainMenuItem(
-                       this, 
-                       new String[] {MenuNames.RASTER},
-                       //new String[] {MenuNames.PLUGINS, 
I18NPlug.getI18N("RasterInfo_Extension")},  
-                       
I18N.get("org.openjump.core.ui.plugin.raster.RasterQueryPlugIn"), 
-                               false, 
-                               getIcon(),
-                               
createEnableCheck(context.getWorkbenchContext()));
-       
-   }
-    
-    public boolean execute(PlugInContext context) throws Exception
-    {
-        try
-        {
-            context.getLayerViewPanel().setCurrentCursorTool( new 
RasterQueryCursorTool());
+public class RasterQueryPlugIn extends AbstractPlugIn {
+
+    /*
+     * [2013_05_27] Giuseppe Aruta Simple plugin that allows to inspect raster 
cell value for
+     *  DTM ver 0.1 2013_05_27
+     * 
+     * [2014_01_24] Giuseppe Aruta - Extended inspection to multiband raster
+     *  layers. Now multiple measure are displayed (and saved) by default. 
Press
+     *  SHIFT to display only last measure. Moving cursor on image shows raster
+     *  cell value on lower panel
+     */
+    private final static String sErrorSeeOutputWindow = I18N
+            
.get("org.openjump.core.ui.plugin.tools.MeasureM_FPlugIn.Error-see-output-window");
+
+    public void initialize(PlugInContext context) throws Exception {
+
+        context.getFeatureInstaller()
+                .addMainMenuPlugin(
+                        this,
+                        new String[] { MenuNames.RASTER },
+                        // new String[] {MenuNames.PLUGINS,
+                        // I18NPlug.getI18N("RasterInfo_Extension")},
+                        
I18N.get("org.openjump.core.ui.plugin.raster.RasterQueryPlugIn"),
+                        false, getIcon(),
+                        createEnableCheck(context.getWorkbenchContext()));
+
+    }
+
+    public boolean execute(PlugInContext context) throws Exception {
+        try {
+
+            context.getLayerViewPanel().setCurrentCursorTool(
+                    new RasterQueryCursorTool());
             return true;
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
             e.printStackTrace();
-               context.getWorkbenchFrame().warnUser(sErrorSeeOutputWindow);
+            context.getWorkbenchFrame().warnUser(sErrorSeeOutputWindow);
             context.getWorkbenchFrame().getOutputFrame().createNewDocument();
-            
context.getWorkbenchFrame().getOutputFrame().addText("MeasureM_FPlugIn 
Exception:" + e.toString());
+            context.getWorkbenchFrame().getOutputFrame()
+                    .addText("MeasureM_FPlugIn Exception:" + e.toString());
             return false;
         }
     }
-  /* 
-    private Icon getIcon()
-    {
-        
-         return IconLoader.icon("Raster_Info.png");
-           }  
-    */
-    public Icon getIcon() 
-    {
-         return IconLoader.icon("information_16x16.png");
-           }
-    
-    
-    public MultiEnableCheck createEnableCheck(final WorkbenchContext 
workbenchContext) {
-        EnableCheckFactory checkFactory = new 
EnableCheckFactory(workbenchContext);
-        return new MultiEnableCheck()
-            .add(checkFactory.createTaskWindowMustBeActiveCheck())
-            .add(checkFactory.createAtLeastNLayerablesMustBeSelectedCheck(1, 
RasterImageLayer.class));
+
+    /*
+     * private Icon getIcon() {
+     * 
+     * return IconLoader.icon("Raster_Info.png"); }
+     */
+    public Icon getIcon() {
+        return IconLoader.icon("grid_info.png");
     }
+
+    public MultiEnableCheck createEnableCheck(
+            final WorkbenchContext workbenchContext) {
+        EnableCheckFactory checkFactory = new EnableCheckFactory(
+                workbenchContext);
+        return new MultiEnableCheck().add(
+                checkFactory.createTaskWindowMustBeActiveCheck()).add(
+                checkFactory.createAtLeastNLayerablesMustBeSelectedCheck(1,
+                        RasterImageLayer.class));
+    }
 }
-


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to