org.jgraph.graph

Class AbstractCellView

public abstract class AbstractCellView extends Object implements CellView, Serializable

The abstract base class for all cell views.
Field Summary
protected AttributeMapallAttributes
Contains the complete set of attributes, including the cell's attributes.
protected AttributeMapattributes
Hashtable for attributes.
protected Objectcell
Reference to the cell for this view
static GraphCellEditorcellEditor
Editor for the cell.
protected ListchildViews
Cached child views.
protected Rectangle2DgroupBounds
Cached bounds of all children if vertex is a group
protected CellViewparent
Cached parent view
Constructor Summary
AbstractCellView()
Constructs an empty abstract cell view.
AbstractCellView(Object cell)
Constructs a view for the specified model object, and invokes update on the new instance.
Method Summary
MapchangeAttributes(GraphLayoutCache cache, Map change)
Applies change to the attributes of the view and calls update.
voidchildUpdated()
Indicates to parent, if any, that this child has been updated.
protected AttributeMapcreateAttributeMap()
Hook for subclassers to avoid creating an empty AttributeMap during construction of the instance.
AttributeMapgetAllAttributes()
Returns the attributes of the view combined with the attributes of the corresponding cell.
AttributeMapgetAttributes()
Return the attributes of the view.
Rectangle2DgetBounds()
Returns the cached bounds for the group if isleaf is false
static Rectangle2DgetBounds(CellView[] views)
Returns the bounding box for the specified views.
ObjectgetCell()
Returns the model object that this view represents.
protected AttributeMapgetCellAttributes(GraphModel model)
Hook for subclassers to avoid cloning the cell's attributes.
static Point2DgetCenterPoint(CellView vertex)
CellView[]getChildViews()
Returns the child views of this view.
static CellView[]getDescendantViews(CellView[] views)
Returns all views, including descendants that have a parent in views without the PortViews.
GraphCellEditorgetEditor()
Returns a cell editor for the view.
abstract CellHandlegetHandle(GraphContext context)
Returns a cell handle for the view.
CellViewgetParentView()
Returns the parent view for this view.
Point2DgetPerimeterPoint(EdgeView edge, Point2D source, Point2D p)
Returns the intersection of the bounding rectangle and the straight line between the source and the specified point p.
abstract CellViewRenderergetRenderer()
Obtains the renderer instance for this view
ComponentgetRendererComponent(JGraph graph, boolean selected, boolean focus, boolean preview)
Returns a renderer component, configured for the view.
protected booleanincludeInGroupBounds(CellView view)
This is used to exclude certain cell views from the group bounds computation.
booleanintersects(JGraph graph, Rectangle2D rect)
Returns true if the view intersects the given rectangle.
booleanisLeaf()
Returns true if the view is a leaf.
protected voidmergeAttributes()
Implements the merging of the cell's attributes, initially stored in allAttributes, and the location attributes.
voidrefresh(GraphLayoutCache cache, CellMapper mapper, boolean createDependentViews)
Create child views and reload properties for this view.
voidremoveFromParent()
Removes this view from the list of children of the parent.
voidscale(double sx, double sy, Point2D origin)
Scale view (group) by sx, sy.
voidsetAttributes(AttributeMap attributes)
Sets the attributes of this view to the specified value
voidsetBounds(Rectangle2D bounds)
Sets the bounds of this view.
voidsetCell(Object cell)
Sets the model object that this view represents to the specified cell
voidtranslate(double dx, double dy)
Translates view (group) by dx, dy.
voidupdate(GraphLayoutCache cache)
Update attributes for this view and indicate to the parent this child has been updated
protected voidupdateGroupBounds()
Updates the bounds of this view and its children

Field Detail

allAttributes

protected AttributeMap allAttributes
Contains the complete set of attributes, including the cell's attributes. The values in this map are overriden by the corresponding values in attributes.

attributes

protected AttributeMap attributes
Hashtable for attributes. Value in this map override the values in allAttributes.

cell

protected Object cell
Reference to the cell for this view

cellEditor

public static transient GraphCellEditor cellEditor
Editor for the cell.

childViews

protected List childViews
Cached child views. Default is a ArrayList with allocation size 0.

groupBounds

protected transient Rectangle2D groupBounds
Cached bounds of all children if vertex is a group

parent

protected CellView parent
Cached parent view

Constructor Detail

AbstractCellView

public AbstractCellView()
Constructs an empty abstract cell view. You should set a cell on this view using setCell before doing anything. Optionally you can also set a different attribute map using setAttributeMap. Note: To change the attribute map you should now use the changeAttributes method.

AbstractCellView

public AbstractCellView(Object cell)
Constructs a view for the specified model object, and invokes update on the new instance.

Parameters: cell reference to the model object

Method Detail

changeAttributes

public Map changeAttributes(GraphLayoutCache cache, Map change)
Applies change to the attributes of the view and calls update.

Parameters: change a map of attribute changes to apply

Returns: the undo map that reverses this change

childUpdated

public void childUpdated()
Indicates to parent, if any, that this child has been updated.

createAttributeMap

protected AttributeMap createAttributeMap()
Hook for subclassers to avoid creating an empty AttributeMap during construction of the instance. Override this and return null if you want to avoid creation of an attribute map at construction time.

getAllAttributes

public AttributeMap getAllAttributes()
Returns the attributes of the view combined with the attributes of the corresponding cell. The view's attributes override the cell's attributes with the same key.

getAttributes

public AttributeMap getAttributes()
Return the attributes of the view.

Returns: the attributes of this view

getBounds

public Rectangle2D getBounds()
Returns the cached bounds for the group if isleaf is false

getBounds

public static Rectangle2D getBounds(CellView[] views)
Returns the bounding box for the specified views.

Parameters: views the views for whom the bounding box is to be determined

Returns: the bounding box of the specified views

getCell

public Object getCell()
Returns the model object that this view represents.

Returns: the model object that this view represents

getCellAttributes

protected AttributeMap getCellAttributes(GraphModel model)
Hook for subclassers to avoid cloning the cell's attributes. Return model.getAttributes(cell) to avoid cloning.

getCenterPoint

public static Point2D getCenterPoint(CellView vertex)

getChildViews

public CellView[] getChildViews()
Returns the child views of this view.

Returns: the child views of this view

getDescendantViews

public static CellView[] getDescendantViews(CellView[] views)
Returns all views, including descendants that have a parent in views without the PortViews. Note: Iterative Implementation using view.getChildViews. This returns the array in inverse order, ie with the top most cell view at index 0.

Parameters: views the cell views whose descendants are to be returned

Returns: the specified views and all their descendant views

getEditor

public GraphCellEditor getEditor()
Returns a cell editor for the view.

Returns: the cell editor for this view

getHandle

public abstract CellHandle getHandle(GraphContext context)
Returns a cell handle for the view.

Parameters: context the context of this cell view (cells indirectly affected by it)

Returns: the cell handle for this view

getParentView

public CellView getParentView()
Returns the parent view for this view.

Returns: the parent view for this view

getPerimeterPoint

public Point2D getPerimeterPoint(EdgeView edge, Point2D source, Point2D p)
Returns the intersection of the bounding rectangle and the straight line between the source and the specified point p. The specified point is expected not to intersect the bounds. Note: You must override this method if you use a different renderer. This is because this method relies on the VertexRenderer interface, which can not be safely assumed for subclassers.

getRenderer

public abstract CellViewRenderer getRenderer()
Obtains the renderer instance for this view

Returns: the renderer instance for this view

getRendererComponent

public Component getRendererComponent(JGraph graph, boolean selected, boolean focus, boolean preview)
Returns a renderer component, configured for the view. The method used to obtain the renderer instance must install the necessary attributes from this view

Parameters: graph the JGraph instance of the view selected whether or not this view is selected focus whether or not this view is the focus preview whether or not it is a preview of the view

Returns: the renderer component for this view with this views attributes installed

includeInGroupBounds

protected boolean includeInGroupBounds(CellView view)
This is used to exclude certain cell views from the group bounds computation. This implementation returns false for edges that connect to one of their ancestor groups (eg. parent).

Parameters: view the cell view to be included in the group bounds or not

Returns: whether or not to include the specified cell in the group bounds

intersects

public boolean intersects(JGraph graph, Rectangle2D rect)
Returns true if the view intersects the given rectangle.

Parameters: graph the JGraph instance of the view rect the rectangle within which intersection is being checked for

Returns: whether or not the rectangle specified intersects the view

isLeaf

public boolean isLeaf()
Returns true if the view is a leaf.

Returns: true if the view is a leaf

mergeAttributes

protected void mergeAttributes()
Implements the merging of the cell's attributes, initially stored in allAttributes, and the location attributes. The result should be stored in allAttributes. This hook is for subclassers to change the merging strategy.

refresh

public void refresh(GraphLayoutCache cache, CellMapper mapper, boolean createDependentViews)
Create child views and reload properties for this view. Invokes update first.

Parameters: cache the graph model to be used mapper the cell mapper to be used createDependentViews whether or not to create a view if one does not already exist

removeFromParent

public void removeFromParent()
Removes this view from the list of children of the parent.

scale

public void scale(double sx, double sy, Point2D origin)
Scale view (group) by sx, sy.

Parameters: sx the multiple by which the x coordinate position of the cell view is to be scaled sy the multiple by which the y coordinate position of the cell view is to be scaled origin the origin point from which the scaling will calculate

setAttributes

public void setAttributes(AttributeMap attributes)
Sets the attributes of this view to the specified value

Parameters: attributes the new attributes to set

setBounds

public void setBounds(Rectangle2D bounds)
Sets the bounds of this view. Calls translateView and scaleView.

Parameters: bounds the new bounds for this cell view

setCell

public void setCell(Object cell)
Sets the model object that this view represents to the specified cell

Parameters: cell the model object this view will represent

translate

public void translate(double dx, double dy)
Translates view (group) by dx, dy.

Parameters: dx the x-coordinate amount to translate by dy the y-coordinate amount to translate by

update

public void update(GraphLayoutCache cache)
Update attributes for this view and indicate to the parent this child has been updated

updateGroupBounds

protected void updateGroupBounds()
Updates the bounds of this view and its children
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.