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.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 a Node or NodeVariable.
    static int ALIGN_CENTER
    Controls horizontal or vertical text alignment within a Node or NodeVariable.
    static int ALIGN_LEFT
    Controls horizontal text alignment within a Node or NodeVariable.
    static int ALIGN_RIGHT
    Controls horizontal text alignment within a Node or NodeVariable.
    static int ALIGN_TOP
    Controls vertical text alignment within a Node or NodeVariable.
    static java.awt.Color CONNECTION_COLOR
    The default Node male connection point color.
    static java.awt.Color CONNECTION_POINT_COLOR
    The default Node female connection point color.
    static int CORNER_RADIUS
    The default Node outer border radius.
    static java.awt.Color NODE_COLOR_BACKGROUND
    The default Node background color.
    static java.awt.Color NODE_COLOR_BORDER
    The default Node border color.
    static java.awt.Color NODE_COLOR_FONT_CLEAN
    The default Node font color.
    static java.awt.Color NODE_COLOR_FONT_DIRTY
    The default Node font color for variables when
    static java.awt.Color NODE_COLOR_INTERNAL_BORDER
    The default Node internal border between NodeVariable.
    static java.awt.Color NODE_COLOR_TITLE_BACKGROUND
    The default Node tile bar background color
    static java.awt.Color NODE_COLOR_TITLE_FONT
    The default Node tile bar font color
    static java.awt.Color PANEL_COLOR_BACKGROUND
    The default JPanel 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 of NodeGraphViewPanel.
  • Method Summary

    Modifier and Type Method Description
    void addViewListener​(NodeGraphViewListener p)
    NodeGraphViewListeners register here.
    java.awt.Rectangle getNodeInternalBounds​(java.awt.Rectangle r)
    Returns the adjusted inner bounds of a Node.
    void paintBezierBetweenTwoPoints​(java.awt.Graphics g, java.awt.Point p0, java.awt.Point p3)
    Paint a cubic bezier using Graphics 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 one Node
    void paintNodeBackground​(java.awt.Graphics g, Node n)
    Paint the background of one Node
    void paintNodeBorder​(java.awt.Graphics g, Node n)
    Paint the outside border of one Node.
    void paintNodeTitleBar​(java.awt.Graphics g, Node n)
    Paint the title bar of one Node.
    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 one NodeVariable.
    void paintVariableConnectionPoints​(java.awt.Graphics g, NodeVariable<?> v)
    Paint the female end of connection points of one NodeVariable.
    void removeViewListener​(NodeGraphViewListener p)
    NodeGraphViewListeners unregister here.
    void updatePaintAreaBounds()
    Update the bounds of every node in the model NodeGraph.

    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_BACKGROUND
      The default Node background color.
    • NODE_COLOR_BORDER

      public static final java.awt.Color NODE_COLOR_BORDER
      The default Node border color.
    • NODE_COLOR_INTERNAL_BORDER

      public static final java.awt.Color NODE_COLOR_INTERNAL_BORDER
      The default Node internal border between NodeVariable.
    • PANEL_COLOR_BACKGROUND

      public static final java.awt.Color PANEL_COLOR_BACKGROUND
      The default JPanel background color.
    • NODE_COLOR_FONT_CLEAN

      public static final java.awt.Color NODE_COLOR_FONT_CLEAN
      The default Node font color.
    • NODE_COLOR_FONT_DIRTY

      public static final java.awt.Color NODE_COLOR_FONT_DIRTY
      The default Node font color for variables when
      getIsDirty()
      . is true.
    • NODE_COLOR_TITLE_FONT

      public static final java.awt.Color NODE_COLOR_TITLE_FONT
      The default Node tile bar font color
    • NODE_COLOR_TITLE_BACKGROUND

      public static final java.awt.Color NODE_COLOR_TITLE_BACKGROUND
      The default Node tile bar background color
    • CONNECTION_POINT_COLOR

      public static final java.awt.Color CONNECTION_POINT_COLOR
      The default Node female connection point color.
    • CONNECTION_COLOR

      public static final java.awt.Color CONNECTION_COLOR
      The default Node male connection point color.
    • CORNER_RADIUS

      public static final int CORNER_RADIUS
      The default Node outer border radius.
      See Also:
      Constant Field Values
    • ALIGN_LEFT

      public static final int ALIGN_LEFT
      Controls horizontal text alignment within a Node or NodeVariable. See paintText(Graphics, String, Rectangle, int, int) for more information.
      See Also:
      Constant Field Values
    • ALIGN_RIGHT

      public static final int ALIGN_RIGHT
      Controls horizontal text alignment within a Node or NodeVariable. See paintText(Graphics, String, Rectangle, int, int) for more information.
      See Also:
      Constant Field Values
    • ALIGN_CENTER

      public static final int ALIGN_CENTER
      Controls horizontal or vertical text alignment within a Node or NodeVariable. See paintText(Graphics, String, Rectangle, int, int) for more information.
      See Also:
      Constant Field Values
    • ALIGN_TOP

      public static final int ALIGN_TOP
      Controls vertical text alignment within a Node or NodeVariable. See paintText(Graphics, String, Rectangle, int, int) for more information.
      See Also:
      Constant Field Values
    • ALIGN_BOTTOM

      public static final int ALIGN_BOTTOM
      Controls vertical text alignment within a Node or NodeVariable. See paintText(Graphics, String, Rectangle, int, int) for more information.
      See Also:
      Constant Field Values
  • Constructor Details

  • Method Details

    • paintComponent

      protected void paintComponent​(java.awt.Graphics g)
      Overrides:
      paintComponent in class javax.swing.JComponent
    • updatePaintAreaBounds

      public void updatePaintAreaBounds()
      Update the bounds of every node in the model NodeGraph.
    • paintNode

      public void paintNode​(java.awt.Graphics g, Node n)
      Paint one Node
      Parameters:
      g - the Graphics context
      n - the Node to paint.
    • paintNodeBackground

      public void paintNodeBackground​(java.awt.Graphics g, Node n)
      Paint the background of one Node
      Parameters:
      g - the Graphics context
      n - the Node to paint.
    • paintNodeTitleBar

      public void paintNodeTitleBar​(java.awt.Graphics g, Node n)
      Paint the title bar of one Node.
      Parameters:
      g - the Graphics context
      n - the Node to paint.
    • paintVariable

      public void paintVariable​(java.awt.Graphics g, NodeVariable<?> v)
      Paint one NodeVariable.
      Parameters:
      g - the Graphics context
      v - the NodeVariable to paint.
    • getNodeInternalBounds

      public java.awt.Rectangle getNodeInternalBounds​(java.awt.Rectangle r)
      Returns the adjusted inner bounds of a Node. Nodes have a left and right margin useful for printing labels and values without overlapping the NodeConnection points. these edges form an inner bound. Given a NodeVariable.getRectangle(), this
      Parameters:
      r - the outer bounsd of the node.
      Returns:
      the adjusted inner bounds of a Node.
    • paintNodeBorder

      public void paintNodeBorder​(java.awt.Graphics g, Node n)
      Paint the outside border of one Node.
      Parameters:
      g - the Graphics context
      n - the Node to paint.
    • paintVariableConnectionPoints

      public void paintVariableConnectionPoints​(java.awt.Graphics g, NodeVariable<?> v)
      Paint the female end of connection points of one NodeVariable.
      Parameters:
      g - the Graphics context
      v - the NodeVariable 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 context
      str - the text to paint
      box - the bounding limits
      alignH - the desired horizontal alignment. Can be any one of ALIGN_LEFT, ALIGN_RIGHT, or ALIGN_CENTER
      alignV - the desired vertical alignment. Can be any one of ALIGN_TOP, ALIGN_BOTTOM, or ALIGN_CENTER
    • paintConnectionAtPoint

      public void paintConnectionAtPoint​(java.awt.Graphics g, java.awt.Point p)
      Paint the male end of one connection point.
      Parameters:
      g - the Graphics context
      p - 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 using Graphics from p0 to p3.
      Parameters:
      g - the Graphics painting tool.
      p0 - the first point of the cubic bezier spline.
      p3 - the last point of the cubic bezier spline.
    • addViewListener

      public void addViewListener​(NodeGraphViewListener p)
      NodeGraphViewListeners register here.
      Parameters:
      p - the NodeGraphViewListener to register.
    • removeViewListener

      public void removeViewListener​(NodeGraphViewListener p)
      NodeGraphViewListeners unregister here.
      Parameters:
      p - the NodeGraphViewListener to unregister.