Java Drawing DrawTop

Language

JP  US  UK

 

Shape Container

 H. Jyounishi, Tokyo Japan
 

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

Summary:The ShapeContainer is a container of a shape element (ShapeElement). If the shape element is a group element (GroupElement), the ShapeContainer represents a group of shapes.
Relevant major classes of Java SE: java.awt, java.awt.geom
Class on this page: ShapeContainer

1. Overview
1.1 Structure of the ShapeContainer
∙ The ShapeContainer class is a container of a various kind of shape element (ShapeElement).
∙ The ShapeContainer can be a container of grouped shapes. In this case, the ShapeContainer has a group element (GroupElement).
∙ The ShapeContainer always has a PaintStyle object which defines the drawing style of a ShapeElement and it can have a TextBox object.


Figure 1 The structure of an ShapeContainer object
: shape element=> ShapeElement, Parametric curve=> Curve2D


1.2 A single and a group shape

(a) Sample Drawings
The gray small texts such as Round_Rectangle(No-0), Rectangle(No-4) and so on represent the shape name (shapeId) of the ShsperContainer.


(b) Components - Group shapes


(c) The Structure of ContainerList.
∙ Group shape and single shape:

The Group(No-1), Group(No-2) and Group(No-5) are group shapes, and the others are single shapes.

∙ The child elements of a group shape:

They are stored in the childrenList (ArrayList) of group element. In (c), links from childrenList to child elements are represented by arrows.

Figure 2. A single shape and a group


1.3 Drawing the ShapeContainer
Object
Description
Shape element
Calls the DrawShapeUtil.drawShapeElement method to draw the shape element.
If the shape element is a GroupElement, then calls the drawShape method of the child ShapeContainer recursively.
TextBox
Gets the TextBox object which is linked from the ShapeContainer and calls the TextBox.drawTextBox method.
Selection box, resize handles
If the shape element is a line, calls the DrawShapeUtil.drawLineSelection method, othewise calls the DrawShapeUtil.drawSelection method.
∙ Line:Draws the resize handles at the endpoints (Figure 5).
∙ Others:Draws the selection box and resize handles (Figure 3). If the shape element is a open polyline or a open curve, then draws the the resize handles at the endpoints (Figure 5).
: The line width of the selection box and the mark size of the resize handles are independent of the scale (zoom) factor (Figure 4). This is because if these are dependent of the scale (zoom) factor, the selection box and the resize handles are displayed small on the canvas for the small scale factor, then the operation of moving a shape with the selection box or resizing a shape with the resize handle may be difficult.
Control points, tangent lines Calls the DrawShapeUtil.drawSegmentModifiers method.
The control shapes means control points and tangent lines which are used for modifying a shape.
=> Figure 1.2, Figure 1.3, Figure 1.4 in Modifying shape
The node points of a polyline and a cubic curve
Calls the DrawShapeUtil.drawNodeMark to draw the node points (Figure 6).


Figure 3 The selection box and the resize handles


Scale factor=100% Scale factor=144% Scale factor=173%

Figure 4 The line width of the selection box and the mark size of the resize handles




(a) Resize handles at the endpoints



(b) Selection box and resize handles


If the shape element is not closed, draws the resize handle at the endpoints.

Figure 5. Resize handles



Figure 6. Node Points


2. Class ShapeContainerreturn=>page top
public class ShapeContainer
Field Description
shapeId
private String shapeId
The identifier of a shape object which is configured from a key word - a string representing a type of a shape element - and a serial number. Here, the key word is "Line", "Polyline", "Rectangle", "Ellipse" or so on, and the serial number is generated by the ContainerManager.getUniqueSerialNumber method.
(a)The clone of a ShapeContainer has the same shapeId as the original ShapeContainer.
(b)When a shape element of a ShapeContainer object is replaced, the portion of the shapeId related to the shape element type changes, but its serial number does not change.
For (a) and (b) above, set a new shapeId before writing to ContainerList by ContainerManager.
The new shapeId can be obtained with the setNewShapeId method of this class.
: shapeId => "Rectangle(No-1)", "Round_Rectangle(No-2)", "Ellipse(No-3)", "Image(No-4)", "Line(No-10)", "Polyline(No-11)", "CubicCurve(No-12)", "GeneralCurve(No-13)", "Group(No-14)".
containerIndex
protected int containerIndex
The index of the ContainerList (index of ArrayList).
=> ContainerList
parent
private ShapeContainer parent
Sets a parent ShapeContainer to this field, if this object is a child object of a group
element
public ShapeElement element
Sets the ShapeElement object to this field.
textBox
public TextBox textBox
If this shape (ShapeContainer) has a text box, sets the TextBox object to this field.
paintStyle
PaintStyle paintStyle
Sets the PaintStyle object to this field.
property

public HashMap<String, Object> property = new HashMap<String, Object>()

Stores property informations (properties) as the form of key and value(object).
Currently the following properties are used

key value (object)
ORIGINAL_TYPE string - RECTANGLE, ROUND_RECTAGGLE etc.
ENABLE RESIZING boolean true
KEEP_ASPECT_RATIO boolean false
KEEP_LINE_DIRECTION boolean false
KEEP_CONNECTOR_CONNECTIONS boolean true
ENABLE_UNGROUPING boolean true

=> User's guide Behavior of a shape for each property in shape format dialog

selected
private boolean selected
True if this shape (ShapeContainer) is selected.
visible
private boolean visible
True if this shape (ShapeContainer) should be displayed on the canvas.
mode
protected int mode
The mode of this shape.
Command.NORMAL_MODE/ CREATING_MODE/ MOVING_MODE/ RESIZING_MODE/ MOVING_ENDPT_MODE/ MODIFYING_SHAPE_MODEODE can be set to this field.
changeCode
private int changeCode
This field is referred for undo setting by the ContainerManager.
=> The undo support function of the ContainerManager.
If the ShapeContainer or its linked objects (ShapeElement, PaintStyle, TextBox) are changed, the change code is set to this field. The change codes are defined in the UndoConstants class.
connectorTarget
Permission

boolean connectorTarget
Permission

True if the shape allows to be connected by connectors.
connector
Permission

boolean connectorPermission
True if the shape can be a connector.
A line or a polyline can be a connector, so this field is effective when the shape of this ShapeContainer is a line or a polyline.
=> Connector
SHAPE
public static int SHAPE
The constant representing that the shape element isn't a group.
GROUP
public static int GROUP
The constant representing that the shape element is a group.

Method Description
Constructor
public ShapeContainer()
Create a new PaintStyle object and sets it to paintStyle field.
getContainerType
public int getContainerType()
Returns SHAPE if the ShapeElement of this ShapeContainer isn't a GroupElement. Returns GROUP if the ShapeElement of this ShapeContainer is a GroupElement.
getShapeId
public String getShapeId()
Returns the shapeId field.
setShapeId
public void setShapeId(String shapeId)
Sets the shapeId parameter to the shapeId field.
This method is called only from the SerializableElementUtil object when an ShapeContainer object is inverted from a file data and the ContainerManager.backup method.
setNewShapeId
public void setShapeId(ContainerManager manager, boolean withChildren)
Parameters:
manager - ContainerManager object.
withChildren - If true and this object is a group of shapes, then sets new shape Ids to the children of this object.
Processing;
This method creates the shape id and sets it to shapeId field. If the withChildren equals true
, then sets shape Ids to the children of this object.
Here, calls the ContainerManager.getUniqueSerialNumber method to get the serial number, and calls the configureShapeId method with the serial number to get shapeId.
configureShapeId
private String configureShapeId(int number)
Parameters:
number - The serial number.
Returns:
The string of the shapeId.
Processing;
Configures the shape Id using the returned value of the ShapeElement.getShapeIdString method and the numberparameter.
getSerialNumber public int getSerialNumber()
Returns:
The serial number which was generated by the ContainerManager.getUniqueSerialNumber method.
Processing;
Gets the serial number from shapeId.
getSerialNumber
(static)
public static int getSerialNumber(String shapeId)
Parameters:
shapeId - The shape id.
Returns:
Returns the serial number of this object.
Processing;
Gets the serial number from shapeId.
getContainerIndex public int getContainerIndex()
Returns the containerIndex field.
setContainerIndex public void setContainerIndex(int containerIndex)
Sets the containerIndex parameter to the containerIndex field.
getParent
public ShapeContainer getParent()
Return the parent field.
setParent
public void setParent(ShapeContainer parent)
Sets the parent parameter to the parent field.
getTopParent
public ShapeContainer getTopParent()
Return this object if this object has no parent, otherwise return the top parent by calling this method of the parent ShapeContainer recursively.
getElement
public ShapeElement getElement()
Returns the element field.
setElement
public void setElement(ShapeElement element)
Sets the element parameter to the element field.
getMode
public int getMode()
Returns the mode field.
setMode
public void setMode(int mode)
Sets the mode parameter to the mode field.
setSelected
public void setSelected(boolean selected)
Sets the selected parameter to the selected field.
If the selected parameter equals false and the returned value of the isEditableTextBox equals true, then calls makeTextBoxEditable(false).
If the ShapeElement of this ShapeContainer is a GroupElement, then sets the parameter of selected to all the child ShapeContainer objects. To list up all the child ShapeContainer objects, the getGroupedContainers method is used.
isSelected
public boolean isSelected()
Returns the selected field.
setVisible public void setVisible(boolean visible)
Sets the visible parameter to the visible field.
isVisible public boolean isVisible()
Returns the visible field.
isClosed public boolean isClosed()
Returns true if the shape element of this ShapeContainer is a closed shape (the boundary is closed).
isEditableTextBox
public boolean isEditableTextBox()
Returns true if this object has a TextBox and its TextBox is editable.
makeTextBoxEditable
public void makeTextBoxEditable(boolean activate)
If this ShapeContainer hasn't a text box, skips the following steps.
If the activate parameter equals true, then calls the following methods.
if(!this.isSelected()) this.setSelected(true);
this.getTextBox().activateMouseListener(true);
If the activate parameter equals false, then calls the following method.
this.getTextBox().activateMouseListener(false);
makeTextBoxEditable public void makeTextBoxEditable(Point2D point, int ctrl)
Parameters:
point - The clicked point by the mouse.
ctrl - 0/1/2
If the mouse was clicked with holding down Shift/Ctrl key, the ctrl is 1/2.
Processing:
This method is called by the SelectionLS.execSelection method when the inside of a text box was clicked.
If this ShapeContainer hasn't a text box, skips the following steps.
∙ If the activate equals true, then calls the following method.
this.getTextBox().activateMouseListener(true);
∙ Displays the text cursor (caret) at the nearest position to the point in the text box.

Performs the same logic as the TextBox.mouseClicked method.

Calls the TextBox.getCaretPositionAtMouse method to get the text cursor (caret) position.
Calls the TextBox.setCaretPositionOrSelection method to set the text cursor (caret) position to the text box.

getChangeCode
public int getChangeCode()
Returns the changeCode field, if this object isn't a group of shapes, otherwise returns the changeCode of the child ShapeContainer. The child ShapeContainers are got by the getGroupedSingleShapeContainers method.
setChangeCode
public void setChangeCode(int code)
Sets the code parameter to the changeCode field.
resetChangeCode
public void resetChangeCode()
Resets the changeCode (Sets -1 to the changeCode).
setProperty public void setProperty(String key, Object object)
Parameters:
key - property key
object - property value
=>property
Processing:
Stores property key and value of this shape.
getProperty public Object getProperty(String key)
Parameters:
key - property key
Returns:
Returns the property value (object) by the specified property key.
removeProperty public void removeProperty(String key)
Parameters:
key - property key
Processing:
Removes the property key and the value (object) from the property.
getBooleanProperty public boolean getBooleanProperty()
Returns:
Returns the boolean value of the key.
getPaintStyle public PaintStyle getPaintStyle()
Returns the paintStyle field.
setPaintStyle public void setPaintStyle(PaintStyle paintStyle)
Sets the paintStyle parameter to the paintStyle field.
getColors public Color[] getColors()
Returns the array of the colors which are used in the PaintStyle object and the CommittedTextContainer object.
hasTextBox public boolean hasTextBox()
Returns true if this ShapeContainer has a text box.
addTextBox public int addTextBox()
Returns:
0 - Normal end.
1 - A text box isn't added because this object represents a group.
2 - The type of the ShapeElemnt isn't allowd =>bug.
3 - The ShapeElemnt isn't closed.
4 - This object already has a text box.
5 - A textarea is not found =>bug.
6 - the created textArea is too small(The width or height is under 10px).
Processing:
Creates a new TextBox object and sets it to the textBox field. To set a text area(textArea) to the newly created TextBox, this method calls the ShapeElement.createTextArea abstract method and sets its reurn value to the TextBox as follow.
newTextBox.setTextArea(textArea);
Here the reurn value represents the textArea of the Rectangle2D.
=> User's guide create TextBox, add/delete text box
addTextBox public void addTextBox(Rectangle2D textArea)
Parameters:
textArea - The rectangle in which a new text box is placed.
Processing:
This method is called by SerializableElementUtil to convert the SerializableElement data to the ShapeContainer and its subordinate objects.
This method creates a new TextBox object and sets it to the textBox field. And registers this object to the new TextBox by the setShapeContainer method.
deleteTextBox public int deleteTextBox() Sets null to the textBox field of this object.
getTextBox public TextBox getTextBox()
Returns the textBox field.
setTextBox public void setTextBox(TextBox textBox)
Sets the textBox parameter to the textBox field.
setConnectorTarget
Permission

public void setConnectorTargetPermission(boolean permission)
Sets the permission parameter to the connectorTargetPermission field.
This method is not used currently.
setConnectorPermission
public void setConnectorPermission(boolean permission)
Sets the permission parameter to the connectorPermission field.
If the shape of this ShapeContainer isn't a line or a polyline, sets false to the connectorPermission field.
Sets false in the CutShape. Set true in the MoveResizeShapeLS when an end point of a line or a polyline is moved.
This method is not used except the above currently.
isConnectorTarget
public boolean isConnectorTarget()
Returns the connectorTargetPermission field.
isConnector
public boolean isConnector()
Returns the connectorPermission field.
compare
public boolean compare(ShapeContainer container)
Return true if this object equals the container.
compare
public boolean compare(ShapeContainer[] containers)
Return true if this object equals any of the containers.
getGroupedContainers
public ShapeContainer[] getGroupedContainers()
Returns:
The array which stores this object and all the child objects.
The first element of the array stores this object.
Processing:
If the ShapeElement of this object is a single shape element (not group element), then returns this object, else returns this object and all the child objects. All the child objects are searched by the GroupElement.getGroupedContainers method.
Search example of the GroupElement.getGroupedContainers:

If this object is the Single shape(No-0) in Figure 2, then returns Single shape(No-0).
If this object is Group(No-1), then returns the Group(No-1), Group(No-2), Single shape(No-3), Single shape(No-4), Group(No-5), Single shape(No-6), Single shape(No-7).

getGroupedSingleShape
Containers

public ShapeContainer[] getGroupedSingleShapeContainers()
Returns:
The array which stores this object or all the child objects of this excluding group objects.
Processing:
If the ShapeElement of this object is a single shape element (not group element), then returns this object, else returns this object and all the child objects excluding group objects. All the child objects are searched by the GroupElement.getGroupedSingleShapeContainers.
Example: If this object is the Single shape(No-0) in Figure 2, then returns Single shape(No-0) If this ShapeContainer is Group(No-1), then returns the Single shape(No-3), Single shape(no-4), Single shape(no-6). and , Single shape(no-7).
getGroupedTextBoxes
public TextBox[] getGroupedTextBoxes()
Returns:
The array of all the TextBox objects which are linked from this ShapeContainer object.
Processing
To list up all the TextBox objects, the getGroupedSingleShapeContainers method is used.
Example: If this ShapeContainer is the "Single shape 0" in Figure 2, then returns "TextBox 0". If this ShapeContainer is "Group 0", then returns the "TextBox 4" and "TextBox 2".
getGroupedTextBox
public TextBox getGroupedTextBox(String shapeId)
Returns:
The TextBox object which is linked from this ShapeContainer object and whose ShapeContainer has the shapeId.
Processing:
To list up all the TextBox objects, the getGroupedTextBoxes method is used.
getGroupedPaintStyles
publpublic PaintStyle[] getGroupedPaintStyles()
Returns:
The array of all the PaintStyle objects which are linked from this object..
Processing
To list up all the PaintStyle objects, the getGroupedSingleShapeContainers method is eused.
Example: If this object is the "Single shape 0" in Figure 2, then returns "PaintStyle 0". If this ShapeContainer is "Group 0", then returns the "PaintStyle 3", "PaintStyle 4" and "PaintStyle 2".
getGroupedPaintStyle
public PaintStyle getGroupedPaintStyle(String shapeId)
Returns:
The PaintStyle object which is linked from this object and whose ShapeContainer has the shapeId.
Processing:
To list up all the PaintStyle objects, the getGroupedTextBoxes method is used.
getBoundingBox
public Rectangle2D getBoundingBox()
Returns the bounding box which encloses this shape.
Calls the ShapeElement.getBoundingBox method.
setTextBoxLayout

public void setTextBoxLayout(Insets textBoxInsets, int textAlign, double lineSpace)
Parameters:
textBoxInsets - The inner margin of the text box.
textAlign - The text align. Left align: 0. Center Align; 1, Right align: 2.
lineSpace - The line space.
Processing:
Sets the parameters to the text box of this object. If the shape element of this object is a group of shapes, then sets the attributes to all the text boxes of the child objects of this object.
To list up all the child objects, the getGroupedSingleShapeContainers method is used.
setFillColor
public void setFillColor(Color fillColor)
Parameters:
fillColor - The fill color with which the inside of the shape is painted.
Processing:
Sets the fillColor to the shape element of this object. If this object is a group of shapes, then sets the fillColor to all the shape elements of the child objects of this object.
To list up all the child objects, the getGroupedSingleShapeContainers method is used.
setLineColor
public void setLineColor(Color lineColor)
Parameters:
lineColor - The line color with which the boundary of the shape is painted.
Processing:
Sets the lineColor to the shape element of this object. If the shape element of this object is a group, then sets the lineColor to all the shape elements of the child objects of this object.
To list up all the child objects, the getGroupedSingleShapeContainers method is used.
setLineWidth
public void setLineWidth(String lineWidth)
Parameters:
lineWidth - The line width of the boundary of the shape.
Processing:
Sets the lineWidth to the shape element of this object. If this object is a group, then sets the ineWidth to all the shape elements of the child objects of this object.
To list up all the child objects, the getGroupedSingleShapeContainers method is used.
setLineStroke
public void setlineStroke(String lineStroke)
Parameters:
lineStroke - The line stroke of the boundary of the shape.
Processing:
Sets the lineStroke to the shape element of this object. If the shape element of this object is a group, then sets the lineStroke to all the shape elements of the child objects of this object.
To list up all the child objects, the getGroupedSingleShapeContainers method is used.
setArrowStyle
public void setArrowStyle(String arrowStyle)
Parameters:
arrowStyle - The arrow style. This attribute is effective for a line and a polyline.
Processing:
Sets the arrowStyle to the shape element of this object. If the shape element of this object is a group, then sets the arrowStyle to all the shape elements of the child objects of this object.
To list up all the child objects, the getGroupedSingleShapeContainers method is used.
drawShape
public void drawShape(Graphics g)
If the shape element of this object is a group, then draws the group by the recursive call of the drawShape method, otherwise performs the following.
∙ Drawing the shape element.

Calls the DrawShapeUtil.drawShapeElement method.
∙ Drawing the TextBox, if this object has a text box.

Calls the TextBox.drawTextBox method.
∙ Drawing the control points if the mode of this object equals Command.MODIFYING_SHAPE_MODEODE

Calls the DrawShapeUtil.drawSegmentModifiers method.
∙ Drawing the selection box and the resize handles if the parent of this object is null.

Calls the DrawShapeUtil.drawSelection method.
=> Drawing the objects in ShapeContainer

clone
public Object clone()
Returns:
The clone of this object.
Processing:
∙ If the shape element of this object isn't a group, then performs the following.

Creates a new ShapeContainer object and the clones of TextBox, PaintStyle of this object and combines the clones with the new ShapeContainer object by bi-directional links.
∙ If the shape element of this object is a group, then performs the following.

Creates a new ShapeContainer object and a new GroupElement object and them by a bi-directional link.
Gets the child objects from the GroupElement object of this object and creates the clones of the child objects. Then adds them to the the new GroupElement object by the addChildren method.
: The shapeId of the cloned ShapeContainer equals the shapeId of this object.

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.