net.refractions.udig.tools.edit.support
Class EditBlackboard

java.lang.Object
  extended by net.refractions.udig.tools.edit.support.EditBlackboard

public class EditBlackboard
extends java.lang.Object

Maps between each pixel to a list of coordinates. Also provides convenience methods to move all coordinates at a location

Author:
jeichar

Field Summary
protected  java.util.Map<Point,java.util.List<LazyCoord>> coordMapping
           
 
Constructor Summary
EditBlackboard(int width, int height, java.awt.geom.AffineTransform toScreen, MathTransform layerToMap)
          Creates a PixelCoordMap.
 
Method Summary
 Point addCoordinate(Coordinate coord, PrimitiveShape shape)
           
 java.util.Map<Geometry,EditGeom> addGeometry(Geometry geom, java.lang.String featureID)
          Adds a Geometry to the contained geometries.
 Coordinate addPoint(int x, int y, PrimitiveShape shape)
          Adds a Coordinate at the x,y location on the screen to the end of the geomtry.
 java.util.List<ClosestEdge> addToNearestEdge(int x, int y, boolean treatUnknownAsPolygon)
          Adds a Coordinate the nearest edge .
 ClosestEdge addToNearestEdge(int x, int y, EditGeom geom, boolean treatUnknownAsPolygon)
          Adds a Coordinate the nearest edge .
 void clear()
          Removes all EditGeometries from blackboard and places an empty one on the black board.
 boolean contains(java.lang.String fid)
          Returns true if the blackboard currently holds the noted feature ID.
 void fireBatchedEvents()
          Fires all the batched events and resets the EditBlackboard so that it no longer batches events.
 java.util.List<ClosestEdge> getCandidates(int x, int y, boolean treatUnknownAsPolygon)
          Returns the GeomShapes that will have the coordinate added if #addToNearestEdge(int, int) is called.
 java.util.List<Coordinate> getCoords(int x, int y)
          returns the list of coordinates at location:(x,y) TREAT COORDINATES AS IMMUTABLE!!
 java.util.List<EditGeom> getGeoms()
          The list of geometries mapped.
 java.util.List<EditGeom> getGeoms(int x, int y)
          Returns a list of the geometries with vertices at the position (x,y).
 int getHeight()
           
 java.util.Set<EditBlackboardListener> getListeners()
          Returns the list of Listeners so that listeners can be added and removed.
 Selection getSelection()
           
 int getWidth()
           
 Coordinate insertCoord(int x, int y, int pointIndex, PrimitiveShape shape)
          Adds a Coordinate at the index indicated.
 Point insertCoordinate(Coordinate coord, int index, PrimitiveShape shape)
           
 void insertCoords(int pointIndex, Point p, java.util.List<Coordinate> coords, PrimitiveShape shape)
          Inserts the list of coordinates into the shape at the index indicated.
 boolean isCollapseVertices()
           
 java.util.List<Coordinate> moveCoords(int x, int y, int endX, int endY)
          Moves all the coordinates at location by an offset of (deltaX, deltaY).
 void moveSelection(int diffX, int diffY, Selection selection)
          Moves the selection
 EditGeom newGeom(java.lang.String featureId, ShapeType type)
          Creates a new EditGeom in the map.
 Point overVertex(Point location, int radius)
          Returns the point closest to location.
 Point overVertex(Point location, int radius, boolean ignore)
          Returns the point closest to location.
 void removeCoordinate(int pointIndex, Coordinate coord, PrimitiveShape shape)
          Removes a coordinate from the shape.
 void removeCoords(int x, int y, PrimitiveShape shape)
          Deletes the coordinates at the provided point in the provided shape.
 java.util.List<Coordinate> removeCoordsAtPoint(int x, int y)
          Deletes all the coordinates at a location TREAT COORDINATES AS IMMUTABLE!!
 java.util.List<EditGeom> removeGeometries(java.util.Collection<EditGeom> geomsToRemove)
          Removes all the geometries in the list from the blackboard and all the coordinates in the geometries
 boolean selectionAdd(Point point)
           
 boolean selectionAddAll(java.util.Collection<Point> points)
           
 void selectionClear()
           
 boolean selectionRemove(Point point)
           
 boolean selectionRemoveAll(java.util.Collection<Point> points)
           
 boolean selectionRetainAll(java.util.Collection<Point> points)
           
 void setCollapseVertices(boolean collapseVertices)
           
 void setCoords(Point point, Coordinate newValue)
          Sets all the coordinates at the point to provided coordinate.
 java.util.Map<Geometry,EditGeom> setGeometries(Geometry geom, java.lang.String featureId)
          Adds a Geometry to the contained geometries.
 void setHeight(int height)
           
 void setMapLayerTransform(MathTransform mapToLayer)
           
 void setToScreenTransform(java.awt.geom.AffineTransform newToScreen)
          Modifies the mapping of points to coordinates so that the transform passed in as a parameter is the new toScreen transform.
 void setWidth(int width)
           
 void startBatchingEvents()
          Changes the behaviour of the EditBlackboard so that events are not fired but batched together until fireBatchedEvents() is called.
 Coordinate toCoord(Point point)
           
 Point toPoint(Coordinate coord)
          Transforms a Coordinate into the point location it would occupy on the screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

coordMapping

protected java.util.Map<Point,java.util.List<LazyCoord>> coordMapping
Constructor Detail

EditBlackboard

public EditBlackboard(int width,
                      int height,
                      java.awt.geom.AffineTransform toScreen,
                      MathTransform layerToMap)
Creates a PixelCoordMap. A default GeomShape will be created and can be obtained by getGeoms().get(0)

Parameters:
width - width of the current ViewportPane
height - height of the current ViewportPane
toScreen - transform to take the coordinates to a screen location.
layerToMap - transform to transform coordinates from a layer's CRS to the map's CRS
coords - coordinates that need to be mapped.
Method Detail

getListeners

public java.util.Set<EditBlackboardListener> getListeners()
Returns the list of Listeners so that listeners can be added and removed. This is thread safe. Each Listener can only be added once.

Returns:
Returns the listeners.

setGeometries

public java.util.Map<Geometry,EditGeom> setGeometries(Geometry geom,
                                                      java.lang.String featureId)
Adds a Geometry to the contained geometries. If the Geometry is a MultiGeometry it will not be in the mapping only the sub geometries will be in the geometry.

Parameters:
geom - the geometry that will be added.
featureId - The id of the feature the geometry was part of. Maybe null.

addGeometry

public java.util.Map<Geometry,EditGeom> addGeometry(Geometry geom,
                                                    java.lang.String featureID)
Adds a Geometry to the contained geometries. If the Geometry is a MultiGeometry it will not be in the mapping only the sub geometries will be in the geometry.

Parameters:
geom - the geometry that will be added.
featureID - The id of the feature the geometry was part of. Maybe null.

addToNearestEdge

public ClosestEdge addToNearestEdge(int x,
                                    int y,
                                    EditGeom geom,
                                    boolean treatUnknownAsPolygon)
                             throws java.lang.IllegalArgumentException
Adds a Coordinate the nearest edge .

If two edges are equidistant the first edge in the geometry will be targeted edge

Parameters:
x - the x screen location to place the new coordinate
y - the x screen location to place the new coordinate
geom - the geometry to append the point to.
treatUnknownAsPolygon - declares whether to treat geometries of type UNKNOWN as a polygon
Throws:
java.lang.IllegalArgumentException

addToNearestEdge

public java.util.List<ClosestEdge> addToNearestEdge(int x,
                                                    int y,
                                                    boolean treatUnknownAsPolygon)
                                             throws java.lang.IllegalArgumentException
Adds a Coordinate the nearest edge .

If two edges of the same geometry are equidistant the first edge in the geometry will be targeted edge

If two edges of different geometries are equidistant both will have a vertex added.

If the vertex would end up being added to the same location as an existing vertex then no vertext is added

Parameters:
x - the x screen location to place the new coordinate
y - the x screen location to place the new coordinate
treatUnknownAsPolygon - declares whether to treat geometries of type UNKNOWN as a polygon
Returns:
the list of GeomShapes that had the coordinate added to.
Throws:
java.lang.IllegalArgumentException

addPoint

public Coordinate addPoint(int x,
                           int y,
                           PrimitiveShape shape)
                    throws java.lang.IllegalArgumentException
Adds a Coordinate at the x,y location on the screen to the end of the geomtry. Closure of the hole is not enforced.

Parameters:
x - the x screen location to place the new coordinate
y - the x screen location to place the new coordinate
holeIndex - the hole to append to.
Returns:
Throws:
java.lang.IllegalArgumentException

addCoordinate

public Point addCoordinate(Coordinate coord,
                           PrimitiveShape shape)

insertCoordinate

public Point insertCoordinate(Coordinate coord,
                              int index,
                              PrimitiveShape shape)

insertCoord

public Coordinate insertCoord(int x,
                              int y,
                              int pointIndex,
                              PrimitiveShape shape)
                       throws java.lang.IllegalArgumentException
Adds a Coordinate at the index indicated.

The index is the position in the coordinate list in the shell of the geometry.

Parameters:
x - the x screen location to place the new coordinate
y - the x screen location to place the new coordinate
pointIndex - the index in terms of points in the shape to add the coordinate.
geom - the geometry to append the point to.
Returns:
added coordinate. Do not modify coordinate otherwise the state of this class will be wrong and bugs will occur in the code.
Throws:
java.lang.IllegalArgumentException

insertCoords

public void insertCoords(int pointIndex,
                         Point p,
                         java.util.List<Coordinate> coords,
                         PrimitiveShape shape)
Inserts the list of coordinates into the shape at the index indicated.

Parameters:
pointIndex - the location that the coordinates will be inserted.
coords - coords that will inserted.insertCoords
shape - the shape that will have the coords inserted.

getCandidates

public java.util.List<ClosestEdge> getCandidates(int x,
                                                 int y,
                                                 boolean treatUnknownAsPolygon)
Returns the GeomShapes that will have the coordinate added if #addToNearestEdge(int, int) is called.

Parameters:
x - the x screen location to place the new coordinate
y - the x screen location to place the new coordinate
treatUnknownAsPolygon - declares whether to treat geometries of type UNKNOWN as a polygon
Returns:
the GeomShapes that will have the coordinate added if #addToNearestEdge(int, int) is called.

getCoords

public java.util.List<Coordinate> getCoords(int x,
                                            int y)
returns the list of coordinates at location:(x,y) TREAT COORDINATES AS IMMUTABLE!!

This is a dangerous method because the coordinates are mutable but if they are modified outside of this class then the model is messed up and crazy bugs will happen. The weakness is permitted for performance reasons. I'm trusting people to not be stupid.

Returns:
the list of coordinates at location:(x,y). TREAT COORDINATES AS IMMUTABLE!!

getGeoms

public java.util.List<EditGeom> getGeoms()
The list of geometries mapped.

Returns:
list of geometries mapped.

getGeoms

public java.util.List<EditGeom> getGeoms(int x,
                                         int y)
Returns a list of the geometries with vertices at the position (x,y). Edges are not calculated.

Parameters:
x - x coordinate of point
y - x coordinate of point
Returns:

moveCoords

public java.util.List<Coordinate> moveCoords(int x,
                                             int y,
                                             int endX,
                                             int endY)
Moves all the coordinates at location by an offset of (deltaX, deltaY).

Parameters:
x - x coordinate of coords to move
y - y coordinate of coords to move
deltaX - the number of pixels to move coords in the positive x direction(Screen space)
deltaY - the number of pixels to move coords in the positive y direction(Screen space)

moveSelection

public void moveSelection(int diffX,
                          int diffY,
                          Selection selection)
Moves the selection

Parameters:
diffX - the distance to move the geometry in the x direction. The delta is in pixels.
diffY - the distance to move the geometry in the y direction. The delta is in pixels.
selection - the selection to move.

removeCoordsAtPoint

public java.util.List<Coordinate> removeCoordsAtPoint(int x,
                                                      int y)
Deletes all the coordinates at a location TREAT COORDINATES AS IMMUTABLE!!

Returns:
the deleted coordinates. TREAT COORDINATES AS IMMUTABLE!!

removeCoords

public void removeCoords(int x,
                         int y,
                         PrimitiveShape shape)
Deletes the coordinates at the provided point in the provided shape.

Parameters:
x - x coordinate in screen coords
y - y coordinate in screen coords
shape - shape to delete from.

removeCoordinate

public void removeCoordinate(int pointIndex,
                             Coordinate coord,
                             PrimitiveShape shape)
Removes a coordinate from the shape. The index indicates which point to remove, the Point parameter is a check to ensure that the correct point is indicated, and the coord is the coordinate that will be removed

Parameters:
pointIndex - index of point in shape
coord - coordinate to remove
shape - shape to remove from

toCoord

public Coordinate toCoord(Point point)

toPoint

public Point toPoint(Coordinate coord)
Transforms a Coordinate into the point location it would occupy on the screen.

Parameters:
coord - coordinate object
Returns:
point coordinate would occupy on the screen.

setToScreenTransform

public void setToScreenTransform(java.awt.geom.AffineTransform newToScreen)
Modifies the mapping of points to coordinates so that the transform passed in as a parameter is the new toScreen transform.

Parameters:
transform - new transform

getSelection

public Selection getSelection()

clear

public void clear()
Removes all EditGeometries from blackboard and places an empty one on the black board.


removeGeometries

public java.util.List<EditGeom> removeGeometries(java.util.Collection<EditGeom> geomsToRemove)
Removes all the geometries in the list from the blackboard and all the coordinates in the geometries

Parameters:
geomsToRemove - the list of geometries to remove.

newGeom

public EditGeom newGeom(java.lang.String featureId,
                        ShapeType type)
Creates a new EditGeom in the map. If there is only one geometry on the bb and it has no points and has not been editted it will be removed.

Parameters:
featureId - The id of the feature the geometry was part of. Maybe null.
type - the type of geometry to create if null then the type will be unknown
Returns:
the created geometry

getHeight

public int getHeight()
Returns:
Returns the height.

setHeight

public void setHeight(int height)
Parameters:
height - The height to set.

getWidth

public int getWidth()
Returns:
Returns the width.

setWidth

public void setWidth(int width)
Parameters:
width - The width to set.

isCollapseVertices

public boolean isCollapseVertices()
Returns:
Returns the collapseVertices.

setCollapseVertices

public void setCollapseVertices(boolean collapseVertices)
Parameters:
collapseVertices - The collapseVertices to set.

overVertex

public Point overVertex(Point location,
                        int radius)
Returns the point closest to location. The search is a square of height and width radius + 1.

Parameters:
location - the locations to start searching from.
radius - the distance away from location to search.
Returns:
the point closest to location or null if no point exists.

overVertex

public Point overVertex(Point location,
                        int radius,
                        boolean ignore)
Returns the point closest to location. If ignore is true the point at locations will not be returned. The search is a square of height and width radius + 1.

Parameters:
location - the locations to start searching from.
radius - radius the distance away from location to search.
ignore - true if the vertex at location is ignored
Returns:
the point closest to location or null if no point exists.

startBatchingEvents

public void startBatchingEvents()
Changes the behaviour of the EditBlackboard so that events are not fired but batched together until fireBatchedEvents() is called.


fireBatchedEvents

public void fireBatchedEvents()
Fires all the batched events and resets the EditBlackboard so that it no longer batches events.


selectionAdd

public boolean selectionAdd(Point point)

selectionAddAll

public boolean selectionAddAll(java.util.Collection<Point> points)

selectionClear

public void selectionClear()

selectionRemoveAll

public boolean selectionRemoveAll(java.util.Collection<Point> points)

selectionRemove

public boolean selectionRemove(Point point)

selectionRetainAll

public boolean selectionRetainAll(java.util.Collection<Point> points)

contains

public boolean contains(java.lang.String fid)
Returns true if the blackboard currently holds the noted feature ID.

Parameters:
fid - Feature ID
Returns:
boolean

setMapLayerTransform

public void setMapLayerTransform(MathTransform mapToLayer)

setCoords

public void setCoords(Point point,
                      Coordinate newValue)
Sets all the coordinates at the point to provided coordinate. The coodinate must still map to the point

Parameters:
point - the point at which all the coordinates will be changed
newValue - the new coordinate value of coordinates at the point