templates.presentation
Class EventLinker

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by templates.presentation.EventLinker
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class EventLinker
extends javax.swing.JComponent
implements java.awt.event.MouseMotionListener, java.awt.event.MouseListener

The UI element which handles the user actions to establish links between the events of two template design components. This is an element which displays the events of the template components and the links between them, and lets the user modify the linking of events. Employed by EventLinksDialog .

Author:
Lenko Grigorov
See Also:
EventLinksDialog, Serialized Form

Nested Class Summary
protected  class EventLinker.AddEventToModel
          Action to mark an event for addition to the underlying model of the corresponding template component when the user commits all changes.
protected  class EventLinker.EventLabel
          The UI component used to render an event label in the event linker.
protected  class EventLinker.LabelLink
          The UI component used to render a link between two events.
 
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
protected  Connector connector
          The connector connecting the template components whose event links are displayed.
protected  TemplateDiagram diagram
          The diagram which contains the Connector connecting the template components whose event links are displayed.
protected static int EVENT_SPACING
          The top and bottom margins of event labels (in pixels).
protected  boolean isLeftLeft
          Information about whether the left Entity of the Connector is located to the left of the right Entity of the Connector.
protected  java.util.Set<EventLinker.EventLabel> labels
          The event labels for the events of the template components.
protected static int LINK_SENSITIVITY
          The degree of proximity to be used when checking if a point lies on the link between events (in pixels).
protected static int LINK_SPACING
          The left and right margins of event labels (in pixels).
protected  java.util.Set<EventLinker.LabelLink> links
          The representations of the links between events.
protected  java.awt.FontMetrics metrics
          The FontMetrics to be used when computing the sizes of the event labels on the screen.
protected static int MIN_HEIGHT
          The minimal height of the event linker component (in pixels).
protected static int MIN_LINK_WIDTH
          The minimal horizontal space which should be available to render event links (in pixels).
protected  EventLinker.EventLabel mouseDownOn
          The event label on which the user pressed the mouse button, if any.
protected static int NOTE_SPACE
          The space which should be available next to event labels to paint the warning sign that an event is not a part of the alphabet of the underlying model of the corresponding template component (in pixels).
protected static java.awt.Color SELECTED_COLOR
          The color for event links selected by the user.
protected  EventLinker.LabelLink selectedLink
          The event link selected by the user.
protected  boolean wasDragging
          Information about whether the user was dragging the mouse cursor before releasing the mouse button.
 
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
 
Constructor Summary
EventLinker(TemplateDiagram diagram, Connector connector)
          Construct and set up the event linker component.
 
Method Summary
 void addExtraLeftEvent(java.lang.String name)
          Add an event to the left template component of the Connector.
 void addExtraRightEvent(java.lang.String name)
          Add an event to the right template component of the Connector.
 void commitChanges()
          Commit all changes to the linking of events, as well as the addition of events to the underlying models of the template components linked by the Connector.
protected  EventLinker.EventLabel findMatchingRightLabel(java.lang.String name)
          Retrieve the event label for an event from the right template component of the Connector.
protected  EventLinker.EventLabel getLabel(java.lang.String name, Entity mom)
          Retrieve the event label for the event with the given name, part of the template component of the given Entity.
protected  EventLinker.EventLabel getLabelAt(java.awt.Point p)
          Retrieve the event label which contains the given point.
protected  int getLabelMaxY()
          Retrieve the maximum of the vertical positions of all event labels (including the label heights).
protected  int getMaxLabelWidth()
          Retrieve the maximum of the widths of all event labels.
 java.awt.Dimension getMinimumSize()
           
 java.awt.Dimension getPreferredSize()
           
protected  void linkLabels(EventLinker.EventLabel first, EventLinker.EventLabel second)
          Establish a link between the event from the given event labels.
 void matchEvents()
          Remove all existing links between events and only establish links between events with the same name.
 void mouseClicked(java.awt.event.MouseEvent arg0)
          Do nothing.
 void mouseDragged(java.awt.event.MouseEvent arg0)
          Record the fact that the mouse was dragged.
 void mouseEntered(java.awt.event.MouseEvent arg0)
          Do nothing.
 void mouseExited(java.awt.event.MouseEvent arg0)
          Do nothing.
 void mouseMoved(java.awt.event.MouseEvent arg0)
          Repaint the UI element to reflect the updated position of the mouse cursor.
 void mousePopupTrigger(java.awt.event.MouseEvent arg0)
          Show the context (right-click) pop-up menu for the item under the mouse cursor.
 void mousePressed(java.awt.event.MouseEvent arg0)
          Process the depression of the mouse button to perform any relevant action such as starting the drawing of a new link, completing an already started link, etc.
 void mouseReleased(java.awt.event.MouseEvent arg0)
          Process the release of the mouse button to perform any relevant action such as selecting a link, completing an already started link, etc.
 void paint(java.awt.Graphics g)
           
 void unlinkAll()
          Remove all links between the events of the template components connected by the Connector given during initialization.
 void unlinkLabel(EventLinker.EventLabel label)
          Remove all links which link the event from the given event label.
 void update()
          Update the positions of the event labels.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EVENT_SPACING

protected static final int EVENT_SPACING
The top and bottom margins of event labels (in pixels).

See Also:
Constant Field Values

LINK_SPACING

protected static final int LINK_SPACING
The left and right margins of event labels (in pixels).

See Also:
Constant Field Values

LINK_SENSITIVITY

protected static final int LINK_SENSITIVITY
The degree of proximity to be used when checking if a point lies on the link between events (in pixels).

See Also:
Constant Field Values

MIN_LINK_WIDTH

protected static final int MIN_LINK_WIDTH
The minimal horizontal space which should be available to render event links (in pixels).

See Also:
Constant Field Values

MIN_HEIGHT

protected static final int MIN_HEIGHT
The minimal height of the event linker component (in pixels).

See Also:
Constant Field Values

NOTE_SPACE

protected static final int NOTE_SPACE
The space which should be available next to event labels to paint the warning sign that an event is not a part of the alphabet of the underlying model of the corresponding template component (in pixels).

See Also:
Constant Field Values

SELECTED_COLOR

protected static final java.awt.Color SELECTED_COLOR
The color for event links selected by the user.


isLeftLeft

protected boolean isLeftLeft
Information about whether the left Entity of the Connector is located to the left of the right Entity of the Connector. Set to true if the left entity is located to the left of the right entity, set to false otherwise.


diagram

protected TemplateDiagram diagram
The diagram which contains the Connector connecting the template components whose event links are displayed.


connector

protected Connector connector
The connector connecting the template components whose event links are displayed.


metrics

protected java.awt.FontMetrics metrics
The FontMetrics to be used when computing the sizes of the event labels on the screen.


labels

protected java.util.Set<EventLinker.EventLabel> labels
The event labels for the events of the template components.


links

protected java.util.Set<EventLinker.LabelLink> links
The representations of the links between events.


mouseDownOn

protected EventLinker.EventLabel mouseDownOn
The event label on which the user pressed the mouse button, if any.


wasDragging

protected boolean wasDragging
Information about whether the user was dragging the mouse cursor before releasing the mouse button.


selectedLink

protected EventLinker.LabelLink selectedLink
The event link selected by the user.

Constructor Detail

EventLinker

public EventLinker(TemplateDiagram diagram,
                   Connector connector)
Construct and set up the event linker component.

Parameters:
diagram - the diagram which contains the Connector connecting the template components whose event links are to be displayed
connector - the connector connecting the template components whose event links are to be displayed
Method Detail

update

public void update()
Update the positions of the event labels.


getLabel

protected EventLinker.EventLabel getLabel(java.lang.String name,
                                          Entity mom)
Retrieve the event label for the event with the given name, part of the template component of the given Entity.

Parameters:
name - the name of the event
mom - the Entity to whose TemplateComponent the event belongs
Returns:
the event label for this event if it exists; null otherwise

addExtraLeftEvent

public void addExtraLeftEvent(java.lang.String name)
Add an event to the left template component of the Connector.

The event will appear in the list of events available for linking, however, it will not be added to the underlying model of the template component.

Parameters:
name - the name for the new event

addExtraRightEvent

public void addExtraRightEvent(java.lang.String name)
Add an event to the right template component of the Connector.

The event will appear in the list of events available for linking, however, it will not be added to the underlying model of the template component.

Parameters:
name - the name for the new event

getMaxLabelWidth

protected int getMaxLabelWidth()
Retrieve the maximum of the widths of all event labels.

Returns:
the maximum of the widths of all event labels; or 0 if there are no event labels

getLabelMaxY

protected int getLabelMaxY()
Retrieve the maximum of the vertical positions of all event labels (including the label heights).

Returns:
the maximum of the vertical positions of all event labels (including the label heights); or 0 if there are no event labels

getLabelAt

protected EventLinker.EventLabel getLabelAt(java.awt.Point p)
Retrieve the event label which contains the given point.

Parameters:
p - the point
Returns:
the event label which contains the given point, if such a label exists; null otherwise

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class javax.swing.JComponent

paint

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

linkLabels

protected void linkLabels(EventLinker.EventLabel first,
                          EventLinker.EventLabel second)
Establish a link between the event from the given event labels. Remove any links that already link each of these events, if necessary.

Parameters:
first - the event label with the first event to be linked
second - the event label with the second event to be linked

unlinkLabel

public void unlinkLabel(EventLinker.EventLabel label)
Remove all links which link the event from the given event label.

Parameters:
label - the event label with the event whose links should be removed

unlinkAll

public void unlinkAll()
Remove all links between the events of the template components connected by the Connector given during initialization.


findMatchingRightLabel

protected EventLinker.EventLabel findMatchingRightLabel(java.lang.String name)
Retrieve the event label for an event from the right template component of the Connector.

Parameters:
name - the name of the event
Returns:
the event label for the event from the right template component of the Connector, if the right template component has an event with the given name; null otherwise

matchEvents

public void matchEvents()
Remove all existing links between events and only establish links between events with the same name.


mouseDragged

public void mouseDragged(java.awt.event.MouseEvent arg0)
Record the fact that the mouse was dragged.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent arg0)
Repaint the UI element to reflect the updated position of the mouse cursor.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent arg0)
Do nothing.

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

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent arg0)
Do nothing.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent arg0)
Do nothing.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent arg0)
Process the depression of the mouse button to perform any relevant action such as starting the drawing of a new link, completing an already started link, etc.

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

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent arg0)
Process the release of the mouse button to perform any relevant action such as selecting a link, completing an already started link, etc.

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

mousePopupTrigger

public void mousePopupTrigger(java.awt.event.MouseEvent arg0)
Show the context (right-click) pop-up menu for the item under the mouse cursor.

Parameters:
arg0 - the description of the mouse event

commitChanges

public void commitChanges()
Commit all changes to the linking of events, as well as the addition of events to the underlying models of the template components linked by the Connector.