Panel which displays a given graph embedding and reacts to changes in
both the embedding and the graph it represents.
The graph embedding which is displayed on this panel must be of type
EmbeddingModel
and its peer graph must be of type
GraphModel
.
Some methods of this class however
require the peer graph to be of type
MutableGraphModel
.
The panel displays a two-dimensional embedding which is assumed to use coordinates
in the range (-1.0,-1.0)-(1.0,1.0). These coordinates are scaled by a fixed scale factor
which is determined at construction time. The center of the panel is used as the center
of the coordinate system.
The actual rendering of the graph elements is delegated to a
Renderer
which is assigned to this panel. Extra information on how to render specific
elements of the graph is retrieved from a
GraphContext
object
that is associated with this panel.
addInsideOfRectangle
public Collection addInsideOfRectangle(Rectangle2D bounds,
Collection set)
Add all elements to the given set whose embedding coordinates
are within the given bounds.
set
- Set to which the elements should be added
- The value of the set argument
clearSelection
public void clearSelection()
Clear the selection.
close
public void close()
Decouples all listeners. Should be called immediately before the panel
is removed so it can be garbage collected.
componentHidden
public void componentHidden(ComponentEvent e)
componentMoved
public void componentMoved(ComponentEvent e)
componentResized
public void componentResized(ComponentEvent e)
Recenters the drawing when the component changes size.
componentShown
public void componentShown(ComponentEvent e)
dimensionChanged
public void dimensionChanged(int oldDimension)
Called when the dimension of the embedding was changed, and as a
consequence that all coordinates have changed as well.
- dimensionChanged in interface EmbeddingListener
edgeAdded
public void edgeAdded(Edge edge)
Called after an edge was added to the graph.
- edgeAdded in interface GraphListener
edge
- Edge that was added to the graph.
edgeRestored
public void edgeRestored(Edge edge)
Called when an edge that was previously removed
was restored to the graph.
- edgeRestored in interface GraphListener
embeddedRectangle
public Rectangle2D embeddedRectangle(Rectangle mouseRect)
Convert the given rectangle in mouse coordinates to a rectangle
in embedding coordinates.
embeddingChanged
public void embeddingChanged()
Called after a major change in the embedding. For instance when the
coordinates of all vertices change at the same time. Note that
also the peer of the embedding may have changed.
- embeddingChanged in interface EmbeddingListener
fillGraphBundle
public void fillGraphBundle(GraphBundle bundle)
Copies the current Graph to the given GraphBundle.
bundle
- the GraphBundle to be filled
getAnchorElement
public Element getAnchorElement()
Return the 'anchor' element. The anchor element
is a temporary element used by some mouse handlers.
getAnnotation
public AnnotationView getAnnotation()
Return the annotation used by this panel.
getContext
public GraphContext getContext()
Return the graph context associated with this panel.
getDropLocation
public Point getDropLocation()
Return the last drag-and-drop location where this component is a target.
getEmbedding
public EmbeddingView getEmbedding()
Return the embedding used by this panel.
getGraph
public GraphView getGraph()
Return the graph displayed by this panel.
getGuides
public Guides getGuides()
Return the current guides for this panel.
getUndoManager
public UndoManager getUndoManager()
Return the undo manager used by this panel.
graphChanged
public void graphChanged()
Called when the graph was changed in a major way. For instance, when all
vertices and edges were removed in one go or when the graph was
reinitialized from a file.
- graphChanged in interface GraphListener
isAttached
public boolean isAttached(Edge edge)
Checks whether the given edge is still attached to its parent.
isAttached
public boolean isAttached(Vertex vertex)
Checks whether the given vertex is still attached to its parent.
isDirty
public boolean isDirty()
isDropInProgress
public boolean isDropInProgress()
Is a drag-and-drop operation in progress where
this component is a target?
joinAnchorToVertex
public void joinAnchorToVertex(Vertex vertex,
boolean leader)
Join the anchor to the given vertex.
vertex
- Vertex to which the anchor should be joinedleader
- Is this command the first of an undo/redo group?
loadGraph
public void loadGraph(EmbeddingView newEmbedding,
AnnotationView newAnnotation)
Change the embedding and graph to be used by this panel to a copy of the
given embedding.
mouseCoordinates
public void mouseCoordinates(Vertex v,
int[] coord)
Store the mouse coordinates of the given vertex into the given array.
The array must have dimension at least 2.
paintBackground
protected void paintBackground(Graphics2D g2)
Paint a background overlay.
See
GraphPanel
for the order in which the various
paint methods are executed.
This implementation is delegates to the current guides object.
paintEdges
protected void paintEdges(Graphics2D g2)
Paint all edges of the graph using the current renderer.
See
GraphPanel
for the order in which the various
paint methods are executed.
paintVertices
protected void paintVertices(Graphics2D g2)
Paint all vertices of the graph using the current vertex renderer.
See
GraphPanel
for the order in which the various
paint methods are executed.
removeGuidesListener
public void removeGuidesListener(GuidesListener l)
selectAll
public void selectAll()
Select all graph elements.
setAnchorElement
public void setAnchorElement(Element anchor)
Set the 'anchor' element. The anchor element
is a temporary element used by some mouse handlers.
setDirty
public void setDirty(boolean dirty)
setDropTarget
public void setDropTarget(DropTarget dt)
setGraph
public void setGraph(EmbeddingModel embedding,
AnnotationModel annotation)
Change the embedding to be used by this panel. Clears the selection.
setGuides
public void setGuides(Guides guides)
Install guides for this panel.
guides
- New guide object or null to remove the guides.
setRollOver
public void setRollOver(int mouseX,
int mouseY)
Set the roll over element in the corresponding graph context
to an element which lies near to the given mouse coordinates.
update
public void update(Observable o,
Object arg)
vertexAdded
public void vertexAdded(Vertex vertex)
Called after a vertex was added to the graph.
- vertexAdded in interface GraphListener
vertex
- Vertex that was added to the graph
vertexRemoved
public void vertexRemoved(Vertex vertex)
Called when a vertex was removed from the graph. Implies that
all edges through this vertex were also removed. These removals will
not be notified separately.
- vertexRemoved in interface GraphListener
vertex
- vertex that was removed
vertexRestored
public void vertexRestored(Vertex vertex)
Called when a vertex that was previously removed
was restored to the graph.
- vertexRestored in interface GraphListener
void paintComponent
protected @Override void paintComponent(Graphics g)
Paints the graph on the panel using the current renderer.
Paints background, edges and then vertices.