Package com.marginallyclever.donatello
Class NodeGraphViewPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.marginallyclever.donatello.NodeGraphViewPanel
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,javax.accessibility.Accessible
public class NodeGraphViewPanel
extends javax.swing.JPanel
NodeGraphViewPanel
visualizes the contents of a NodeGraph
with Java Swing.
It can call on NodeGraphViewListener
s to add additional flavor.
Override this to implement a unique look and feel.- Since:
- 2022-02-11
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
-
Field Summary
Fields Modifier and Type Field Description static int
ALIGN_BOTTOM
Controls vertical text alignment within aNode
orNodeVariable
.static int
ALIGN_CENTER
Controls horizontal or vertical text alignment within aNode
orNodeVariable
.static int
ALIGN_LEFT
Controls horizontal text alignment within aNode
orNodeVariable
.static int
ALIGN_RIGHT
Controls horizontal text alignment within aNode
orNodeVariable
.static int
ALIGN_TOP
Controls vertical text alignment within aNode
orNodeVariable
.static java.awt.Color
CONNECTION_COLOR
The defaultNode
male connection point color.static java.awt.Color
CONNECTION_POINT_COLOR
The defaultNode
female connection point color.static int
CORNER_RADIUS
The defaultNode
outer border radius.static java.awt.Color
NODE_COLOR_BACKGROUND
The defaultNode
background color.static java.awt.Color
NODE_COLOR_BORDER
The defaultNode
border color.static java.awt.Color
NODE_COLOR_FONT_CLEAN
The defaultNode
font color.static java.awt.Color
NODE_COLOR_FONT_DIRTY
The defaultNode
font color for variables whenstatic java.awt.Color
NODE_COLOR_INTERNAL_BORDER
The defaultNode
internal border betweenNodeVariable
.static java.awt.Color
NODE_COLOR_TITLE_BACKGROUND
The defaultNode
tile bar background colorstatic java.awt.Color
NODE_COLOR_TITLE_FONT
The defaultNode
tile bar font colorstatic java.awt.Color
PANEL_COLOR_BACKGROUND
The defaultJPanel
background color.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
Constructors Constructor Description NodeGraphViewPanel(NodeGraph model)
Constructs one new instance ofNodeGraphViewPanel
. -
Method Summary
Modifier and Type Method Description void
addViewListener(NodeGraphViewListener p)
NodeGraphViewListener
s register here.java.awt.Rectangle
getNodeInternalBounds(java.awt.Rectangle r)
Returns the adjusted inner bounds of aNode
.void
paintBezierBetweenTwoPoints(java.awt.Graphics g, java.awt.Point p0, java.awt.Point p3)
Paint a cubic bezier usingGraphics
from p0 to p3.protected void
paintComponent(java.awt.Graphics g)
void
paintConnectionAtPoint(java.awt.Graphics g, java.awt.Point p)
Paint the male end of one connection point.void
paintNode(java.awt.Graphics g, Node n)
Paint oneNode
void
paintNodeBackground(java.awt.Graphics g, Node n)
Paint the background of oneNode
void
paintNodeBorder(java.awt.Graphics g, Node n)
Paint the outside border of oneNode
.void
paintNodeTitleBar(java.awt.Graphics g, Node n)
Paint the title bar of oneNode
.void
paintText(java.awt.Graphics g, java.lang.String str, java.awt.Rectangle box, int alignH, int alignV)
Use the graphics context to paint text within a box with the provided alignment.void
paintVariable(java.awt.Graphics g, NodeVariable<?> v)
Paint oneNodeVariable
.void
paintVariableConnectionPoints(java.awt.Graphics g, NodeVariable<?> v)
Paint the female end of connection points of oneNodeVariable
.void
removeViewListener(NodeGraphViewListener p)
NodeGraphViewListener
s unregister here.void
updatePaintAreaBounds()
Update the bounds of every node in the modelNodeGraph
.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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
NODE_COLOR_BACKGROUND
public static final java.awt.Color NODE_COLOR_BACKGROUNDThe defaultNode
background color. -
NODE_COLOR_BORDER
public static final java.awt.Color NODE_COLOR_BORDERThe defaultNode
border color. -
NODE_COLOR_INTERNAL_BORDER
public static final java.awt.Color NODE_COLOR_INTERNAL_BORDERThe defaultNode
internal border betweenNodeVariable
. -
PANEL_COLOR_BACKGROUND
public static final java.awt.Color PANEL_COLOR_BACKGROUNDThe defaultJPanel
background color. -
NODE_COLOR_FONT_CLEAN
public static final java.awt.Color NODE_COLOR_FONT_CLEANThe defaultNode
font color. -
NODE_COLOR_FONT_DIRTY
public static final java.awt.Color NODE_COLOR_FONT_DIRTYThe defaultNode
font color for variables whengetIsDirty()
. is true. -
NODE_COLOR_TITLE_FONT
public static final java.awt.Color NODE_COLOR_TITLE_FONTThe defaultNode
tile bar font color -
NODE_COLOR_TITLE_BACKGROUND
public static final java.awt.Color NODE_COLOR_TITLE_BACKGROUNDThe defaultNode
tile bar background color -
CONNECTION_POINT_COLOR
public static final java.awt.Color CONNECTION_POINT_COLORThe defaultNode
female connection point color. -
CONNECTION_COLOR
public static final java.awt.Color CONNECTION_COLORThe defaultNode
male connection point color. -
CORNER_RADIUS
public static final int CORNER_RADIUSThe defaultNode
outer border radius.- See Also:
- Constant Field Values
-
ALIGN_LEFT
public static final int ALIGN_LEFTControls horizontal text alignment within aNode
orNodeVariable
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
- Constant Field Values
-
ALIGN_RIGHT
public static final int ALIGN_RIGHTControls horizontal text alignment within aNode
orNodeVariable
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
- Constant Field Values
-
ALIGN_CENTER
public static final int ALIGN_CENTERControls horizontal or vertical text alignment within aNode
orNodeVariable
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
- Constant Field Values
-
ALIGN_TOP
public static final int ALIGN_TOPControls vertical text alignment within aNode
orNodeVariable
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
- Constant Field Values
-
ALIGN_BOTTOM
public static final int ALIGN_BOTTOMControls vertical text alignment within aNode
orNodeVariable
. SeepaintText(Graphics, String, Rectangle, int, int)
for more information.- See Also:
- Constant Field Values
-
-
Constructor Details
-
NodeGraphViewPanel
Constructs one new instance ofNodeGraphViewPanel
.- Parameters:
model
- theNodeGraph
model to paint.
-
-
Method Details
-
paintComponent
protected void paintComponent(java.awt.Graphics g)- Overrides:
paintComponent
in classjavax.swing.JComponent
-
updatePaintAreaBounds
public void updatePaintAreaBounds()Update the bounds of every node in the modelNodeGraph
. -
paintNode
Paint oneNode
- Parameters:
g
- theGraphics
contextn
- theNode
to paint.
-
paintNodeBackground
Paint the background of oneNode
- Parameters:
g
- theGraphics
contextn
- theNode
to paint.
-
paintNodeTitleBar
Paint the title bar of oneNode
.- Parameters:
g
- theGraphics
contextn
- theNode
to paint.
-
paintVariable
Paint oneNodeVariable
.- Parameters:
g
- theGraphics
contextv
- theNodeVariable
to paint.
-
getNodeInternalBounds
public java.awt.Rectangle getNodeInternalBounds(java.awt.Rectangle r)Returns the adjusted inner bounds of aNode
. Nodes have a left and right margin useful for printing labels and values without overlapping theNodeConnection
points. these edges form an inner bound. Given aNodeVariable.getRectangle()
, this- Parameters:
r
- the outer bounsd of the node.- Returns:
- the adjusted inner bounds of a
Node
.
-
paintNodeBorder
Paint the outside border of oneNode
.- Parameters:
g
- theGraphics
contextn
- theNode
to paint.
-
paintVariableConnectionPoints
Paint the female end of connection points of oneNodeVariable
.- Parameters:
g
- theGraphics
contextv
- theNodeVariable
to paint.
-
paintText
public void paintText(java.awt.Graphics g, java.lang.String str, java.awt.Rectangle box, int alignH, int alignV)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
-
paintConnectionAtPoint
public void paintConnectionAtPoint(java.awt.Graphics g, java.awt.Point p)Paint the male end of one connection point.- Parameters:
g
- theGraphics
contextp
- the center of male end to paint.
-
paintBezierBetweenTwoPoints
public void paintBezierBetweenTwoPoints(java.awt.Graphics g, java.awt.Point p0, java.awt.Point p3)Paint a cubic bezier usingGraphics
from p0 to p3.- Parameters:
g
- theGraphics
painting tool.p0
- the first point of the cubic bezier spline.p3
- the last point of the cubic bezier spline.
-
addViewListener
NodeGraphViewListener
s register here.- Parameters:
p
- theNodeGraphViewListener
to register.
-
removeViewListener
NodeGraphViewListener
s unregister here.- Parameters:
p
- theNodeGraphViewListener
to unregister.
-