Package com.mxgraph.view
Class mxGraphView
- java.lang.Object
-
- com.mxgraph.util.mxEventSource
-
- com.mxgraph.view.mxGraphView
-
public class mxGraphView extends mxEventSource
Implements a view for the graph. This class is in charge of computing the absolute coordinates for the relative child geometries, the points for perimeters and edge styles and keeping them cached in cell states for faster retrieval. The states are updated whenever the model or the view state (translate, scale) changes. The scale and translate are honoured in the bounds. This class fires the following events: mxEvent.UNDO fires after the root was changed in setCurrentRoot. Theedit
property contains the mxUndoableEdit which contains the mxCurrentRootChange. mxEvent.SCALE_AND_TRANSLATE fires after the scale and transle have been changed in scaleAndTranslate. Thescale
,previousScale
,translate
andpreviousTranslate
properties contain the new and previous scale and translate, respectively. mxEvent.SCALE fires after the scale was changed in setScale. Thescale
andpreviousScale
properties contain the new and previous scale. mxEvent.TRANSLATE fires after the translate was changed in setTranslate. Thetranslate
andpreviousTranslate
properties contain the new and previous value for translate. mxEvent.UP and mxEvent.DOWN fire if the current root is changed by executing a mxCurrentRootChange. The event name depends on the location of the root in the cell hierarchy with respect to the current root. Theroot
andprevious
properties contain the new and previous root, respectively.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
mxGraphView.mxCurrentRootChange
Action to change the current root in a view.-
Nested classes/interfaces inherited from class com.mxgraph.util.mxEventSource
mxEventSource.mxIEventListener
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Object
currentRoot
mxCell that acts as the root of the displayed cell hierarchy.protected mxGraph
graph
Reference to the enclosing graph.protected mxRectangle
graphBounds
Caches the current bounds of the graph.protected double
scale
Specifies the scale.protected java.util.Hashtable<java.lang.Object,mxCellState>
states
Maps from cells to cell states.protected mxPoint
translate
Point that specifies the current translation.-
Fields inherited from class com.mxgraph.util.mxEventSource
eventListeners, eventsEnabled, eventSource
-
-
Constructor Summary
Constructors Constructor Description mxGraphView(mxGraph graph)
Constructs a new view for the given graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear(java.lang.Object cell, boolean force, boolean recurse)
Removes the state of the given cell and all descendants if the given cell is not the current root.mxCellState
createState(java.lang.Object cell)
Creates and returns a cell state for the given cell.mxRectangle
getBoundingBox(mxCellState state)
Shortcut to validateCell with visible set to true.mxRectangle
getBoundingBox(mxCellState state, boolean recurse)
Returns the bounding box of the shape and the label for the given cell state and its children if recurse is true.mxRectangle
getBoundingBox(java.lang.Object[] cells)
Returns the bounding box for an array of cells or null, if no cells are specified.mxRectangle
getBounds(java.lang.Object[] cells)
Returns the bounding box for an array of cells or null, if no cells are specified.mxRectangle
getBounds(java.lang.Object[] cells, boolean boundingBox)
Returns the bounding box for an array of cells or null, if no cells are specified.mxCellState[]
getCellStates(java.lang.Object[] cells)
Returns the states for the given array of cells.java.lang.Object
getCurrentRoot()
Returns the current root.mxEdgeStyle.mxEdgeStyleFunction
getEdgeStyle(mxCellState edge, java.util.List<mxPoint> points, java.lang.Object source, java.lang.Object target)
Returns the edge style function to be used to compute the absolute points for the given state, control points and terminals.mxGraph
getGraph()
Returns the enclosing graph.mxRectangle
getGraphBounds()
Returns the cached diagram bounds.mxPoint
getNextPoint(mxCellState edge, mxCellState opposite, boolean source)
Returns the nearest point in the list of absolute points or the center of the opposite terminal.mxRectangle
getPerimeterBounds(mxCellState terminal, double border)
Returns the perimeter bounds for the given terminal, edge pair.mxPerimeter.mxPerimeterFunction
getPerimeterFunction(mxCellState state)
Returns the perimeter function for the given state.mxPoint
getPerimeterPoint(mxCellState terminal, mxPoint next, boolean orthogonal)
Returns a point that defines the location of the intersection point between the perimeter and the line between the center of the shape and the given point.mxPoint
getPerimeterPoint(mxCellState terminal, mxPoint next, boolean orthogonal, double border)
Returns a point that defines the location of the intersection point between the perimeter and the line between the center of the shape and the given point.mxPoint
getPoint(mxCellState state)
Returns the absolute center point along the given edge.mxPoint
getPoint(mxCellState state, mxGeometry geometry)
Returns the absolute point on the edge for the given relative geometry as a point.mxPoint
getRelativePoint(mxCellState edgeState, double x, double y)
Gets the relative point that describes the given, absolute label position for the given edge state.double
getRoutingCenterX(mxCellState state)
Returns the x-coordinate of the center point for automatic routing.double
getRoutingCenterY(mxCellState state)
Returns the y-coordinate of the center point for automatic routing.double
getScale()
Returns the current scale.mxCellState
getState(java.lang.Object cell)
Returns the state for the given cell or null if no state is defined for the cell.mxCellState
getState(java.lang.Object cell, boolean create)
Returns the cell state for the given cell.java.util.Hashtable<java.lang.Object,mxCellState>
getStates()
Returns the dictionary that maps from cells to states.mxCellState
getTerminalPort(mxCellState state, mxCellState terminal, boolean source)
Returns a cell state that represents the source or target terminal or port for the given edge.mxPoint
getTranslate()
Returns the current translation.java.lang.Object
getVisibleTerminal(java.lang.Object edge, boolean source)
Returns the nearest ancestor terminal that is visible.double
getWordWrapWidth(mxCellState state)
Returns the width for wrapping the label of the given state at scale 1.void
invalidate()
Invalidates all cell states.void
invalidate(java.lang.Object cell)
Invalidates the state of the given cell, all its descendants and connected edges.void
reload()
Removes all existing cell states and invokes validate.mxCellState
removeState(java.lang.Object cell)
Removes and returns the mxCellState for the given cell.void
revalidate()
void
scaleAndTranslate(double scale, double dx, double dy)
Sets the scale and translation.java.lang.Object
setCurrentRoot(java.lang.Object root)
Sets and returns the current root and fires an undo event.void
setGraphBounds(mxRectangle value)
Sets the graph bounds.void
setScale(double value)
Sets the current scale and revalidates the view.void
setStates(java.util.Hashtable<java.lang.Object,mxCellState> states)
Returns the dictionary that maps from cells to states.void
setTranslate(mxPoint value)
Sets the current translation and invalidates the view.java.lang.String
toString()
mxPoint
transformControlPoint(mxCellState state, mxPoint pt)
Transforms the given control point to an absolute point.mxRectangle
updateBoundingBox(mxCellState state)
Updates the bounding box in the given cell state.void
updateCellState(mxCellState state)
Updates the given cell state.void
updateEdgeBounds(mxCellState state)
Updates the given state using the bounding box of the absolute points.void
updateEdgeState(mxCellState state, mxGeometry geo)
Validates the given cell state.void
updateFixedTerminalPoint(mxCellState edge, mxCellState terminal, boolean source, mxConnectionConstraint constraint)
Sets the fixed source or target terminal point on the given edge.void
updateFixedTerminalPoints(mxCellState edge, mxCellState source, mxCellState target)
Sets the initial absolute terminal points in the given state before the edge style is computed.void
updateFloatingTerminalPoint(mxCellState edge, mxCellState start, mxCellState end, boolean source)
Updates the absolute terminal point in the given state for the given start and end state, where start is the source if source is true.void
updateFloatingTerminalPoints(mxCellState state, mxCellState source, mxCellState target)
Updates the terminal points in the given state after the edge style was computed for the edge.void
updateLabel(mxCellState state)
Updates the label of the given state.void
updateLabelBounds(mxCellState state)
Updates the label bounds in the given state.void
updatePoints(mxCellState edge, java.util.List<mxPoint> points, mxCellState source, mxCellState target)
Updates the absolute points in the given state using the specified array of points as the relative points.void
updateVertexLabelOffset(mxCellState state)
Updates the absoluteOffset of the given vertex cell state.void
updateVertexState(mxCellState state, mxGeometry geo)
Validates the given cell state.void
validate()
First validates all bounds and then validates all points recursively on all visible cells.java.lang.Object
validateCell(java.lang.Object cell)
Shortcut to validateCell with visible set to true.java.lang.Object
validateCell(java.lang.Object cell, boolean visible)
Recursively creates the cell state for the given cell if visible is true and the given cell is visible.mxCellState
validateCellState(java.lang.Object cell)
Shortcut to validateCellState with recurse set to true.mxCellState
validateCellState(java.lang.Object cell, boolean recurse)
Validates the cell state for the given cell.-
Methods inherited from class com.mxgraph.util.mxEventSource
addListener, fireEvent, fireEvent, getEventSource, isEventsEnabled, removeListener, removeListener, setEventsEnabled, setEventSource
-
-
-
-
Field Detail
-
graph
protected mxGraph graph
Reference to the enclosing graph.
-
currentRoot
protected java.lang.Object currentRoot
mxCell that acts as the root of the displayed cell hierarchy.
-
graphBounds
protected mxRectangle graphBounds
Caches the current bounds of the graph.
-
scale
protected double scale
Specifies the scale. Default is 1 (100%).
-
translate
protected mxPoint translate
Point that specifies the current translation. Default is a new empty point.
-
states
protected java.util.Hashtable<java.lang.Object,mxCellState> states
Maps from cells to cell states.
-
-
Constructor Detail
-
mxGraphView
public mxGraphView(mxGraph graph)
Constructs a new view for the given graph.- Parameters:
graph
- Reference to the enclosing graph.
-
-
Method Detail
-
getGraph
public mxGraph getGraph()
Returns the enclosing graph.- Returns:
- Returns the enclosing graph.
-
getStates
public java.util.Hashtable<java.lang.Object,mxCellState> getStates()
Returns the dictionary that maps from cells to states.
-
setStates
public void setStates(java.util.Hashtable<java.lang.Object,mxCellState> states)
Returns the dictionary that maps from cells to states.
-
getGraphBounds
public mxRectangle getGraphBounds()
Returns the cached diagram bounds.- Returns:
- Returns the diagram bounds.
-
setGraphBounds
public void setGraphBounds(mxRectangle value)
Sets the graph bounds.
-
getCurrentRoot
public java.lang.Object getCurrentRoot()
Returns the current root.
-
setCurrentRoot
public java.lang.Object setCurrentRoot(java.lang.Object root)
Sets and returns the current root and fires an undo event.- Parameters:
root
- mxCell that specifies the root of the displayed cell hierarchy.- Returns:
- Returns the object that represents the current root.
-
scaleAndTranslate
public void scaleAndTranslate(double scale, double dx, double dy)
Sets the scale and translation. Fires a "scaleAndTranslate" event after calling revalidate. Revalidate is only called if isEventsEnabled.- Parameters:
scale
- Decimal value that specifies the new scale (1 is 100%).dx
- X-coordinate of the translation.dy
- Y-coordinate of the translation.
-
getScale
public double getScale()
Returns the current scale.- Returns:
- Returns the scale.
-
setScale
public void setScale(double value)
Sets the current scale and revalidates the view. Fires a "scale" event after calling revalidate. Revalidate is only called if isEventsEnabled.- Parameters:
value
- New scale to be used.
-
getTranslate
public mxPoint getTranslate()
Returns the current translation.- Returns:
- Returns the translation.
-
setTranslate
public void setTranslate(mxPoint value)
Sets the current translation and invalidates the view. Fires a property change event for "translate" after calling revalidate. Revalidate is only called if isEventsEnabled.- Parameters:
value
- New translation to be used.
-
getBounds
public mxRectangle getBounds(java.lang.Object[] cells)
Returns the bounding box for an array of cells or null, if no cells are specified.- Parameters:
cells
-- Returns:
- Returns the bounding box for the given cells.
-
getBoundingBox
public mxRectangle getBoundingBox(java.lang.Object[] cells)
Returns the bounding box for an array of cells or null, if no cells are specified.- Parameters:
cells
-- Returns:
- Returns the bounding box for the given cells.
-
getBounds
public mxRectangle getBounds(java.lang.Object[] cells, boolean boundingBox)
Returns the bounding box for an array of cells or null, if no cells are specified.- Parameters:
cells
-- Returns:
- Returns the bounding box for the given cells.
-
reload
public void reload()
Removes all existing cell states and invokes validate.
-
revalidate
public void revalidate()
-
invalidate
public void invalidate()
Invalidates all cell states.
-
clear
public void clear(java.lang.Object cell, boolean force, boolean recurse)
Removes the state of the given cell and all descendants if the given cell is not the current root.- Parameters:
cell
-force
-recurse
-
-
invalidate
public void invalidate(java.lang.Object cell)
Invalidates the state of the given cell, all its descendants and connected edges.
-
validate
public void validate()
First validates all bounds and then validates all points recursively on all visible cells.
-
getBoundingBox
public mxRectangle getBoundingBox(mxCellState state)
Shortcut to validateCell with visible set to true.
-
getBoundingBox
public mxRectangle getBoundingBox(mxCellState state, boolean recurse)
Returns the bounding box of the shape and the label for the given cell state and its children if recurse is true.- Parameters:
state
- Cell state whose bounding box should be returned.recurse
- Boolean indicating if the children should be included.
-
validateCell
public java.lang.Object validateCell(java.lang.Object cell)
Shortcut to validateCell with visible set to true.
-
validateCell
public java.lang.Object validateCell(java.lang.Object cell, boolean visible)
Recursively creates the cell state for the given cell if visible is true and the given cell is visible. If the cell is not visible but the state exists then it is removed using removeState.- Parameters:
cell
- Cell whose cell state should be created.visible
- Boolean indicating if the cell should be visible.
-
validateCellState
public mxCellState validateCellState(java.lang.Object cell)
Shortcut to validateCellState with recurse set to true.
-
validateCellState
public mxCellState validateCellState(java.lang.Object cell, boolean recurse)
Validates the cell state for the given cell.- Parameters:
cell
- Cell whose cell state should be validated.recurse
- Boolean indicating if the children of the cell should be validated.
-
updateCellState
public void updateCellState(mxCellState state)
Updates the given cell state.- Parameters:
state
- Cell state to be updated.
-
updateVertexState
public void updateVertexState(mxCellState state, mxGeometry geo)
Validates the given cell state.
-
updateEdgeState
public void updateEdgeState(mxCellState state, mxGeometry geo)
Validates the given cell state.
-
updateVertexLabelOffset
public void updateVertexLabelOffset(mxCellState state)
Updates the absoluteOffset of the given vertex cell state. This takes into account the label position styles.- Parameters:
state
- Cell state whose absolute offset should be updated.
-
updateLabel
public void updateLabel(mxCellState state)
Updates the label of the given state.
-
getWordWrapWidth
public double getWordWrapWidth(mxCellState state)
Returns the width for wrapping the label of the given state at scale 1.
-
updateLabelBounds
public void updateLabelBounds(mxCellState state)
Updates the label bounds in the given state.
-
updateBoundingBox
public mxRectangle updateBoundingBox(mxCellState state)
Updates the bounding box in the given cell state.- Parameters:
state
- Cell state whose bounding box should be updated.
-
updateFixedTerminalPoints
public void updateFixedTerminalPoints(mxCellState edge, mxCellState source, mxCellState target)
Sets the initial absolute terminal points in the given state before the edge style is computed.- Parameters:
edge
- Cell state whose initial terminal points should be updated.source
- Cell state which represents the source terminal.target
- Cell state which represents the target terminal.
-
updateFixedTerminalPoint
public void updateFixedTerminalPoint(mxCellState edge, mxCellState terminal, boolean source, mxConnectionConstraint constraint)
Sets the fixed source or target terminal point on the given edge.- Parameters:
edge
- Cell state whose initial terminal points should be updated.
-
updatePoints
public void updatePoints(mxCellState edge, java.util.List<mxPoint> points, mxCellState source, mxCellState target)
Updates the absolute points in the given state using the specified array of points as the relative points.- Parameters:
edge
- Cell state whose absolute points should be updated.points
- Array of points that constitute the relative points.source
- Cell state that represents the source terminal.target
- Cell state that represents the target terminal.
-
transformControlPoint
public mxPoint transformControlPoint(mxCellState state, mxPoint pt)
Transforms the given control point to an absolute point.
-
getEdgeStyle
public mxEdgeStyle.mxEdgeStyleFunction getEdgeStyle(mxCellState edge, java.util.List<mxPoint> points, java.lang.Object source, java.lang.Object target)
Returns the edge style function to be used to compute the absolute points for the given state, control points and terminals.
-
updateFloatingTerminalPoints
public void updateFloatingTerminalPoints(mxCellState state, mxCellState source, mxCellState target)
Updates the terminal points in the given state after the edge style was computed for the edge.- Parameters:
state
- Cell state whose terminal points should be updated.source
- Cell state that represents the source terminal.target
- Cell state that represents the target terminal.
-
updateFloatingTerminalPoint
public void updateFloatingTerminalPoint(mxCellState edge, mxCellState start, mxCellState end, boolean source)
Updates the absolute terminal point in the given state for the given start and end state, where start is the source if source is true.- Parameters:
edge
- Cell state whose terminal point should be updated.start
- Cell state for the terminal on "this" side of the edge.end
- Cell state for the terminal on the other side of the edge.source
- Boolean indicating if start is the source terminal state.
-
getTerminalPort
public mxCellState getTerminalPort(mxCellState state, mxCellState terminal, boolean source)
Returns a cell state that represents the source or target terminal or port for the given edge.
-
getPerimeterPoint
public mxPoint getPerimeterPoint(mxCellState terminal, mxPoint next, boolean orthogonal)
Returns a point that defines the location of the intersection point between the perimeter and the line between the center of the shape and the given point.
-
getPerimeterPoint
public mxPoint getPerimeterPoint(mxCellState terminal, mxPoint next, boolean orthogonal, double border)
Returns a point that defines the location of the intersection point between the perimeter and the line between the center of the shape and the given point.- Parameters:
terminal
- Cell state for the source or target terminal.next
- Point that lies outside of the given terminal.orthogonal
- Boolean that specifies if the orthogonal projection onto the perimeter should be returned. If this is false then the intersection of the perimeter and the line between the next and the center point is returned.border
- Optional border between the perimeter and the shape.
-
getRoutingCenterX
public double getRoutingCenterX(mxCellState state)
Returns the x-coordinate of the center point for automatic routing.- Returns:
- Returns the x-coordinate of the routing center point.
-
getRoutingCenterY
public double getRoutingCenterY(mxCellState state)
Returns the y-coordinate of the center point for automatic routing.- Returns:
- Returns the y-coordinate of the routing center point.
-
getPerimeterBounds
public mxRectangle getPerimeterBounds(mxCellState terminal, double border)
Returns the perimeter bounds for the given terminal, edge pair.
-
getPerimeterFunction
public mxPerimeter.mxPerimeterFunction getPerimeterFunction(mxCellState state)
Returns the perimeter function for the given state.
-
getNextPoint
public mxPoint getNextPoint(mxCellState edge, mxCellState opposite, boolean source)
Returns the nearest point in the list of absolute points or the center of the opposite terminal.- Parameters:
edge
- Cell state that represents the edge.opposite
- Cell state that represents the opposite terminal.source
- Boolean indicating if the next point for the source or target should be returned.- Returns:
- Returns the nearest point of the opposite side.
-
getVisibleTerminal
public java.lang.Object getVisibleTerminal(java.lang.Object edge, boolean source)
Returns the nearest ancestor terminal that is visible. The edge appears to be connected to this terminal on the display.- Parameters:
edge
- Cell whose visible terminal should be returned.source
- Boolean that specifies if the source or target terminal should be returned.- Returns:
- Returns the visible source or target terminal.
-
updateEdgeBounds
public void updateEdgeBounds(mxCellState state)
Updates the given state using the bounding box of the absolute points. Also updates terminal distance, length and segments.- Parameters:
state
- Cell state whose bounds should be updated.
-
getPoint
public mxPoint getPoint(mxCellState state)
Returns the absolute center point along the given edge.
-
getPoint
public mxPoint getPoint(mxCellState state, mxGeometry geometry)
Returns the absolute point on the edge for the given relative geometry as a point. The edge is represented by the given cell state.- Parameters:
state
- Represents the state of the parent edge.geometry
- Optional geometry that represents the relative location.- Returns:
- Returns the mxpoint that represents the absolute location of the given relative geometry.
-
getRelativePoint
public mxPoint getRelativePoint(mxCellState edgeState, double x, double y)
Gets the relative point that describes the given, absolute label position for the given edge state.
-
getCellStates
public mxCellState[] getCellStates(java.lang.Object[] cells)
Returns the states for the given array of cells. The array contains all states that are not null, that is, the returned array may have less elements than the given array.
-
getState
public mxCellState getState(java.lang.Object cell)
Returns the state for the given cell or null if no state is defined for the cell.- Parameters:
cell
- Cell whose state should be returned.- Returns:
- Returns the state for the given cell.
-
getState
public mxCellState getState(java.lang.Object cell, boolean create)
Returns the cell state for the given cell. If create is true, then the state is created if it does not yet exist.- Parameters:
cell
- Cell for which a new state should be returned.create
- Boolean indicating if a new state should be created if it does not yet exist.- Returns:
- Returns the state for the given cell.
-
removeState
public mxCellState removeState(java.lang.Object cell)
Removes and returns the mxCellState for the given cell.- Parameters:
cell
- mxCell for which the mxCellState should be removed.- Returns:
- Returns the mxCellState that has been removed.
-
createState
public mxCellState createState(java.lang.Object cell)
Creates and returns a cell state for the given cell.- Parameters:
cell
- Cell for which a new state should be created.- Returns:
- Returns a new state for the given cell.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-