Search this API

y.view
Class MouseInputMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.MouseInputMode
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class MouseInputMode
extends ViewMode

This class is a ViewMode implementation that delegates Mouse2DEvents to MouseInputEditor instances. The corresponding MouseInputEditor instances are queried using the MouseInputEditorProvider interface that may be implemented by NodeRealizer, EdgeRealizer, and Drawable classes. Node and edge realizers do not have to implement this interface themselves, but can also delegate the calls to an instance of an external class, since this class uses NodeRealizer.getMouseInputEditorProvider() and EdgeRealizer.getMouseInputEditorProvider() respectively.
Additionally it is possible to add and remove any number of providers to this class that will be queried for editor instances.
This mode uses findMouseInputEditor(Graph2DView, double, double, HitInfo) whenever it receives a Mouse Event and tries to set the returned MouseInputEditor instance as the current MouseInputEditor. Then it registers a ChangeListener to the editor via its MouseInputEditor.addChangeListener(ChangeListener) method and delivers Mouse2DEvents to that instance until it notifies this mode via a ChangeEvent that it does not any longer want to be the current MouseInputEditor.
By default this mode does not search the Drawables, NodeRealizers, and EdgeRealizers for the MouseInputEditorProvider interface but queries the internal list of providers only. Use the corresponding properties to enable the search for each of those elements.
This ViewMode has integrated support in EditMode.

See Also:
MouseInputEditor, MouseInputEditorProvider, addMouseInputEditorProvider(MouseInputEditorProvider), EditMode.setMouseInputMode(MouseInputMode)
 

Field Summary
 
Fields inherited from class y.view.ViewMode
ACTIVE_PROPERTY, ACTIVE_VIEW_PROPERTY, CHILD_MODE_PROPERTY, EDITING_PROPERTY, GRAB_FOCUS_ENABLED_PROPERTY, lastClickEvent, lastDragEvent, lastMoveEvent, lastPressEvent, lastReleaseEvent, MODIFIER_MASK_PROPERTY, NAME_PROPERTY, originalX, originalY, PARENT_MODE_PROPERTY, view
 
Constructor Summary
MouseInputMode()
          Constructs a new MouseInputMode that queries the list of MouseInputEditorProviders only.
 
Method Summary
 void addMouseInputEditorProvider(MouseInputEditorProvider provider)
          Adds a MouseInputEditorProvider to the list of providers that will be queried in findMouseInputEditor(Graph2DView, double, double, HitInfo) for editors when this mode receives mouse events.
protected  void editingStopped()
          Callback method when the current editor has stopped editing.
 MouseInputEditor findMouseInputEditor(Graph2DView view, double x, double y, HitInfo hitInfo)
          Callback method that determines the new MouseInputEditor if no current editor is set for this view.
 MouseInputEditor getCurrentEditor()
          Returns the current MouseInputEditor instance that is the receiver of the Mouse2DEvents.
protected  void grabFocus()
          Callback called by mousePressed(java.awt.event.MouseEvent) to initiate a focus request of the Graph2DView associated to this mode.
 boolean isDrawableSearchingEnabled()
          Returns whether Drawables will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo).
 boolean isEdgeSearchingEnabled()
          Returns whether EdgeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the EdgeRealizer is hit by the current mouse event.
 boolean isNodeSearchingEnabled()
          Returns whether NodeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the NodeRealizer is hit by the current mouse event.
 boolean isReactivateParentOnEditingStopped()
          Returns whether to reactivate the parent ViewMode if editingStopped() is invoked.
 void mouseClicked(java.awt.event.MouseEvent e)
          A mouse button get clicked
 void mouseDragged(java.awt.event.MouseEvent e)
          The mouse gets dragged
 void mouseEntered(java.awt.event.MouseEvent e)
          The mouse enters the viewer component.
 void mouseExited(java.awt.event.MouseEvent e)
          The mouse leaves the viewer component.
 void mouseMoved(java.awt.event.MouseEvent e)
          The Mouse gets moved.
 void mousePressed(java.awt.event.MouseEvent e)
          A mouse button gets pressed.
 void mouseReleased(java.awt.event.MouseEvent e)
          A mouse button get released
 void removeMouseInputEditorProvider(MouseInputEditorProvider provider)
          Removes a previously added MouseInputEditorProvider from the list of providers.
 void setDrawableSearchingEnabled(boolean drawableSearchingEnabled)
          Determines whether Drawables will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo).
 void setEdgeSearchingEnabled(boolean edgeSearchingEnabled)
          Determines whether EdgeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the EdgeRealizer is hit by the current mouse event.
 void setNodeSearchingEnabled(boolean nodeSearchingEnabled)
          Determines whether NodeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the NodeRealizer is hit by the current mouse event.
 void setReactivateParentOnEditingStopped(boolean reactivateParentOnEditingStopped)
          Determines whether to reactivate the parent ViewMode if editingStopped() is invoked.
 boolean startEditor(MouseInputEditor newEditor)
          Sets the current MouseInputEditor instance programmatically and tries to start it.
 void stopEditing()
          Stops the current editor.
 
Methods inherited from class y.view.ViewMode
activate, addPropertyChangeListener, addPropertyChangeListener, cancelEditing, deactivateChild, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastClickEvent, getLastDragEvent, getLastHitInfo, getLastMoveEvent, getLastPressEvent, getLastReleaseEvent, getModifierMask, getName, getParent, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseDraggedLeft, mouseDraggedMiddle, mouseDraggedRight, mouseMoved, mousePressedLeft, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleasedLeft, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, removePropertyChangeListener, removePropertyChangeListener, setActiveView, setChild, setChild, setEditing, setGrabFocusEnabled, setGridMode, setLastHitInfo, setModifierMask, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MouseInputMode

public MouseInputMode()
Constructs a new MouseInputMode that queries the list of MouseInputEditorProviders only.

Method Detail

isDrawableSearchingEnabled

public boolean isDrawableSearchingEnabled()
Returns whether Drawables will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo).

Returns:
whether to check for the interface in all Drawables

isReactivateParentOnEditingStopped

public boolean isReactivateParentOnEditingStopped()
Returns whether to reactivate the parent ViewMode if editingStopped() is invoked.

Returns:
whether to reactivate the parent

setReactivateParentOnEditingStopped

public void setReactivateParentOnEditingStopped(boolean reactivateParentOnEditingStopped)
Determines whether to reactivate the parent ViewMode if editingStopped() is invoked. The default is true.

Parameters:
reactivateParentOnEditingStopped - whether to reactivate the parent

setDrawableSearchingEnabled

public void setDrawableSearchingEnabled(boolean drawableSearchingEnabled)
Determines whether Drawables will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo).

Parameters:
drawableSearchingEnabled - whether to check for the interface in all Drawables

isNodeSearchingEnabled

public boolean isNodeSearchingEnabled()
Returns whether NodeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the NodeRealizer is hit by the current mouse event.

Returns:
whether to check for the interface in the hit realizer

setNodeSearchingEnabled

public void setNodeSearchingEnabled(boolean nodeSearchingEnabled)
Determines whether NodeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the NodeRealizer is hit by the current mouse event.

Parameters:
nodeSearchingEnabled - whether to check for the interface in the hit realizer

isEdgeSearchingEnabled

public boolean isEdgeSearchingEnabled()
Returns whether EdgeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the EdgeRealizer is hit by the current mouse event.

Returns:
whether to check for the interface in the hit realizer

setEdgeSearchingEnabled

public void setEdgeSearchingEnabled(boolean edgeSearchingEnabled)
Determines whether EdgeRealizers will be checked whether they implement the MouseInputEditorProvider interface in findMouseInputEditor(Graph2DView, double, double, HitInfo) when the Node of the EdgeRealizer is hit by the current mouse event.

Parameters:
edgeSearchingEnabled - whether to check for the interface in the hit realizer

addMouseInputEditorProvider

public void addMouseInputEditorProvider(MouseInputEditorProvider provider)
Adds a MouseInputEditorProvider to the list of providers that will be queried in findMouseInputEditor(Graph2DView, double, double, HitInfo) for editors when this mode receives mouse events.

Parameters:
provider - a new provider instance to add to the list
Throws:
java.lang.NullPointerException - if provider is null

removeMouseInputEditorProvider

public void removeMouseInputEditorProvider(MouseInputEditorProvider provider)
Removes a previously added MouseInputEditorProvider from the list of providers.

Parameters:
provider - a new provider instance to add to the list
See Also:
addMouseInputEditorProvider(MouseInputEditorProvider)

getCurrentEditor

public MouseInputEditor getCurrentEditor()
Returns the current MouseInputEditor instance that is the receiver of the Mouse2DEvents.

Returns:
the current editor or null if there is no current editor
See Also:
startEditor(MouseInputEditor)

stopEditing

public void stopEditing()
Stops the current editor.


startEditor

public boolean startEditor(MouseInputEditor newEditor)
Sets the current MouseInputEditor instance programmatically and tries to start it. If there is an editor currently active it will first be stopped.

Parameters:
newEditor - the new editor or null
Returns:
whether the new editor has been successfully started and the mode is now "editing"

editingStopped

protected void editingStopped()
Callback method when the current editor has stopped editing. This method will reactivate the parent ViewMode.


mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
A mouse button gets pressed.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class ViewMode

grabFocus

protected void grabFocus()
Callback called by mousePressed(java.awt.event.MouseEvent) to initiate a focus request of the Graph2DView associated to this mode.


mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
A mouse button get released

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class ViewMode

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
A mouse button get clicked

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Overrides:
mouseClicked in class ViewMode

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
The mouse gets dragged

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class ViewMode

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
The Mouse gets moved. Delegates to ViewMode.mouseMoved(double,double).

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Overrides:
mouseMoved in class ViewMode

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
The mouse enters the viewer component.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Overrides:
mouseEntered in class ViewMode

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Description copied from class: ViewMode
The mouse leaves the viewer component.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class ViewMode

findMouseInputEditor

public MouseInputEditor findMouseInputEditor(Graph2DView view,
                                             double x,
                                             double y,
                                             HitInfo hitInfo)
Callback method that determines the new MouseInputEditor if no current editor is set for this view. By default, the registered mouse input editor providers are searched first, then, depending on whether they should be searched, node and edge as returned by the given HitInfo object are searched.
If Drawables should also be searched, the following sequence is used:
  1. drawables from the graph
  2. foreground drawables from the view
  3. background drawables from the view
Note that the search is stopped as soon as a MouseInputEditor is found. This editor will then be returned.

Parameters:
view - the view that will host the new editor instance
x - the x coordinate of the mouse event
y - the y coordinate of the mouse event
hitInfo - The HitInfo object to use. If null is given, a new HitInfo object is retrieved from the current view.
Returns:
The MouseInputEditor that should be started or null if none was found.
See Also:
setNodeSearchingEnabled(boolean), setEdgeSearchingEnabled(boolean), setDrawableSearchingEnabled(boolean)

© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.