Java Drawing DrawTop

Language

JP  US  UK

 

Shape Element

 H. Jyounishi, Tokyo Japan
 

Frame (Index), No frame                 version:0.3(latest)  

Summary:A shape element has a geometric data of a shape and provides the various methods for shape operations such as moving, resizing, transforming, modifying and so on.
In addition, the special purpose shape elements are prepared. The one is a image element which is used for exchange an image data with other applications. The other is a group element which is used for representing a group of shapes.

Relevant major classes of Java SE: java.awt.geom.*

Classes on this page: ShapeElement, RectangleElement, RoundRectangleElement, EllipseElement, ImageElement, LineElement, PolylineElement, CubicCurveElement, GeneralCurveElement, GroupElement
Remarks:
Drawing a shape Element => Figure1 in the Drawing Panel

1. The types of the shape elements

The types of the shape elements are a rectangle, round rectangle, ellipse, line, polyline, cubic curve and general curve. The general curve is used for representing a trimmed curve (Cutting shape) and a connected curve (Connecting curves) of lines, curves (arcs, polylines and piecewise cubic curves).
An image element is a special purpose element whose element is an image. It is used for exchanging an image data with other application such as MS Word, MS PowerPoint and so on by cut, copy and paste operation.
Another special purpose element is a group element which is used for representing a group of shapes. The group element has no shape data but has a list of its child objects.


2. Abstract class ShapeElement return=>page top
public abstract class ShapeElement
The ShapeElement abstract class is the base of various shape element classes and they are described as extended classes of the ShapeElement.
Field Description
shapeContainer ShapeContainer shapeContainer
The shapeContainer object which maintains this ShapeElement.
curve2D Curve2D curve2D
The parametric curve object (Curve2D) which represents the boundary curve of a closed shape, or the curve itself of an open shape.
curve2DSave Curve2D curve2DSave
The parametric curve object (Curve2D). This field is set by the mouseStart method and used for moving, resizing and modifying the shape Element.
textAreaSave Rectangle2D textAreaSave
Stores the textArea of the TextBox which the shapeContainer has.
startPoint Point2D startPoint
The starting point of the mouse drag. This field is set by the mouseStart method and used for moving, resizing and modifying the shape Element.
startBox Rectangle2D startBox
The bounding box of the shape elemnt at the star of the mouse drag. This field is set by the mouseStart method and used for moving, resizing and modifying the shape Element.
discreteAngledLine DiscreteAngledLine discreteAngledLine
Set the DiscreteAngledLine object. This field is set by the mouseStart method.
workVector Vector workVector
The Vector object for work.

Method Description
getTypeE
(abstract)
public abstract int getTypeE()
Returns:
The code representing the shape element type which is defined in the Command class.
Command.RECTANGLE/ ROUNDRECTAGLE/ ELLIPSE/ IMAGE/ LINE/ POLYLINE etc.
getShapeIdString
(abstract)
public abstract String getShapeIdString
Returns:
The string representing the shape element type. They are "Rectangle, "Round_Rectangle""Line", "Polyline" and so on.
getShapeContainer public ShapeContainer getShapeContainer()
Returns the shapeContainer field.
setShapeContainer public void setShapeContainer(ShapeContainer container)
Sets the container parameter to the shapeContainer field.
isClosed public boolean isClosed()
Returns true if the shape element is a closed shape.
getShape public Shape getShape()
Returns:
The object which is defined by the java.awt.Shape interface.
: The returned object of this method is used for displaying the shape element and checking that a given point is contained in the shape element if it's a close shape.
=> The extension of java.awt.geom
getCurve2D public Curve2D getCurve2D()
Returns the curve2D field.
setCurve2D public void setCurve2D(Curve2D curve2D)
Sets the curve2D parameter to the curve2D field.
getGeneralCurveElement public GeneralCurveElement getGeneralCurveElement()
Converts a shape element to a GeneralCurveElement and return it.
When a curve becomes a multipath (or subpath) by the processing like cutting and division for a curve, this method is used to change into a GeneralCurveElement which can handle multipath.
The inverse method of this is GeneralCurveElement.getSimpleShapeElements method.
getSerializableCurve2D public SerializableCurve2D getSerializableCurve2D()
Returns:
The SerializableCurve2D object which is used for writing a shape data to a file or storing it to the clipboard for pasting.
Processing:
Calls the getSerializableCurve2D of the Curve2D.
setSerializableCurve2D public void setSerializableCurve2D(SerializableCurve2D sdata)
parameters:
sdata - The SerializableCurve2D object.
Processing:
Creates a Curve2D object from the sdata and sets it to the curve2D field.
∙ Gets the array of the SerializableSegment2D objects from the sdata and creates new Segment2D objects.
∙ Creates a new object of the Curve2D by the constructor of the Curve2D subclass and sets it to the curve2D field.
=> Creating the Curve2D from the SerializableCurve2D
getBoundingBox public Rectangle2D getBoundingBox()
Returns the bounding box which enclose this shape element.
getEndPTs public abstract Point2D[] getEndPTs()
Returns the both endpoints of this shape element if this shape element is a open shape (the boundary isn't closed). If this shape element is a closed shape, then returns the 0-length array.
createTextArea
(abstract)
public abstract Rectangle2D createTextArea()
Returns:
The Rectangle2D object which determines the text area(textArea) of a TextBox object.
=> ShapeContainer.addTextBox method.
Processing:
When the addTextBox method adds the TextBox to the ShapeContainer object which posesses this object, the addTextBox method call this method to get a text area(textArea).
The textArea for the basic shape like RectangleElement, RoundRectangleElement, EllipseElement and so on can be easily calculated. However in the case of PolylineElement or CubicCurveElement, it is a little difficult, especially in the case that it has a concave part.
In this case, gets the textArea using the ShapeElementUtil.getInscribedBox method.
getSegmentModifiers (abstract) public abstract SegmentModifier[] getSegmentModifiers()
getModifierPTs (abstract) public abstract Point2D[] getModifierPTs()
getSegmentModifiers
(abstract)
public abstract SegmentModifier[] getSegmentModifiers()
Returns:
The array of the SegmentModifier objects which is used for modifying a shape by the ModifyShape class. If the shape element is not allowed to be modified, return the length-0 array.
: This method is called when the mouse drag starts by the mouseStart method and this method sets the the control points, control lines and so on to the SegmentModifier objects..
=> ModifyShape, SegmentModifier
getModifierPTs
(abstract)
public abstract Point2D[] getModifierPTs()
Returns:
The array of the control points.
Processing:
The control points are extracted from the SegmentModifier objects stored in the workVector field.
mouseStart public abstract void mouseStart(int ctrl, Point2D starPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key), 3 (with the mouse right button pressed)
startPoint - The starting point of the mouse drag
Processing:
This method is called by the init method of the MoveResizeShapeLS and the mousePressed method of the ModifyShapeLS to stores the initial data of this object that will be rewrited during the mouse drag.
• Sets the current curve2D to the Curve2Dsave field.
• Sets the current textArea to the textAreaSave field.
• Sets other data, such as the startPoint and the startBox.
mouseEnd public abstract void mouseEnd()
Processing:
Nothing is done currently.
create
(abstract)
public abstract void create (Point2D startPoint, Point2D currentPoint)
Parameters:
startPoint - The start point of the mouse drag.
currentpoint - The current point of the mouse drag.
Processing:
This method is called by the mouseDragged method of the CreateShapeLS to create a line.
create
(abstract)
public abstract void create(Point2D[] points)
Parameters:
points - The array of the clicked points.
Processing:
This method is called by the mouseMoved method of the CreateShapeLS to create a polyline or a piecewise cubic curve.
create
(abstract)
public abstract void create(Rectangle2D boundingBox)
Parameters:
boundingBox - The dragged rectangle.
Processing:
This method is called by the mouseDragged method of the CreateShapeLS to create a basic shape (rectangle, round rectangle or ellipse) which fits the dragged rectangle.
move public void move(int ctrl, Point2D currentPoint, boolean moveTextBox)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key)
currentPoint - The current point of the mouse drag.
moveTextBox - If true, then resize the text box simultaneously.
Processing:
This method is called by the mouseDragged method of the MoveResizeShapeLS to move the selected shapes.
: Before this method is called, the mouseStart method to records the initial state.
resize public void resize(int ctrl, Point2D currentPoint, int mousePositionCode, boolean resizeTextBox)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key)
currentPoint - The current point of the mouse drag.
mousePositionCode - The code defined in the MousePositionInfo such as NW_RESIZE - SW_RESIZE, N_RESIZE- W_RESIZE.
resizeTextBox - If true, then resize the text box simultaneously.
Processing:
This method is called by the mouseDragged method of the MoveResizeShapeLS to resize the selected shapes.
This method calls the ShapeElementUtil.resizeRectangle static method to resize the shape element.
:
(1) Before this method is called, the mouseStart method to records the initial state.
(2) This method works under the properties of UNRESIZABLE and KEEP_ASPECT_RATIO.
moveResize public void resize(Rectangle2D oldBox, Rectangle2D newBox, boolean resizeTextBox)
Parameters:
oldBox - The previous rectangle.
newBox - The current rectangle.
resizeTextBox - If true, then resize the text box simultaneously.
Processing:
Transforms this shape element using the transformation from the oldBox to the newBox.
This method calls the resizeSegment method of the Segment2D to resize the Segment2D objects which constitute the curve2D.
And this method also calls the resizeTextArea method of the TextBox to move or resize the text box if the parent ShapeContainer has a text box.
: This method can be used to move this shape element, nor resize.
moveEndPoint
(abstract)
public abstract void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key), 3 (with the mouse right button pressed)
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
currentPoint - The current point of the mouse drag.
Processing:
This method is called by the mouseDragged method of the MoveResizeShapeLS to move the endpoint of the line, polyline or piecewise cubic curve.
: Before this method is called, the mouseStart method to records the initial state.
moveEndPoint
(abstract)
public abstract void moveEndPoint(int ctrl, int movePtIndex, Point2D oldPoint, Point2D newPoint)
Parameters:
ctrl - If the moving direction is limitted to horizontal or vertical, sets ctrl 1/2.
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
oldPoint - The old point of the moving point.
newPoint - The new point of the moving point.
Processing:
This method is used for moving an end point of a line or polyline without dragging the mouse.
modify
(abstract)
public abstract void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key), 3 (with the mouse right button pressed)
oldPoint - The previous point of the mouse drag.
currentPoint - The current point of the mouse drag.
Processing:
This method is called by the mouseDragged method of the ModifyShapeLS.
: Before this method is called, the mouseStart method to records the initial state.
=> RoundRectangleElement.modify, PolylineElemet.modify, CubicCureveElement.modify, GeneralCurveElement.modify
modifyPoint public abstract void modifyPoint(Point2D point, String command)
transform public void transform(Matrix2D M)
Parameters:
M - the Matrix2D for transforming this shape element.
Processing:
This method calls the transformSegment method of the Segment2D to transform the Segment2D objects which constitute the curve2D.
clone
(abstract)
public abstract Object clone()
Returns the cloned object of this object.
toString
(abstract)
public abstract String toString()
Return the string representing this object.

: Creating the Curve2D from the SerializableCurve2D
SerializableSegment2D[] segs=sdata.serializableSegments;
int size=segs.length;
Segment2D[] segments=new Segment2D[size];
for(int i=0;i<size;i++){
segments[i]=new Segment2D(segs[i].type, segs[i].shape, segs[i].affineTransform);
}
int curve2Dtype=sdata.type;
switch(curve2Dtype){
case Curve2D.RECTANGLE :{
this.curve2D=new Rectangle2DE(segments); break;
}
case Curve2D.ROUND_RECTANGLE :{
this.curve2D=new RoundRectangle2DE(segments); break;
}
case Curve2D.ELLIPSE :{
this.curve2D=new Ellipse2DE(segments); break;
}
case Curve2D.LINE:{
this.curve2D=new Line2DE(segments); break;
}
case Curve2D.POLYLINE:{
this.curve2D=new Polyline2DE(segments); break;
}
case Curve2D.CUBIC_CURVE :{
this.curve2D=new CubicCurve2DE(segments); break;
}
case Curve2D.GENERAL_CURVE :{
this.curve2D=new GeneralCurve2DE(segments); break;
}
} //switch

3. Class RectangleElement return=>page top
public class RectangleElement extends ShapeElement
Method Description
getTypeE public int getTypeE()
Returns the Command.RECTANGLE.
getShapeIdString public String getShapeIdString()
Returns the "Rectangle".
createTextArea public Rectangle2D createTextArea()
Returns the Rectangle2D object which is inscribed to the boundary of this shape element.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Returns the 0-length array.
getModifierPTs public Point2D[] getModifierPTs()
Returns the 0-length array.
create public void create(Point2D startPoint, Point2D currentPoint)
Nothing is done.
create public void create(Rectangle2D boundingBox)
Create a new Rectangle2DE object with the boundingBox parameter and set the new object to the curve2D.
=> The create method of the ShapeElement
create public void create(Point2D[] points)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Nothing is done. => ShapeElement.moveEndPoint
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D oldPoint, Point2D newPoint) newPoint)
Nothing is done.
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Nothing is done.
modifyPoint public void modifyPoint(Point2D point, String command){}
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


4. Class RoundRectangleElement return=>page top
public class RoundRectangleElement extends ShapeElement
Field Description
segmentModifiers SegmentModifier[] segmentModifiers
This RoundRectangleElement object can be changed its radius of the corner arcs by dragging the control point. This field is used to store the SegmentModifier objects that are necessary for the operation.
hitSegmentModifier SegmentModifier hitSegmentModifier
Stores the hit SegmentModifier object when the mouse button is pressed to start the mouse drag. The hit test is performend by the SegmentModifier.getHitSegmentModifier method.

Method Description
getTypeE public int getTypeE()
Returns the Command.ROUND_RECTANGLE.
getShapeIdString public String getShapeIdString()
Returns the "Round_Rectangle".
createTextArea public Rectangle2D createTextArea()
Returns the Rectangle2D object which is inscribed to the boundary of this shape element.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Returns:
The array of the two SegmentModifier objects. The two SegmentModifier objects corresponds to the two endpoints of the left lower corner arc.
=> Modifying shape Figure 1.1
getModifierPTs public CurvePT[] getModifierPTs()
Returns:
The array of the two CurvePT objects.
The two CurvePT objects are created by using the returned value of the getSegmentModifiers method.
mouseStart
(override)
public void mouseStart(int ctrl, Point2D startPoint)
The method overriding the ShapeElement.mouseStart.
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
startPoint - The start point of the mouse drag.
Processing:
• Calls the getSegmentModifiers method and sets its returns to segmentModifiers field.
• Calls the SegmentModifier.getHitSegmentModifier method and sets its returns to hitSegmentModifier field.
create public void create(Point2D startPoint, Point2D currentPoint)
Nothing is done.
create public void create(Rectangle2D boundingBox)
Create a new RoundRectangle2DE object which fits to the boundingBox and sets the new object to the curve2D.
=> The create method of the ShapeElement
create public void create(Point2D[] points)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D oldPoint, Point2D newPoint) newPoint)
Nothing is done.
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key). Currently this parameter isn't refereed.
startPoint - The start point of the mouse drag.
currentPoint - The current point of the mouse drag.
Processing:
This method changes the radius of the corner arcs by dragging the control point. The SegmentModifier that was hit to the mouse when the mouse button was pressed, is stored in the hitSegmentModifier. The point is moved by the vector of (currentPoint-oldPoint) and the radius of the corner arcs will be recalculated
If the radius reached the maximum, then this method stop moving the control point.
=> Figure 1.1 in Modifying shape
modifyPoint public void modifyPoint(Point2D point, String command)
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


5. Class EllipseElement return=>page top
public class EllipseElement extends ShapeElement
Method Description
getTypeE public int getTypeE()
Returns the Command.ELLIPSE.
getShapeIdString public String getShapeIdString()
Returns the "Ellipse".
createTextArea public Rectangle2D createTextArea()
Returns the Rectangle2D object which is inscribed to the boundary of this shape element.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Returns the 0-length array.
getModifierPTs public CurvePT[] getModifierPTs()
Returns the 0-length array.
create public void create(Rectangle2D boundingBox)
Create a new Ellipse2DE object which fits to the boundingBox and set the new object to the curve2D.
=> The create method of the ShapeElement
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D oldPoint, Point2D newPoint) newPoint)
Nothing is done.
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Nothing is done.
modifyPoint public void modifyPoint(Point2D point, String command)
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


6. Class ImageElement return=>page top

public class ImageElement extends ShapeElement

The image element is the special purpose element whose element is a image. It is used for exchanging a image data with other application such as MS Word, MS PowerPoint and so on by cut, copy and paste operation.
The following field is added to this class.

Field Description
bufferedImage private BufferedImage bufferedImage
Store the image data.

This class maintains the image data within the rectangle, so the methods are the same as those of the RectangleElement except the proprietary methods which handles a image data.

Method Description
getTypeE public int getTypeE()
Returns the Command.IMAGE.
getShapeIdString public String getShapeIdString()
Returns the "Image".
createTextArea public Rectangle2D createTextArea()
Retuns null.
getBufferedImage
(proprietary)
public Image getBufferedImage()
Returns the bufferedImage field.
getByteImage
(proprietary)
public byte[] getByteImage()
Returns:
The byte array which stores the image data by byte format.
Processing:
This method converts the bufferedImage to byte format by using the java.io.ByteArrayOutputStream class.
: The Image and BufferedImage objects can't be written to a file because they are aren't serializable. To write to the file, this method is employed.
setByteImage
(proprietary)
public void setByteImage(byte[] byteData)
Parameter:
byteData - The byte array of a image data.
Processing:
This method provides the reverse operation of the getByteImage method.
This method writes the byteData to the the bufferedImage by using the java.io.ByteArrayInputStream class.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Returns the 0-length array.
getModifierPTs public CurvePT[] getModifierPTs()
Returns the 0-length array.
create public void create(Rectangle2D boundingBox)
Create a new Rectangle2DE object which fits to the boundingBox and set the new object to the curve2D.
=> The create method of the ShapeElement
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D oldPoint, Point2D newPoint)
Nothing is done.
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Nothing is done.
modifyPoint public void modifyPoint(Point2D point, String command)
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


7. Class LineElement return=>page top
public class LineElement extends ShapeElement
Method Description
getTypeE public int getTypeE()
Returns the Command.LINE.
getShapeIdString public String getShapeIdString()
Return the "Line".
createTextArea public Rectangle2D createTextArea()
Returns null.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Returns the 0-length array.
getModifierPTs public CurvePT[] getModifierPTs()
Returns the 0-length array.
mouseStart
(override)
public void mouseStart(int ctrl, Point2D startPoint)
The method overriding the ShapeElement.mouseStart.
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
startPoint - The start point of the mouse drag.
Processing:
Calls the ShapeElement.mouseStart method
create public void create(Point2D startPoint, Point2D currentPoint)
Parameters:
startPoint - The start point of the mouse drag.
currentPoint - The current point of the mouse drag.
Processing:
Create a new Line2DE object whose endpoints correspond to startPoint and currentPoint and set the new object to the curve2D.
=> The create method of the ShapeElement
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
currentPoint - The current point of the mouse drag.
Processing:
This method is called from the MoveResizeShapeLS.mouseDragged method.
moveEndPoint public void moveEndPoint(int ctrl, int movingPoint, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - If the moving direction is limitted to horizontal or vertical, sets ctrl 1/2.
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
oldPoint - The old point of the moving point.
newPoint - The new point of the moving point.
Processing:
This method moves the specified endpoint by the vector of (currentPoint-oldPoint). If the ctrl greater than 0, then the specified endpoint is moved in x-direction or y-direction.
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Nothing is done.
modifyPoint public void modifyPoint(Point2D point, String command)
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


8. Class PolylineElement return=>page top
public class PolylineElement extends ShapeElement
Method Description
getTypeE public int getTypeE()
Return the Command.POLYLINE.
getShapeIdString public String getShapeIdString()
Returns the "Polyline".
createTextArea public Rectangle2D createTextArea() Gets the inscribed rectangle by the ShapeElementUtil.getInscribedBox method and returns it.
getModifierPTs public CurvePT[] getModifierPTs()
Not used. Returns the 0-length array.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Not used. Returns the 0-length array.
mouseStart
(override)
public void mouseStart(int ctrl, Point2D startPoint)
The method overriding the ShapeElement.mouseStart.
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
startPoint - The start point of the mouse drag.
Processing:
Calls the ShapeElement.mouseStart method
create public void create(Point2D[] points)
Parameters:
points - The segment junction points of the polyline.
Processing:
Create a new Polyline2DE object whose segment junction points correspond to the points and set the new object to the curve2D.
=> The create method of the ShapeElement
moveEndPoint
public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
currentPoint - The current point of the mouse drag.
Processing:
This method is called by the mouseDragged method of the MoveResizeShapeLS.
: Before this method is called, the mouseStart method to records the initial state.
moveEndPoint public void moveEndPoint(int ctrl, int movingPoint, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - If the moving direction is limitted to horizontal or vertical, sets ctrl 1/2.
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
oldPoint - The old point of the moving point.
newPoint - The new point of the moving point.
Processing:
This method moves the specified endpoint by the vector of (currentPoint-oldPoint). If the ctrl greater than 0, then the specified endpoint is moved in x-direction or y-direction by using the DiscreteAngledLine.getControlledPT method. This method is convenient method when the polyline is used as a connector.
To move the line segment whose endpoint equals the specified endpoint, the moveLineSegment method is employed.
=> The operation of the moveEndPoint, Moving/resizing shape Polyline
moveLineSegment private Line2D moveLineSegment(Line2D line, double moveX, double moveY)
Parameters:
line - The line to be moved
moveX - The x-movement.
moveY - The y-movement.
Returns:
The moved line which is denoted as newLine in the Figure below.
Processing:
This method is called by the moveEndPoint.
The start endpoint of the line is moved by the vector of moveVec (moveX, moveY) as the Figure below. The other endpoint of the line is moved by the vector of moveN which is the projected vector of the moveVec to the normal direction of the line.

=> The operation of the moveEndPoint
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Nothing is done.
modifyPoint public void modifyPoint(Point2D point, String command)
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.

The operation of moveEndPoint return=>page top
Drags the endpoint (square mark) of the polyline, then the line segment connecting to the endpoint will be translated in parallel with changing its length as the figure below. This feature is convenient for a connector.


Original polyline



Moves the right endpoint to upper right


Original polyline


Moves the right endpoint to upper right



Original shapes

Moves the right ellipse to lower right.
The connector endpoint moves.


9. Class CubicCurveElement return=>page top
public class CubicCurveElement extends ShapeElement
Method Description
getTypeE public int getTypeE()
Returns the Command.CUBIC_CURVE.
getShapeIdString public String getShapeIdString()
returns the "CubicCurve.
createTextArea public Rectangle2D createTextArea()
Gets the inscribed rectangle by the ShapeElementUtil.getInscribedBox method and returns it.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Not used. Returns the 0-length array.
getModifierPTs public Point2D[] getModifierPTs()
Not used. Returns the 0-length array.
mouseStart
(override)
public void mouseStart(int ctrl, Point2D startPoint)
The method overriding the ShapeElement.mouseStart.
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
startPoint - The start point of the mouse drag.
Processing:
Calls the ShapeElement.mouseStart method
create public void create(Point2D[] points)
Parameters:
points - The segment junction points of the polyline.
Processing:
Create a new CubicCurve2DE object whose segment junction points correspond to the points and set the new object to the curve2D.
=> The create method of the ShapeElement
moveEndPoint public void moveEndPoint(int ctrl, int movingPoint, Point2D currentPoint)
Nothing is done in the current version.
moveEndPoint public void moveEndPoint(int ctrl, int movingPoint, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - If the moving direction is limitted to horizontal or vertical, sets ctrl 1/2.
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
oldPoint - The old point of the moving point.
newPoint - The new point of the moving point.
Processing:
This method moves the specified endpoint by the vector of (currentPoint-oldPoint). If the ctrl greater than 0, then the specified endpoint is moved in x-direction or y-direction. The cubic curve is transformed by the scaling and rotation matrix to match the specified endpoint to the moved endpoint.
Here the scaling and rotation matrix is created by the getRotationMatrix method of the Matrix2D.

modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Nothing is done.
modifyPoint public void modifyPoint(Point2D point, String command)
Nothing is done.
clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


10. Class GeneralCurveElement return=>page top
public class GeneralCurveElement extends ShapeElement

The GeneralCurveElement is created as the result of cutting a shape or connecting curves. It can't be created by the mouse drag or mouse click, so the create method of this class is dummy.

Field Description
segmentModifiers SegmentModifier[] segmentModifiers
This RoundRectangleElement object can be changed its radius of the corner arcs by dragging the control point. This field is used to store the SegmentModifier objects that are necessary for the operation.
hitSegmentModifier SegmentModifier hitSegmentModifier
Stores the hit SegmentModifier object when the mouse button is pressed to start the mouse drag. The hit test is performend by the SegmentModifier.getHitSegmentModifier method.
topologyChanged boolean topologyChanged
The topology of the curve2D may be changed by the "modify shape" command. For examples, an unclosed curve2D turns into a closed curve, or a single curve2D is divided into two curve2D sub paths. This field is set true if the curve2D topology is changed. Once true is set to this field, the mouse drag operaion is ignored in the modify method.

Method Description
getTypeE public int getTypeE()
Returns the Command.GENERAL_CURVE.
getShapeIdString public String getShapeIdString()
Returns the "GeneralCurve".
createTextArea public Rectangle2D createTextArea()
Gets the inscribed rectangle by the ShapeElementUtil.getInscribedBox method and returns it.
getSimpleShapeElements public ShapeElement[] getSimpleShapeElements()
If this element has a multi-path curve, thenthis method devides a multi-path curve into plural single paths and creates shape elemens for each single path and returns them.
The returned each element is converted to a simple element as possible. For example, it consists of a polyline, then returns a PolylineElement.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
• This method is called from the mouseStart method.

The mouseStart method is called when the mouse button is pressed to perform "modifu shape" command (ModifyShapeLS.mousePressed).

• Creates SegmentModifier objects for all segment junction points.
• The created SegmentModifier object are displayed by the DrawShapeUtil.drawSegmentModifiers method.
• The processing for each junction point is performed by the SegmentModifier.getSegmentModifiers method.
getModifierPTs public CurvePT[] getModifierPTs()
Returns:
The array of the control points of the general curve. The control points are the segment junction points, middle points of the line segments and the endpoints of the tangent lines.
=> Figure 1.4 in Modifying shape
mouseStart
(override)
public void mouseStart(int ctrl, Point2D startPoint)
The method overriding the ShapeElement.mouseStart.
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
startPoint - The start point of the mouse drag.
Processing:
create public void create(Point2D[] points)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Nothing is done in the current version.
moveEndPoint public void moveEndPoint(int ctrl, int movingPoint, Point2D startPoint, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - If the moving direction is limitted to horizontal or vertical, sets ctrl 1/2.
movingPtIndex - If the movingPtIndexequals 0, move the start point, otherwise move the end point.
oldPoint - The old point of the moving point.
newPoint - The new point of the moving point.
Processing:
This method moves the specified endpoint by the vector of (currentPoint-oldPoint). If the ctrl greater than 0, then the specified endpoint is moved in x-direction or y-direction. The general curve is transformed by the scaling and rotation matrix to match the specified endpoint to the moved endpoint.
Here the scaling and rotation matrix is created by the getRotationMatrix method of the Matrix2D and the each curve segment is transformed by the transformSegment method of the Segment2D.
modify public void modify(int ctrl, Point2D oldPoint, Point2D currentPoint)
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
oldPoint - The previous point of the mouse drag.
currentPoint - The current point of the mouse drag.
Processing:
• This method is called from the ModifyShapeLS.mouseDragged.
• The actual processing is performed by the SegmentModifier.modify method.
=> Figure 1.4 in Modifying shape
modifyPoint public void modifyPoint(Point2D point, String command)
Parameters:
point - The point to be added.
command - "add_point"/ "delete_point"/ "smooth"/"cusp"/ "disconnect"
Processing:
• This method is called from the ModifyShapeLS.mouseClicked method.
• The actual processing is performed by the static methods of the SegmentModifier.
Calls the following static method according to the command.

SegmentModifier.addPoint
SegmentModifier.deletePoint
SegmentModifier.smoothPoint
SegmentModifier.cuspPoint
SegmentModifier.disconnectPoint

clone public abstract Object clone()
Returns the cloned object of this object.
toString public abstract String toString()
Return the string representing this object.


11. Class GroupElement return=>page top
public class GroupElement extends ShapeElement

The ShapeContainer representing a group has a GroupElement whose list has links to to child ShapeContainer objects.
The child ShapeContainer can be also a group, so the hierarchy of ShapeContainer objects is as the figure below.
In the figure, the ContainerList is the ArrayList which stores the ShapeContainer objects on one page and the ContainerList is managed by the ContainerManager object. The symbol of "Element" means an ShapeContainer which is not a group and has a real shape data, and the symbol of "Group" means an ShapeContainer which is group and has a GroupElement.


Figure 11.1 The hierarchy of a group object
Group: ShapeContainer+GroupElement,
Single shape: ShapeContainer+RectangleElement/RoundRectangleElement/etc.

Field Description
childrenList private ArrayList childrenList
The ArraiList which stores the links to the child ShapeContainer objects.

Method Description
getTypeE public int getTypeE()
Returns the Command.GROUP.
getShapeIdString public String getShapeIdString()
Returns the string of "Group".
isClosed public boolean isClosed()
Returns false.
getShape public Shape getShape()
Returns null.
getCurve2D public Curve2D getCurve2D()
Returns null.
setCurve2D public void setCurve2D(Curve2D curve2D)
Nothis is done.
getSerializableCurve2D public SerializableCurve2D getSerializableCurve2D()
Returns null.
setSerializableCurve2D public void setSerializableCurve2D(SerializableCurve2D curve2D)
Nothing is done.
getBoundingBox public Rectangle2D getBoundingBox()
Returns:
The bounding box enclosing the group.
Processing:
Gets the all shapes in the group by the getGroupedSingleShapeContainers method, then calculates the bounding box which enclose all the shapes in the group.
getEndPTs public Point2D[] getEndPTs()
Returns the array of 0-length.
createTextArea public Rectangle2D createTextArea()
Returns null.
getSegmentModifiers public SegmentModifier[] getSegmentModifiers()
Returns null.
getModifierPTs public Point2D[] getModifierPTs()
Returns the array of 0-length.
mouseStart
(override)
public void mouseStart(int ctrl, Point2D startPoint)
The method overriding the ShapeElement.mouseStart.
Parameters:
ctrl - 1 or 2 (with holding down the Shift or Ctrl key).
startPoint - The start point of the mouse drag.
Processing:
Calls the mouseStart method of each child shape element.
create public void create (Point2D startPoint, Point2D currentPoint)
Nothing is done.
create public void create(Point2D[] points)
Nothing is done.
create public void create(Rectangle2D boundingBox)
Nothing is done.
move
(override)
public void resize(Rectangle2D oldBox, Rectangle2D newBox)
This method is overriding the ShapeElement.move method.
Gets the all shapes in the group by the getGroupedSingleShapeContainers method, then move all the shapes in the group by the moveResize method of the ShapeElement.
resize
(override)
public void resize(Rectangle2D oldBox, Rectangle2D newBox)
This method is overriding the ShapeElement.resize method.
Gets the all shapes in the group by the getGroupedSingleShapeContainers method, then resizes all the shapes in the group by the moveResize method of the ShapeElement.
moveResize
(override)
public void resize(Rectangle2D oldBox, Rectangle2D newBox, boolean resizeTextBox)
This method is overriding the ShapeElement.move method.
Gets the all shapes in the group by the getGroupedSingleShapeContainers method, then resizes all the shapes in the group by the moveResize method of the ShapeElement.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D currentPoint)
Nothing is done.
moveEndPoint public void moveEndPoint(int ctrl, int movePtIndex, Point2D oldPoint, Point2D newPoint)
Nothing is done.
getChildrenList
(proprietary)
public ArrayList getChildrenList()
Returns the ArrayList which stores the links to the child ShapeContainer objects
setChildrenList
(proprietary)
public void setChildrenList(ArrayList childrenList)
Sets the parameter to the childrenList.
getChildren
(proprietary)
public ShapeContainer[] getChildren()
Returns the child ShapeContainer objects from the childrenList.
addChildren
(proprietary)
public void addChildren(ShapeContainer container)
Adds the parameter to the childrenList.
getGroupedContainers
(proprietary)
public ShapeContainer[] getGroupedContainers()
Returns the array of all the descendant ShapeContainer objects which are linked from this object via the childrenList.
All the descendant ShapeContainer objects are searched by the next getGroupedContainers method.
Example: If this GroupElement is the element of the Group 0 in Figure 11.1, then returns the array of the Group1, Single shape 0, Single shape 1 and Single shape 2.
getGroupedContainers
(proprietary)
protected void getGroupedContainers(Vector vector)
Gets all the descendant ShapeContainer objects which are linked from this object via the childrenList.
The search are performed by the recursive call of this method.
geGroupedSingleShape
Containers

(proprietary)
public ShapeContainer[] getGroupedSingleShapeContainers()
Returns all the descendant ShapeContainer objects which are single shape objects and are linked from this object via the childrenList. All the descendant single shape ShapeContainer objects are searched by the next getGroupedSingleShapeContainers method.
Example: If this GroupElement is the element of the Group 0 in Figure 11.1, then returns the array of the Single shape 0, Single shape 1 and Single shape 2,.
getGroupedSingleShape
Containers

(proprietary)
protected void getGroupedSingleShapeContainers(Vector vector)
Returns all the ShapeContainer objects which single shape objects and are linked from this object via the childrenList. The search are performed by the recursive call of this method.
clone public Object clone()
Nothing is done.
toString public String toString()
Returns the string representing this object.
toShortString public String toShortString()
Returns the short string representing this object.




Copyright (c) 2009-2013
All other trademarks are property of their respective owners.