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 NodeGraphViewListeners 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.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainerNested 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 intALIGN_BOTTOMControls vertical text alignment within aNodeorNodeVariable.static intALIGN_CENTERControls horizontal or vertical text alignment within aNodeorNodeVariable.static intALIGN_LEFTControls horizontal text alignment within aNodeorNodeVariable.static intALIGN_RIGHTControls horizontal text alignment within aNodeorNodeVariable.static intALIGN_TOPControls vertical text alignment within aNodeorNodeVariable.static java.awt.ColorCONNECTION_COLORThe defaultNodemale connection point color.static java.awt.ColorCONNECTION_POINT_COLORThe defaultNodefemale connection point color.static intCORNER_RADIUSThe defaultNodeouter border radius.static java.awt.ColorNODE_COLOR_BACKGROUNDThe defaultNodebackground color.static java.awt.ColorNODE_COLOR_BORDERThe defaultNodeborder color.static java.awt.ColorNODE_COLOR_FONT_CLEANThe defaultNodefont color.static java.awt.ColorNODE_COLOR_FONT_DIRTYThe defaultNodefont color for variables whenstatic java.awt.ColorNODE_COLOR_INTERNAL_BORDERThe defaultNodeinternal border betweenNodeVariable.static java.awt.ColorNODE_COLOR_TITLE_BACKGROUNDThe defaultNodetile bar background colorstatic java.awt.ColorNODE_COLOR_TITLE_FONTThe defaultNodetile bar font colorstatic java.awt.ColorPANEL_COLOR_BACKGROUNDThe defaultJPanelbackground 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_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields 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 voidaddViewListener(NodeGraphViewListener p)NodeGraphViewListeners register here.java.awt.RectanglegetNodeInternalBounds(java.awt.Rectangle r)Returns the adjusted inner bounds of aNode.voidpaintBezierBetweenTwoPoints(java.awt.Graphics g, java.awt.Point p0, java.awt.Point p3)Paint a cubic bezier usingGraphicsfrom p0 to p3.protected voidpaintComponent(java.awt.Graphics g)voidpaintConnectionAtPoint(java.awt.Graphics g, java.awt.Point p)Paint the male end of one connection point.voidpaintNode(java.awt.Graphics g, Node n)Paint oneNodevoidpaintNodeBackground(java.awt.Graphics g, Node n)Paint the background of oneNodevoidpaintNodeBorder(java.awt.Graphics g, Node n)Paint the outside border of oneNode.voidpaintNodeTitleBar(java.awt.Graphics g, Node n)Paint the title bar of oneNode.voidpaintText(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.voidpaintVariable(java.awt.Graphics g, NodeVariable<?> v)Paint oneNodeVariable.voidpaintVariableConnectionPoints(java.awt.Graphics g, NodeVariable<?> v)Paint the female end of connection points of oneNodeVariable.voidremoveViewListener(NodeGraphViewListener p)NodeGraphViewListeners unregister here.voidupdatePaintAreaBounds()Update the bounds of every node in the modelNodeGraph.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, updateMethods 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, validateTreeMethods 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, transferFocusUpCycleMethods 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 defaultNodebackground color. - 
NODE_COLOR_BORDER
public static final java.awt.Color NODE_COLOR_BORDERThe defaultNodeborder color. - 
NODE_COLOR_INTERNAL_BORDER
public static final java.awt.Color NODE_COLOR_INTERNAL_BORDERThe defaultNodeinternal border betweenNodeVariable. - 
PANEL_COLOR_BACKGROUND
public static final java.awt.Color PANEL_COLOR_BACKGROUNDThe defaultJPanelbackground color. - 
NODE_COLOR_FONT_CLEAN
public static final java.awt.Color NODE_COLOR_FONT_CLEANThe defaultNodefont color. - 
NODE_COLOR_FONT_DIRTY
public static final java.awt.Color NODE_COLOR_FONT_DIRTYThe defaultNodefont color for variables whengetIsDirty()
. is true. - 
NODE_COLOR_TITLE_FONT
public static final java.awt.Color NODE_COLOR_TITLE_FONTThe defaultNodetile bar font color - 
NODE_COLOR_TITLE_BACKGROUND
public static final java.awt.Color NODE_COLOR_TITLE_BACKGROUNDThe defaultNodetile bar background color - 
CONNECTION_POINT_COLOR
public static final java.awt.Color CONNECTION_POINT_COLORThe defaultNodefemale connection point color. - 
CONNECTION_COLOR
public static final java.awt.Color CONNECTION_COLORThe defaultNodemale connection point color. - 
CORNER_RADIUS
public static final int CORNER_RADIUSThe defaultNodeouter border radius.- See Also:
 - Constant Field Values
 
 - 
ALIGN_LEFT
public static final int ALIGN_LEFTControls horizontal text alignment within aNodeorNodeVariable. 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 aNodeorNodeVariable. 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 aNodeorNodeVariable. 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 aNodeorNodeVariable. 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 aNodeorNodeVariable. SeepaintText(Graphics, String, Rectangle, int, int)for more information.- See Also:
 - Constant Field Values
 
 
 - 
 - 
Constructor Details
- 
NodeGraphViewPanel
Constructs one new instance ofNodeGraphViewPanel.- Parameters:
 model- theNodeGraphmodel to paint.
 
 - 
 - 
Method Details
- 
paintComponent
protected void paintComponent(java.awt.Graphics g)- Overrides:
 paintComponentin classjavax.swing.JComponent
 - 
updatePaintAreaBounds
public void updatePaintAreaBounds()Update the bounds of every node in the modelNodeGraph. - 
paintNode
Paint oneNode- Parameters:
 g- theGraphicscontextn- theNodeto paint.
 - 
paintNodeBackground
Paint the background of oneNode- Parameters:
 g- theGraphicscontextn- theNodeto paint.
 - 
paintNodeTitleBar
Paint the title bar of oneNode.- Parameters:
 g- theGraphicscontextn- theNodeto paint.
 - 
paintVariable
Paint oneNodeVariable.- Parameters:
 g- theGraphicscontextv- theNodeVariableto 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 theNodeConnectionpoints. 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- theGraphicscontextn- theNodeto paint.
 - 
paintVariableConnectionPoints
Paint the female end of connection points of oneNodeVariable.- Parameters:
 g- theGraphicscontextv- theNodeVariableto 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_CENTERalignV- 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- theGraphicscontextp- 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 usingGraphicsfrom p0 to p3.- Parameters:
 g- theGraphicspainting tool.p0- the first point of the cubic bezier spline.p3- the last point of the cubic bezier spline.
 - 
addViewListener
NodeGraphViewListeners register here.- Parameters:
 p- theNodeGraphViewListenerto register.
 - 
removeViewListener
NodeGraphViewListeners unregister here.- Parameters:
 p- theNodeGraphViewListenerto unregister.
 
 -