org.grinvin.gred

Class MutableGraphPanel

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

public class MutableGraphPanel
extends GraphPanel

Graph panel which is backed by a 2-dimensional mutable embedding model. Extends GraphPanel with the ability to add vertices and change vertex coordinates.

Field Summary

Fields inherited from class org.grinvin.gred.GraphPanel

anchor, backgroundColor, context, embedding, graph, guides, renderer, scale, undoManager

Constructor Summary

MutableGraphPanel(MutableEmbeddingModel embedding, Renderer renderer, GraphContext context, double scale)
Create a new graph panel with given peer.

Method Summary

@Override
Embedding getEmbedding()
Returns the (mutable) embedding used by this panel.
@Override
Graph getGraph()
Returns the (mutable) graph displayed by this panel.
Vertex
addNewVertex(int mouseX, int mouseY, Object annotation, boolean leader)
Add a new vertex at the given mouse coordinates using the given annotation.
void
clear()
Removes the current graph
void
closure()
Replaces the current graph with its closure
void
complement()
Replaces the current graph with its complement.
void
connectSelection()
Connects the current selected vertices (i.e.
void
deleteSelection()
Delete the current selection.
void
edgeInducedSubGraph()
Replaces the current graph with the graph induced by the selected edges.
void
finalizeEmbeddingChange(String key)
Finalize a change in embedding.
EmbeddingView
getSavedEmbedding()
Return the embedding saved by initiateEmbeddingChange().
void
initiateEmbeddingChange()
Initiate an upcoming change to an embedding.
boolean
isDirty()
void
lineGraph()
Replaces the current graph with its line graph
void
mergeSelection()
Merges the current selected vertices.
void
moveSelection(int diffx, int diffy)
Move the current selection by the given number of pixels (in mouse coordinates)
void
setDirty(boolean dirty)
void
setSnapToGuides(boolean snapToGuides)
Indicates whether new vertices added should be 'snapped' to the guides.
void
snapAllToGuides()
Snap all the vertices to the current guides.
void
snapSelectionToGuides()
Snap the current selection to the current guides.
void
splitEdge(Edge edge, boolean joinToAnchor, int mouseX, int mouseY, Object annotation, boolean leader)
Split an edge and optionally join the new vertex to the anchor.
void
splitSelection()
Splits the current selected vertices.
void
undoEmbeddingChange()
Undo the latest embedding change, by reverting to the coordinates of the embedding saved by initiateEmbeddingChange().
void
vertexInducedSubGraph()
Replaces the current graph with the graph induced by the selected vertices.
@Override
void close()
@Override
void setEmbedding(EmbeddingModel originalEmbedding)

Methods inherited from class org.grinvin.gred.GraphPanel

addInsideOfRectangle, clearSelection, close, componentHidden, componentMoved, componentResized, componentShown, dimensionChanged, edgeAdded, edgeChanged, edgeRemoved, edgeRestored, embeddedRectangle, embeddingChanged, fillGraphBundle, getAnchorElement, getContext, getDropLocation, getEmbedding, getGraph, getGuides, getUndoManager, graphChanged, isAttached, isAttached, isDirty, isDropInProgress, joinAnchorToVertex, loadEmbedding, mouseCoordinates, paintBackground, paintEdges, paintVertices, selectAll, setAnchorElement, setDirty, setDropTarget, setEmbedding, setGuides, setRollOver, update, vertexAdded, vertexChanged, vertexCoordinatesChanged, vertexRemoved, vertexRestored, void paintComponent

Constructor Details

MutableGraphPanel

public MutableGraphPanel(MutableEmbeddingModel embedding,
                         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 MutableGraphModel.
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

Embedding getEmbedding

public @Override Embedding getEmbedding()
Returns the (mutable) embedding used by this panel.

Graph getGraph

public @Override Graph getGraph()
Returns the (mutable) graph displayed by this panel.

addNewVertex

public Vertex addNewVertex(int mouseX,
                           int mouseY,
                           Object annotation,
                           boolean leader)
Add a new vertex at the given mouse coordinates using the given annotation.
Parameters:
leader - Is this command the first of an undo/redo group?
Returns:
the newly created vertex

clear

public void clear()
Removes the current graph

closure

public void closure()
Replaces the current graph with its closure

complement

public void complement()
Replaces the current graph with its complement.

connectSelection

public void connectSelection()
Connects the current selected vertices (i.e. they become a clique).

deleteSelection

public void deleteSelection()
Delete the current selection.

edgeInducedSubGraph

public void edgeInducedSubGraph()
Replaces the current graph with the graph induced by the selected edges.

finalizeEmbeddingChange

public void finalizeEmbeddingChange(String key)
Finalize a change in embedding. Hands the change over to the undo manager.
Parameters:
key - Resource key for the caption of the undo/redo button

getSavedEmbedding

public EmbeddingView getSavedEmbedding()
Return the embedding saved by initiateEmbeddingChange().

initiateEmbeddingChange

public void initiateEmbeddingChange()

isDirty

public boolean isDirty()
Overrides:
isDirty in interface GraphPanel

lineGraph

public void lineGraph()
Replaces the current graph with its line graph

mergeSelection

public void mergeSelection()
Merges the current selected vertices.

moveSelection

public void moveSelection(int diffx,
                          int diffy)
Move the current selection by the given number of pixels (in mouse coordinates)

setDirty

public void setDirty(boolean dirty)
Overrides:
setDirty in interface GraphPanel

setSnapToGuides

public void setSnapToGuides(boolean snapToGuides)
Indicates whether new vertices added should be 'snapped' to the guides.

snapAllToGuides

public void snapAllToGuides()
Snap all the vertices to the current guides.

snapSelectionToGuides

public void snapSelectionToGuides()
Snap the current selection to the current guides.

splitEdge

public void splitEdge(Edge edge,
                      boolean joinToAnchor,
                      int mouseX,
                      int mouseY,
                      Object annotation,
                      boolean leader)
Split an edge and optionally join the new vertex to the anchor.

splitSelection

public void splitSelection()
Splits the current selected vertices.

undoEmbeddingChange

public void undoEmbeddingChange()

vertexInducedSubGraph

public void vertexInducedSubGraph()
Replaces the current graph with the graph induced by the selected vertices.

void close

public @Override void close()

void setEmbedding

public @Override void setEmbedding(EmbeddingModel originalEmbedding)