JGraph X 1.2.0.8


com.mxgraph.view
Class mxGraphView

java.lang.Object
  extended by com.mxgraph.util.mxEventSource
      extended by 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. The edit property contains the mxUndoableEdit which contains the mxCurrentRootChange. mxEvent.SCALE_AND_TRANSLATE fires after the scale and transle have been changed in scaleAndTranslate. The scale, previousScale, translate and previousTranslate properties contain the new and previous scale and translate, respectively. mxEvent.SCALE fires after the scale was changed in setScale. The scale and previousScale properties contain the new and previous scale. mxEvent.TRANSLATE fires after the translate was changed in setTranslate. The translate and previousTranslate 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. The root and previous properties contain the new and previous root, respectively.


Nested Class Summary
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
protected  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  Hashtable<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
mxGraphView(mxGraph graph)
          Constructs a new view for the given graph.
 
Method Summary
protected  void childMoved(mxCellState parentState, mxCellState childState)
          Invoked when a child state was moved as a result of late evaluation of its position.
 void clear(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(Object cell)
          Creates and returns a cell state for the given cell.
 mxRectangle getBoundingBox(Object[] cells)
          Returns the bounding box for an array of cells or null, if no cells are specified.
 mxRectangle getBounds(Object[] cells)
          Returns the bounding box for an array of cells or null, if no cells are specified.
 mxRectangle getBounds(Object[] cells, boolean boundingBox)
          Returns the bounding box for an array of cells or null, if no cells are specified.
 mxCellState[] getCellStates(Object[] cells)
          Returns the states for the given array of cells.
 Object getCurrentRoot()
          Returns the current root.
 mxEdgeStyle.mxEdgeStyleFunction getEdgeStyle(mxCellState edgeState, List<mxPoint> points, Object source, 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 state, Object opposite, boolean isSource)
          Returns the nearest point in the list of absolute points or the center of the opposite terminal.
 mxRectangle getPerimeterBounds(mxCellState terminal, mxCellState edge, boolean isSource)
          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 state, Object start, Object end, boolean isSource)
          Returns a point that defines the location of the connection point between the edge represented by the given state and the source or target end of the edge, depending on isSource.
 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(Object cell)
          Returns the state for the given cell or null if no state is defined for the cell.
 mxCellState getState(Object cell, boolean create)
          Returns the cell state for the given cell.
 Hashtable<Object,mxCellState> getStates()
          Returns the dictionary that maps from cells to states.
 mxPoint getTranslate()
          Returns the current translation.
 Object getVisibleTerminal(Object edge, boolean isSource)
          Returns the nearest ancestor terminal that is visible.
 void invalidate()
          Invalidates all cell states.
 void invalidate(Object cell)
          Invalidates the state of the given cell, all its descendants and connected edges.
 void reload()
          Removes all existing cell states and invokes revalidate.
 mxCellState removeState(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.
 Object setCurrentRoot(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(Hashtable<Object,mxCellState> states)
          Returns the dictionary that maps from cells to states.
 void setTerminalPoints(mxCellState state)
          Sets the initial absolute terminal points in the given state.
 void setTranslate(mxPoint value)
          Sets the current translation and invalidates the view.
 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 updateEdgeBounds(mxCellState state)
          Updates the given state using the bounding box of the absolute points.
 void updateLabelBounds(mxCellState state)
          Updates the label bounds in the given state.
 void updatePoints(mxCellState state, List<mxPoint> points, Object source, Object target)
          Updates the absolute points in the given state using the specified array of points as the relative points.
 void updateTerminalPoint(mxCellState state, Object start, Object end, boolean isSource)
          Updates the absolute terminal point in the given state for the given start and end state, where start is the source if isSource is true.
 void updateTerminalPoints(mxCellState state, Object source, Object target)
          Updates the terminal points in the given state.
 void updateVertexLabelOffset(mxCellState state)
          Updates the absoluteOffset of the given vertex cell state.
 void validate()
          First validates all bounds and then validates all points recursively on all visible cells.
 void validateBounds(mxCellState parentState, Object cell)
          Validates the bounds of the given parent's child using the given parent state as the origin for the child.
 mxRectangle validatePoints(mxCellState parentState, Object cell)
          Validates the points for the state of the given cell recursively if the cell is not collapsed and returns the bounding box of all visited states as a rectangle.
 
Methods inherited from class com.mxgraph.util.mxEventSource
addListener, fireEvent, fireEvent, getEventSource, isEventsEnabled, removeListener, removeListener, setEventsEnabled, setEventSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

graph

protected mxGraph graph
Reference to the enclosing graph.


currentRoot

protected 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 Hashtable<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 Hashtable<Object,mxCellState> getStates()
Returns the dictionary that maps from cells to states.


setStates

public void setStates(Hashtable<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 Object getCurrentRoot()
Returns the current root.


setCurrentRoot

public Object setCurrentRoot(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(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(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(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 revalidate.


revalidate

public void revalidate()

invalidate

public void invalidate()
Invalidates all cell states.


clear

public void clear(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(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.


validateBounds

public void validateBounds(mxCellState parentState,
                           Object cell)
Validates the bounds of the given parent's child using the given parent state as the origin for the child. The validation is carried out recursively for all non-collapsed descendants.

Parameters:
parentState - Object that represents the state of the parent cell.
cell - Cell for which the bounds in the state should be updated.

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.

validatePoints

public mxRectangle validatePoints(mxCellState parentState,
                                  Object cell)
Validates the points for the state of the given cell recursively if the cell is not collapsed and returns the bounding box of all visited states as a rectangle.

Parameters:
parentState - Object that represents the state of the parent cell.
cell - Cell for which the points in the state should be updated.
Returns:
Returns the bounding box for the given cell.

childMoved

protected void childMoved(mxCellState parentState,
                          mxCellState childState)
Invoked when a child state was moved as a result of late evaluation of its position. This is invoked for relative edge children whose position can only be determined after the points of the parent edge are updated in validatePoints, and validates the bounds of all descendants of the child using validateBounds.


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.

setTerminalPoints

public void setTerminalPoints(mxCellState state)
Sets the initial absolute terminal points in the given state.

Parameters:
state - Cell state whose initial terminal points should be updated.

updatePoints

public void updatePoints(mxCellState state,
                         List<mxPoint> points,
                         Object source,
                         Object target)
Updates the absolute points in the given state using the specified array of points as the relative points.

Parameters:
state - Cell state whose absolute points should be updated.
points - Array of points that constitute the relative points.
source - Cell that represents the visual source.
target - Cell that represents the visual target.

transformControlPoint

public mxPoint transformControlPoint(mxCellState state,
                                     mxPoint pt)
Transforms the given control point to an absolute point.


getEdgeStyle

public mxEdgeStyle.mxEdgeStyleFunction getEdgeStyle(mxCellState edgeState,
                                                    List<mxPoint> points,
                                                    Object source,
                                                    Object target)
Returns the edge style function to be used to compute the absolute points for the given state, control points and terminals.


updateTerminalPoints

public void updateTerminalPoints(mxCellState state,
                                 Object source,
                                 Object target)
Updates the terminal points in the given state.

Parameters:
state - Cell state whose terminal points should be updated.
source - Cell that represents the visual source.
target - Cell that represents the visual target.

updateTerminalPoint

public void updateTerminalPoint(mxCellState state,
                                Object start,
                                Object end,
                                boolean isSource)
Updates the absolute terminal point in the given state for the given start and end state, where start is the source if isSource is true.

Parameters:
state - Cell state whose terminal point should be updated.
start - Cell state for the source or target terminal.
end - Cell state for the opposite terminal.
isSource - Boolean indicating if start is the state of the source terminal.

getPerimeterPoint

public mxPoint getPerimeterPoint(mxCellState state,
                                 Object start,
                                 Object end,
                                 boolean isSource)
Returns a point that defines the location of the connection point between the edge represented by the given state and the source or target end of the edge, depending on isSource.

Parameters:
state - Cell state of the connecting edge.
start - Cell state for the source or target terminal.
end - Cell state for the opposite terminal.
isSource - Boolean indicating if start is the state of the source terminal.
Returns:
Returns the connection point between the edge and the terminal.

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,
                                      mxCellState edge,
                                      boolean isSource)
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 state,
                            Object opposite,
                            boolean isSource)
Returns the nearest point in the list of absolute points or the center of the opposite terminal.

Parameters:
state - Cell state that represents the edge.
opposite - Cell that represents the opposite terminal.
isSource - 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 Object getVisibleTerminal(Object edge,
                                 boolean isSource)
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.
isSource - 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(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(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(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(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(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.

JGraph X 1.2.0.8


Copyright (c) 2008 Gaudenz Alder. All rights reserved.