http://www.jpicedt.org

jpicedt.graphic.model
Class PicNodeConnection

java.lang.Object
  extended by jpicedt.graphic.model.AbstractElement
      extended by jpicedt.graphic.model.PicNodeConnection
All Implemented Interfaces:
Element, ActionFactory

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:

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
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 inside forwardChangedUpdate()); 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).
static int CONTROL_A
          index of control point A
static int CONTROL_B
          index of control point B
static String EDGE_NCCURVE
           
static String EDGE_NCLINE
           
 
Fields inherited from class jpicedt.graphic.model.AbstractElement
attributeSet, name, parent, view
 
Constructor Summary
PicNodeConnection(NodeableElement nodeA, NodeableElement nodeB, String edgeType, PicAttributeSet set)
           
PicNodeConnection(PicNodeConnection src)
           
 
Method Summary
 PicNodeConnection clone()
          Returns a clone of this Element
 Shape createShape()
          Returns a Shape that holds the geometry of the connection.
 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.
 Rectangle2D getBoundingBox(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.
 PicPoint getCtrlPt(int index, PicPoint src)
          Return the user-controlled point having the given index.
 String getDefaultName()
           
 PicPoint getEndPointA(PicPoint pt)
          Returns the coordinates of the edge's end-point at node A
 PicPoint getEndPointB(PicPoint pt)
          Returns the coordinates of the edge's end-point at node B
 int getFirstPointIndex()
          Return the index of the first user-controlled point that can be retrieved by getCtrlPt()
 int getLastPointIndex()
          Return the index of the last user-controlled point that can be retrieved by getCtrlPt()
 NodeableElement getNodeA()
          Returns the first node.
 NodeableElement getNodeB()
          Returns the second node.
 int getNodeIndex(NodeableElement o)
          Returns the index (0 or 1) of the given node, or -1 if the given node is not connected to this edge.
 PicVector getTangentA(PicVector v)
          Return the tangent to the node connection at node A.
 PicVector getTangentB(PicVector v)
          Return the tangent to the node connection at node B.
 void mirror(PicPoint ptOrg, PicVector normalVector)
          Effectue une réflexion sur this relativement à l'axe défini par ptOrg et normalVector.
 void rotate(PicPoint ptOrg, double angle)
          Rotate this Element by the given angle along the given point
 void scale(double ptOrgX, double ptOrgY, double sx, double sy, UserConfirmationCache ucc)
          Scale children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.
 void setCtrlPt(int index, PicPoint pt)
          convenience call to setCtrlPt(int, PicPoint, null)
 void setCtrlPt(int index, PicPoint pt, EditPointConstraint constraint)
          Set the user-controlled point indexed by "index" to the given value, using the specified geometrical constraint.
 void setNodeA(NodeableElement o)
          Sets the first node.
 void setNodeB(NodeableElement o)
          Sets the second node.
 void shear(PicPoint ptOrg, double shx, double shy, UserConfirmationCache ucc)
          Shear this Element by the given params wrt to the given origin
 void syncArrowGeometry(ArrowView v, ArrowView.Direction d)
          Helper for the associated View.
 String toString()
          Returns a String representation of the attribute set for this AbstractElement
 void translate(double dx, double dy)
          Translate both nodes and connections by the given vector
 
Methods inherited from class jpicedt.graphic.model.AbstractElement
anchorPointsIterator, createActions, fireChangedUpdate, getAttribute, getAttributeSet, getCtrlPtSubset, getDrawing, getName, getParent, getView, pullOutOfGroup, removeView, replaceBy, scale, scale, scale, setAttribute, setAttributeSet, setName, setParent, setViewFromFactory, shear
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EDGE_NCLINE

public static final String EDGE_NCLINE
See Also:
Constant Field Values

EDGE_NCCURVE

public static final String EDGE_NCCURVE
See Also:
Constant Field Values

CONTROL_A

public static final int CONTROL_A
index of control point A

See Also:
Constant Field Values

CONTROL_B

public static final int CONTROL_B
index of control point B

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 inside forwardChangedUpdate()); 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

Constructor Detail

PicNodeConnection

public PicNodeConnection(NodeableElement nodeA,
                         NodeableElement nodeB,
                         String edgeType,
                         PicAttributeSet set)

PicNodeConnection

public PicNodeConnection(PicNodeConnection src)
Method Detail

clone

public PicNodeConnection clone()
Description copied from class: AbstractElement
Returns a clone of this Element

Specified by:
clone in interface Element
Specified by:
clone in class AbstractElement

getDefaultName

public String getDefaultName()
Specified by:
getDefaultName in class AbstractElement

createShape

public Shape createShape()
Returns a Shape that holds the geometry of the connection. May be used, for instance, by the associated view.

Specified by:
createShape in interface Element
Overrides:
createShape in class AbstractElement

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

syncArrowGeometry

public void syncArrowGeometry(ArrowView v,
                              ArrowView.Direction d)
Helper for the associated View. This implementation updates the geometry of the given ArrowView only if isArc()==true.

Specified by:
syncArrowGeometry in interface Element
Overrides:
syncArrowGeometry in class AbstractElement

getNodeA

public NodeableElement getNodeA()
Returns the first node.

Returns:
null if nodeA not set yet

getNodeB

public NodeableElement getNodeB()
Returns the second node.

Returns:
null if mgrB not set yet

getNodeIndex

public int getNodeIndex(NodeableElement 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(NodeableElement o)
Sets the first node.


setNodeB

public void setNodeB(NodeableElement o)
Sets the second node.


getCtrlPt

public PicPoint getCtrlPt(int index,
                          PicPoint src)
Description copied from interface: Element
Return 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 the setPoint method.

Parameters:
index - the point index, should be greater or equal to the value returned by getFirstPointIndex, and lower or equal to getLastPointIndex.
Returns:
the point indexed by index ; if dest is null, concrete implementation of this method should allocate a new PicPoint and return it, otherwise directly modify dest and return it as well for convenience.

getFirstPointIndex

public int getFirstPointIndex()
Description copied from interface: Element
Return the index of the first user-controlled point that can be retrieved by getCtrlPt()


getLastPointIndex

public int getLastPointIndex()
Description copied from interface: Element
Return the index of the last user-controlled point that can be retrieved by getCtrlPt()


setCtrlPt

public void setCtrlPt(int index,
                      PicPoint pt)
Description copied from class: AbstractElement
convenience call to setCtrlPt(int, PicPoint, null)

Specified by:
setCtrlPt in interface Element
Overrides:
setCtrlPt in class AbstractElement

setCtrlPt

public void setCtrlPt(int index,
                      PicPoint pt,
                      EditPointConstraint constraint)
Description copied from interface: Element
Set 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 Rectangle2D getBoundingBox(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.

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 type
node - 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 vector
dy - The Y coordinate of translation vector
Since:
jPicEdt 1.4pre5

scale

public void scale(double ptOrgX,
                  double ptOrgY,
                  double sx,
                  double sy,
                  UserConfirmationCache ucc)
Scale children by (sx,sy) using (ptOrgX,ptOrgY) as origin ; sx and sy can be negative.

ucc - une valeur UserConfirmationCache permettant de demander à l'utilisateur confirmation, de se souvenir de la dernière confirmation qu'il a donné, ou de ses préférences.

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

mirror

public void mirror(PicPoint ptOrg,
                   PicVector normalVector)
Effectue une réflexion sur this relativement à l'axe défini par ptOrg et normalVector.

Parameters:
ptOrg - le PicPoint par lequel passe l'axe de réflexion.
normalVector - le PicVector normal à l'axe de réflexion.

shear

public void shear(PicPoint ptOrg,
                  double shx,
                  double shy,
                  UserConfirmationCache ucc)
Shear this Element by the given params wrt to the given origin

ucc - une valeur UserConfirmationCache permettant de demander à l'utilisateur confirmation, de se souvenir de la dernière confirmation qu'il a donné, ou de ses préférences.

toString

public String toString()
Description copied from class: AbstractElement
Returns a String representation of the attribute set for this AbstractElement

Overrides:
toString in class AbstractElement

http://www.jpicedt.org

Submit a bug : syd@jpicedt.org