Package jpicedt.graphic.model
Class PicNodeConnection
- java.lang.Object
-
- jpicedt.graphic.model.AbstractElement
-
- jpicedt.graphic.model.PicNodeConnection
-
- All Implemented Interfaces:
Element,PicObjectConstants
public class PicNodeConnection extends AbstractElement
This class represents a connection between two DefaultLeafElement's. It directly inherits from AbstractElement because BranchElement (after thinking it over carefully) is not the most appropriate choice in many respects: - first, the connection is a sort of branch-element, yet its geometry is directly implemented here (as a GeneralPath) rather than in a separate class, so this is quite different from BranchElement, where the whole geometry is delegated to children. - second, the relationship b/w this class and the two DefaultLeafElement's is definitely not a parent/child one, seeing that a node may be linked to more than one connection (which is forbidden in a parent/child relation as in BranchElement) - third, (child-)nodes need to hold a reference to the many (parent) node-connections, so that the connection geometry can keep up with any change made to the geometry of the children. This is the idea behind the improvement of the fireChangedUpdate() method in DefaultLeafElement (april'05) whereby, in addition to standard child-parent event dispatching, change events are also dispatched to every appropriate connection, if any, irrespective of the nature of the (real) parent (e.g., Drawing.RootElement or PicGroup). In particular, this means that one DefaultLeafElement may belong to a given group A, while the other DefaultLeafElement may belong to another group B, and at the same time both DefaultLeafElement's may share the same connection (now, this also implies that a PicNodeConnection may have "dangling" bonds if we cut/delete one of the groups [pending] the view might get confused ?).
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanchangeLocka semaphor that signals a change of state is underway in this PicNodeConnection and it shouldn't process events coming from its node before the change is completed (hence this is used insideforwardChangedUpdate()); set it to true each time you start modifying nodes AND edge simulatneously and you don't want events to be forwarded to the root of the hierarchy before everything is completed (e.g.static java.lang.StringEDGE_NCCURVEstatic java.lang.StringEDGE_NCLINE-
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, parent, view
-
Fields inherited from interface jpicedt.graphic.model.PicObjectConstants
ARROW_GLOBAL_SCALE_LENGTH, ARROW_GLOBAL_SCALE_WIDTH, ARROW_INSET_SCALE, ARROW_LENGTH_SCALE, ARROW_WIDTH_LINEWIDTH_SCALE, ARROW_WIDTH_MINIMUM_MM, BRACKET_LENGTH_SCALE, CROSSHATCH, CROSSHATCH_FILLED, DASH_OPAQUE, DASH_TRANSPARENT, DASH1, DASH2, DASH3, DASHED, DIMEN, DOT_SEP, DOT_SEP1, DOT_SEP2, DOT_SEP3, DOTTED, DOUBLE_COLOR, DOUBLE_LINE, DOUBLE_SEP, FILL_COLOR, FILL_STYLE, HATCH_ANGLE, HATCH_COLOR, HATCH_SEP, HATCH_WIDTH, HLINES, HLINES_FILLED, INNER, LEFT_ARROW, LINE_COLOR, LINE_STYLE, LINE_WIDTH, MIDDLE, NONE, OUTER, OVER_STRIKE, OVER_STRIKE_COLOR, OVER_STRIKE_WIDTH, POLYDOTS_ANGLE, POLYDOTS_CIRCLE, POLYDOTS_DISK, POLYDOTS_PENTAGON, POLYDOTS_PENTAGON_FILLED, POLYDOTS_PLUS, POLYDOTS_SCALE_H, POLYDOTS_SCALE_V, POLYDOTS_SIZE_LINEWIDTH_SCALE, POLYDOTS_SIZE_MINIMUM_MM, POLYDOTS_SQUARE, POLYDOTS_SQUARE_FILLED, POLYDOTS_STYLE, POLYDOTS_SUPERIMPOSE, POLYDOTS_TRIANGLE, POLYDOTS_TRIANGLE_FILLED, PS_POINT, PST_CUSTOM, RBRACKET_LENGTH_SCALE, RIGHT_ARROW, SHADOW, SHADOW_ANGLE, SHADOW_COLOR, SHADOW_SIZE, SOLID, TBAR_WIDTH_LINEWIDTH_SCALE, TBAR_WIDTH_MINIMUM_MM, TEXT_BOX_CIRCLE, TEXT_BOX_NO_FRAME, TEXT_BOX_OVAL, TEXT_BOX_RECTANGLE, TEXT_FRAME, TEXT_HALIGN_CENTER, TEXT_HALIGN_LEFT, TEXT_HALIGN_RIGHT, TEXT_HOR_ALIGN, TEXT_ROTATION, TEXT_VALIGN_BASELINE, TEXT_VALIGN_BOTTOM, TEXT_VALIGN_CENTER, TEXT_VALIGN_TOP, TEXT_VERT_ALIGN, VLINES, VLINES_FILLED
-
-
Constructor Summary
Constructors Constructor Description PicNodeConnection(DefaultLeafElement _nodeA, DefaultLeafElement _nodeB, java.lang.String _edgeType, PicAttributeSet set)PicNodeConnection(PicNodeConnection src)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Returns a clone of this Elementjava.awt.ShapefetchEdgeShape()Returns a Shape that holds the geometry of the connection.voidforwardChangedUpdate(Element node, DrawingEvent.EventType eventType)Called by a child-node (=a DefaultLeafElement) to inform this connection of some change that occured to one of its nodes.booleangetAllowsChildren()Returns true if the receiver allows children.java.awt.geom.Rectangle2DgetBoundingBox(java.awt.geom.Rectangle2D r)Returns the bounding box (i.e.PicPointgetEndPointA(PicPoint pt)Returns the coordinates of the edge's end-point at node APicPointgetEndPointB(PicPoint pt)Returns the coordinates of the edge's end-point at node BintgetFirstPointIndex()Return the index of the first user-controlled point that can be retrieved by getPoint()intgetLastPointIndex()Return the index of the last user-controlled point that can be retrieved by getPoint()java.lang.StringgetName()Return a non-localised string representing this element's name.DefaultLeafElementgetNodeA()Returns the first node.DefaultLeafElementgetNodeB()Returns the second node.intgetNodeIndex(DefaultLeafElement o)Returns the index (0 or 1) of the given node, or -1 if the given node is not connected to this edge.PicPointgetPoint(int index, PicPoint src)Return the user-controlled point having the given index.doublegetPointX(int index)Same asgetPoint(), yet return the x-coordinate only.doublegetPointY(int index)Same asgetPoint(), yet return the y-coordinate only.PicVectorgetTangentA(PicVector v)Return the tangent to the node connection at node A.PicVectorgetTangentB(PicVector v)Return the tangent to the node connection at node B.voidrotate(PicPoint ptOrg, double angle)Rotate this Element by the given angle along the given pointvoidscale(double ptOrgX, double ptOrgY, double sx, double sy)Scale children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.voidsetNodeA(DefaultLeafElement o)Sets the first node.voidsetNodeB(DefaultLeafElement o)Sets the second node.voidsetPoint(int index, PicPoint pt)Set the user-controlled point indexed by "index" to the given value.voidsetPoint(int index, PicPoint pt, EditPointConstraint constraint)Set the user-controlled point indexed by "index" to the given value, using the specified geometrical constraint.voidshear(PicPoint ptOrg, double shx, double shy)Shear this Element by the given params wrt to the given originjava.lang.StringtoString()Returns a String representation of the attribute set for this AbstractElementvoidtranslate(double dx, double dy)Translate both nodes and connections by the given vector-
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, fireChangedUpdate, getAttribute, getAttributeSet, getDrawing, getParent, getView, removeView, scale, setAttribute, setAttributeSet, setParent, setViewFromFactory
-
-
-
-
Field Detail
-
EDGE_NCLINE
public static final java.lang.String EDGE_NCLINE
- See Also:
- Constant Field Values
-
EDGE_NCCURVE
public static final java.lang.String EDGE_NCCURVE
- See Also:
- Constant Field Values
-
changeLock
protected boolean changeLock
a semaphor that signals a change of state is underway in this PicNodeConnection and it shouldn't process events coming from its node before the change is completed (hence this is used insideforwardChangedUpdate()); set it to true each time you start modifying nodes AND edge simulatneously and you don't want events to be forwarded to the root of the hierarchy before everything is completed (e.g. to get rid of side-effects, or to reduce the burden for the repaint manager).Example of use : whenever we call
translate()on this PicNodeConnection- this first raises the changeLock semaphor,
- then calls translate() on every node: this in turn make nodes forward a DrawingEvent to their connection (= this PicNodeConnection), yet this event is trapped here, hence not propagated upward ; note however that nodes update their own view whatever the value of the changeLock semaphor ;
- then lower the changeLock semaphor, and fire a change-update event (which in turn will propagate the event upward along the tree).
- Notice that, as opposed to BranchElement (and as a consequence of each node having possibly more than one connection), translating (or rotating or whatsoever) this edge and its two nodes as a single block also results in OTHER edges being affected... There, however, the changeLock semaphor will be down, and these PicNodeConnection's will update their state properly.
-
-
Constructor Detail
-
PicNodeConnection
public PicNodeConnection(DefaultLeafElement _nodeA, DefaultLeafElement _nodeB, java.lang.String _edgeType, PicAttributeSet set)
-
PicNodeConnection
public PicNodeConnection(PicNodeConnection src)
-
-
Method Detail
-
clone
public java.lang.Object clone()
Description copied from class:AbstractElementReturns a clone of this Element- Specified by:
clonein interfaceElement- Specified by:
clonein classAbstractElement
-
getName
public java.lang.String getName()
Description copied from interface:ElementReturn a non-localised string representing this element's name. This may be used by a UI to display some information related to this element, or by a localizer to fetch a i18n'd string.
-
fetchEdgeShape
public java.awt.Shape fetchEdgeShape()
Returns a Shape that holds the geometry of the connection. May be used, for instance, by the associated view.
-
getEndPointA
public PicPoint getEndPointA(PicPoint pt)
Returns the coordinates of the edge's end-point at node A
-
getEndPointB
public PicPoint getEndPointB(PicPoint pt)
Returns the coordinates of the edge's end-point at node B
-
getTangentA
public PicVector getTangentA(PicVector v)
Return the tangent to the node connection at node A. Useful for instance to compute the direction of the first arrow.- Returns:
- a unit-length vector
-
getTangentB
public PicVector getTangentB(PicVector v)
Return the tangent to the node connection at node B. Useful for instance to compute the direction of the second arrow.- Returns:
- a unit-length vector
-
getNodeA
public DefaultLeafElement getNodeA()
Returns the first node.- Returns:
- null if nodeA not set yet
-
getNodeB
public DefaultLeafElement getNodeB()
Returns the second node.- Returns:
- null if nodeB not set yet
-
getNodeIndex
public int getNodeIndex(DefaultLeafElement o)
Returns the index (0 or 1) of the given node, or -1 if the given node is not connected to this edge.
-
setNodeA
public void setNodeA(DefaultLeafElement o)
Sets the first node.
-
setNodeB
public void setNodeB(DefaultLeafElement o)
Sets the second node.
-
getPoint
public PicPoint getPoint(int index, PicPoint src)
Description copied from interface:ElementReturn the user-controlled point having the given index. The general contract is to return an IMMUTABLE instance of PicPoint, so that the only way to alter the geometry of this element is by calling thesetPointmethod.- Parameters:
index- the point index, should be greater or equal to the value returned bygetFirstPointIndex, and lower or equal togetLastPointIndex.- Returns:
- the point indexed by
index; ifsrcis null, concrete implementation of this method should allocate a new PicPoint and return it, otherwise directly modifysrcand return it as well for convenience.
-
getPointX
public double getPointX(int index)
Description copied from interface:ElementSame asgetPoint(), yet return the x-coordinate only.- Parameters:
index- the point index, should be greater or equal to the value returned bygetFirstPointIndex, and lower or equal togetLastPointIndex.- Returns:
- the X-coord of the point indexed by
index.
-
getPointY
public double getPointY(int index)
Description copied from interface:ElementSame asgetPoint(), yet return the y-coordinate only.- Parameters:
index- the point index, should be greater or equal to the value returned bygetFirstPointIndex, and lower or equal togetLastPointIndex.- Returns:
- the Y-coord of the point indexed by
index.
-
getFirstPointIndex
public int getFirstPointIndex()
Description copied from interface:ElementReturn the index of the first user-controlled point that can be retrieved by getPoint()
-
getLastPointIndex
public int getLastPointIndex()
Description copied from interface:ElementReturn the index of the last user-controlled point that can be retrieved by getPoint()
-
setPoint
public void setPoint(int index, PicPoint pt)Description copied from interface:ElementSet the user-controlled point indexed by "index" to the given value. This should be a convenience call to setPoint(index,pt,null), i.e. using no particular geometrical constraint.
-
setPoint
public void setPoint(int index, PicPoint pt, EditPointConstraint constraint)Description copied from interface:ElementSet the user-controlled point indexed by "index" to the given value, using the specified geometrical constraint. Constraints depend on the particular concrete implementation, and may involve restricting movement along a particular direction, moving several points at once to preserve parallelism,...constraint- a geometry constraint, or null if no particular constraint is being imposed (aka default).
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox(java.awt.geom.Rectangle2D r)
Returns the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of the \\begin{picture} command.- Returns:
- the bounding box (i.e. the surrounding rectangle) in double precision Used e.g. to determine the arguments of the \\begin{picture} command. If r is null, allocate a new rectangle and returns it. Otherwise the source rectangle is modified and returned for convenience. [todo:reynal] this really need to be improved : this method would probably better be moved to the attached view, since the latter knows exactly what the TRUE bounding box is.
-
getAllowsChildren
public boolean getAllowsChildren()
Description copied from interface:ElementReturns true if the receiver allows children.
-
forwardChangedUpdate
public void forwardChangedUpdate(Element node, DrawingEvent.EventType eventType)
Called by a child-node (=a DefaultLeafElement) to inform this connection of some change that occured to one of its nodes. See DefaultLeafElement.fireChangedUpdate() for more details. This gives a chance to the receiver to update its layout, then to propagate the change-event upward.- Parameters:
eventType- the event typenode- the node that sent the change-event.
-
translate
public void translate(double dx, double dy)Translate both nodes and connections by the given vector- Parameters:
dx- The X coordinate of translation vectordy- The Y coordinate of translation vector- Since:
- jPicEdt 1.4pre5
-
scale
public void scale(double ptOrgX, double ptOrgY, double sx, double sy)Scale children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.
-
rotate
public void rotate(PicPoint ptOrg, double angle)
Rotate this Element by the given angle along the given point- Parameters:
angle- rotation angle in radians
-
shear
public void shear(PicPoint ptOrg, double shx, double shy)
Shear this Element by the given params wrt to the given origin
-
toString
public java.lang.String toString()
Description copied from class:AbstractElementReturns a String representation of the attribute set for this AbstractElement- Overrides:
toStringin classAbstractElement
-
-