Class GraphViewPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.marginallyclever.donatello.graphview.GraphViewPanel
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
GraphViewPanel
visualizes the contents of a Graph
with Java Swing.
It can call on GraphViewListener
s to add additional flavor.
Override this to implement a unique look and feel.- Since:
- 2022-02-11
- Author:
- Dan Royer
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Controls vertical text alignment within aNode
orPort
.static final int
Controls horizontal or vertical text alignment within aNode
orPort
.static final int
Controls horizontal text alignment within aNode
orPort
.static final int
Controls horizontal text alignment within aNode
orPort
.static final int
Controls vertical text alignment within aNode
orPort
.static final int
The maximum number of characters to display in aPort
.Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
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
ConstructorsConstructorDescriptionGraphViewPanel
(com.marginallyclever.nodegraphcore.Graph model) Constructs one new instance ofGraphViewPanel
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
GraphViewListener
s register here.static Rectangle
Returns the adjusted inner bounds of aNode
.double
getZoom()
Returns the current scalevoid
void
moveAndZoomToFit
(Rectangle rectangle) pan and zoom the camera to fit the rectangle in the view.void
moveAndZoomToFit
(List<com.marginallyclever.nodegraphcore.Node> selectedNodes) pan and zoom the camera such that it can see all the selected nodes.void
paintBezierBetweenTwoPoints
(Graphics g, Point p0, Point p3) Paint a cubic bezier usingGraphics
from p0 to p3.void
paintConnection
(Graphics g, com.marginallyclever.nodegraphcore.Connection c) Paint the male end of connection points at thisPort
.void
Paint the male end of one connection point.void
Paint oneNode
void
paintNodeBackground
(Graphics g, com.marginallyclever.nodegraphcore.Node n) Paint the background of oneNode
void
paintNodeBorder
(Graphics g, com.marginallyclever.nodegraphcore.Node n) Paint the outside border of oneNode
.void
paintNodeTitleBar
(Graphics g, com.marginallyclever.nodegraphcore.Node n) Paint the title bar of oneNode
.void
paintOnePort
(Graphics g, com.marginallyclever.nodegraphcore.port.Port<?> v) Paint onePort
.void
paintPortConnectionPoints
(Graphics g, com.marginallyclever.nodegraphcore.port.Port<?> v) Paint the female end of connection points of onePort
.static void
Use the graphics context to paint text within a box with the provided alignment.void
GraphViewListener
s unregister here.void
static void
setHints
(Graphics2D g2) Set rendering hints for theGraphics2D
context.void
setLineWidth
(Graphics g, float r) Sets the Graphics context line width.void
setZoom
(double zoom) Sets the scale.transformScreenToWorldPoint
(Point point) Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, 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
-
ALIGN_LEFT
public static final int ALIGN_LEFTControls horizontal text alignment within aNode
orPort
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
-
ALIGN_RIGHT
public static final int ALIGN_RIGHTControls horizontal text alignment within aNode
orPort
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
-
ALIGN_CENTER
public static final int ALIGN_CENTERControls horizontal or vertical text alignment within aNode
orPort
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
-
ALIGN_TOP
public static final int ALIGN_TOPControls vertical text alignment within aNode
orPort
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
-
ALIGN_BOTTOM
public static final int ALIGN_BOTTOMControls vertical text alignment within aNode
orPort
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
-
MAX_CHARS_PER_RORT
public static final int MAX_CHARS_PER_RORTThe maximum number of characters to display in aPort
.- See Also:
-
-
Constructor Details
-
GraphViewPanel
public GraphViewPanel(com.marginallyclever.nodegraphcore.Graph model) Constructs one new instance ofGraphViewPanel
.- Parameters:
model
- theGraph
model to paint.
-
-
Method Details
-
loadSettings
public void loadSettings() -
saveSettings
public void saveSettings() -
setHints
Set rendering hints for theGraphics2D
context.- Parameters:
g2
- theGraphics2D
context.
-
transformScreenToWorldPoint
-
paintNode
-
paintNodeBackground
-
paintNodeTitleBar
-
paintOnePort
-
getNodeInternalBounds
Returns the adjusted inner bounds of aNode
. Nodes have a left and right margin useful for printing labels and values without overlapping theConnection
points. these edges form an inner bound. Given aPort.getRectangle()
, this- Parameters:
r
- the outer bounsd of the node.- Returns:
- the adjusted inner bounds of a
Node
.
-
paintNodeBorder
-
paintPortConnectionPoints
-
paintText
Use the graphics context to paint text within a box with the provided alignment.- Parameters:
g
- the graphics contextstr
- the text to paintbox
- the bounding limitsalignH
- the desired horizontal alignment. Can be any one ofALIGN_LEFT
,ALIGN_RIGHT
, orALIGN_CENTER
alignV
- the desired vertical alignment. Can be any one ofALIGN_TOP
,ALIGN_BOTTOM
, orALIGN_CENTER
-
paintConnection
-
paintConnectionAtPoint
-
paintBezierBetweenTwoPoints
-
addViewListener
GraphViewListener
s register here.- Parameters:
p
- theGraphViewListener
to register.
-
removeViewListener
GraphViewListener
s unregister here.- Parameters:
p
- theGraphViewListener
to unregister.
-
setLineWidth
-
getZoom
public double getZoom()Returns the current scale- Returns:
- the current scale
-
setZoom
public void setZoom(double zoom) Sets the scale. Must be greater than or equal to 1.- Parameters:
zoom
- Must be greater than or equal to 1.
-
getSettings
-
moveAndZoomToFit
pan and zoom the camera to fit the rectangle in the view.- Parameters:
rectangle
- the rectangle to fit.
-
moveAndZoomToFit
pan and zoom the camera such that it can see all the selected nodes.- Parameters:
selectedNodes
- the nodes to fit. if there are none, allow all.
-
getCameraPosition
- Returns:
- a copy of the current camera position. it is in absolute world coordinates.
-
getPreviousMousePosition
-