Package com.mxgraph.swing.handler
Class mxConnectionHandler
- java.lang.Object
-
- com.mxgraph.swing.util.mxMouseAdapter
-
- com.mxgraph.swing.handler.mxConnectionHandler
-
- All Implemented Interfaces:
java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.util.EventListener
public class mxConnectionHandler extends mxMouseAdapter
Connection handler creates new connections between cells. This control is used to display the connector icon, while the preview is used to draw the line. mxEvent.CONNECT fires between begin- and endUpdate in mouseReleased. Thecellproperty contains the inserted edge, theeventandtargetproperties contain the respective arguments that were passed to mouseReleased.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanactiveprotected java.awt.Rectangleboundsstatic java.awt.CursorCONNECT_CURSORprotected javax.swing.ImageIconconnectIconSpecifies the icon to be used for creating new connections.protected mxConnectPreviewconnectPreviewprotected booleancreateTargetSpecifies if the source should be cloned and used as a target if no target was selected.protected booleanenabledprotected java.lang.Stringerrorprotected mxEventSourceeventSourceHolds the event source.protected java.awt.Pointfirstprotected mxGraphComponentgraphComponentprotected booleanhandleEnabledSpecifies if a handle should be used for creating new connections.protected inthandleSizeSpecifies the size of the handle to be used for creating new connections.protected booleankeepOnTopAppearance and event handling order wrt subhandles.protected mxCellMarkermarkerprotected mxEventSource.mxIEventListenerresetHandlerprotected booleanselectprotected mxCellStatesource
-
Constructor Summary
Constructors Constructor Description mxConnectionHandler(mxGraphComponent graphComponent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddGraphListeners(mxGraph graph)Installs the listeners to update the handles after any changes.voidaddListener(java.lang.String eventName, mxEventSource.mxIEventListener listener)Adds the given event listener.protected mxConnectPreviewcreateConnectPreview()java.lang.ObjectcreateTargetVertex(java.awt.event.MouseEvent e, java.lang.Object source)javax.swing.ImageIcongetConnecIcon()mxConnectPreviewgetConnectPreview()intgetHandleSize()mxCellMarkergetMarker()booleanisActive()booleanisConnecting()Returns true if the source terminal has been clicked and a new connection is currently being previewed.booleanisCreateTarget()booleanisEnabled()booleanisHandleEnabled()booleanisHighlighting()Returns true if no connectIcon is specified and handleEnabled is false.booleanisKeepOnTop()booleanisSelect()booleanisValidSource(java.lang.Object cell)booleanisValidTarget(java.lang.Object cell)Returns true.voidmouseDragged(java.awt.event.MouseEvent e)voidmouseMoved(java.awt.event.MouseEvent e)voidmousePressed(java.awt.event.MouseEvent e)voidmouseReleased(java.awt.event.MouseEvent e)voidpaint(java.awt.Graphics g)protected voidremoveGraphListeners(mxGraph graph)Removes all installed listeners.voidremoveListener(mxEventSource.mxIEventListener listener)Removes the given event listener.voidremoveListener(mxEventSource.mxIEventListener listener, java.lang.String eventName)Removes the given event listener for the specified event name.voidreset()voidsetBounds(java.awt.Rectangle value)voidsetConnectIcon(javax.swing.ImageIcon value)voidsetConnectPreview(mxConnectPreview value)voidsetCreateTarget(boolean value)voidsetEnabled(boolean value)voidsetHandleEnabled(boolean value)voidsetHandleSize(int value)voidsetKeepOnTop(boolean value)voidsetMarker(mxCellMarker value)voidsetSelect(boolean value)voidstart(java.awt.event.MouseEvent e, mxCellState state)java.lang.StringvalidateConnection(java.lang.Object source, java.lang.Object target)Returns the error message or an empty string if the connection for the given source target pair is not valid.-
Methods inherited from class com.mxgraph.swing.util.mxMouseAdapter
mouseClicked, mouseEntered, mouseExited
-
-
-
-
Field Detail
-
CONNECT_CURSOR
public static java.awt.Cursor CONNECT_CURSOR
-
graphComponent
protected mxGraphComponent graphComponent
-
eventSource
protected mxEventSource eventSource
Holds the event source.
-
connectPreview
protected mxConnectPreview connectPreview
-
connectIcon
protected javax.swing.ImageIcon connectIcon
Specifies the icon to be used for creating new connections. If this is specified then it is used instead of the handle. Default is null.
-
handleSize
protected int handleSize
Specifies the size of the handle to be used for creating new connections. Default is mxConstants.CONNECT_HANDLE_SIZE.
-
handleEnabled
protected boolean handleEnabled
Specifies if a handle should be used for creating new connections. This is only used if no connectIcon is specified. If this is false, then the source cell will be highlighted when the mouse is over the hotspot given in the marker. Default is mxConstants.CONNECT_HANDLE_ENABLED.
-
select
protected boolean select
-
createTarget
protected boolean createTarget
Specifies if the source should be cloned and used as a target if no target was selected. Default is false.
-
keepOnTop
protected boolean keepOnTop
Appearance and event handling order wrt subhandles.
-
enabled
protected boolean enabled
-
first
protected transient java.awt.Point first
-
active
protected transient boolean active
-
bounds
protected transient java.awt.Rectangle bounds
-
source
protected transient mxCellState source
-
marker
protected transient mxCellMarker marker
-
error
protected transient java.lang.String error
-
resetHandler
protected transient mxEventSource.mxIEventListener resetHandler
-
-
Constructor Detail
-
mxConnectionHandler
public mxConnectionHandler(mxGraphComponent graphComponent)
- Parameters:
graphComponent-
-
-
Method Detail
-
addGraphListeners
protected void addGraphListeners(mxGraph graph)
Installs the listeners to update the handles after any changes.
-
removeGraphListeners
protected void removeGraphListeners(mxGraph graph)
Removes all installed listeners.
-
createConnectPreview
protected mxConnectPreview createConnectPreview()
-
getConnectPreview
public mxConnectPreview getConnectPreview()
-
setConnectPreview
public void setConnectPreview(mxConnectPreview value)
-
isConnecting
public boolean isConnecting()
Returns true if the source terminal has been clicked and a new connection is currently being previewed.
-
isActive
public boolean isActive()
-
isHighlighting
public boolean isHighlighting()
Returns true if no connectIcon is specified and handleEnabled is false.
-
isEnabled
public boolean isEnabled()
-
setEnabled
public void setEnabled(boolean value)
-
isKeepOnTop
public boolean isKeepOnTop()
-
setKeepOnTop
public void setKeepOnTop(boolean value)
-
setConnectIcon
public void setConnectIcon(javax.swing.ImageIcon value)
-
getConnecIcon
public javax.swing.ImageIcon getConnecIcon()
-
setHandleEnabled
public void setHandleEnabled(boolean value)
-
isHandleEnabled
public boolean isHandleEnabled()
-
setHandleSize
public void setHandleSize(int value)
-
getHandleSize
public int getHandleSize()
-
getMarker
public mxCellMarker getMarker()
-
setMarker
public void setMarker(mxCellMarker value)
-
setCreateTarget
public void setCreateTarget(boolean value)
-
isCreateTarget
public boolean isCreateTarget()
-
setSelect
public void setSelect(boolean value)
-
isSelect
public boolean isSelect()
-
reset
public void reset()
-
createTargetVertex
public java.lang.Object createTargetVertex(java.awt.event.MouseEvent e, java.lang.Object source)
-
isValidSource
public boolean isValidSource(java.lang.Object cell)
-
isValidTarget
public boolean isValidTarget(java.lang.Object cell)
Returns true. The call to mxGraph.isValidTarget is implicit by calling mxGraph.getEdgeValidationError in validateConnection. This is an additional hook for disabling certain targets in this specific handler.
-
validateConnection
public java.lang.String validateConnection(java.lang.Object source, java.lang.Object target)Returns the error message or an empty string if the connection for the given source target pair is not valid. Otherwise it returns null.
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
- Specified by:
mousePressedin interfacejava.awt.event.MouseListener- Overrides:
mousePressedin classmxMouseAdapter
-
start
public void start(java.awt.event.MouseEvent e, mxCellState state)
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener- Overrides:
mouseMovedin classmxMouseAdapter
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Overrides:
mouseDraggedin classmxMouseAdapter
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener- Overrides:
mouseReleasedin classmxMouseAdapter
-
setBounds
public void setBounds(java.awt.Rectangle value)
-
addListener
public void addListener(java.lang.String eventName, mxEventSource.mxIEventListener listener)Adds the given event listener.
-
removeListener
public void removeListener(mxEventSource.mxIEventListener listener)
Removes the given event listener.
-
removeListener
public void removeListener(mxEventSource.mxIEventListener listener, java.lang.String eventName)
Removes the given event listener for the specified event name.
-
paint
public void paint(java.awt.Graphics g)
-
-