org.grinvin.list

Class GraphViewPanel

Implemented Interfaces:
ComponentListener, AnnotationListener, EmbeddingListener, EventListener, GraphListener, Observer

public class GraphViewPanel
extends JPanel
implements ComponentListener, EmbeddingListener, AnnotationListener, GraphListener, Observer

Provides a view of the Graph. TODO: clean this up, refactor common code with GraphPanel

Field Summary

protected AnnotationView
annotation
protected Color
backgroundColor
Panel background color.
protected GraphContext
context
protected EmbeddingView
embedding
protected GraphView
graph
protected Guides
guides
Current Guides object for this panel.
protected Renderer
renderer
protected double
scale

Constructor Summary

GraphViewPanel(EmbeddingView embedding, AnnotationView annotation, Renderer renderer, GraphContext context, double scale)
Create a new graph panel with given peer.

Method Summary

void
annotationChanged()
void
componentHidden(ComponentEvent e)
void
componentMoved(ComponentEvent e)
void
componentResized(ComponentEvent e)
Recenters the drawing when the component changes size.
void
componentShown(ComponentEvent e)
void
dimensionChanged(int oldDimension)
Called when the dimension of the embedding was changed, and as a consequence that all coordinates have changed as well.
void
edgeAdded(Edge edge)
Called after an edge was added to the graph.
void
edgeChanged(Edge edge)
Called when the annotation of an edge changes.
void
edgeRemoved(Edge edge)
Called when an edge was removed from the graph.
void
edgeRestored(Edge edge)
Called when an edge that was previously removed was restored to the graph.
void
elementAnnotationChanged(Element element)
void
embeddingChanged()
Called after a major change in the embedding.
void
graphChanged()
Called when the graph was changed in a major way.
protected void
paintBackground(Graphics2D g2)
Paint a background overlay.
protected void
paintEdges(Graphics2D g2)
Paint all edges of the graph using the current renderer.
protected void
paintVertices(Graphics2D g2)
Paint all vertices of the graph using the current vertex renderer.
void
update(Observable o, Object arg)
void
vertexAdded(Vertex vertex)
Called after a vertex was added to the graph.
void
vertexChanged(Vertex vertex)
Called when the annotation of a vertex changes.
void
vertexCoordinatesChanged(Vertex vertex)
Called after a vertex was given new coordinates.
void
vertexRemoved(Vertex vertex)
Called when a vertex was removed from the graph.
void
vertexRestored(Vertex vertex)
Called when a vertex that was previously removed was restored to the graph.
protected @Override
void paintComponent(Graphics g)
Paints the graph on the panel using the current renderer.

Field Details

annotation

protected AnnotationView annotation

backgroundColor

protected Color backgroundColor
Panel background color.

context

protected GraphContext context

embedding

protected EmbeddingView embedding

graph

protected GraphView graph

guides

protected Guides guides
Current Guides object for this panel.

renderer

protected Renderer renderer

scale

protected double scale

Constructor Details

GraphViewPanel

public GraphViewPanel(EmbeddingView embedding,
                      AnnotationView annotation,
                      Renderer renderer,
                      GraphContext context,
                      double scale)
Create a new graph panel with given peer. The panel is given a preferred size large enough to display the coordinate range (-1.1,-1.1)-(1.1,1.1).
Parameters:
embedding - Embedding displayed in this panel. The peer of this embedding should be of type GraphModel.
renderer - Renderer for this panel.
context - Graph context for this panel.
scale - Number of pixels corresponding to a unit length in the embedding.

Method Details

annotationChanged

public void annotationChanged()
Specified by:
annotationChanged in interface AnnotationListener

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.
Specified by:
dimensionChanged in interface EmbeddingListener

edgeAdded

public void edgeAdded(Edge edge)
Called after an edge was added to the graph.
Specified by:
edgeAdded in interface GraphListener
Parameters:
edge - Edge that was added to the graph.

edgeChanged

public void edgeChanged(Edge edge)
Called when the annotation of an edge changes.
Specified by:
edgeChanged in interface GraphListener

edgeRemoved

public void edgeRemoved(Edge edge)
Called when an edge was removed from the graph.
Specified by:
edgeRemoved in interface GraphListener

edgeRestored

public void edgeRestored(Edge edge)
Called when an edge that was previously removed was restored to the graph.
Specified by:
edgeRestored in interface GraphListener

elementAnnotationChanged

public void elementAnnotationChanged(Element element)
Specified by:
elementAnnotationChanged in interface AnnotationListener

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.
Specified by:
embeddingChanged in interface EmbeddingListener

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.
Specified by:
graphChanged in interface GraphListener

paintBackground

protected void paintBackground(Graphics2D g2)
Paint a background overlay. See GraphViewPanel 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 GraphViewPanel 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 GraphViewPanel for the order in which the various paint methods are executed.


update

public void update(Observable o,
                   Object arg)

vertexAdded

public void vertexAdded(Vertex vertex)
Called after a vertex was added to the graph.
Specified by:
vertexAdded in interface GraphListener
Parameters:
vertex - Vertex that was added to the graph

vertexChanged

public void vertexChanged(Vertex vertex)
Called when the annotation of a vertex changes.
Specified by:
vertexChanged in interface GraphListener

vertexCoordinatesChanged

public void vertexCoordinatesChanged(Vertex vertex)
Called after a vertex was given new coordinates.
Specified by:
vertexCoordinatesChanged in interface EmbeddingListener

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.
Specified by:
vertexRemoved in interface GraphListener
Parameters:
vertex - vertex that was removed

vertexRestored

public void vertexRestored(Vertex vertex)
Called when a vertex that was previously removed was restored to the graph.
Specified by:
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.