com.jfimagine.jfgraph.shape.base
Class Port

java.lang.Object
  |
  +--com.jfimagine.jfgraph.shape.base.AbstractObject
        |
        +--com.jfimagine.jfgraph.shape.base.Port
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ArcPort, CurvePort, EllipsePort

public class Port
extends AbstractObject

Port Class. A port is used for connecting other ports of shapes.

Version:
$Revision: 1.1 $
Author:
CookieMaker

Field Summary
static java.lang.String KEY_SEPARATOR
          A char seperating each parentId-index pair
protected  AbstractObject m_parent
          A parent object of this port.
protected  JFPoint m_portPoint
          A point for x,y coordinates.
static java.lang.String PAIR_SEPARATOR
          A char seperating all the parentId-index pairs in the string list
static int PORTTYPE_CUSTOM
          Arbitrary port.
static int PORTTYPE_DEFAULT
          A default port of a specified shape.
static java.lang.String XML_CONNECTEDLIST
          A XML string tag represents the ports list attached to this port
static java.lang.String XML_FIRSTPOINTX
          A XML string tag represents the x coordinates of first reference point.
static java.lang.String XML_FIRSTPOINTY
          A XML string tag represents the y coordinates of first reference point.
static java.lang.String XML_PARENTID
          A XML string tag represents the parent id of this port
static java.lang.String XML_PERCENTPOS
          A XML string tag represents the percent position of this port.
static java.lang.String XML_PORT
          A XML string tag represents a jfport
static java.lang.String XML_PORTTYPE
          A XML string tag represents current type of this port
static java.lang.String XML_SECONDPOINTX
          A XML string tag represents the x coordinates of second reference point.
static java.lang.String XML_SECONDPOINTY
          A XML string tag represents the y coordinates of second reference point.
static java.lang.String XML_XOFFSET
          A XML string tag represents the x coordinates of this port
static java.lang.String XML_YOFFSET
          A XML string tag represents the y coordinates of this port
 
Fields inherited from class com.jfimagine.jfgraph.shape.base.AbstractObject
m_lastError, XML_OBJECTID, XML_OBJECTTYPE
 
Constructor Summary
Port()
          Constructor for Port
Port(AbstractObject parent, int portType, JFPoint firstPoint, JFPoint secondPoint, JFPoint portPoint)
          Constructor for Port.
 
Method Summary
protected  void appendChildToDOM(Element element, JFVersion version)
          Append necessary xml child for current element, this method will be called internally by toDOM.
 boolean attachPort(Port port)
          Attach this port to a specified port of other shape.
 void attachRealPort(ObjectList shapeList)
          A loadFromStream method should only load an parentId-objectId list of ports attached, So here we use an attachRealPort to ACTUALLY attach some ports to this port
 java.lang.Object clone()
          Creates a new object of the same class and with the same contents as this object.
protected  AbstractObject cloneMe()
          Creates a new AbstractObject of the same class and with the same contents as this object.
 void collectAttachedList()
          Collect all the port in the attachedList to a string, actually the method should generate a new parentId-index pair list string, each pair seperated by PAIR_SEPARATOR, and pair itself seperated by KEY_SEPARATOR
 void detachAll()
          Detach all relational ports of this port.
 boolean detachPort(Port port)
          Detach this port to a specified port of other shape.
 void draw(java.awt.Graphics g, boolean isXorMode)
          Draw current object on graphic canvas.
 boolean equals(java.lang.Object obj)
          Determines whether or not two objects are equal.
protected  void extractChildFromDOM(Element element, JFVersion version)
          Extract needed xml child from current element, this method will be called internally by fromDOM.
 void finishMoving()
          Finish moving port.
 void flipBy(double baseY)
          Reverse this object by a y coordinate.
 java.util.List getAttachedList()
          Get attached port list.
 java.lang.String getAttachedListStr()
          Get attached port list str.
 Port getAttachedPortByIndex(int index)
          Get a attached port of current port by index.
 int getAttachedPortIndex(int parentId, int objectId)
          Get the index of an attached port in the attached port list..
 int getAttachedPortIndex(Port port)
          Get the index of an attached port in the attached port list..
 int getAttachedSize()
          Get the quantity of attached ports.
 JFPoint getFirstPoint()
          Get the first reference point of this port.
 AbstractObject getParent()
          Get parent object of this port.
 int getParentId()
          Get the key of parent shape of this port
 double getPercentPos()
          Get the percent position of this port.
 JFPoint getPortPoint()
          Get the port point of current port.
 int getPortType()
          Get the Type of current port.
 JFPoint getSecondPoint()
          Get the second reference point of this port.
 double getXOffset()
          Get the x offset of current port.
 double getYOffset()
          Get the y offset of current port.
 int hashCode()
          Returns the hashcode for this Object.
 boolean intersects(JFPoint pnt)
          Test if current object intersects with a specified point.
 void loadFromStream(JFReader stream, boolean skipHead, JFVersion version)
          Load port data from a binary stream
 void mirrorBy(double baseX)
          Mirror this object by a x coordinate.
 void moveBy(double x, double y)
          Move current object by an x and y offset.
 void moveRelationalPorts(ObjectList movedList, boolean isMovePorts)
          move relational ports.
 void rotateBy(double baseX, double baseY, double theta)
          Rotate current object by a specified point and an angle theta.
 void saveToStream(JFWriter stream, JFVersion version)
          Save this Port to a binary stream
 void scaleBy(double baseX, double baseY, double scale)
          Scale this port by a point, and specified scale.
 void scaleBy(double baseX, double baseY, double xScale, double yScale)
          Scale this port by a point, and specified scale.
 void setAttachedList(java.util.List attachedList)
          Set attached port list.
 void setAttachedListStr(java.lang.String attachedListStr)
          Set attached port list str.
 void setFirstPoint(double x, double y)
          Set the first reference point of this port.
 void setFirstPoint(JFPoint pnt)
          Set the first reference point of this port.
 void setParent(AbstractObject obj)
          Set parent object of this port.
 void setParentId(int parentId)
          Set the key of parent shape of this port
 void setPercentPos(double percentPos)
          Set the percent position of this port.
 void setPortPoint(double x, double y)
          Set the port point of current port.
 void setPortPoint(JFPoint pnt)
          Set the port point of current port.
 void setPortType(int portType)
          Set the Type of current port.
 void setSecondPoint(double x, double y)
          Set the second reference point of this port.
 void setSecondPoint(JFPoint pnt)
          Set the second reference point of this port.
 void setXOffset(double xOffset)
          Set the x offset of current port.
 void setYOffset(double yOffset)
          Set the y offset of current port.
 java.lang.String toString()
          Convert this port to String
 void unboundBrokenPorts()
          unbound broken ports.
 
Methods inherited from class com.jfimagine.jfgraph.shape.base.AbstractObject
fromDOM, getLastError, getMaxObjectId, getObjectId, getObjectType, getXMLTag, getZoomScale, isShowDesign, setLastError, setObjectId, setObjectType, setShowDesign, setValue, setXMLTag, setZoomScale, toDOM
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_PORT

public static final java.lang.String XML_PORT
A XML string tag represents a jfport

See Also:
Constant Field Values

XML_PORTTYPE

public static final java.lang.String XML_PORTTYPE
A XML string tag represents current type of this port

See Also:
Constant Field Values

XML_PARENTID

public static final java.lang.String XML_PARENTID
A XML string tag represents the parent id of this port

See Also:
Constant Field Values

XML_XOFFSET

public static final java.lang.String XML_XOFFSET
A XML string tag represents the x coordinates of this port

See Also:
Constant Field Values

XML_YOFFSET

public static final java.lang.String XML_YOFFSET
A XML string tag represents the y coordinates of this port

See Also:
Constant Field Values

XML_FIRSTPOINTX

public static final java.lang.String XML_FIRSTPOINTX
A XML string tag represents the x coordinates of first reference point.

See Also:
Constant Field Values

XML_FIRSTPOINTY

public static final java.lang.String XML_FIRSTPOINTY
A XML string tag represents the y coordinates of first reference point.

See Also:
Constant Field Values

XML_SECONDPOINTX

public static final java.lang.String XML_SECONDPOINTX
A XML string tag represents the x coordinates of second reference point.

See Also:
Constant Field Values

XML_SECONDPOINTY

public static final java.lang.String XML_SECONDPOINTY
A XML string tag represents the y coordinates of second reference point.

See Also:
Constant Field Values

XML_PERCENTPOS

public static final java.lang.String XML_PERCENTPOS
A XML string tag represents the percent position of this port.

See Also:
Constant Field Values

XML_CONNECTEDLIST

public static final java.lang.String XML_CONNECTEDLIST
A XML string tag represents the ports list attached to this port

See Also:
Constant Field Values

PORTTYPE_DEFAULT

public static final int PORTTYPE_DEFAULT
A default port of a specified shape. A default port will always has a default position of a shape.

See Also:
Constant Field Values

PORTTYPE_CUSTOM

public static final int PORTTYPE_CUSTOM
Arbitrary port. An custom port is defined by user and will has arbitrary position on the shape. But it will always on the outline of the shape.

See Also:
Constant Field Values

PAIR_SEPARATOR

public static final java.lang.String PAIR_SEPARATOR
A char seperating all the parentId-index pairs in the string list

See Also:
Constant Field Values

KEY_SEPARATOR

public static final java.lang.String KEY_SEPARATOR
A char seperating each parentId-index pair

See Also:
Constant Field Values

m_portPoint

protected JFPoint m_portPoint
A point for x,y coordinates.


m_parent

protected AbstractObject m_parent
A parent object of this port.

Constructor Detail

Port

public Port()
Constructor for Port


Port

public Port(AbstractObject parent,
            int portType,
            JFPoint firstPoint,
            JFPoint secondPoint,
            JFPoint portPoint)
Constructor for Port.

Parameters:
parent - parent object of this port.
portType - The type of a port.
firstPoint - The first reference end point of a port.
secondPoint - The second reference end point of a port.
portPoint - The port point of a port.
Method Detail

getPortType

public int getPortType()
Get the Type of current port.

Returns:
The Port Type.

setPortType

public void setPortType(int portType)
Set the Type of current port.

Parameters:
portType - The Type of current port
Returns:
No return.

getParentId

public int getParentId()
Get the key of parent shape of this port

Returns:
The parent shape's key.

setParentId

public void setParentId(int parentId)
Set the key of parent shape of this port

Parameters:
parentId - The parent shape's key.
Returns:
No return.

getParent

public AbstractObject getParent()
Get parent object of this port.

Returns:
parent object.

setParent

public void setParent(AbstractObject obj)
Set parent object of this port.


getXOffset

public double getXOffset()
Get the x offset of current port.
The x offset is the x coordinate position relative to the port which index=0

Returns:
The x offset of current port.

setXOffset

public void setXOffset(double xOffset)
Set the x offset of current port.
The x offset is the x coordinate position relative to the port which index=0

Parameters:
xOffset - The x offset of current port.
Returns:
No return.

getYOffset

public double getYOffset()
Get the y offset of current port.
The y offset is the y coordinate position relative to the port which index=0

Returns:
The y offset of current port.

setYOffset

public void setYOffset(double yOffset)
Set the y offset of current port.
The y offset is the y coordinate position relative to the port which index=0

Parameters:
yOffset - The y offset of current port.
Returns:
No return.

getPortPoint

public JFPoint getPortPoint()
Get the port point of current port.

Returns:
The port point.

setPortPoint

public void setPortPoint(JFPoint pnt)
Set the port point of current port.

Parameters:
pnt - The port point.

setPortPoint

public void setPortPoint(double x,
                         double y)
Set the port point of current port.


getFirstPoint

public JFPoint getFirstPoint()
Get the first reference point of this port.

Returns:
The first reference point.

setFirstPoint

public void setFirstPoint(JFPoint pnt)
Set the first reference point of this port.

Parameters:
pnt - A new first reference point.

setFirstPoint

public void setFirstPoint(double x,
                          double y)
Set the first reference point of this port.


getSecondPoint

public JFPoint getSecondPoint()
Get the second reference point of this port.

Returns:
The second reference point.

setSecondPoint

public void setSecondPoint(JFPoint pnt)
Set the second reference point of this port.

Parameters:
pnt - A new second reference point.

setSecondPoint

public void setSecondPoint(double x,
                           double y)
Set the second reference point of this port.


finishMoving

public void finishMoving()
Finish moving port. When we have already set a new first point or second point, and we want to keep the percent position for this port according these two points, we need to call a 'finishMoving' method here.


getPercentPos

public double getPercentPos()
Get the percent position of this port.

Returns:
The percent position.

setPercentPos

public void setPercentPos(double percentPos)
Set the percent position of this port.

Parameters:
percentPos - A new percent position.

getAttachedList

public java.util.List getAttachedList()
Get attached port list.

Returns:
The list of ports attached to current port.

setAttachedList

public void setAttachedList(java.util.List attachedList)
Set attached port list.

Parameters:
attachedList - The list of ports attached to current port.

getAttachedListStr

public java.lang.String getAttachedListStr()
Get attached port list str.

Returns:
The string of the ports list attached to current port.

setAttachedListStr

public void setAttachedListStr(java.lang.String attachedListStr)
Set attached port list str.

Parameters:
attachedListStr - The string of the ports list attached to current port.

getAttachedSize

public int getAttachedSize()
Get the quantity of attached ports.

Returns:
The quantity.

attachPort

public boolean attachPort(Port port)
Attach this port to a specified port of other shape.

Parameters:
port - A new port of other shape.

detachPort

public boolean detachPort(Port port)
Detach this port to a specified port of other shape.

Parameters:
port - A port of other shape.

detachAll

public void detachAll()
Detach all relational ports of this port.


moveRelationalPorts

public void moveRelationalPorts(ObjectList movedList,
                                boolean isMovePorts)
move relational ports.

Parameters:
movedList - An object list that has already processed, so don't change them further.
isMovePorts - Move ports or move ports' parent objects.True move ports, false otherwise.

unboundBrokenPorts

public void unboundBrokenPorts()
unbound broken ports.


getAttachedPortIndex

public int getAttachedPortIndex(Port port)
Get the index of an attached port in the attached port list..

Parameters:
port - An attached port.
Returns:
The index. return -1 if false.

getAttachedPortIndex

public int getAttachedPortIndex(int parentId,
                                int objectId)
Get the index of an attached port in the attached port list..

Parameters:
parentId - The parent id of a new port.
objectId - The object id of a new port.
Returns:
The index. return -1 if false.

getAttachedPortByIndex

public Port getAttachedPortByIndex(int index)
Get a attached port of current port by index.

Parameters:
index - An index in the list.
Returns:
A port found.

collectAttachedList

public void collectAttachedList()
Collect all the port in the attachedList to a string, actually the method should generate a new parentId-index pair list string, each pair seperated by PAIR_SEPARATOR, and pair itself seperated by KEY_SEPARATOR

Returns:
No return.

attachRealPort

public void attachRealPort(ObjectList shapeList)
                    throws ListException
A loadFromStream method should only load an parentId-objectId list of ports attached, So here we use an attachRealPort to ACTUALLY attach some ports to this port

Parameters:
shapeList - A shapeList used to pick out their ports for this port's attached list
ListException

draw

public void draw(java.awt.Graphics g,
                 boolean isXorMode)
Draw current object on graphic canvas.

Parameters:
g - A graphic canvas.
isXorMode - If is in xor mode now.

intersects

public boolean intersects(JFPoint pnt)
Test if current object intersects with a specified point.

Parameters:
pnt - A JFPoint used to test intersection.

scaleBy

public void scaleBy(double baseX,
                    double baseY,
                    double scale)
Scale this port by a point, and specified scale.

Parameters:
scale - A scale value.

scaleBy

public void scaleBy(double baseX,
                    double baseY,
                    double xScale,
                    double yScale)
Scale this port by a point, and specified scale.

Parameters:
xScale - A scale value in x coordinate.
yScale - A scale value in y coordinate.

moveBy

public void moveBy(double x,
                   double y)
Move current object by an x and y offset.


rotateBy

public void rotateBy(double baseX,
                     double baseY,
                     double theta)
Rotate current object by a specified point and an angle theta.

Parameters:
theta - A rotate angle.

mirrorBy

public void mirrorBy(double baseX)
Mirror this object by a x coordinate. We make a left-right mirror here.

Parameters:
baseX - A mirror base x coordinate.

flipBy

public void flipBy(double baseY)
Reverse this object by a y coordinate. We make a up-down flip here.

Parameters:
baseY - A flip base y coordinate.

toString

public java.lang.String toString()
Convert this port to String

Overrides:
toString in class AbstractObject
Returns:
An string represents the content of the port

cloneMe

protected AbstractObject cloneMe()
                          throws java.lang.CloneNotSupportedException
Creates a new AbstractObject of the same class and with the same contents as this object. This method implements the method defined in AbstractObject.

Specified by:
cloneMe in class AbstractObject
Returns:
A clone of this class.
java.lang.CloneNotSupportedException

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates a new object of the same class and with the same contents as this object.

Overrides:
clone in class AbstractObject
Returns:
A clone of this instance.
java.lang.CloneNotSupportedException

hashCode

public int hashCode()
Returns the hashcode for this Object.

Overrides:
hashCode in class AbstractObject
Returns:
hash code for this Point2D.

equals

public boolean equals(java.lang.Object obj)
Determines whether or not two objects are equal.

Overrides:
equals in class AbstractObject
Parameters:
obj - an object to be compared with this object
Returns:
true if the object to be compared is an instance of Port and has the same values; false otherwise.

appendChildToDOM

protected void appendChildToDOM(Element element,
                                JFVersion version)
Append necessary xml child for current element, this method will be called internally by toDOM.

Overrides:
appendChildToDOM in class AbstractObject
Parameters:
element - A XML element to append child xml nodes
version - A file version notification so this object can obey the rules to save data.

extractChildFromDOM

protected void extractChildFromDOM(Element element,
                                   JFVersion version)
Extract needed xml child from current element, this method will be called internally by fromDOM.

Overrides:
extractChildFromDOM in class AbstractObject
Parameters:
element - An element used to extract needed xml child
version - A file version notification so this object can obey the rules to fetch data.

saveToStream

public void saveToStream(JFWriter stream,
                         JFVersion version)
                  throws java.io.IOException
Save this Port to a binary stream

Overrides:
saveToStream in class AbstractObject
Parameters:
stream - An binary output stream
version - A file version notification so this object can obey the rules to fetch data.
Throws:
java.io.IOException

loadFromStream

public void loadFromStream(JFReader stream,
                           boolean skipHead,
                           JFVersion version)
                    throws java.io.IOException
Load port data from a binary stream

Overrides:
loadFromStream in class AbstractObject
Parameters:
stream - An binary input stream
skipHead - Skip head 'TYPE' check, an shape object should always has its own shape-type stored, if this shape-type has already been readed, this loadFromStream should/could not read the type anymore.
version - A file version notification so this object can obey the rules to fetch data.
Throws:
java.io.IOException


Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All Rights Reserved.