com.jfimagine.jfgraph.shape.rectangle
Class AbstractRectangle

java.lang.Object
  |
  +--com.jfimagine.jfgraph.shape.base.AbstractObject
        |
        +--com.jfimagine.jfgraph.shape.base.AbstractShape
              |
              +--com.jfimagine.jfgraph.shape.rectangle.AbstractRectangle
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
JFDiamond, JFEllipse, JFHexagon, JFImage, JFIsoscelesTrapezoid, JFIsoscelesTriangle, JFParallelogram, JFRectangle, JFRoundedRectangle, JFTrapezoid

public abstract class AbstractRectangle
extends AbstractShape

Abstract Rectangle class. It's a class as base of Arc, rectangle,ellipse

Version:
$Revision: 1.1 $
Author:
CookieMaker

Field Summary
protected  FillFormat m_fillFormat
          fill format of current fill.
protected  JFPoint m_firstNode
          first node settled while drawing.
protected  LineFormat m_lineFormat
          line format of current line.
protected  LineSeg m_lineSeg
          line segment object for rectangle calculations.
protected  int m_nodeAdded
          while drawing rectangle, how many nodes have been decided. called by addnode method.
protected  Rect m_originalRect
           
protected  Rect m_rect
          An rectangle object for the outline of this rectangle.
static java.lang.String XML_LEFTBOTTOMX
          A XML string tag represents the left-bottom x coordinate offset of this rectangle
static java.lang.String XML_LEFTBOTTOMY
          A XML string tag represents the left-bottom y coordinate offset of this rectangle
static java.lang.String XML_LEFTTOPX
          A XML string tag represents the left-top x coordinate offset of this rectangle
static java.lang.String XML_LEFTTOPY
          A XML string tag represents the left-top y coordinate offset of this rectangle
static java.lang.String XML_RIGHTBOTTOMX
          A XML string tag represents the right-bottom x coordinate offset of this rectangle
static java.lang.String XML_RIGHTBOTTOMY
          A XML string tag represents the right-bottom y coordinate offset of this rectangle
static java.lang.String XML_RIGHTTOPX
          A XML string tag represents the right-top x coordinate offset of this rectangle
static java.lang.String XML_RIGHTTOPY
          A XML string tag represents the right-top y coordinate offset of this rectangle
 
Fields inherited from class com.jfimagine.jfgraph.shape.base.AbstractShape
m_boundsNodeList, m_fontFormat, m_label, m_nodeList, m_portList, m_propertyList, XML_DISABLEMODIFYINGPROPERTIES, XML_DISABLEMOTION, XML_DISABLESCALING, XML_INVISIBLE, XML_LABEL, XML_SHOWLABEL
 
Fields inherited from class com.jfimagine.jfgraph.shape.base.AbstractObject
m_lastError, XML_OBJECTID, XML_OBJECTTYPE
 
Constructor Summary
AbstractRectangle()
          Constructor.
 
Method Summary
 void addNode(double x, double y)
          Add a new node for current node list.
 Port addPort(double x, double y)
          Add a new port to this shape.
protected  void appendChildToDOM(Element element, JFVersion version)
          Append necessary xml child for current element, this method will be called internally by toDOM.
 java.lang.Object clone()
          Creates a new object of the same class and with the same contents as this object.
 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.
 boolean finishDrawing()
          Finish drawing object.
 void finishMoveNode(Node node, double x, double y, java.awt.Graphics g)
          finish move/adjust a node of current object.
 void flipBy()
          Reverse this rectangle by a central y coordinate of this rectangle.
 void flipBy(double baseY)
          Reverse this rectangle by a y coordinate.
 Rect getBounds()
          Get the bounds of this rectangle.
 FillFormat getFillFormat()
          Get the fill format of current line.
 double getHeight()
          Get the height of current rectangle.
 LineFormat getLineFormat()
          Get the line format of current line.
 JFPoint getMoveNodePos(Node node, JFPoint movePos, int moveCase)
          When moving a node, in some cases, e.g. ctrl key or shift key pressed to force preserving the form of a shape, or force equilateral shapes, we need to recalculate the actual moving node's position.
 Node getNodeByVertexType(int vertexType)
          Get a node by vertex type.
 Rect getOriginalRect()
          Get an original rectangle if this rectangle.
 double getRotateAngle()
          Get the rotate angle of current rectangle.
 int getVertexTypeByNode(Node node)
          Get vertex type by a node.
 double getWidth()
          Get the width of current rectangle.
 double getX()
          Get the x offset of current rectangle.
 double getY()
          Get the y offset of current rectangle.
 int hashCode()
          Returns the hashcode for this Object.
 boolean ifCompleteDrawing()
          If a rectanglue has been drew.
protected  void initNodes()
          Init all nodes of this rectangle.
protected  void initPorts()
          Init all ports of this rectangle.
 boolean intersects(JFPoint pnt)
          Test if current object intersects with a specified point.
 boolean intersects(Rect rect)
          Test if current object intersects with a specified rectangle.
 void loadFromStream(JFReader stream, boolean skipHead, JFVersion version)
          Load object data from a binary stream
 void mirrorBy()
          Mirror this rectangle by a central x coordinate of this rectangle.
 void mirrorBy(double baseX)
          Mirror this rectangle by a x coordinate.
 void moveBy(double x, double y)
          Move current object by an x and y offset.
 void moveNode(Node node, double x, double y, java.awt.Graphics g)
          Move/adjust a node of current object.
 Node removeLastNode()
          Remove last node added by addNode method.
 void rotateBy(double theta)
          Rotate this rectangle by an angle theta.
 void rotateBy(double baseX, double baseY, double theta)
          Rotate this line by a specified point and an angle theta.
 void saveToStream(JFWriter stream, JFVersion version)
          Save this object to a binary stream
 void scaleBy(JFPoint basePoint, double xScale, double yScale)
          Scale current object by a specified x and y scale.
 void scaleBy(JFPoint basePoint, JFPoint refPoint1, JFPoint refPoint2, double scale)
          Scale current object by specified points and scale percent.
 void setFillFormat(FillFormat fillFormat)
          Set the fill format of current line.
 void setLineFormat(LineFormat lineFormat)
          Set the line format of current line.
 void setRect(double x, double y, double w, double h)
          Set the value of this rectangle.
 void setRect(Rect rect)
          Set the value of current rectangle.
 void startMoveNode(Node node)
          Start move a node.
 java.lang.String toString()
          Convert this object to String
 
Methods inherited from class com.jfimagine.jfgraph.shape.base.AbstractShape
addNode, attachPort, attachRealPort, attachRealPort, clearAccessTimes, detachPort, drawInvisibleBounds, drawLabel, drawLabelPicked, drawPicked, drawPort, fetchSubObjects, finishMoveLabel, getAccessTimes, getArrow, getFontFormat, getLabel, getNodeByIndex, getNodeByObjectId, getNodeCount, getNodeList, getPortByIndex, getPortByObjectId, getPortCount, getPortList, getPropertyByIndex, getPropertyByObjectId, getPropertyCount, getPropertyList, incAccessTimes, initBoundsNodeList, initLabel, isDisableModifyingProperties, isDisableMotion, isDisableScaling, isInvisible, isOpenShape, isRotatable, labelIntersects, labelIntersects, movePort, moveRelationalPorts, nodeIntersects, pickPort, portIntersects, removePort, rotateNode, setArrow, setDisableModifyingProperties, setDisableMotion, setDisableScaling, setFontFormat, setInvisible, setLabel, setNodeList, setObjectId, setParent, setPortList, setZoomScale, startMoveLabel, unboundBrokenPorts
 
Methods inherited from class com.jfimagine.jfgraph.shape.base.AbstractObject
cloneMe, fromDOM, getLastError, getMaxObjectId, getObjectId, getObjectType, getXMLTag, getZoomScale, isShowDesign, setLastError, setObjectType, setShowDesign, setValue, setXMLTag, toDOM
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

XML_LEFTTOPX

public static final java.lang.String XML_LEFTTOPX
A XML string tag represents the left-top x coordinate offset of this rectangle

See Also:
Constant Field Values

XML_LEFTTOPY

public static final java.lang.String XML_LEFTTOPY
A XML string tag represents the left-top y coordinate offset of this rectangle

See Also:
Constant Field Values

XML_RIGHTTOPX

public static final java.lang.String XML_RIGHTTOPX
A XML string tag represents the right-top x coordinate offset of this rectangle

See Also:
Constant Field Values

XML_RIGHTTOPY

public static final java.lang.String XML_RIGHTTOPY
A XML string tag represents the right-top y coordinate offset of this rectangle

See Also:
Constant Field Values

XML_LEFTBOTTOMX

public static final java.lang.String XML_LEFTBOTTOMX
A XML string tag represents the left-bottom x coordinate offset of this rectangle

See Also:
Constant Field Values

XML_LEFTBOTTOMY

public static final java.lang.String XML_LEFTBOTTOMY
A XML string tag represents the left-bottom y coordinate offset of this rectangle

See Also:
Constant Field Values

XML_RIGHTBOTTOMX

public static final java.lang.String XML_RIGHTBOTTOMX
A XML string tag represents the right-bottom x coordinate offset of this rectangle

See Also:
Constant Field Values

XML_RIGHTBOTTOMY

public static final java.lang.String XML_RIGHTBOTTOMY
A XML string tag represents the right-bottom y coordinate offset of this rectangle

See Also:
Constant Field Values

m_lineFormat

protected LineFormat m_lineFormat
line format of current line.


m_fillFormat

protected FillFormat m_fillFormat
fill format of current fill.


m_rect

protected Rect m_rect
An rectangle object for the outline of this rectangle.


m_lineSeg

protected LineSeg m_lineSeg
line segment object for rectangle calculations.


m_firstNode

protected JFPoint m_firstNode
first node settled while drawing.


m_nodeAdded

protected int m_nodeAdded
while drawing rectangle, how many nodes have been decided. called by addnode method.


m_originalRect

protected Rect m_originalRect
Constructor Detail

AbstractRectangle

public AbstractRectangle()
Constructor.

Method Detail

getX

public double getX()
Get the x offset of current rectangle. The x offset is the left-x coordinate position of this rectangle.

Returns:
The x offset of current rectangle.

getY

public double getY()
Get the y offset of current rectangle. The y offset is the top-y coordinate position of this rectangle.

Returns:
The y offset of current rectangle.

getWidth

public double getWidth()
Get the width of current rectangle.

Returns:
The width of current rectangle 'box'.

getHeight

public double getHeight()
Get the height of current rectangle.

Returns:
The height of current rectangle 'box'.

setRect

public void setRect(double x,
                    double y,
                    double w,
                    double h)
Set the value of this rectangle.

Parameters:
x - X coordiate.
y - Y coordiate.
w - Width of this rectangle.
h - Height of this rectangle.

setRect

public void setRect(Rect rect)
Set the value of current rectangle.

Parameters:
rect - A new rectangle.

getOriginalRect

public Rect getOriginalRect()
Get an original rectangle if this rectangle. An original rectangle will has no rotation,mirror or flip.

Returns:
The original rectangle of current rectangle.

getRotateAngle

public double getRotateAngle()
Get the rotate angle of current rectangle. This will be used specially in JFText or JFImage.

Returns:
The rotate angle.

getBounds

public Rect getBounds()
Get the bounds of this rectangle.

Overrides:
getBounds in class AbstractShape
Returns:
The bounds rectangle of current rectangle.

getFillFormat

public FillFormat getFillFormat()
Get the fill format of current line.

Overrides:
getFillFormat in class AbstractShape
Returns:
The fill format.

setFillFormat

public void setFillFormat(FillFormat fillFormat)
Set the fill format of current line.

Overrides:
setFillFormat in class AbstractShape
Parameters:
fillFormat - A new fill format.

getLineFormat

public LineFormat getLineFormat()
Get the line format of current line.

Overrides:
getLineFormat in class AbstractShape
Returns:
The line format.

setLineFormat

public void setLineFormat(LineFormat lineFormat)
Set the line format of current line.

Overrides:
setLineFormat in class AbstractShape
Parameters:
lineFormat - A new line format.

initNodes

protected void initNodes()
Init all nodes of this rectangle. We will always consider that a rectangle object has four nodes. node1 as left-top vertex, node2 as right-top vertex, node3 as left-bottom vertex, node4 as right-bottom vertex.


initPorts

protected void initPorts()
Init all ports of this rectangle. An object will always has its one or more stable ports and some customized ports, for rectangle, it will has four stable ports as below, port1 at middle top, port2 at middle right, port3 at middle bottom, port4 at middle left,


getNodeByVertexType

public Node getNodeByVertexType(int vertexType)
Get a node by vertex type.

Parameters:
vertexType - Vertex type of current node.
Returns:
A node of current rectangle.

getVertexTypeByNode

public int getVertexTypeByNode(Node node)
Get vertex type by a node.

Parameters:
node - A node of this rectangle.
Returns:
the vertex type of this node.

addNode

public void addNode(double x,
                    double y)
Add a new node for current node list. here this method will always be called by DrawState class or any drawing class.

Overrides:
addNode in class AbstractShape

removeLastNode

public Node removeLastNode()
Remove last node added by addNode method.

Overrides:
removeLastNode in class AbstractShape
Returns:
Last node that remained.

ifCompleteDrawing

public boolean ifCompleteDrawing()
If a rectanglue has been drew.

Overrides:
ifCompleteDrawing in class AbstractShape
Returns:
True when complete, false otherwise.

finishDrawing

public boolean finishDrawing()
Finish drawing object.

Overrides:
finishDrawing in class AbstractShape

draw

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

Specified by:
draw in class AbstractShape
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.

Specified by:
intersects in class AbstractShape
Parameters:
pnt - A JFPoint used to test intersection.

intersects

public boolean intersects(Rect rect)
Test if current object intersects with a specified rectangle.

Specified by:
intersects in class AbstractShape
Parameters:
rect - A Rect used to test intersection.

addPort

public Port addPort(double x,
                    double y)
Add a new port to this shape.

Overrides:
addPort in class AbstractShape

getMoveNodePos

public JFPoint getMoveNodePos(Node node,
                              JFPoint movePos,
                              int moveCase)
When moving a node, in some cases, e.g. ctrl key or shift key pressed to force preserving the form of a shape, or force equilateral shapes, we need to recalculate the actual moving node's position.

Overrides:
getMoveNodePos in class AbstractShape
Parameters:
movePos - Desire moving position of a node.
moveCase - Move case of a node, normal, shift key pressed or ctrl key pressed
Returns:
The actual moving position of a node.

startMoveNode

public void startMoveNode(Node node)
Start move a node.

Overrides:
startMoveNode in class AbstractShape
Parameters:
node - The node will be moved.

finishMoveNode

public void finishMoveNode(Node node,
                           double x,
                           double y,
                           java.awt.Graphics g)
finish move/adjust a node of current object.

Overrides:
finishMoveNode in class AbstractShape
Parameters:
node - Currently moving node.
g - current drawing canvas.

moveNode

public void moveNode(Node node,
                     double x,
                     double y,
                     java.awt.Graphics g)
Move/adjust a node of current object.

Overrides:
moveNode in class AbstractShape
Parameters:
node - Currently moving node.
g - current drawing canvas.

scaleBy

public void scaleBy(JFPoint basePoint,
                    JFPoint refPoint1,
                    JFPoint refPoint2,
                    double scale)
Scale current object by specified points and scale percent. We only support a concurrent width-height scale here, suppose width as the length from basePoint to refPoint1, height as the length from basePoint to refPoint2, and one scale percent acts on both width and height.

Specified by:
scaleBy in class AbstractShape
Parameters:
basePoint - A base point that is unmovable.
refPoint1 - A 'width' reference point.
refPoint2 - A 'height' reference point.
scale - A reference scale percent.

scaleBy

public void scaleBy(JFPoint basePoint,
                    double xScale,
                    double yScale)
Scale current object by a specified x and y scale.
This is a special scale method used to scale a shape in arbitrary x and y scale.
Please see AbstractShape.scaleBy for detailed description.

Specified by:
scaleBy in class AbstractShape
Parameters:
basePoint - A base scale point for scaling reference.
xScale - A scale percentage in x coordinate, default to 1.0
yScale - A scale percentage in y coordinate, default to 1.0

moveBy

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

Specified by:
moveBy in class AbstractShape

rotateBy

public void rotateBy(double theta)
Rotate this rectangle by an angle theta.

Specified by:
rotateBy in class AbstractShape
Parameters:
theta - A rotate angle.

rotateBy

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

Specified by:
rotateBy in class AbstractShape
Parameters:
theta - A rotate angle.

mirrorBy

public void mirrorBy()
Mirror this rectangle by a central x coordinate of this rectangle. We make a left-right flip here.

Specified by:
mirrorBy in class AbstractShape

mirrorBy

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

Specified by:
mirrorBy in class AbstractShape
Parameters:
baseX - A mirror base x coordinate.

flipBy

public void flipBy()
Reverse this rectangle by a central y coordinate of this rectangle. We make a up-down flip here.

Specified by:
flipBy in class AbstractShape

flipBy

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

Specified by:
flipBy in class AbstractShape
Parameters:
baseY - A flip base y coordinate.

toString

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

Overrides:
toString in class AbstractShape
Returns:
An string represents the content of the object

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 AbstractShape
Returns:
A clone of this instance.
java.lang.CloneNotSupportedException

hashCode

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

Overrides:
hashCode in class AbstractShape
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 AbstractShape
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 AbstractShape
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 AbstractShape
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 object to a binary stream

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

loadFromStream

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

Overrides:
loadFromStream in class AbstractShape
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.