dods.clients.importwizard.TMAP.map
Class MapTool

java.lang.Object
  extended by java.awt.geom.RectangularShape
      extended by java.awt.geom.Rectangle2D
          extended by java.awt.Rectangle
              extended by dods.clients.importwizard.TMAP.map.MapTool
All Implemented Interfaces:
MapConstants, Shape, Serializable, Cloneable
Direct Known Subclasses:
PTTool, XTool, XYTool, YTool

public abstract class MapTool
extends Rectangle
implements MapConstants

A rectangular map tool defined by x, y, width and height. This abstract superclass defines a rectangular tool with nine ToolHandles (small rectangles) which allow reshaping and repositioning of the tool on a MapCanvas. The abstract method which makes this class abstract is the draw(Graphics g) method.

Version:
3.0 Sept 09 1999
Author:
Jonathan Callahan
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.geom.Rectangle2D
Rectangle2D.Double, Rectangle2D.Float
 
Field Summary
protected  boolean active
          Returns true if the tool is "active".
protected  boolean bottom_edge_scroll
           
protected  Rectangle boundingRect
          The bounding rectangle in which this tool moves freely.
protected  Rectangle canvas_clipRect
          The area of the map canvas occupied by the map.
protected  Color color
          The color of the tool.
 double delta_X
          Delta for this tool in "user" values.
 double delta_Y
          Delta for this tool in "user" values.
protected  boolean drawHandles
          Whether the tool handles should be drawn or not.
 MapGrid grid
          The grid on which this tool acts.
protected  ToolHandle[] handle
          The array of handles for this tool.
protected  boolean left_edge_scroll
           
protected  int mouseDownHandle
          The handle type to return when mouseDown doesn't activate one of the handles.
 boolean needsRange_X
          Whether or not the tool should always have a range of values along the X axis.
 boolean needsRange_Y
          Whether or not the tool should always have a range of values along the Y axis.
protected  int numHandles
          The number of handles in this tool.
 double[] range_X
          Range for this tool in "user" values.
 double[] range_Y
          Range for this tool in "user" values.
protected  boolean right_edge_scroll
           
protected  boolean snap_X
          Whether the tool snaps to the underlying grid or not.
protected  boolean snap_Y
          Whether the tool snaps to the underlying grid or not.
protected  boolean top_edge_scroll
           
 double[] user_X
          Current "user" values for the left, middle and right edges of this tool.
 double[] user_Y
          Current "user" values for the bottom, middle and top edges of this tool.
 
Fields inherited from class java.awt.Rectangle
height, width, x, y
 
Fields inherited from class java.awt.geom.Rectangle2D
OUT_BOTTOM, OUT_LEFT, OUT_RIGHT, OUT_TOP
 
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
MapTool()
          Constructs a new MapTool.
MapTool(Dimension d, Color color)
          Constructs a MapTool and initializes it with the specified parameters.
MapTool(int width, int height, Color color)
          Constructs a MapTool and initializes it with the specified parameters.
MapTool(int x, int y, int width, int height, Color color)
          Constructs and initializes a MapTool with the specified parameters.
MapTool(Point p, Color color)
          Constructs a MapTool and initializes it with the specified parameters.
MapTool(Point p, Dimension d, Color color)
          Constructs a MapTool and initializes it with a specified parameters.
MapTool(Rectangle rect, Color color)
          Constructs a MapTool and initializes it with the specified parameters.
 
Method Summary
 void adjustWidthHeight()
          Adjust the width or height for those tools which don't specify an extent of width or height.
 void applyClipRect(int c_r_x, int c_r_y, int c_r_width, int c_r_height)
          Sets the bounding rectangle for this tool.
 void applyClipRect(Rectangle rect)
          Applies the canvas_clipRect after potential scrolling so that a new boundingRect can be calculated for this tool.
 void bump_against_sides(int mouse_x, int mouse_y)
          Allows movement of the tool within the bounding rectangle specified in applyClipRect().
protected  int check_for_zero_range()
          Checks to make sure that tools which require ranges along X or Y do indeed describe.
abstract  void draw(Graphics g)
          Draws a MapTool.
 Color getColor()
          Gets the color for this tool.
 double getDelta_X()
          Gets delta_X for this tool.
 double getDelta_Y()
          Gets delta_Y for this tool.
 MapGrid getGrid()
          Returns the grid on which this tool acts.
 Rectangle getRectangle()
          Gets the rectangle for this tool.
 boolean getSnap_X()
          Gets snap_X for this tool.
 boolean getSnap_Y()
          Gets snap_Y for this tool.
 void handle_reshape(int mouse_x, int mouse_y)
          Reshapes the tool.
 void intersect(int x, int y, int width, int height)
          Resizes the tool to the intersection of the current tool rectangle and the specified rectangle.
 boolean is_active()
          Returns the state of the tool.
 void mouseDown(int mouse_x, int mouse_y)
          Notifies tool of a mouseDown event.
 void mouseDrag(int mouse_x, int mouse_y)
          Notifies tool of a mouseDrag event.
 int mouseMove(int mouse_x, int mouse_y)
          Notifies tool of a mouseMove event.
 void mouseUp(int mouse_x, int mouse_y)
          Notifies tool of a mouseUp event.
protected  void saveHandles()
          Saves the current positions of all the handles.
 void setBounds(int x, int y, int width, int height)
          Reshapes the tool using pixel values
 void setBounds(Rectangle rect)
          Reshapes the tool using a rectangle specified in pixel values
 void setColor(Color color)
          Sets the color for this tool.
 void setDelta_X(double delta)
          Sets delta_X for this tool in "user" coordinates.
 void setDelta_Y(double delta)
          Sets delta_Y for this tool in "user" coordinates.
 void setGrid(MapGrid grid)
          Sets the grid on which this tool acts.
 void setLocation(int x, int y)
          Moves the tool to a new x, y location interpreting x and y as pixels.
 void setRange_X(double lo, double hi)
          Sets the X range of this tool in "user" coordinates.
 void setRange_Y(double lo, double hi)
          Sets the Y range of this tool in "user" coordinates.
 void setSnapping(boolean snap_X, boolean snap_Y)
          Sets the "snap to grid" state.
 void setUser_X()
          Sets the user_X values for this tool.
 void setUser_X(double lo, double hi)
          Sets the user_X values for this tool.
 void setUser_XY()
          Sets the user_X/Y values for this tool.
 void setUser_XY(double Xlo, double Xhi, double Ylo, double Yhi)
          Sets the user_X/Y values for this tool.
 void setUser_Y()
          Sets the user_Y values for this tool.
 void setUser_Y(double lo, double hi)
          Sets the user_Y values for this tool.
 void setUserBounds(double left, double right, double bottom, double top)
          Reshapes the tool using user values
 void setUserLocation(double x, double y)
          Moves the tool to a new x, y location interpreting x and y as user values on this tools grid.
 String toString()
          Returns the String representation of the tool's values.
 
Methods inherited from class java.awt.Rectangle
add, add, add, contains, contains, contains, contains, createIntersection, createUnion, equals, getBounds, getBounds2D, getHeight, getLocation, getSize, getWidth, getX, getY, grow, inside, intersection, intersects, isEmpty, move, outcode, reshape, resize, setLocation, setRect, setSize, setSize, translate, union
 
Methods inherited from class java.awt.geom.Rectangle2D
add, add, add, contains, contains, getPathIterator, getPathIterator, hashCode, intersect, intersects, intersectsLine, intersectsLine, outcode, setFrame, setRect, union
 
Methods inherited from class java.awt.geom.RectangularShape
clone, contains, contains, getCenterX, getCenterY, getFrame, getMaxX, getMaxY, getMinX, getMinY, intersects, setFrame, setFrame, setFrameFromCenter, setFrameFromCenter, setFrameFromDiagonal, setFrameFromDiagonal
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.Shape
contains, contains, contains, contains, getPathIterator, getPathIterator, intersects, intersects
 

Field Detail

left_edge_scroll

protected boolean left_edge_scroll

right_edge_scroll

protected boolean right_edge_scroll

top_edge_scroll

protected boolean top_edge_scroll

bottom_edge_scroll

protected boolean bottom_edge_scroll

user_X

public double[] user_X
Current "user" values for the left, middle and right edges of this tool.

Access these values with LO, MID or HI as in: user_X[LO].
DO NOT SET THESE VALUES. They should only be read.


user_Y

public double[] user_Y
Current "user" values for the bottom, middle and top edges of this tool.

Access these values with LO, MID or HI as in: user_Y[LO].
DO NOT SET THESE VALUES. They should only be read.


range_X

public double[] range_X
Range for this tool in "user" values. The tool will be restricted to movement within this range.

Access these values with LO or HI as in: range_X[LO].


range_Y

public double[] range_Y
Range for this tool in "user" values. The tool will be restricted to movement within this range.

Access these values with LO or HI as in: range_Y[LO].


delta_X

public double delta_X
Delta for this tool in "user" values. This determins the grid spacing for this tool along the X axis and is used for grid snapping. A value of 0.0 tells the MapCanvas to use the default value calculated by MapGrid.setDomain_X.


delta_Y

public double delta_Y
Delta for this tool in "user" values. This determins the grid spacing for this tool along the Y axis and is used for grid snapping. A value of 0.0 tells the MapCanvas to use the default value calculated by MapGrid.setDomain_Y.


drawHandles

protected boolean drawHandles
Whether the tool handles should be drawn or not.


snap_X

protected boolean snap_X
Whether the tool snaps to the underlying grid or not.


snap_Y

protected boolean snap_Y
Whether the tool snaps to the underlying grid or not.


needsRange_X

public boolean needsRange_X
Whether or not the tool should always have a range of values along the X axis.


needsRange_Y

public boolean needsRange_Y
Whether or not the tool should always have a range of values along the Y axis.


grid

public MapGrid grid
The grid on which this tool acts. This is just a reference to the MapGrid associated with the MapCanvas.


boundingRect

protected Rectangle boundingRect
The bounding rectangle in which this tool moves freely. The boundingRect is the intersection of the canvas_clipRect and the tool X and Y ranges. The boundingRect defines the area of free movement before the tool either 1) bumps against a side or 2) causes the image to scroll.


canvas_clipRect

protected Rectangle canvas_clipRect
The area of the map canvas occupied by the map. The bounding rectangle will be some rectangular subset of this area.


color

protected Color color
The color of the tool.


active

protected boolean active
Returns true if the tool is "active". An "active" tool is one that is currently being dragged or resized by the mouse.


handle

protected ToolHandle[] handle
The array of handles for this tool.


numHandles

protected int numHandles
The number of handles in this tool.


mouseDownHandle

protected int mouseDownHandle
The handle type to return when mouseDown doesn't activate one of the handles.(eg. NW).

Constructor Detail

MapTool

public MapTool()
Constructs a new MapTool.


MapTool

public MapTool(int x,
               int y,
               int width,
               int height,
               Color color)
Constructs and initializes a MapTool with the specified parameters.

Parameters:
x - the x coordinate
y - the y coordinate
width - the width of the MapTool
height - the height of the MapTool
color - the color of the MapTool

MapTool

public MapTool(Rectangle rect,
               Color color)
Constructs a MapTool and initializes it with the specified parameters.

Parameters:
rect - the rectangle of the MapTool
color - the color of the MapTool

MapTool

public MapTool(int width,
               int height,
               Color color)
Constructs a MapTool and initializes it with the specified parameters.

Parameters:
width - the width of the MapTool
height - the height of the MapTool
color - the color of the MapTool

MapTool

public MapTool(Point p,
               Dimension d,
               Color color)
Constructs a MapTool and initializes it with a specified parameters.

Parameters:
p - the point
d - dimension
color - the color of the MapTool

MapTool

public MapTool(Point p,
               Color color)
Constructs a MapTool and initializes it with the specified parameters.

Parameters:
p - the value of the x and y coordinate
color - the color of the MapTool

MapTool

public MapTool(Dimension d,
               Color color)
Constructs a MapTool and initializes it with the specified parameters.

Parameters:
d - the value of the width and height
color - the color of the MapTool
Method Detail

toString

public String toString()
Returns the String representation of the tool's values.

Overrides:
toString in class Rectangle

is_active

public boolean is_active()
Returns the state of the tool.

Returns:
the state of the tool.

setSnapping

public void setSnapping(boolean snap_X,
                        boolean snap_Y)
Sets the "snap to grid" state. When snap_X or snap_Y is true, MapTools will snap to gridpoints along these axes where gridpoints are defined by the MapGrid associated with the MapCanvas.

Parameters:
snap_X - whether snapping is in effect for the X axis.
snap_Y - whether snapping is in effect for the Y axis.

getSnap_X

public boolean getSnap_X()
Gets snap_X for this tool.


getSnap_Y

public boolean getSnap_Y()
Gets snap_Y for this tool.


getGrid

public MapGrid getGrid()
Returns the grid on which this tool acts.

Returns:
the MapGrid on which this tool acts.

setGrid

public void setGrid(MapGrid grid)
Sets the grid on which this tool acts.

Parameters:
new_grid - the new grid

setRange_X

public void setRange_X(double lo,
                       double hi)
Sets the X range of this tool in "user" coordinates.

Note: If you wish to use setRange_X() to restrict the movement of the tool then you must set modulo_X = false in the associated MapGrid. Otherwise the mapGrid boundingRect restricting the tool's movement will default to the entire globe.

Parameters:
lo - the "user" value of the low end of the data range along X.
hi - the "user" value of the high end of the data range along X.

setRange_Y

public void setRange_Y(double lo,
                       double hi)
Sets the Y range of this tool in "user" coordinates.

Parameters:
lo - the "user" value of the low end of the data range along Y.
hi - the "user" value of the highe end of the data range along Y.

setDelta_X

public void setDelta_X(double delta)
Sets delta_X for this tool in "user" coordinates. This delta_X value will override the default value calculated in MapGrid.setDomain_X.

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

getDelta_X

public double getDelta_X()
Gets delta_X for this tool.


setDelta_Y

public void setDelta_Y(double delta)
Sets delta_Y for this tool in "user" coordinates. This delta_X value will override the default value calculated in MapGrid.setDomain_Y.

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

getDelta_Y

public double getDelta_Y()
Gets delta_Y for this tool.


intersect

public void intersect(int x,
                      int y,
                      int width,
                      int height)
Resizes the tool to the intersection of the current tool rectangle and the specified rectangle.

Parameters:
x - the x location in pixels
y - the y location in pixels
width - the width in pixels
height - the height in pixels
See Also:
Rectangle

setLocation

public void setLocation(int x,
                        int y)
Moves the tool to a new x, y location interpreting x and y as pixels.

Overrides:
setLocation in class Rectangle
Parameters:
x - the x location in pixels
y - the y location in pixels
See Also:
Rectangle

setUserLocation

public void setUserLocation(double x,
                            double y)
Moves the tool to a new x, y location interpreting x and y as user values on this tools grid.

Parameters:
x - the x location in user values
y - the y location in user values
See Also:
// JC_TODO: This method should do the same checks found in // JC_TODO: setUserBounds().

setBounds

public void setBounds(Rectangle rect)
Reshapes the tool using a rectangle specified in pixel values

Overrides:
setBounds in class Rectangle
Parameters:
rect - a rectangle specified in pixels
See Also:
Rectangle

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
Reshapes the tool using pixel values

Overrides:
setBounds in class Rectangle
Parameters:
x - the x location in pixels
y - the y location in pixels
width - the width in pixels
height - the height in pixels
See Also:
Rectangle

setUserBounds

public void setUserBounds(double left,
                          double right,
                          double bottom,
                          double top)
Reshapes the tool using user values

Parameters:
left - the left in user values
right - the right in user values
bottom - the bottom location in user values
top - the top location in user values
See Also:
This method of reshaping the tool does checks against the tool's associated grid to make sure the tool stays within the range and domain.

getColor

public Color getColor()
Gets the color for this tool.

Returns:
the Color of this tool.

setColor

public void setColor(Color color)
Sets the color for this tool.

Parameters:
color - the Color of this tool.

getRectangle

public Rectangle getRectangle()
Gets the rectangle for this tool.

Returns:
the Rectangle of this tool.

saveHandles

protected void saveHandles()
Saves the current positions of all the handles.


check_for_zero_range

protected int check_for_zero_range()
Checks to make sure that tools which require ranges along X or Y do indeed describe.


applyClipRect

public void applyClipRect(Rectangle rect)
Applies the canvas_clipRect after potential scrolling so that a new boundingRect can be calculated for this tool.

Parameters:
rect - the MapCanvas clipRect rectangle.

applyClipRect

public void applyClipRect(int c_r_x,
                          int c_r_y,
                          int c_r_width,
                          int c_r_height)
Sets the bounding rectangle for this tool. MapTools are always constrained to remain within the bounding rectangle. This behavior allows for a tool to be used to select data within a specified range which may be smaller than the domain represented by the base image used in the MapCanvas.

Parameters:
c_r_x - the x coordinate of the boundingRect
c_r_y - the y coordinate of the boundingRect
c_r_width - the width of the boundingRect.
c_r_height - the height of the boundingRect.

handle_reshape

public void handle_reshape(int mouse_x,
                           int mouse_y)
Reshapes the tool.

Parameters:
mouse_x - new mouse X position for one of the handles
mouse_y - new mouse Y position for one of the handles

setUser_XY

public void setUser_XY()
Sets the user_X/Y values for this tool.


setUser_XY

public void setUser_XY(double Xlo,
                       double Xhi,
                       double Ylo,
                       double Yhi)
Sets the user_X/Y values for this tool.


setUser_X

public void setUser_X()
Sets the user_X values for this tool.


setUser_Y

public void setUser_Y()
Sets the user_Y values for this tool.


setUser_X

public void setUser_X(double lo,
                      double hi)
Sets the user_X values for this tool.

Parameters:
lo - the lower value in "user" units.
hi - the higher value in "user" units. This method sets the user values directly rather than going through the interpolation in the tool. Whenever map.reshape_tool() or map.center_tool() is called, this method should be used because we don't want to allow the possibility of the grid altering the user values simply because the image has fewer pixels than grid points.

setUser_Y

public void setUser_Y(double lo,
                      double hi)
Sets the user_Y values for this tool.

Parameters:
lo - the lower value in "user" units.
hi - the higher value in "user" units. This method sets the user values directly rather than going through the interpolation in the tool. Whenever map.reshape_tool() or map.center_tool() is called, this method should be used because we don't want to allow the possibility of the grid altering the user values simply because the image has fewer pixels than grid points.

adjustWidthHeight

public void adjustWidthHeight()
Adjust the width or height for those tools which don't specify an extent of width or height. XTool, YTool, PTTool and decendents retain a width and height but these may need to be adjusted as the tool is moved near the sides.


draw

public abstract void draw(Graphics g)
Draws a MapTool. This is the abstract method which makes this class abstract.

Parameters:
g - the graphics context for the drawing operation.

mouseMove

public int mouseMove(int mouse_x,
                     int mouse_y)
Notifies tool of a mouseMove event. Returns Frame.MOVE_CURSOR if the mouse moves of the center tool handle.

Parameters:
mouse_x - current mouse X
mouse_y - current mouse Y
Returns:
the type of cursor to display.

mouseDown

public void mouseDown(int mouse_x,
                      int mouse_y)
Notifies tool of a mouseDown event.

Parameters:
mouse_x - current mouse X
mouse_y - current mouse Y

mouseDrag

public void mouseDrag(int mouse_x,
                      int mouse_y)
Notifies tool of a mouseDrag event.

Parameters:
mouse_x - current mouse X
mouse_y - current mouse Y

mouseUp

public void mouseUp(int mouse_x,
                    int mouse_y)
Notifies tool of a mouseUp event.

Parameters:
x - current mouseX
y - current mouseY

bump_against_sides

public void bump_against_sides(int mouse_x,
                               int mouse_y)
Allows movement of the tool within the bounding rectangle specified in applyClipRect().

Parameters:
x - current mouseX
y - current mouseY