java.awt.image.ImageObserver
, java.awt.MenuContainer
, java.io.Serializable
mxCellTracker
public class mxCellMarker
extends javax.swing.JComponent
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 Map 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 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);
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
Modifier and Type | Field | Description |
---|---|---|
protected java.awt.Color |
currentColor |
Holds the current marker color.
|
static java.awt.Stroke |
DEFAULT_STROKE |
Specifies the default stroke for the marker.
|
protected boolean |
enabled |
Specifies if the marker is enabled.
|
protected mxEventSource |
eventSource |
Holds the event source.
|
protected mxGraphComponent |
graphComponent |
Holds the enclosing graph component.
|
protected double |
hotspot |
Specifies the portion of the width and height that should trigger
a highlight.
|
protected boolean |
hotspotEnabled |
Specifies if the hotspot is enabled.
|
protected java.awt.Color |
invalidColor |
Specifies the valid- and invalidColor for the marker.
|
static boolean |
KEEP_ON_TOP |
Specifies if the highlights should appear on top of everything
else in the overlay pane.
|
protected mxCellState |
markedState |
Holds the marked state.
|
protected boolean |
swimlaneContentEnabled |
Specifies if the the content area of swimlane should be non-transparent
to mouse events.
|
protected java.awt.Color |
validColor |
Specifies the valid- and invalidColor for the marker.
|
protected mxCellState |
validState |
Holds the marked state if it is valid.
|
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor | 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.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addListener(java.lang.String eventName,
mxEventSource.mxIEventListener listener) |
Adds the given event listener.
|
protected java.lang.Object |
getCell(java.awt.event.MouseEvent e) |
Returns the state at the given location.
|
java.awt.Color |
getCurrentColor() |
Returns the current color.
|
double |
getHotspot() |
Returns the hotspot.
|
java.awt.Color |
getInvalidColor() |
Returns the color used for invalid highlights.
|
mxCellState |
getMarkedState() |
Returns the marked state.
|
protected java.awt.Color |
getMarkerColor(java.awt.event.MouseEvent e,
mxCellState state,
boolean isValid) |
Returns the valid- or invalidColor depending on the value of isValid.
|
protected mxCellState |
getState(java.awt.event.MouseEvent e) |
Uses getCell, getMarkedState and intersects to return the state for
the given event.
|
protected mxCellState |
getStateToMark(mxCellState state) |
Returns the state to be marked for the given state under the mouse.
|
java.awt.Color |
getValidColor() |
Returns the color used for valid highlights.
|
mxCellState |
getValidState() |
Returns the valid state.
|
boolean |
hasValidState() |
Returns true if validState is not null.
|
void |
highlight(mxCellState state,
java.awt.Color color) |
|
void |
highlight(mxCellState state,
java.awt.Color color,
boolean valid) |
|
protected boolean |
intersects(mxCellState state,
java.awt.event.MouseEvent e) |
Returns true if the given mouse event intersects the given state.
|
boolean |
isEnabled() |
Returns true if the marker is enabled, that is, if it processes events
in process.
|
boolean |
isHotspotEnabled() |
Returns true if hotspot is used in intersects.
|
boolean |
isSwimlaneContentEnabled() |
Returns true if the content area of swimlanes is non-transparent to
events.
|
protected boolean |
isValidState(mxCellState state) |
Returns true if the given state is a valid state.
|
void |
mark() |
Marks the markedState and fires a mxEvent.MARK event.
|
void |
paint(java.awt.Graphics g) |
Paints the outline of the markedState with the currentColor.
|
mxCellState |
process(java.awt.event.MouseEvent e) |
Processes the given event and marks the state returned by getStateAt
with the color returned by getMarkerColor.
|
void |
removeListener(mxEventSource.mxIEventListener listener) |
Removes the given event listener.
|
void |
removeListener(mxEventSource.mxIEventListener listener,
java.lang.String eventName) |
Removes the given event listener for the specified event name.
|
void |
reset() |
Resets the state of the cell marker.
|
void |
setCurrentColor(java.awt.Color value) |
Sets the current color.
|
void |
setEnabled(boolean enabled) |
Sets the enabled state of the marker.
|
void |
setHotspot(double hotspot) |
Sets the hotspot.
|
void |
setHotspotEnabled(boolean enabled) |
Specifies whether the hotspot should be used in intersects.
|
void |
setInvalidColor(java.awt.Color value) |
Sets the color used for invalid highlights.
|
void |
setMarkedState(mxCellState value) |
Sets the marked state.
|
void |
setSwimlaneContentEnabled(boolean swimlaneContentEnabled) |
Sets if the content area of swimlanes should not be transparent to
events.
|
void |
setValidColor(java.awt.Color value) |
Sets the color used for valid highlights.
|
void |
unmark() |
Hides the marker and fires a mxEvent.MARK event.
|
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
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, validateTree
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, updateUI
public static boolean KEEP_ON_TOP
public static java.awt.Stroke DEFAULT_STROKE
protected mxEventSource eventSource
protected mxGraphComponent graphComponent
protected boolean enabled
protected double hotspot
protected boolean hotspotEnabled
protected boolean swimlaneContentEnabled
protected java.awt.Color validColor
protected java.awt.Color invalidColor
protected transient java.awt.Color currentColor
protected transient mxCellState validState
protected transient mxCellState markedState
public mxCellMarker(mxGraphComponent graphComponent)
graphComponent
- public mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor)
public mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor, java.awt.Color invalidColor)
public mxCellMarker(mxGraphComponent graphComponent, java.awt.Color validColor, java.awt.Color invalidColor, double hotspot)
public void setEnabled(boolean enabled)
setEnabled
in class javax.swing.JComponent
public boolean isEnabled()
isEnabled
in class java.awt.Component
public void setHotspot(double hotspot)
public double getHotspot()
public void setHotspotEnabled(boolean enabled)
public boolean isHotspotEnabled()
public void setSwimlaneContentEnabled(boolean swimlaneContentEnabled)
public boolean isSwimlaneContentEnabled()
public void setValidColor(java.awt.Color value)
public java.awt.Color getValidColor()
public void setInvalidColor(java.awt.Color value)
public java.awt.Color getInvalidColor()
public boolean hasValidState()
public mxCellState getValidState()
public void setCurrentColor(java.awt.Color value)
public java.awt.Color getCurrentColor()
public void setMarkedState(mxCellState value)
public mxCellState getMarkedState()
public void reset()
public mxCellState process(java.awt.event.MouseEvent e)
public void highlight(mxCellState state, java.awt.Color color)
public void highlight(mxCellState state, java.awt.Color color, boolean valid)
public void mark()
public void unmark()
protected boolean isValidState(mxCellState state)
protected java.awt.Color getMarkerColor(java.awt.event.MouseEvent e, mxCellState state, boolean isValid)
protected mxCellState getState(java.awt.event.MouseEvent e)
protected java.lang.Object getCell(java.awt.event.MouseEvent e)
protected mxCellState getStateToMark(mxCellState state)
protected boolean intersects(mxCellState state, java.awt.event.MouseEvent e)
public void addListener(java.lang.String eventName, mxEventSource.mxIEventListener listener)
public void removeListener(mxEventSource.mxIEventListener listener)
public void removeListener(mxEventSource.mxIEventListener listener, java.lang.String eventName)
public void paint(java.awt.Graphics g)
paint
in class javax.swing.JComponent
Copyright (c) 2010-2017 Gaudenz Alder, JGraph Ltd. All rights reserved.