wGmdh.jGmdh.gui
Class NodebuttonPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by wGmdh.jGmdh.gui.NodebuttonPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public final class NodebuttonPanel
extends javax.swing.JPanel

See Also:
Serialized Form

Nested Class Summary
static class NodebuttonPanel.ArmButtonRunnable
           
static class NodebuttonPanel.DrawLineRunnable
          A Runnable that draws lines on Graphics.
static class NodebuttonPanel.HighlightButtonRunnable
           
static class NodebuttonPanel.UnarmButtonRunnable
           
 class NodebuttonPanel.UnhighlightButtonRunnable
           
static class NodebuttonPanel.UnpressButtonRunnable
           
 
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 inherited from class javax.swing.JComponent
accessibleContext, 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
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
 
Method Summary
 void addNodeAsButton(NodeGraphics nodeGr, boolean visible)
           
protected  NodeGraphics armModelIteration(java.awt.Graphics2D g2, NodeGraphics visited, int index)
          Used to draw model links on Graphics + arming, performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue.
protected  NodeGraphics armModelIterationHelper(java.awt.Graphics2D g2, NodeGraphics visited, int index)
          Used to draw model links on Graphics + arming, performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue.
 void armModelIterative(java.awt.Graphics g, NodeGraphics root)
          Called from the arming thread, (painting also gets done from there).
protected  NodeGraphics fakeLinkModelIteration(java.awt.Graphics g2, NodeGraphics graphNode, int index)
          Used in conjunction with relinkArmed.
 void finalize()
           
 GuiManager getGuiManager()
           
protected  NodeGraphics highlightModelIteration(java.awt.Graphics2D g2, NodeGraphics visited)
          Used to draw model links on Graphics, performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue.
 java.lang.String highlightModelIterative(java.awt.Graphics g, NodeGraphics root)
          Called from the highlighting thread, repaints after each iteration.
protected  NodeGraphics linkModelIteration(java.awt.Graphics g2, NodeGraphics graphNode, int index)
          Used to draw model links on Graphics.
protected  void linkModelIterative(java.awt.Graphics g, int index)
          Call it from the arming thread.
 void paintChildren(java.awt.Graphics g)
           
 void paintComponent(java.awt.Graphics g)
          TODO: Provided we have a good graph traversal algorithm for drawing the links/vertices, if we have multiple models to draw, treat them as one graph, thus avoiding unneccessary multiple traversals.
 void relinkArmed(java.awt.Graphics buffer)
          Call it from the arming thread and sync with overlay.
protected  boolean relinkHighlighted(java.awt.Graphics g)
          Traverses mgr.highlightedNodes and draws links to their children
protected  NodeGraphics removeFakeEntries(NodeGraphics graphNode, int index)
          Used in conjunction with relinkArmed.
 void setGuiManager(GuiManager mgr)
           
 java.lang.String toString(double[] d)
          Array of doubles to html, without parts.
protected  NodeGraphics unarmModelIteration(java.awt.Graphics g, NodeGraphics graphNode, int index)
           
 void unarmModelIterative(java.awt.Graphics g, NodeGraphics root)
          Unarms the buttons and clears links, if neccessary.
 void unhighlightModel(java.awt.Graphics g)
          Unhighlights the buttons.
protected  NodeGraphics whenDraggedIteration(java.awt.Graphics2D g2, NodeGraphics visited, NodeGraphics dragged)
          Invoked by whenDraggedIterative
 void whenDraggedIterative(java.awt.Graphics g, NodeGraphics root, NodeGraphics dragged)
          This method gets invoked on every armed GMDH network when user starts dragging of a button.
 
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, 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, transferFocusBackward, 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, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

setGuiManager

public void setGuiManager(GuiManager mgr)

getGuiManager

public GuiManager getGuiManager()

paintChildren

public void paintChildren(java.awt.Graphics g)
Overrides:
paintChildren in class javax.swing.JComponent

finalize

public void finalize()
              throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

addNodeAsButton

public void addNodeAsButton(NodeGraphics nodeGr,
                            boolean visible)

toString

public java.lang.String toString(double[] d)
Array of doubles to html, without parts. Each member in new row.

Parameters:
d -
Returns:
s

highlightModelIteration

protected NodeGraphics highlightModelIteration(java.awt.Graphics2D g2,
                                               NodeGraphics visited)
Used to draw model links on Graphics, performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue. Called from the highlighting thread

Parameters:
g2 - Image to draw to.
visited - Model to process.
Returns:
NodeGraphics to process in the next iteration

highlightModelIterative

public java.lang.String highlightModelIterative(java.awt.Graphics g,
                                                NodeGraphics root)
                                         throws TooBig
Called from the highlighting thread, repaints after each iteration.

Parameters:
g -
root -
Returns:
mathematical representation of GMDH polynomial
Throws:
TooBig

unhighlightModel

public void unhighlightModel(java.awt.Graphics g)
Unhighlights the buttons. Repaints from the corresponding runnable.

Parameters:
g2 - Image to draw to.
graphNode - Model to draw.

whenDraggedIterative

public void whenDraggedIterative(java.awt.Graphics g,
                                 NodeGraphics root,
                                 NodeGraphics dragged)
This method gets invoked on every armed GMDH network when user starts dragging of a button. Every node in the network, whose root is received as a parameter, gets visited. If a visited node has a link to the dragged node, it gets stored, otherwise this link gets drawn on g.

Parameters:
g -
root -
dragged -

whenDraggedIteration

protected NodeGraphics whenDraggedIteration(java.awt.Graphics2D g2,
                                            NodeGraphics visited,
                                            NodeGraphics dragged)
Invoked by whenDraggedIterative

Parameters:
g2 -
visited -
dragged -
Returns:

armModelIteration

protected NodeGraphics armModelIteration(java.awt.Graphics2D g2,
                                         NodeGraphics visited,
                                         int index)
Used to draw model links on Graphics + arming, performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue. Called from the arming worker thread

Parameters:
g2 - Image to draw to.
graphNode - Model to draw.
index - Index of root of this GMDH network which it's stored under in armedNodes
Returns:
NodeGraphics to process in the next iteration

armModelIterationHelper

protected NodeGraphics armModelIterationHelper(java.awt.Graphics2D g2,
                                               NodeGraphics visited,
                                               int index)
Used to draw model links on Graphics + arming, performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue. Called from the arming worker thread

Parameters:
g2 - Image to draw to.
visited -
index - Index of root of this GMDH network which it's stored under in armedNodes
Returns:
NodeGraphics to process in the next iteration

armModelIterative

public void armModelIterative(java.awt.Graphics g,
                              NodeGraphics root)
Called from the arming thread, (painting also gets done from there).

Parameters:
g -
root -

linkModelIteration

protected NodeGraphics linkModelIteration(java.awt.Graphics g2,
                                          NodeGraphics graphNode,
                                          int index)
Used to draw model links on Graphics. No button state changes. Performs one iteration of non-recursive, breadth-first traversal, using a (FIFO) queue. Called from the arming worker thread

Parameters:
g2 - Graphics to draw to.
graphNode -
index -
Returns:
NodeGraphics to process in the next iteration

fakeLinkModelIteration

protected NodeGraphics fakeLinkModelIteration(java.awt.Graphics g2,
                                              NodeGraphics graphNode,
                                              int index)
Used in conjunction with relinkArmed. It uses a fake directReferences entry as a flag to determine whether we visited the node or not. Other than the condition when it returns null and the fakeIndex management, it is the same as linkModelIteration, so check that one out.

Parameters:
g2 - Graphics to draw to.
graphNode -
index - fake directReferences index, same as directReferences.size()-1
Returns:
NodeGraphics to process in the next iteration

linkModelIterative

protected void linkModelIterative(java.awt.Graphics g,
                                  int index)
Call it from the arming thread.

Parameters:
g -
index -

relinkArmed

public void relinkArmed(java.awt.Graphics buffer)
Call it from the arming thread and sync with overlay. In order to avoid multiple traversals, we will fake an entra armedNodes.get(i).directReferences - we add one extra reference to each node that marks if the node already has been visited (and its links have been drawn). At the end of the method this fake reference gets erased. Therefore it is essential to synchronize it (and related methods) with the arming executor - armedNodes.get(i).directReferences might get messed up otherwise.

Parameters:
buffer -

removeFakeEntries

protected NodeGraphics removeFakeEntries(NodeGraphics graphNode,
                                         int index)
Used in conjunction with relinkArmed. Removes fake entries in directReferences that are used as flags. This method also avoids multiple traversals.

Parameters:
graphNode -
index - index to remove
Returns:

relinkHighlighted

protected boolean relinkHighlighted(java.awt.Graphics g)
Traverses mgr.highlightedNodes and draws links to their children

Parameters:
g -
Returns:

unarmModelIteration

protected NodeGraphics unarmModelIteration(java.awt.Graphics g,
                                           NodeGraphics graphNode,
                                           int index)

unarmModelIterative

public void unarmModelIterative(java.awt.Graphics g,
                                NodeGraphics root)
Unarms the buttons and clears links, if neccessary. Non-recursive, breadth-first, using a (FIFO) queue. Will be called from the arming thread

Parameters:
g - Image to draw to.
root - Model to draw.

paintComponent

public void paintComponent(java.awt.Graphics g)
TODO: Provided we have a good graph traversal algorithm for drawing the links/vertices, if we have multiple models to draw, treat them as one graph, thus avoiding unneccessary multiple traversals. For the time being, we treat and draw each model separately, but specifically mark nodes that are shared by different models

Overrides:
paintComponent in class javax.swing.JComponent