psdi.workflow.diagram

Class Diagram

  • java.lang.Object
    • java.awt.Component
      • java.awt.Container
        • javax.swing.JComponent
          • javax.swing.JPanel
            • psdi.workflow.diagram.Diagram
  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible


    public class Diagram
    extends javax.swing.JPanel

    This class displays the workflow diagram.

    A diagram node is built for each workflow node and the relationships attached to it. The entering and leaving relationships are ordered based on the destination and origin. This removes as much line interferance as possible without reorganizing the nodes. Each line is routed using the vertical and horizontal channels between each row and column. The node postions are then calculated based on the channels size. The paint code draws each line absed on the channels it goes through.

    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 and Description
      protected java.util.Hashtable channels 
      protected java.util.Hashtable channelSet 
      protected int columnCount 
      protected int[] columns 
      protected DiagramConfiguration configuration 
      protected static int[] curvePoints 
      protected static int DASH_LENGTH 
      protected static int GAP_LENGTH 
      protected static int LINE_NEGATIVE 
      protected static int LINE_NORMAL 
      protected static int LINE_SELECTED 
      protected java.util.TreeSet lines 
      protected java.util.Vector listeners 
      protected java.util.Hashtable nodeIndex 
      protected java.util.TreeSet nodes 
      protected java.awt.Dimension preferredSize 
      protected int rowCount 
      protected int[] rows 
      protected WorkflowEntity selection 
      protected Workflow workflow 
      • 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 and Description
      Diagram(Workflow workflow)
      Constructs a diagram object to display a workflow
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addDiagramListener(DiagramListener listener)
      Adds a listener to the diagram
      void buildDiagram()
      Builds the diagram based on the current workflow and configuration.
      protected DiagramWorkflowNode createDiagramNode(WorkflowNode node, int imageScale)
      Creates a workflow node
      protected void drawArrow(java.awt.Graphics g, int x, int y, int state)
      Draws an right pointing arrow at the end of a line
      protected void drawLine(java.awt.Graphics g, WorkflowRelationship rel)
      Draws a line representing the relationship.
      protected void drawLine(java.awt.Graphics g, WorkflowRelationship rel, int x1, int y1, int x2, int y2, int state)
      Draws a line.
      protected void drawLineSegment(java.awt.Graphics g, int x1, int y1, int x2, int y2, boolean dashed)
      Draws a line segment.
      protected void fireListeners(DiagramEvent e)
      Fires an event for all the listeners
      protected DiagramLineChannel getChannel(int index, int orientation, int position)
      Returns channel for a given index,orientation and position creating it if necessary
      java.awt.image.BufferedImage getImage()
      Gets the image of the workflow diagram.
      protected java.awt.Color getLineColor(int state)
      Returns the line color for the line state
      protected java.lang.Object getNodeKey(int row, int column)
      Returns a unique key for the node based on its location
      protected java.awt.Point getPoint(int x, int y)
      Returns the row and column within the diagram for a given x,y value.
      java.awt.Dimension getPreferredSize()
      Returns the preferred size - this is the diagram size
      protected java.awt.Point[] getSegments(Line line)
      Returns the list of segments the line is be drawn in.
      protected boolean isStraight(int fromRow, int fromColumn, int toRow, int toColumn)
      Returns true if a line can be run straight between the positions and false otherwise
      protected void paintComponent(java.awt.Graphics g)
      Paints the components
      void removeDiagramListener(DiagramListener listener)
      Removes a listener from the diagram
      void selectNode(WorkflowEntity node, boolean state)
      Sets the selection state of a node.
      void setConfiguration(DiagramConfiguration configuration)
      Sets the configuration for the diagram
      void setSelection(WorkflowEntity selection)
      Sets the current selection for the diagram.
      void setWorkflow(Workflow workflow)
      Sets a new workflow
      • 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, 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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, 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 Detail

      • nodes

        protected java.util.TreeSet nodes
      • channels

        protected java.util.Hashtable channels
      • nodeIndex

        protected java.util.Hashtable nodeIndex
      • rowCount

        protected int rowCount
      • columnCount

        protected int columnCount
      • preferredSize

        protected java.awt.Dimension preferredSize
      • channelSet

        protected java.util.Hashtable channelSet
      • lines

        protected java.util.TreeSet lines
      • listeners

        protected java.util.Vector listeners
      • rows

        protected int[] rows
      • columns

        protected int[] columns
      • curvePoints

        protected static final int[] curvePoints
    • Constructor Detail

      • Diagram

        public Diagram(Workflow workflow)
        Constructs a diagram object to display a workflow
        Parameters:
        workflow - The workflow to display
    • Method Detail

      • setWorkflow

        public void setWorkflow(Workflow workflow)
        Sets a new workflow
        Parameters:
        workflow - The workflow to display
      • setConfiguration

        public void setConfiguration(DiagramConfiguration configuration)
        Sets the configuration for the diagram
        Parameters:
        configuration - The configuration object
      • setSelection

        public void setSelection(WorkflowEntity selection)
        Sets the current selection for the diagram.
        Parameters:
        selection - The new selection
      • selectNode

        public void selectNode(WorkflowEntity node,
                               boolean state)
        Sets the selection state of a node.
        Parameters:
        node - The node to select
        state - The selection state
      • getPoint

        protected java.awt.Point getPoint(int x,
                                          int y)
        Returns the row and column within the diagram for a given x,y value.
        Parameters:
        x - The x location
        y - The y location
        Returns:
        The point as a column,row
      • buildDiagram

        public void buildDiagram()
        Builds the diagram based on the current workflow and configuration.
      • createDiagramNode

        protected DiagramWorkflowNode createDiagramNode(WorkflowNode node,
                                                        int imageScale)
        Creates a workflow node
        Parameters:
        node - The workflow node
        imageScale - The scaling for the image
      • getPreferredSize

        public java.awt.Dimension getPreferredSize()
        Returns the preferred size - this is the diagram size
        Overrides:
        getPreferredSize in class javax.swing.JComponent
        Returns:
        The preferred size
      • getChannel

        protected DiagramLineChannel getChannel(int index,
                                                int orientation,
                                                int position)
        Returns channel for a given index,orientation and position creating it if necessary
        Parameters:
        index - The channel index
        orientation - The channel orientation
        position - The channel poisiton
        Returns:
        The channel
      • isStraight

        protected boolean isStraight(int fromRow,
                                     int fromColumn,
                                     int toRow,
                                     int toColumn)
        Returns true if a line can be run straight between the positions and false otherwise
        Parameters:
        fromRow - The originating row
        fromColumn - The origination column
        toRow - The destination row
        toColumn - The destination column
        Returns:
        The true if straight line is possible.
      • getNodeKey

        protected java.lang.Object getNodeKey(int row,
                                              int column)
        Returns a unique key for the node based on its location
        Returns:
        The node key
      • paintComponent

        protected void paintComponent(java.awt.Graphics g)
        Paints the components
        Overrides:
        paintComponent in class javax.swing.JComponent
        Parameters:
        g - The graphics context
      • drawLine

        protected void drawLine(java.awt.Graphics g,
                                WorkflowRelationship rel)

        Draws a line representing the relationship. There are 3 basic lines that can be drawn.

         
              A horizontal line between 2 nodes 
              A 3 segement line between 2 nodes in different rows 
              A 5 segement line between 2 nodes with intervening nodes
              <pre>
        Parameters:
        g - The graphics context
        rel - The relationship
      • drawLine

        protected void drawLine(java.awt.Graphics g,
                                WorkflowRelationship rel,
                                int x1,
                                int y1,
                                int x2,
                                int y2,
                                int state)
        Draws a line. This handles line crossing calling drawLineSegment to draw each part of the line
        Parameters:
        g - The graphics context
        rel - The workflow relationship the line belongs to
        x1 - The x coordinate of the line start
        y1 - The y coordinate of the line start
        x2 - The x coordinate of the line end
        y2 - The y coordinate of the line end
        state - The state of the line to be drawn
      • drawLineSegment

        protected void drawLineSegment(java.awt.Graphics g,
                                       int x1,
                                       int y1,
                                       int x2,
                                       int y2,
                                       boolean dashed)
        Draws a line segment.
        Parameters:
        g - The graphics context
        x1 - The x coordinate of the line start
        y1 - The y coordinate of the line start
        x2 - The x coordinate of the line end
        y2 - The y coordinate of the line end
        dashed - True if a dashed line being drawn
      • drawArrow

        protected void drawArrow(java.awt.Graphics g,
                                 int x,
                                 int y,
                                 int state)
        Draws an right pointing arrow at the end of a line
        Parameters:
        g - The graphics context
        x - The x coordinate of the arrow point
        y - The y coordinate of the arrow point
        state - The state of the line being drawn
      • getLineColor

        protected java.awt.Color getLineColor(int state)
        Returns the line color for the line state
        Parameters:
        state - The state of the line being drawn
        Returns:
        The color
      • getSegments

        protected java.awt.Point[] getSegments(Line line)
        Returns the list of segments the line is be drawn in. This is derived from the intersections with other lines.
        Parameters:
        line - The line to be drawn
        Returns:
        The point list of segements
      • getImage

        public java.awt.image.BufferedImage getImage()
        Gets the image of the workflow diagram. This id done by allocating an off-screen image and drawing into it.
        Returns:
        The image of the diagram
      • addDiagramListener

        public void addDiagramListener(DiagramListener listener)
        Adds a listener to the diagram
        Parameters:
        listener - The diagram listener
      • removeDiagramListener

        public void removeDiagramListener(DiagramListener listener)
        Removes a listener from the diagram
        Parameters:
        listener - The diagram listener
      • fireListeners

        protected void fireListeners(DiagramEvent e)
        Fires an event for all the listeners
        Parameters:
        e - The workflow edit event