dods.clients.importwizard.TMAP.map
Class MapGrid

java.lang.Object
  extended by dods.clients.importwizard.TMAP.map.MapGrid
All Implemented Interfaces:
MapConstants

public class MapGrid
extends Object
implements MapConstants

A grid for use with the MapCanvas.

A MapGrid contains all the information for the conversion of pixels to user values and vice versa. Associating a grid with a map also allows MapTools to work in snap-to-grid mode. version 2.3, 23 Jun 1997

Version:
3.0, 16 Nov 1999
Author:
Jonathan Callahan (NOAA/OAR/PMEL/TMAP)

Field Summary
 double delta_X
          The grid spacing (in "user" coordinates) in the x dimension.
 double delta_Y
          The grid spacing (in "user" coordinates) in the y dimension.
 double[] domain_X
          The data domain along X [in user coordinates].
 double[] domain_Y
          The data domain along Y [in user coordinates].
 Rectangle imageRect
          The rectangle (in pixels) of the base image.
 boolean modulo_X
          Flag determining whether the X axis is modulo or not (eg. longitude).
 double x_factor
          Full "user" domain of x in the base image.
 double x_start
          "user" value of the leftmost pixel in the base image.
 int x_type
          The X axis type.
 double y_factor
          Full "user" domain of y in the base image.
 double y_start
          "user" value of the topmost pixel in the base image.
 int y_type
          The Y axis type.
 
Fields inherited from interface dods.clients.importwizard.TMAP.map.MapConstants
DEPTH_AXIS, HEIGHT_AXIS, HI, LATITUDE_AXIS, LO, LONGITUDE_AXIS, MID, PT, SNAP_MID, SNAP_ON, TIME_AXIS
 
Constructor Summary
MapGrid()
          Constructs a new MapGrid.
MapGrid(double x_lo, double x_hi, double y_lo, double y_hi)
          Constructs and initializes a MapGrid with the specified parameters.
 
Method Summary
 double getDelta_X()
          Gets delta_X which is used in grid snapping.
 double getDelta_Y()
          Gets delta_Y which is used in grid snapping.
 double pixelToUser_X(int pixel_x)
          Converts a pixel value into a "user" value.
 double pixelToUser_Y(int pixel_y)
          Converts a pixel value into a "user" value.
 int rangeToPixels_X(double range_x)
          Converts a "user" range along X to a width in pixels.
 int rangeToPixels_Y(double range_y)
          Converts a "user" range along Y to a width in pixels.
 void setCanvasWidth(int width)
          Sets canvasWidth.
 void setDelta_X(double delta)
          Sets delta_X which is used in grid snapping.
 void setDelta_Y(double delta)
          Sets delta_Y which is used in grid snapping.
 void setDomain_X(double lo, double hi)
          Sets the domain of X of the grid (in "user" coordinates).
 void setDomain_Y(double lo, double hi)
          Sets the domain of Y of the grid (in "user" coordinates).
 int snap_X(int pixel_x, int style)
          Returns the X pixel value nearest the closest X grid point.
 int snap_X(int pixel_x, int style, int shift)
          Returns the X pixel value nearest the closest X grid point.
 int snap_Y(int pixel_y, int style)
          Returns the Y pixel value nearest the closest Y grid point.
 int snap_Y(int pixel_y, int style, int shift)
          Returns the Y pixel value nearest the closest Y grid point.
 double snapUser_X(double user_x, int style)
          Returns the X "user" value nearest the closest X grid point.
 double snapUser_X(double user_x, int style, int shift)
          Returns the X "user" value nearest the closest X grid point.
 double snapUser_Y(double user_y, int style)
          Returns the Y "user" value nearest the closest Y grid point.
 double snapUser_Y(double user_y, int style, int shift)
           
 int userToPixel_X(double user_x)
          Converts a "user" value into a pixel value.
 int userToPixel_Y(double user_y)
          Converts a "user" value into a pixel value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

domain_X

public double[] domain_X
The data domain along X [in user coordinates].


domain_Y

public double[] domain_Y
The data domain along Y [in user coordinates].


x_start

public double x_start
"user" value of the leftmost pixel in the base image.


y_start

public double y_start
"user" value of the topmost pixel in the base image.


x_factor

public double x_factor
Full "user" domain of x in the base image.


y_factor

public double y_factor
Full "user" domain of y in the base image.


delta_X

public double delta_X
The grid spacing (in "user" coordinates) in the x dimension.


delta_Y

public double delta_Y
The grid spacing (in "user" coordinates) in the y dimension.


x_type

public int x_type
The X axis type.

See Also:
MapConstants

y_type

public int y_type
The Y axis type.

See Also:
MapConstants

modulo_X

public boolean modulo_X
Flag determining whether the X axis is modulo or not (eg. longitude).


imageRect

public Rectangle imageRect
The rectangle (in pixels) of the base image. This is a reference to the imageRect in the MapCanvas and will be updated by zoom/pan/scrolling.

Do not alter this property inside of MapGrid.java!

Constructor Detail

MapGrid

public MapGrid()
Constructs a new MapGrid.


MapGrid

public MapGrid(double x_lo,
               double x_hi,
               double y_lo,
               double y_hi)
Constructs and initializes a MapGrid with the specified parameters.

Parameters:
x_lo - the "user" value of the low end of the data domain along x.
x_hi - the "user" value of the high end of the data domain along x.
y_lo - the "user" value of the low end of the data domain along y.
y_hi - the "user" value of the high end of the data domain along y. The data domain is that region represented by the underlying base image.
Method Detail

setCanvasWidth

public void setCanvasWidth(int width)
Sets canvasWidth.

Parameters:
width - the width associated with the MapCanvas.

setDomain_X

public void setDomain_X(double lo,
                        double hi)
Sets the domain of X of the grid (in "user" coordinates). This should coincide with the domain specified by the underlying basemap in MapCanvas.

Parameters:
lo - the "user" value of the low end of the data domain along X.
hi - the "user" value of the high end of the data domain along X. A default delta_X will be calculated. This is overridden by the tool whenever MapTool.setDelta_X() is used to assign a specific delta_X to a tool.

setDomain_Y

public void setDomain_Y(double lo,
                        double hi)
Sets the domain of Y of the grid (in "user" coordinates). This should coincide with the domain specified by the underlying basemap in MapCanvas.

Parameters:
lo - the "user" value of the low end of the data domain along Y.
hi - the "user" value of the high end of the data domain along Y. A default delta_Y will be calculated. This is overridden by the tool whenever MapTool.setDelta_Y() is used to assign a specific delta_Y to a tool.

setDelta_X

public void setDelta_X(double delta)
Sets delta_X which is used in grid snapping.

Parameters:
delta - the "user" spacing of grid cells along the X axis.

getDelta_X

public double getDelta_X()
Gets delta_X which is used in grid snapping.


setDelta_Y

public void setDelta_Y(double delta)
Sets delta_Y which is used in grid snapping.

Parameters:
delta - the "user" spacing of grid cells along the Y axis.

getDelta_Y

public double getDelta_Y()
Gets delta_Y which is used in grid snapping.


pixelToUser_X

public double pixelToUser_X(int pixel_x)
Converts a pixel value into a "user" value.

Parameters:
pixel_x - the X value in pixels.
Returns:
a "user" X value associated with the input.

userToPixel_X

public int userToPixel_X(double user_x)
Converts a "user" value into a pixel value.

Parameters:
user_x - the X value in "user" units.
Returns:
a pixel X value associated with the input.

rangeToPixels_X

public int rangeToPixels_X(double range_x)
Converts a "user" range along X to a width in pixels.

Parameters:
range_x - a "user" range.
Returns:
pixels the equivalent value in pixels.

snap_X

public int snap_X(int pixel_x,
                  int style)
Returns the X pixel value nearest the closest X grid point.

Parameters:
pixel_x - the current X position in pixels.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
Returns:
a new X position in pixels.

snap_X

public int snap_X(int pixel_x,
                  int style,
                  int shift)
Returns the X pixel value nearest the closest X grid point.

Parameters:
pixel_x - the current mouse X position.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
shift - number of grid cells to shift the result
Returns:
a new X position in pixels.

snapUser_X

public double snapUser_X(double user_x,
                         int style)
Returns the X "user" value nearest the closest X grid point.

Parameters:
user_x - the "user" X position.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
Returns:
a new value for user_x.

snapUser_X

public double snapUser_X(double user_x,
                         int style,
                         int shift)
Returns the X "user" value nearest the closest X grid point.

Parameters:
user_x - the "user" X position.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
shift - number of grid cells to shift the result
Returns:
a new value for user_x.

pixelToUser_Y

public double pixelToUser_Y(int pixel_y)
Converts a pixel value into a "user" value. (Note that pixel values increase from top to bottom, whereas user values increase from bottom to top.)

Parameters:
pixel_y - the pixel's y value.
Returns:
a "user" Y value associated with the input.

userToPixel_Y

public int userToPixel_Y(double user_y)
Converts a "user" value into a pixel value. (Note that pixel values increase from top to bottom, whereas user values increase from bottom to top.)

Parameters:
user_y - the "user" y value.
Returns:
a pixel Y value associated with the input.

rangeToPixels_Y

public int rangeToPixels_Y(double range_y)
Converts a "user" range along Y to a width in pixels.

Parameters:
range_y - a "user" range.
Returns:
pixels the equivalent value in pixels.

snap_Y

public int snap_Y(int pixel_y,
                  int style)
Returns the Y pixel value nearest the closest Y grid point.

Parameters:
pixel_y - the current Y position in pixels.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
Returns:
a new Y position in p ixels.

snap_Y

public int snap_Y(int pixel_y,
                  int style,
                  int shift)
Returns the Y pixel value nearest the closest Y grid point.

Parameters:
pixel_y - the current mouse Y position.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
shift - number of grid cells to shift the result
Returns:
a new Y position in pixels.

snapUser_Y

public double snapUser_Y(double user_y,
                         int style)
Returns the Y "user" value nearest the closest Y grid point.

Parameters:
user_y - the "user" Y position.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
Returns:
a new Y position in p ixels.

snapUser_Y

public double snapUser_Y(double user_y,
                         int style,
                         int shift)
Parameters:
user_y - the "user" Y position.
style - which nearby gridpoint to snap to [SNAP_ON, SNAP_MID]
shift - number of grid cells to shift the result
Returns:
a new value for user_y.