Class ShapePickSupport<V,E>
- java.lang.Object
-
- org.jungrapht.visualization.selection.ShapePickSupport<V,E>
-
- Type Parameters:
V- vertex typeE- edge type
- All Implemented Interfaces:
GraphElementAccessor<V,E>,EdgeAccessor<V,E>,VertexAccessor<V>
public class ShapePickSupport<V,E> extends Object implements GraphElementAccessor<V,E>
AGraphElementAccessorthat returns elements whoseShapecontains the specified pick point or region.- Author:
- Tom Nelson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShapePickSupport.StyleThe available picking heuristics:Style.CENTERED: returns the element whose center is closest to the pick point.
-
Field Summary
Fields Modifier and Type Field Description protected intpickSizeprotected ShapePickSupport.StylestyleThe current picking heuristic for this instance.protected VisualizationServer<V,E>vvTheVisualizationServerin which the this instance is being used for picking.
-
Constructor Summary
Constructors Constructor Description ShapePickSupport(VisualizationServer<V,E> vv)Create aShapePickSupportfor the specifiedVisualizationServerwith a default pick footprint.ShapePickSupport(VisualizationServer<V,E> vv, int pickSize)Creates aShapePickSupportfor thevvVisualizationServer, with the specified pick footprint and the default pick style.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanedgesAreFiltered()Quick test to allow optimization ofgetFilteredEdges().protected Collection<V>getContained(Spatial spatial, LayoutModel<V> layoutModel, Shape shape)use the spatial structure to find vertices inside the passed shapeprotected Collection<E>getContained(SpatialRTree.Edges<E,V> spatial, LayoutModel<V> layoutModel, Shape shape)use the spatial R tree to find edges inside the passed shapeEgetEdge(LayoutModel<V> layoutModel, double x, double y)Returns an edge whose shape intersects the 'pickArea' footprint of the passed x,y, coordinates.EgetEdge(LayoutModel<V> layoutModel, Rectangle2D pickFootprint)EgetEdge(LayoutModel<V> layoutModel, Point p)protected EgetEdge(SpatialRTree.Edges<E,V> spatial, LayoutModel<V> layoutModel, double x, double y)uses the spatialRTree to find the closest edge to the point coordsprotected EgetEdge(SpatialRTree.Edges<E,V> spatial, LayoutModel<V> layoutModel, Rectangle2D pickingFootprint)protected Collection<E>getFilteredEdges()protected Collection<V>getFilteredVertices()floatgetPickSize()Returns the layoutSize of the edge picking area.ShapePickSupport.StylegetStyle()Returns the style of picking used by this instance.VgetVertex(LayoutModel<V> layoutModel, double x, double y)Returns the vertex, if any, whose shape contains (x, y).VgetVertex(LayoutModel<V> layoutModel, Rectangle2D pickingFootprint)Returns the vertex, if any, whose shape intersects the supplied pickingFootprint.VgetVertex(LayoutModel<V> layoutModel, Point p)protected VgetVertex(Spatial<V,V> spatial, LayoutModel<V> layoutModel, Rectangle2D pickingFootprint)uses the spatialRTree to find the closest vertex to the pointsCollection<V>getVertices(LayoutModel<V> layoutModel, Shape shape)Returns the vertices whose layout coordinates are contained inShape.protected booleanisEdgeRendered(E edge)Returnstrueif this edge and its endpoints in this graph are all included in the collections of elements to be rendered, andfalseotherwise.protected booleanisVertexRendered(V vertex)Returnstrueif this vertex in this graph is included in the collections of elements to be rendered, andfalseotherwise.protected ShapeprepareFinalEdgeShape(RenderContext<V,E> renderContext, LayoutModel<V> layoutModel, E e)voidsetPickSize(int pickSize)Sets the layoutSize of the edge picking area.voidsetStyle(ShapePickSupport.Style style)Specifies the style of picking to be used by this instance.protected booleanverticesAreFiltered()Quick test to allow optimization ofgetFilteredVertices().
-
-
-
Field Detail
-
pickSize
protected int pickSize
-
vv
protected VisualizationServer<V,E> vv
TheVisualizationServerin which the this instance is being used for picking. Used to retrieve properties such as the layout, renderer, vertex and edge shapes, and coordinate transformations.
-
style
protected ShapePickSupport.Style style
The current picking heuristic for this instance. Defaults toCENTERED.
-
-
Constructor Detail
-
ShapePickSupport
public ShapePickSupport(VisualizationServer<V,E> vv, int pickSize)
Creates aShapePickSupportfor thevvVisualizationServer, with the specified pick footprint and the default pick style. TheVisualizationServeris used to access properties of the current visualization (layout, renderer, coordinate transformations, vertex/edge shapes, etc.).- Parameters:
vv- source of the currentLayout.pickSize- the layoutSize of the pick footprint for line edges
-
ShapePickSupport
public ShapePickSupport(VisualizationServer<V,E> vv)
Create aShapePickSupportfor the specifiedVisualizationServerwith a default pick footprint. of layoutSize 2.- Parameters:
vv- the visualization server used for rendering
-
-
Method Detail
-
getStyle
public ShapePickSupport.Style getStyle()
Returns the style of picking used by this instance. This specifies which of the elements, among those whose shapes contain the pick point, is returned. The available styles are:Style.CENTERED: returns the element whose center is closest to the pick point.Style.LOWEST: returns the first such element encountered. (If the element collection has a consistent ordering, this will also be the element "on the bottom", that is, the one which is rendered first.)Style.HIGHEST: returns the last such element encountered. (If the element collection has a consistent ordering, this will also be the element "on the top", that is, the one which is rendered last.)
- Returns:
- the style of picking used by this instance
-
setStyle
public void setStyle(ShapePickSupport.Style style)
Specifies the style of picking to be used by this instance. This specifies which of the elements, among those whose shapes contain the pick point, will be returned. The available styles are:Style.CENTERED: returns the element whose center is closest to the pick point.Style.LOWEST: returns the first such element encountered. (If the element collection has a consistent ordering, this will also be the element "on the bottom", that is, the one which is rendered first.)Style.HIGHEST: returns the last such element encountered. (If the element collection has a consistent ordering, this will also be the element "on the top", that is, the one which is rendered last.)
- Parameters:
style- the style to set
-
getVertex
public V getVertex(LayoutModel<V> layoutModel, Rectangle2D pickingFootprint)
Returns the vertex, if any, whose shape intersects the supplied pickingFootprint. The pickingFootprint is in the view coordinate system. To test each vertex, it will have its shape transformed to the view coordinate system (what the user sees rendered on the screen).- Parameters:
layoutModel-pickingFootprint- a rectangle in the view coordinate system- Returns:
- the vertex whos shape intersects the pickingFootprint in the view.
-
getVertex
protected V getVertex(Spatial<V,V> spatial, LayoutModel<V> layoutModel, Rectangle2D pickingFootprint)
uses the spatialRTree to find the closest vertex to the points- Parameters:
spatial-layoutModel-pickingFootprint-- Returns:
- the selected vertex
-
getVertex
public V getVertex(LayoutModel<V> layoutModel, Point p)
- Specified by:
getVertexin interfaceVertexAccessor<V>- Parameters:
layoutModel- the source of graph element locationsp- the pick point- Returns:
- the vertex associated with the pick point
-
getVertex
public V getVertex(LayoutModel<V> layoutModel, double x, double y)
Returns the vertex, if any, whose shape contains (x, y). If (x,y) is contained in more than one vertex's shape, returns the vertex whose center is closest to the pick point.- Specified by:
getVertexin interfaceVertexAccessor<V>- Parameters:
x- the x coordinate of the pick pointy- the y coordinate of the pick point- Returns:
- the vertex whose shape contains (x,y), and whose center is closest to the pick point
-
getVertices
public Collection<V> getVertices(LayoutModel<V> layoutModel, Shape shape)
Returns the vertices whose layout coordinates are contained inShape. The shape is in screen coordinates, and the graph vertices are transformed to screen coordinates before they are tested for inclusion.- Specified by:
getVerticesin interfaceGraphElementAccessor<V,E>shape- the region in which the returned vertices are located- Returns:
- the
Collectionof vertices whoselayoutcoordinates are contained inshape.
-
getContained
protected Collection<V> getContained(Spatial spatial, LayoutModel<V> layoutModel, Shape shape)
use the spatial structure to find vertices inside the passed shape- Parameters:
spatial-layoutModel-shape- a target shape in layout coordinates- Returns:
- the vertices contained in the target shape
-
getContained
protected Collection<E> getContained(SpatialRTree.Edges<E,V> spatial, LayoutModel<V> layoutModel, Shape shape)
use the spatial R tree to find edges inside the passed shape- Parameters:
spatial-layoutModel-shape- a target shape in layout coordinates- Returns:
- the vertices contained in the target shape
-
getEdge
protected E getEdge(SpatialRTree.Edges<E,V> spatial, LayoutModel<V> layoutModel, Rectangle2D pickingFootprint)
-
getEdge
public E getEdge(LayoutModel<V> layoutModel, Rectangle2D pickFootprint)
-
getEdge
public E getEdge(LayoutModel<V> layoutModel, double x, double y)
Returns an edge whose shape intersects the 'pickArea' footprint of the passed x,y, coordinates.- Specified by:
getEdgein interfaceEdgeAccessor<V,E>- Parameters:
x- the x coordinate of the location (layout coordinate system)y- the y coordinate of the location (layout coordinate system)- Returns:
- an edge whose shape intersects the pick area centered on the location
(x,y)
-
getEdge
public E getEdge(LayoutModel<V> layoutModel, Point p)
- Specified by:
getEdgein interfaceEdgeAccessor<V,E>- Parameters:
layoutModel- the source of Edge positionsp- the pick point- Returns:
- the vertex associated with the pick point
-
getEdge
protected E getEdge(SpatialRTree.Edges<E,V> spatial, LayoutModel<V> layoutModel, double x, double y)
uses the spatialRTree to find the closest edge to the point coords- Parameters:
spatial-layoutModel-x- in the layout coordinate systemy- in the layout coordinate system- Returns:
- the selected vertex
-
getFilteredVertices
protected Collection<V> getFilteredVertices()
-
getFilteredEdges
protected Collection<E> getFilteredEdges()
-
verticesAreFiltered
protected boolean verticesAreFiltered()
Quick test to allow optimization ofgetFilteredVertices().- Returns:
trueif there is an relaxing vertex filtering mechanism for this visualization,falseotherwise
-
edgesAreFiltered
protected boolean edgesAreFiltered()
Quick test to allow optimization ofgetFilteredEdges().- Returns:
trueif there is an relaxing edge filtering mechanism for this visualization,falseotherwise
-
isVertexRendered
protected boolean isVertexRendered(V vertex)
Returnstrueif this vertex in this graph is included in the collections of elements to be rendered, andfalseotherwise.- Returns:
trueif this vertex is included in the collections of elements to be rendered,falseotherwise.
-
isEdgeRendered
protected boolean isEdgeRendered(E edge)
Returnstrueif this edge and its endpoints in this graph are all included in the collections of elements to be rendered, andfalseotherwise.- Returns:
trueif this edge and its endpoints are all included in the collections of elements to be rendered,falseotherwise.
-
getPickSize
public float getPickSize()
Returns the layoutSize of the edge picking area. The picking area is square; the layoutSize is specified as the length of one side, in view coordinates.- Returns:
- the layoutSize of the edge picking area
-
setPickSize
public void setPickSize(int pickSize)
Sets the layoutSize of the edge picking area.- Parameters:
pickSize- the length of one side of the (square) picking area, in view coordinates
-
prepareFinalEdgeShape
protected Shape prepareFinalEdgeShape(RenderContext<V,E> renderContext, LayoutModel<V> layoutModel, E e)
-
-