com.mxgraph.swing.handler
Class mxCellMarker
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- com.mxgraph.swing.handler.mxCellMarker
-
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
- Direct Known Subclasses:
- mxCellTracker
public class mxCellMarker extends javax.swing.JComponentImplements 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. Thestateproperty 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 MaplastStyle; 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 Hashtable (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:
- Serialized Form
-
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field and Description static java.awt.StrokeDEFAULT_STROKESpecifies the default stroke for the marker.static booleanKEEP_ON_TOPSpecifies if the highlights should appear on top of everything else in the overlay pane.-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor and Description mxCellMarker(mxGraphComponent graphComponent)Constructs a new marker for the given graph component.mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor)Constructs a new marker for the given graph component.mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor, java.awt.Color invalidColor)Constructs a new marker for the given graph component.mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor, java.awt.Color invalidColor, double hotspot)Constructs a new marker for the given graph component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddListener(java.lang.String eventName, mxEventSource.mxIEventListener listener)Adds the given event listener.java.awt.ColorgetCurrentColor()Returns the current color.doublegetHotspot()Returns the hotspot.java.awt.ColorgetInvalidColor()Returns the color used for invalid highlights.mxCellStategetMarkedState()Returns the marked state.java.awt.ColorgetValidColor()Returns the color used for valid highlights.mxCellStategetValidState()Returns the valid state.booleanhasValidState()Returns true if validState is not null.voidhighlight(mxCellState state, java.awt.Color color)voidhighlight(mxCellState state, java.awt.Color color, boolean valid)booleanisEnabled()Returns true if the marker is enabled, that is, if it processes events in process.booleanisHotspotEnabled()Returns true if hotspot is used in intersects.booleanisSwimlaneContentEnabled()Returns true if the content area of swimlanes is non-transparent to events.voidmark()Marks the markedState and fires a mxEvent.MARK event.voidpaint(java.awt.Graphics g)Paints the outline of the markedState with the currentColor.mxCellStateprocess(java.awt.event.MouseEvent e)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, java.lang.String eventName)Removes the given event listener for the specified event name.voidreset()Resets the state of the cell marker.voidsetCurrentColor(java.awt.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(java.awt.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(java.awt.Color value)Sets the color used for valid highlights.voidunmark()Hides the marker and fires a mxEvent.MARK event.-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, getPeer, 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, 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, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
KEEP_ON_TOP
public static boolean KEEP_ON_TOP
Specifies if the highlights should appear on top of everything else in the overlay pane. Default is false.
-
DEFAULT_STROKE
public static java.awt.Stroke DEFAULT_STROKE
Specifies the default stroke for the marker.
-
-
Constructor Detail
-
mxCellMarker
public mxCellMarker(mxGraphComponent graphComponent)
Constructs a new marker for the given graph component.- Parameters:
graphComponent-
-
mxCellMarker
public mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor)
Constructs a new marker for the given graph component.
-
mxCellMarker
public mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor, java.awt.Color invalidColor)
Constructs a new marker for the given graph component.
-
mxCellMarker
public mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor, java.awt.Color invalidColor, double hotspot)
Constructs a new marker for the given graph component.
-
-
Method Detail
-
setEnabled
public void setEnabled(boolean enabled)
Sets the enabled state of the marker.- Overrides:
setEnabledin classjavax.swing.JComponent
-
isEnabled
public boolean isEnabled()
Returns true if the marker is enabled, that is, if it processes events in process.- Overrides:
isEnabledin classjava.awt.Component
-
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
public void setValidColor(java.awt.Color value)
Sets the color used for valid highlights.
-
getValidColor
public java.awt.Color getValidColor()
Returns the color used for valid highlights.
-
setInvalidColor
public void setInvalidColor(java.awt.Color value)
Sets the color used for invalid highlights.
-
getInvalidColor
public java.awt.Color getInvalidColor()
Returns the color used for invalid highlights.
-
hasValidState
public boolean hasValidState()
Returns true if validState is not null.
-
getValidState
public mxCellState getValidState()
Returns the valid state.
-
setCurrentColor
public void setCurrentColor(java.awt.Color value)
Sets the current color.
-
getCurrentColor
public java.awt.Color getCurrentColor()
Returns the current color.
-
setMarkedState
public void setMarkedState(mxCellState value)
Sets the marked state.
-
getMarkedState
public mxCellState getMarkedState()
Returns the marked state.
-
reset
public void reset()
Resets the state of the cell marker.
-
process
public mxCellState process(java.awt.event.MouseEvent e)
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
public void highlight(mxCellState state, java.awt.Color color)
-
highlight
public void highlight(mxCellState state, java.awt.Color color, boolean valid)
-
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.
-
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)
Paints the outline of the markedState with the currentColor.- Overrides:
paintin classjavax.swing.JComponent
-
-
DataMelt 3.0 © DataMelt by jWork.ORG