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 GraphViewListeners 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.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intControls vertical text alignment within aNodeorPort.static final intControls horizontal or vertical text alignment within aNodeorPort.static final intControls horizontal text alignment within aNodeorPort.static final intControls horizontal text alignment within aNodeorPort.static final intControls vertical text alignment within aNodeorPort.static final intThe 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_WINDOWFields inherited from class java.awt.Component
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
ConstructorsConstructorDescriptionGraphViewPanel(com.marginallyclever.nodegraphcore.Graph model) Constructs one new instance ofGraphViewPanel. -
Method Summary
Modifier and TypeMethodDescriptionvoidGraphViewListeners register here.static RectangleReturns the adjusted inner bounds of aNode.doublegetZoom()Returns the current scalevoidvoidmoveAndZoomToFit(Rectangle rectangle) pan and zoom the camera to fit the rectangle in the view.voidmoveAndZoomToFit(List<com.marginallyclever.nodegraphcore.Node> selectedNodes) pan and zoom the camera such that it can see all the selected nodes.voidpaintBezierBetweenTwoPoints(Graphics g, Point p0, Point p3) Paint a cubic bezier usingGraphicsfrom p0 to p3.voidpaintConnection(Graphics g, com.marginallyclever.nodegraphcore.Connection c) Paint the male end of connection points at thisPort.voidPaint the male end of one connection point.voidPaint oneNodevoidpaintNodeBackground(Graphics g, com.marginallyclever.nodegraphcore.Node n) Paint the background of oneNodevoidpaintNodeBorder(Graphics g, com.marginallyclever.nodegraphcore.Node n) Paint the outside border of oneNode.voidpaintNodeTitleBar(Graphics g, com.marginallyclever.nodegraphcore.Node n) Paint the title bar of oneNode.voidpaintOnePort(Graphics g, com.marginallyclever.nodegraphcore.port.Port<?> v) Paint onePort.voidpaintPortConnectionPoints(Graphics g, com.marginallyclever.nodegraphcore.port.Port<?> v) Paint the female end of connection points of onePort.static voidUse the graphics context to paint text within a box with the provided alignment.voidGraphViewListeners unregister here.voidstatic voidsetHints(Graphics2D g2) Set rendering hints for theGraphics2Dcontext.voidsetLineWidth(Graphics g, float r) Sets the Graphics context line width.voidsetZoom(double zoom) Sets the scale.transformScreenToWorldPoint(Point point) Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUIMethods 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, updateMethods 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, validateMethods 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 aNodeorPort. SeepaintText(Graphics, String, Rectangle, int, int)for more information.- See Also:
-
ALIGN_RIGHT
public static final int ALIGN_RIGHTControls horizontal text alignment within aNodeorPort. 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 aNodeorPort. SeepaintText(Graphics, String, Rectangle, int, int)for more information.- See Also:
-
ALIGN_TOP
public static final int ALIGN_TOPControls vertical text alignment within aNodeorPort. SeepaintText(Graphics, String, Rectangle, int, int)for more information.- See Also:
-
ALIGN_BOTTOM
public static final int ALIGN_BOTTOMControls vertical text alignment within aNodeorPort. 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- theGraphmodel to paint.
-
-
Method Details
-
loadSettings
public void loadSettings() -
saveSettings
public void saveSettings() -
setHints
Set rendering hints for theGraphics2Dcontext.- Parameters:
g2- theGraphics2Dcontext.
-
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 theConnectionpoints. 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_CENTERalignV- the desired vertical alignment. Can be any one ofALIGN_TOP,ALIGN_BOTTOM, orALIGN_CENTER
-
paintConnection
-
paintConnectionAtPoint
-
paintBezierBetweenTwoPoints
-
addViewListener
GraphViewListeners register here.- Parameters:
p- theGraphViewListenerto register.
-
removeViewListener
GraphViewListeners unregister here.- Parameters:
p- theGraphViewListenerto 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
-