Class mxCellMarker
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.mxgraph.swing.handler.mxCellMarker
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable
- Direct Known Subclasses:
mxCellTracker
Implements a mouse tracker that marks cells under the mouse.
This class fires the following event:
mxEvent.MARK fires in mark and unmark to notify the listener of a new cell
under the mouse. The
state property contains the mxCellState
of the respective cell or null if no cell is under the mouse.
To create a cell marker which highlights cells "in-place", the following
code can be used:
mxCellMarker highlighter = new mxCellMarker(graphComponent) {
protected Mapinvalid input: '<'String, Object> lastStyle;
public mxCellState process(MouseEvent e)
{
mxCellState state = null;
if (isEnabled())
{
state = getState(e);
boolean isValid = (state != null) ? isValidState(state) : false;
if (!isValid)
{
state = null;
}
highlight(state);
}
return state;
}
public void highlight(mxCellState state)
{
if (validState != state)
{
Rectangle dirty = null;
if (validState != null)
{
validState.setStyle(lastStyle);
dirty = validState.getBoundingBox().getRectangle();
dirty.grow(4, 4);
}
if (state != null)
{
lastStyle = state.getStyle();
state.setStyle(new Hashtableinvalid input: '<'String, Object>(state.getStyle()));
state.getStyle().put("strokeColor", "#00ff00");
state.getStyle().put("fontColor", "#00ff00");
state.getStyle().put("strokeWidth", "3");
Rectangle tmp = state.getBoundingBox().getRectangle();
if (dirty != null)
{
dirty.add(tmp);
}
else
{
dirty = tmp;
}
dirty.grow(4, 4);
}
validState = state;
graphComponent.repaint(dirty);
}
}
public void reset()
{
highlight(null);
}
public void paint(Graphics g)
{
// do nothing
}
};
graphComponent.getConnectionHandler().setMarker(highlighter);
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ColorHolds the current marker color.static StrokeSpecifies the default stroke for the marker.protected booleanSpecifies if the marker is enabled.protected mxEventSourceHolds the event source.protected mxGraphComponentHolds the enclosing graph component.protected doubleSpecifies the portion of the width and height that should trigger a highlight.protected booleanSpecifies if the hotspot is enabled.protected ColorSpecifies the valid- and invalidColor for the marker.static booleanSpecifies if the highlights should appear on top of everything else in the overlay pane.protected mxCellStateHolds the marked state.protected booleanSpecifies if the the content area of swimlane should be non-transparent to mouse events.protected ColorSpecifies the valid- and invalidColor for the marker.protected mxCellStateHolds the marked state if it is valid.Fields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionmxCellMarker(mxGraphComponent graphComponent) Constructs a new marker for the given graph component.mxCellMarker(mxGraphComponent graphComponent, Color validColor) Constructs a new marker for the given graph component.mxCellMarker(mxGraphComponent graphComponent, Color validColor, Color invalidColor) Constructs a new marker for the given graph component.mxCellMarker(mxGraphComponent graphComponent, Color validColor, Color invalidColor, double hotspot) Constructs a new marker for the given graph component. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(String eventName, mxEventSource.mxIEventListener listener) Adds the given event listener.protected ObjectReturns the state at the given location.Returns the current color.doubleReturns the hotspot.Returns the color used for invalid highlights.Returns the marked state.protected ColorgetMarkerColor(MouseEvent e, mxCellState state, boolean isValid) Returns the valid- or invalidColor depending on the value of isValid.protected mxCellStateUses getCell, getMarkedState and intersects to return the state for the given event.protected mxCellStategetStateToMark(mxCellState state) Returns the state to be marked for the given state under the mouse.Returns the color used for valid highlights.Returns the valid state.booleanReturns true if validState is not null.voidhighlight(mxCellState state, Color color) voidhighlight(mxCellState state, Color color, boolean valid) protected booleanintersects(mxCellState state, MouseEvent e) Returns true if the given mouse event intersects the given state.booleanReturns true if the marker is enabled, that is, if it processes events in process.booleanReturns true if hotspot is used in intersects.booleanReturns true if the content area of swimlanes is non-transparent to events.protected booleanisValidState(mxCellState state) Returns true if the given state is a valid state.voidmark()Marks the markedState and fires a mxEvent.MARK event.voidPaints the outline of the markedState with the currentColor.Processes the given event and marks the state returned by getStateAt with the color returned by getMarkerColor.voidremoveListener(mxEventSource.mxIEventListener listener) Removes the given event listener.voidremoveListener(mxEventSource.mxIEventListener listener, String eventName) Removes the given event listener for the specified event name.voidreset()Resets the state of the cell marker.voidsetCurrentColor(Color value) Sets the current color.voidsetEnabled(boolean enabled) Sets the enabled state of the marker.voidsetHotspot(double hotspot) Sets the hotspot.voidsetHotspotEnabled(boolean enabled) Specifies whether the hotspot should be used in intersects.voidsetInvalidColor(Color value) Sets the color used for invalid highlights.voidsetMarkedState(mxCellState value) Sets the marked state.voidsetSwimlaneContentEnabled(boolean swimlaneContentEnabled) Sets if the content area of swimlanes should not be transparent to events.voidsetValidColor(Color value) Sets the color used for valid highlights.voidunmark()Hides the marker and fires a mxEvent.MARK event.Methods inherited from class 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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIMethods inherited from class 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, transferFocusDownCycle, validate, validateTreeMethods inherited from class 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, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
KEEP_ON_TOP
public static boolean KEEP_ON_TOPSpecifies if the highlights should appear on top of everything else in the overlay pane. Default is false. -
DEFAULT_STROKE
Specifies the default stroke for the marker. -
eventSource
Holds the event source. -
graphComponent
Holds the enclosing graph component. -
enabled
protected boolean enabledSpecifies if the marker is enabled. Default is true. -
hotspot
protected double hotspotSpecifies the portion of the width and height that should trigger a highlight. The area around the center of the cell to be marked is used as the hotspot. Possible values are between 0 and 1. Default is mxConstants.DEFAULT_HOTSPOT. -
hotspotEnabled
protected boolean hotspotEnabledSpecifies if the hotspot is enabled. Default is false. -
swimlaneContentEnabled
protected boolean swimlaneContentEnabledSpecifies if the the content area of swimlane should be non-transparent to mouse events. Default is false. -
validColor
Specifies the valid- and invalidColor for the marker. -
invalidColor
Specifies the valid- and invalidColor for the marker. -
currentColor
Holds the current marker color. -
validState
Holds the marked state if it is valid. -
markedState
Holds the marked state.
-
-
Constructor Details
-
mxCellMarker
Constructs a new marker for the given graph component.- Parameters:
graphComponent-
-
mxCellMarker
Constructs a new marker for the given graph component. -
mxCellMarker
Constructs a new marker for the given graph component. -
mxCellMarker
public mxCellMarker(mxGraphComponent graphComponent, Color validColor, Color invalidColor, double hotspot) Constructs a new marker for the given graph component.
-
-
Method Details
-
setEnabled
public void setEnabled(boolean enabled) Sets the enabled state of the marker.- Overrides:
setEnabledin classJComponent
-
isEnabled
-
setHotspot
public void setHotspot(double hotspot) Sets the hotspot. -
getHotspot
public double getHotspot()Returns the hotspot. -
setHotspotEnabled
public void setHotspotEnabled(boolean enabled) Specifies whether the hotspot should be used in intersects. -
isHotspotEnabled
public boolean isHotspotEnabled()Returns true if hotspot is used in intersects. -
setSwimlaneContentEnabled
public void setSwimlaneContentEnabled(boolean swimlaneContentEnabled) Sets if the content area of swimlanes should not be transparent to events. -
isSwimlaneContentEnabled
public boolean isSwimlaneContentEnabled()Returns true if the content area of swimlanes is non-transparent to events. -
setValidColor
Sets the color used for valid highlights. -
getValidColor
Returns the color used for valid highlights. -
setInvalidColor
Sets the color used for invalid highlights. -
getInvalidColor
Returns the color used for invalid highlights. -
hasValidState
public boolean hasValidState()Returns true if validState is not null. -
getValidState
Returns the valid state. -
setCurrentColor
Sets the current color. -
getCurrentColor
Returns the current color. -
setMarkedState
Sets the marked state. -
getMarkedState
Returns the marked state. -
reset
public void reset()Resets the state of the cell marker. -
process
Processes the given event and marks the state returned by getStateAt with the color returned by getMarkerColor. If the markerColor is not null, then the state is stored in markedState. If isValidState returns true, then the state is stored in validState regardless of the marker color. The state is returned regardless of the marker color and valid state. -
highlight
-
highlight
-
mark
public void mark()Marks the markedState and fires a mxEvent.MARK event. -
unmark
public void unmark()Hides the marker and fires a mxEvent.MARK event. -
isValidState
Returns true if the given state is a valid state. If this returns true, then the state is stored in validState. The return value of this method is used as the argument for getMarkerColor. -
getMarkerColor
Returns the valid- or invalidColor depending on the value of isValid. The given state is ignored by this implementation. -
getState
Uses getCell, getMarkedState and intersects to return the state for the given event. -
getCell
Returns the state at the given location. This uses mxGraph.getCellAt. -
getStateToMark
Returns the state to be marked for the given state under the mouse. This returns the given state. -
intersects
Returns true if the given mouse event intersects the given state. This returns true if the hotspot is 0 or the event is inside the hotspot for the given cell state. -
addListener
Adds the given event listener. -
removeListener
Removes the given event listener. -
removeListener
Removes the given event listener for the specified event name. -
paint
Paints the outline of the markedState with the currentColor.- Overrides:
paintin classJComponent
-