| NORSYS SOFTWARE © 2011 | NETICA API | JAVA VERSION 5.02

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## norsys.netica.gui
Class LinkGraphic

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--norsys.netica.gui.LinkGraphic

All Implemented Interfaces:
  DataDisplayer, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.io.Serializable

public class LinkGraphic
extends java.awt.Component
implements DataDisplayer, java.awt.event.MouseListener

A java.awt.Component for displaying a link (arrow) between two NodePanels. By default the links are drawn in a fashion similar to that in Netica Application (TM). Using the `setStroke` method you have full access to the way the body of the link is drawn (color, thickness, solid/dashed, etc.). There are also methods for controlling the width and length of the arrowhead. In the following figure, there are two styles of link shown. Countless other styles and colors are possible.

Fig. 1. Two of many possible styles of LinkGraphic.

Event Handling: LinkGraphic objects will respond only to mouse press, release, and click events. To listen for these events, create a java.awt.event.MouseListener and attach it to the LinkGraphic using addMouseListener, just as you would any other java.awt.Component. Although LinkGraphic objects ignore enter, leave, and drag events, you can handle these events yourself by extending the LinkGraphic class and providing your own handler methods in the child class.

NetPanel objects will construct one LinkGraphic object for each link that exists in the Net they represent. Unlike NodePanel objects, these LinkGraphic objects do not correspond to any VisualObject display properties of links within the Netica Net. Thus, there is currently no way to save or restore link properties when Nets are saved and restored.

You may access the LinkGraphic objects owned by a NetPanel using `NetPanel.getLinkGraphics`, and you may conveniently attach a single MouseListener to all the NetPanel's LinkGraphic objects with a single call to `NetPanel.addListenerToAllComponents`.

The Netica distribution includes a sample program, /examples/NetViewer.java, that illustrates how to work with LinkGraphic objects.

Since:
  3.0
Version:
  5.02 - April 8, 2011
See Also:
  Serialized Form

Inner classes inherited from class java.awt.Component
`java.awt.Component.AccessibleAWTComponent`

Field Summary
`static java.awt.Color` | `defaultForegroundColor` The color of this LinkGraphic upon construction.
`static int` | `defaultLineWidth` The width of this LinkGraphic upon construction.
`static java.awt.Stroke` | `defaultStroke` The java.awt.Stroke used when initially constructing LinkGraphic objects.
`static int` | `DISPLAY_MODE_GRAYED` Used to display this LinkGraphic as "grayed" or "inactive".
`static int` | `DISPLAY_MODE_HILITED` Used to display this LinkGraphic as having been specially selected.
`static int` | `DISPLAY_MODE_NORMAL` Used to display this LinkGraphic in normal fashion.
`static java.awt.Color` | `grayedModeColor` A color to use for signaling that this LinkGraphic is in "grayed out" mode ( see `setDisplayMode(DISPLAY_MODE_GRAYED)`).
`static java.awt.Color` | `hilitedModeColor` A color to use for signaling that this LinkGraphic is in "hilited" mode ( see `setDisplayMode(DISPLAY_MODE_HILITED)`).
`static double` | `LINK_CLICK_DISTANCE_TOLERANCE` Controls the threshold used by isNear.
`static int` | `LINK_DEFAULT_ARROW_HEAD_LENGTH` Used to set the length of the triangle forming a link arrow's head.
`static int` | `LINK_DEFAULT_ARROW_HEAD_WIDTH` Used to set the width of the triangle forming a link arrow's head.

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`

Constructor Summary
`LinkGraphic(java.awt.Container parentContainer, NodePanel childNodePanel, NodePanel parentNodePanel)` public constructors

Method Summary
`int` | `getArrowHeadLength()` Gets the length of the arrow head.
`int` | `getArrowHeadWidth()` Gets the width of the arrow head.
`java.awt.Point` | `getCenterPoint()` Gets the center point of the link.
`NodePanel` | `getChildNodePanel()` Return the NodePanel that is nearest to the arrow end of this link.
`int` | `getDisplayMode()` Returns whether the link is grayed, normal, or hi-lited.
`java.awt.Point` | `getEndPoint()` Gets the endpoint (arrowhead end) of the link.
`NodePanel` | `getParentNodePanel()` Return the NodePanel that is nearest to the start end of this link.
`java.awt.Point` | `getStartPoint()` Gets the startpoint (non-arrowhead end) of the link.
`java.awt.Stroke` | `getStroke()` Returns the java.awt.Stroke used for drawing the line portion (body) of the link.
`boolean` | `isNear(java.awt.Point point)` Returns true if point is within LINK_CLICK_DISTANCE_TOLERANCE pixels of the nearest point on this LinkGraphic.
`void` | `mouseClicked(java.awt.event.MouseEvent event)` Informs all listeners of the click (press and release) event, provided this LinkGraphic is enabled and the mouse was pressed sufficiently near to the link.
`void` | `mouseEntered(java.awt.event.MouseEvent event)` Satisfies MouseListener interface; does nothing (has empty implementation body).
`void` | `mouseExited(java.awt.event.MouseEvent event)` Satisfies MouseListener interface; does nothing (has empty implementation body).
`void` | `mousePressed(java.awt.event.MouseEvent event)` Informs all listeners of the press event, provided this LinkGraphic is enabled and the mouse was pressed sufficiently near to the link.
`void` | `mouseReleased(java.awt.event.MouseEvent event)` Informs all listeners of the release event, provided this LinkGraphic is enabled and the mouse was pressed sufficiently near to the link.
`void` | `paint(java.awt.Graphics g)`
`void` | `refreshDataDisplayed()` Refresh all the data in this graphical Component, so that it correctly represents the current state of the Netica object it represents.
`void` | `setArrowHeadLength(int newLength)` Sets the length of the arrow head.
`void` | `setArrowHeadWidth(int newWidth)` Sets the width of the arrow head.
`void` | `setDisplayMode(int displayMode)` Sets whether the link is displayed as grayed, normal, or hi-lited.
`void` | `setEndPoint(java.awt.Point endPoint)` Sets the endpoint (arrowhead end) of the link, using Graphics coordinates.
`void` | `setStartPoint(java.awt.Point startPoint)` Sets the startpoint (non-arrowhead end) of the link, using Graphics coordinates.
`void` | `setStroke(java.awt.Stroke stroke)` Sets the java.awt.Stroke used for drawing the line portion (body) of the link.
`java.lang.String` | `toString()` Returns a compact description of the link.

Methods inherited from class java.awt.Component
`action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus, update, validate`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

public static double LINK_CLICK_DISTANCE_TOLERANCE

  Controls the threshold used by isNear.

public static int LINK_DEFAULT_ARROW_HEAD_LENGTH

  Used to set the length of the triangle forming a link arrow's head. The length dimension is parallel to the arrow's direction. Experiment to taste.

public static int LINK_DEFAULT_ARROW_HEAD_WIDTH

  Used to set the width of the triangle forming a link arrow's head. The width dimension is perpendicular to the arrow's direction. Experiment to taste.

public static java.awt.Stroke defaultStroke

  The java.awt.Stroke used when initially constructing LinkGraphic objects. The default is java.awt.BasicStroke( 1.0F ), a thin solid line one pixel in width.

public static final int DISPLAY_MODE_GRAYED

  Used to display this LinkGraphic as "grayed" or "inactive". See `setDisplayMode`.

public static final int DISPLAY_MODE_NORMAL

  Used to display this LinkGraphic in normal fashion. See `setDisplayMode`.

public static final int DISPLAY_MODE_HILITED

  Used to display this LinkGraphic as having been specially selected. See `setDisplayMode`.

public static java.awt.Color defaultForegroundColor

  The color of this LinkGraphic upon construction.

public static int defaultLineWidth

  The width of this LinkGraphic upon construction.

public static java.awt.Color grayedModeColor

  A color to use for signaling that this LinkGraphic is in "grayed out" mode ( see `setDisplayMode(DISPLAY_MODE_GRAYED)`). The default is gray.

public static java.awt.Color hilitedModeColor

  A color to use for signaling that this LinkGraphic is in "hilited" mode ( see `setDisplayMode(DISPLAY_MODE_HILITED)`). The default is red.

Constructor Detail

public LinkGraphic ( |
java.awt.Container | parentContainer,
NodePanel | childNodePanel,
NodePanel | parentNodePanel
| ) throws NeticaException

  public constructors

Method Detail

public int getArrowHeadLength ( )

  Gets the length of the arrow head.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_DEFAULT_ARROW_HEAD_LENGTH |  | Initial length upon construction
  setArrowHeadLength |  | Sets it
  getArrowHeadWidth |  | Get the width instead

public int getArrowHeadWidth ( )

  Gets the width of the arrow head.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_DEFAULT_ARROW_HEAD_WIDTH |  | Initial width upon construction
  setArrowHeadWidth |  | Sets it
  getArrowHeadLength |  | Get the length instead

public NodePanel getChildNodePanel ( )

  Return the NodePanel that is nearest to the arrow end of this link.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  getParentNodePanel |  | Retrieve the NodePanel at the other end

public java.awt.Point getCenterPoint ( )

  Gets the center point of the link.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  getStartPoint |  | Gets the start point
  getEndPoint |  | Gets the end point

public int getDisplayMode ( )

  Returns whether the link is grayed, normal, or hi-lited.

  Returns one of DISPLAY_MODE_GRAYED, DISPLAY_MODE_NORMAL, or DISPLAY_MODE_HILITED.
  Version:

  Versions 3.0 and later have this method.
  See Also:

  setDisplayMode |  | Sets it.

public java.awt.Point getEndPoint ( )

  Gets the endpoint (arrowhead end) of the link.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  getStartPoint |  | Gets the start point instead
  setEndPoint |  | Sets it

public NodePanel getParentNodePanel ( )

  Return the NodePanel that is nearest to the start end of this link.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  getChildNodePanel |  | Retrieve the NodePanel at the other end.

public java.awt.Point getStartPoint ( )

  Gets the startpoint (non-arrowhead end) of the link.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  getEndPoint |  | Gets the end point instead
  getCenterPoint |  | Gets the center point instead
  setStartPoint |  | Sets i.

public java.awt.Stroke getStroke ( )

  Returns the java.awt.Stroke used for drawing the line portion (body) of the link.
  Version:
  Versions 3.0 and later have this method.
  See Also:

  setStroke |  | Sets it

public boolean isNear ( |
java.awt.Point | point
| )

  Returns true if point is within LINK_CLICK_DISTANCE_TOLERANCE pixels of the nearest point on this LinkGraphic.
  Parameters:

  java.awt.Point |  | point |  | A point to test

  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_CLICK_DISTANCE_TOLERANCE |  | Controls the threshold of the distance measurement.

public void paint ( |
java.awt.Graphics | g
| )

  Overrides:
    `paint` in class `java.awt.Component`

public void setArrowHeadLength ( |
int | newLength
| )

  Sets the length of the arrow head.
  Parameters:

  int |  | newLength |  |

  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_DEFAULT_ARROW_HEAD_LENGTH |  | Initial length upon construction
  getArrowHeadLength |  | Retrieves it
  setArrowHeadWidth |  | Set the width instead

public void setArrowHeadWidth ( |
int | newWidth
| )

  Sets the width of the arrow head.
  Parameters:

  int |  | newWidth |  |

  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_DEFAULT_ARROW_HEAD_WIDTH |  | Initial width upon construction
  getArrowHeadWidth |  | Retrieves it
  setArrowHeadLength |  | Set the length instead

public void setDisplayMode ( |
int | displayMode
| )

  Sets whether the link is displayed as grayed, normal, or hi-lited.

  For normal mode, this Component's foreground Color is used.
  Parameters:

  int |  | displayMode |  | One of DISPLAY_MODE_GRAYED, DISPLAY_MODE_NORMAL, or DISPLAY_MODE_HILITED.

  Version:
  Versions 3.0 and later have this method.
  See Also:

  getDisplayMode |  | Retrieves it.

public void setEndPoint ( |
java.awt.Point | endPoint
| )

  Sets the endpoint (arrowhead end) of the link, using Graphics coordinates.
  Parameters:

  java.awt.Point |  | endPoint |  | The arrowhead (Node child) end of the link

  Version:
  Versions 3.0 and later have this method.
  See Also:

  setStartPoint |  | Sets the start point instead
  getEndPoint |  | Retrieves it

public void setStartPoint ( |
java.awt.Point | startPoint
| )

  Sets the startpoint (non-arrowhead end) of the link, using Graphics coordinates.
  Parameters:

  java.awt.Point |  | startPoint |  | The start (Node parent) end of the link

  Version:
  Versions 3.0 and later have this method.
  See Also:

  setEndPoint |  | Sets the end point instead
  getStartPoint |  | Retrieves it

public void setStroke ( |
java.awt.Stroke | stroke
| )

  Sets the java.awt.Stroke used for drawing the line portion (body) of the link.
  Parameters:

  Stroke |  | stroke |  | The new stroke to use

  Version:
  Versions 3.0 and later have this method.
  See Also:

  getStroke |  | Retrieves it

public String toString ( )

  Returns a compact description of the link.

  For instance for a link between the Smoking (parent) to the Bronchitis (child) node, it might be:

  LinkGraphic: [parent=Smoking at (544,83), child=Bronchitis at (602,128)]
  Version:

  Versions 3.0 and later have this method.
  Overrides:
    `toString` in class `java.awt.Component`

public void refreshDataDisplayed ( ) throws NeticaException

  Description copied from interface: `DataDisplayer`
  Refresh all the data in this graphical Component, so that it correctly represents the current state of the Netica object it represents.

  If this is a Container object, then it should arrange to invoke the refreshDataDisplayed method of all the DataDisplayer objects it contains.
  Version:

  Versions 3.0 and later have this method.
  Specified by:
    `refreshDataDisplayed` in interface `DataDisplayer`

public void mouseClicked ( |
java.awt.event.MouseEvent | event
| )

  Informs all listeners of the click (press and release) event, provided this LinkGraphic is enabled and the mouse was pressed sufficiently near to the link.

  This link is enabled iff java.awt.Component.isEnabled() returns true.

  The mouse is sufficiently near iff isNear returns true.
  Parameters:

  MouseEvent |  | event |  | The mouseClicked event.

  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_CLICK_DISTANCE_TOLERANCE |  | controls proximity sensitivity
  mousePressed |  | receives mousePressed events instead
  mouseClicked |  | receives mouseClicked events instead

  Specified by:
    `mouseClicked` in interface `java.awt.event.MouseListener`

public void mouseEntered ( |
java.awt.event.MouseEvent | event
| )

  Satisfies MouseListener interface; does nothing (has empty implementation body).
  Specified by:
    `mouseEntered` in interface `java.awt.event.MouseListener`

public void mouseExited ( |
java.awt.event.MouseEvent | event
| )

  Satisfies MouseListener interface; does nothing (has empty implementation body).
  Specified by:
    `mouseExited` in interface `java.awt.event.MouseListener`

public void mousePressed ( |
java.awt.event.MouseEvent | event
| )

  Informs all listeners of the press event, provided this LinkGraphic is enabled and the mouse was pressed sufficiently near to the link.

  This link is enabled iff java.awt.Component.isEnabled() returns true.

  The mouse is sufficiently near iff isNear returns true.
  Parameters:

  MouseEvent |  | event |  | The mousePressed event.

  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_CLICK_DISTANCE_TOLERANCE |  | controls proximity sensitivity
  mouseReleased |  | receives mouseReleased events instead
  mouseClicked |  | receives mouseClicked events instead

  Specified by:
    `mousePressed` in interface `java.awt.event.MouseListener`

public void mouseReleased ( |
java.awt.event.MouseEvent | event
| )

  Informs all listeners of the release event, provided this LinkGraphic is enabled and the mouse was pressed sufficiently near to the link.

  This link is enabled iff java.awt.Component.isEnabled() returns true.

  The mouse is sufficiently near iff isNear returns true.
  Parameters:

  MouseEvent |  | event |  | The mouseReleased event.

  Version:
  Versions 3.0 and later have this method.
  See Also:

  LINK_CLICK_DISTANCE_TOLERANCE |  | controls proximity sensitivity
  mousePressed |  | receives mousePressed events instead
  mouseClicked |  | receives mouseClicked events instead

  Specified by:
    `mouseReleased` in interface `java.awt.event.MouseListener`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD