Package dev.roanh.gmark.util
Class GraphPanel<V,E>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
dev.roanh.gmark.util.GraphPanel<V,E>
- Type Parameters:
V
- The graph node data type.E
- The graph edge data type.
- All Implemented Interfaces:
MouseListener
,MouseMotionListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
Simple component that visualises the nodes and
edges in a
UniqueGraph
. The user able to move
the graph nodes around by dragging. In addition
attached edges will be highlighted when a node is
selected. Nodes are initially placed randomly at
random positions on the canvas.- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
Object that holds both data on the actual graph edge and data required to properly visualise the edge.private class
Object that holds both data on the actual graph node and data required to properly visualise the node.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
Modifier and TypeFieldDescriptionprivate GraphPanel<V,
E>.Node The currently selected node.private boolean
True if the graph should be drawn as a directed graph.Function to convert edge data to a string to show to the user.private List<GraphPanel<V,
E>.Edge> List of edges to render.private Point
Last location the user held down the mouse.Function to convert node data to a string to show to the user.private List<GraphPanel<V,
E>.Node> List of nodes to render.private static final long
Serial ID.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorDescriptionGraphPanel
(UniqueGraph<V, E> graph) Constructs a new graph panel for the given graph.GraphPanel
(UniqueGraph<V, E> graph, Function<V, String> nodeLabel, Function<E, String> edgeLabel) Constructs a new graph panel for the given graph and with the given functions to convert graph data to string form. -
Method Summary
Modifier and TypeMethodDescriptionprivate GraphPanel<V,
E>.Node Finds the first node that contains the given point.void
void
void
void
void
void
void
void
void
setDirected
(boolean directed) Sets whether the graph is directed.void
setGraph
(UniqueGraph<V, E> graph) Sets the graph to display.static void
Utility subroutine to show the query graph of the given CPQ in a JFrame.static void
show
(QueryGraphCPQ cpq) Utility subroutine to show the given CPQ query graph in a JFrame.static <V,
E> void show
(UniqueGraph<V, E> graph) Utility subroutine to show the given graph in a JFrame.static <V,
E> void Utility subroutine to show the given graph in a JFrame.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerial ID.- See Also:
-
nodes
List of nodes to render. -
edges
List of edges to render. -
lastLocation
Last location the user held down the mouse. This will benull
when the user is not dragging the mouse. -
activeNode
The currently selected node. -
nodeLabel
Function to convert node data to a string to show to the user. -
edgeLabel
Function to convert edge data to a string to show to the user. -
directed
private boolean directedTrue if the graph should be drawn as a directed graph.
-
-
Constructor Details
-
GraphPanel
Constructs a new graph panel for the given graph. Data is converted to string form for display purposes using a call to the standardObject.toString()
method.- Parameters:
graph
- The graph to visualise.- See Also:
-
GraphPanel
public GraphPanel(UniqueGraph<V, E> graph, Function<V, String> nodeLabel, Function<E, String> edgeLabel) Constructs a new graph panel for the given graph and with the given functions to convert graph data to string form.- Parameters:
graph
- The graph to visualise.nodeLabel
- The function to use to convert graph node data to a string to display to the user.edgeLabel
- The function to use to convert graph edge data to a string to display to the user.- See Also:
-
-
Method Details
-
setDirected
public void setDirected(boolean directed) Sets whether the graph is directed. Although by definition the inputUniqueGraph
is directed, setting this tofalse
will make it so arrow heads are not drawn and that a directed edge in both directions between two nodes is not drawn as a curved arc.- Parameters:
directed
- True to draw the directed properties of the graph, false to not draw these features.
-
setGraph
Sets the graph to display. This will replace the previous graph if any.- Parameters:
graph
- The new graph to display.
-
findNode
Finds the first node that contains the given point. If such a node exists.- Parameters:
p
- The point to check.- Returns:
- The first node that contains the
given point, or
null
if no such node exists.
-
paintComponent
- Overrides:
paintComponent
in classJComponent
-
mouseDragged
- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
mouseMoved
- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
mouseClicked
- Specified by:
mouseClicked
in interfaceMouseListener
-
mousePressed
- Specified by:
mousePressed
in interfaceMouseListener
-
mouseReleased
- Specified by:
mouseReleased
in interfaceMouseListener
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
-
show
public static <V,E> void show(UniqueGraph<V, E> graph, Function<V, String> nodeLabel, Function<E, String> edgeLabel) Utility subroutine to show the given graph in a JFrame.- Type Parameters:
V
- The vertex data type.E
- The edge data type.- Parameters:
graph
- The graph to display.nodeLabel
- The function to use to determine node labels.edgeLabel
- The function to use to determine edge labels.
-
show
Utility subroutine to show the given graph in a JFrame.- Type Parameters:
V
- The vertex data type.E
- The edge data type.- Parameters:
graph
- The graph to display.
-
show
Utility subroutine to show the query graph of the given CPQ in a JFrame.- Parameters:
q
- The CPQ to display.
-
show
Utility subroutine to show the given CPQ query graph in a JFrame.- Parameters:
cpq
- The CPQ query graph to display.
-