Java Drawing DrawTop

Language

JP  US  UK

 

File Data Format

 H. Jyounishi, Tokyo Japan
 

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

Summary:This page describes the file data format of a shape object.
このページでClass on this page: SerializableElement, SerializableCurve2D, SerializableSegment2D, SerializableAttributedString, SerializableTextBox, SerializablePaintStyle, SerializableElementUtil


1. Overview
(1) SerializableElement

The SerializableElement class is the serializable class which contains all the fields of the ShapeContainer, ShapeElement, TextBox and PaintStyle objects. So the ShapeContainer object can be inverted from the SerializableElement object(s), even if it represents a group of shapes.
The SerializableElement can be written/read to/from a file and is implemented with the write/read methods.

(2) Related classes 

The serializable classes for the Curve2D, Segment2D and java.text.AttributedString classes are defined as the SerializableCurve2D, SerializableSegment2D and SerializableAttributedString.

(3) Utilizing in other functions

Because the SerializableElement object and the related objects are compact and handy, so these are utilized in the following functions.

Editing shape/text (cut/copy and caste)

Shape objects and text objects are converted to the SerializableElement object and the related objects, then they are copied to the clipboard.

Undo, Redo

The SerializableElement object and the related objects are set to the UndoableDrawEdit object.



2. Class SerializableElement 戻る=>page top
public class SerializableElementimplements Serializable
The SerializableElement class is the class which contains all the fileds of the ShapeContainer, ShapeElement, TextBox and PaintStyle objects and has only a few simple methods like toString.
If the ShapeContainer represents a single shape, it is easy to convert to SerializableElement. However, if the ShapeContainer represents a group shape, the group SerializableElement is represented by the tree structure as shown in Figure 2.1 (e). To do this, the child SerializableElements are stored in the field variable: chirdrenList (ArrayList) of the parent SerializableElement.


(a)Original

(b)Grouping two shapes.

(c)Grouping the group shape and the elliptic shape.

(d)Grouping the group shape and the star shape.

(e)The tree structure of the above group (d)

Figure 2.1 SerializableElement of a group shape



Field
Description
containerType
public int containerType
Sets the ShapeContainer.SHAPE or ShapeContainer.GROUP to this field.
containerIndex
public int containerIndex
The containerIndex filed of the ShapeContainer.
parent
public String parent
The parent filed of the ShapeContainer.
shapeId
public String shapeId
The shapeId filed of the ShapeContainer.
date
public Date date
The Date object representing the time at when this object is created.
: The Date object: representing the Calendar's time value (millisecond offset from the Epoch").
fileNameAndPage
public String fileNameAndPage
The string representing the file name and page which stores the ShapeContainer object from which this SerializableElement object is created.
Example: If the file name is "C:\Documents and Settings\My Documents\drawFile\Sample.draw" and the page is three, then this string is "C:\Documents and Settings\My Documents\drawFile\Sample.draw:3"
connectorTarget
Permission

public boolean connectorTargetPermission
The connectorTargetPermission filed of the ShapeContainer.
connectorPermission
public boolean connectorPermission
The connectorPermission filed of the ShapeContainer.
elementType
public String elementType
The string representing the returned value of the getType method of the ShapeElenment.
serializableCurve2D
public SerializableCurve2D serializableCurve2D
The returned value of the getSerializableCurve2D method of the ShapeElenment.
fillColor
public Color fillColor
The fillColor field of the PaintStyle.
lineColor
public Color lineColor
The lineColor field of the PaintStyle.
lineWidth
public float lineWidth
The lineWidth field of the PaintStyle.
dashedStyle
public String dashedStyle
The dashedStyle field of the PaintStyle.
dash
public float[] dash
The dash field of the PaintStyle.
arrowStyle
public int arrowStyle
The arrowStyle field of the PaintStyle.
startArrowType
public int startArrowType
The startArrowType field of the PaintStyle.
endArrowType
public int endArrowType
The endArrowType field of the PaintStyle.
textArea
public Rectangle2D textArea
The textArea field of the TextBox.
attributedString
public SerializableAttributedString attributedString
The attributed string which is got by the getSerializableAttributedString method of the CommittedTextContainer.
textBoxInsets
public Insets textBoxInsets
The textBoxInsets field of the TextBox.
textAlign
int textAlign
The textAlign field of the TextBox.
lineSpace
int lineSpace
The lineSpace field of the TextBox.
imageByteData
public byte[] imageByteData
The byte array of the image which is stored in the bufferedImage field of the ImageElement. To convert the bufferedImage to the byte array, the getByteImage method of the ImageElement is employed.
childrenList
public ArrayList childrenList
This field is created from the childrenList of the GroupElement.
If this object is written to a file, then adds the shapeId of the child ShapeContainer to this list, otherwise adds the SerializableElement object of the child ShapeContainer to this list.

Method
Description
getGroupedElements public SerializableElement[] getGroupedElements()
Returns:
If this SerializableElement object represents a single shape, returns itself. If it represents a group shape, returns itself and all its chilld SerializableElement objects.
For example, returns the array of the Group(No-6), Group(No-5), Group(No-4), Rectangle(No-0), Round_Rectangle(No-1), and Ellipse(No-2) for the group shape in Figur 2.1 (d) and (e)
Processing:
Calls the next getGroupedElementsE method.
getGroupedElementsE public void getGroupedElementsE(Vector vector)
Parameters:
vector - Vector which stores the child SerializableElement objects.
Processing:
Calls this method recursively to search the tree of the group shape and return all the child SerializableElement objects which are stored in the vector.

getGroupTreeDepth public int getGroupTreeDepth(String shapeId)
This method is used to indent the print out of a child SerializableElement object.
=> Figure 2.2
Parameters:
shapeId - The identifier of a shape object.
Returns:
Returns the tree depth of the child SerializableElement object which coincides with shapeId.
For example, the tree depth of the Group(No-6) is 0 and that of the Group(No-4) is 2 in Figure 2.1 (e).
Processing:
Calls the next getGroupTreeDepthE method.

getGroupTreeDepthE public void getGroupTreeDepthE(Vector vector)
Parameters:

vector - Stores shapeId(String), treeDepth(Integer) and findDepth(Integer) to the vector.
∙ treeDepth - The tree depth where this method is searching(work variable).
∙ findDepth - The tree depth of the child SerializableElement object which coincides with shapeId.
If this method can't find such a child SerializableElement object , sets -1 to the findDepth and returns.
Processing:
Calls this method recursively to search the tree of the group shape such as Figur 2.1 (e).

clone public Object clone()
Returns the clone of this object.
cloneHashMap private HashMap<String, Object> cloneHashMap(HashMap<String, Object> hashMap)
Returns the clone of HashMap filed in this object.
toString
public String toString()
Returns a string representation of this object.
Determines the number of spaces in indentation by the treeDepth value returned from the getGroupTreeDepth method and the string of the header, then calls the next toStringE method.
=>Figure 2.2
toStringE private String toStringE(int indent, String header)
Returns a string representation of of this object.
toShortString
public String toShortString()
Returns a short string representing this object.
The indentaion of this method is as same as the toString.
Calls the next toShortStringE method.
=>Figure 2.2
toShortStringE private String toShortStringE(int indent, String header)
Returns a short string representation of this object.

toVeryShortString
public String toVeryShortString()
Returns a very short string representing this object.
The indentaion of this method is as same as the toString.
Calls the next toVeryShortStringE method.
=> Figure 2.2
toVeryShortStringE private String toVeryShortStringE(int indent, String header)
Returns a very short string representation of this object.





Figure 2.2 Print out of the toString(), toShortString() and toVeryShortString()



3. Class SerializableCurve2D 戻る=>page top
public class SerializableCurve2D implements Serializable
This class provides the serializable class which has all the fileds of the Curve2D and the methods to write/read to/from the file. This object is created by the getSerializableCurve2D method of the Curve2D and set to the Curve2D object by the setSerializableCurve2D method.

Field
Description
type
public int type
The returned value of the getType method of the Curve2D. Curve2D.RECTANGLE/ROUND_RECTANGLE/ELLIPSE/LINE...etc.
doubleData
public double[] doubleData
The double array which stores the characteristic data of the parametric curve. Currently this field isn't referred.
points
public Point2D[] points
The array which stores the characteristic points of the parametric curve. Currently this field isn't referred.
serializableSegments
public SerializableSegment2D[] serializableSegments
The array storing the SerializableSegment2D objects which compose the parametric curves of this object.
versions
public static final String[] versions
The array of the String objects representing versions of this class.

Method
Description
setSegments
public void setSegments(SerializableSegment2D[] serializableSegments)
Sets the parameter to the serializableSegments field.
getSegments
public SerializableSegment2D[] getSegments()
Returns the serializableSegments field.
writeSerializable
Curve2
D

public static int writeSerializableCurve2D(ObjectOutputStream out, SerializableCurve2D sCurve2D) throws Exception
Parameters:
out - The ObjectOutputStream object.
sCurve2D - The SerializableCurve2D object.
Processing:
Writes the sCurve2D to the file.
∙ Writes the version to the file.
∙ Writes each field of the SerializableCurve2D object to the file.

Writes the SerializableSegment2D object by the writeSerializableSegment2D method.

readSerializable
Curve2D

public static SerializableCurve2D readSerializableCurve2D(ObjectInputStream in) throws Exception
Parameters:
in - The ObjectInputStream object.
Returns:
The SerializableCurve2D object.
Processing:
Reads the SerializableCurve2D from the file.
∙ Reads the version from the file.
∙ Reads each field of the SerializableCurve2D object from the file.

Reads the SerializableSegment2D object by the readSerializableSegment2D method.



4. Class SerializableSegment2D 戻る=>page top
public class SerializableSegment2D implements Serializable
This class provides the serializable class which has all the fileds of the Segment2D and the methods to write/read to/from the file. This object is created by the getSerializableSegment2D method of the Segment2D and set to the Segment2D object in the setSerializableCurve2D method.

Field
Description
type
public int type
The type field of the Segment2D.
shape
public Shape shape
The shape field of the Segment2D.
affineTransform
public AffineTransform affineTransform
The affineTransform field of the Segment2D.
versions
public static final String[] versions
The array of the String objects representing versions of this class.

Method
Description
writeSerializable
Segment2D
public static int writeSerializableSegment2D(ObjectOutputStream out, SerializableSegment2D sSegment2D) throws Exception
Parameters:
out - The ObjectOutputStream object.
sSegment2D - The SerializableSegment2D object.
Processing:
∙ Writes the version to the file.
∙ Writes each field of the SerializableSegment2D object to the file.
readSerializable
Segment2D
public static SerializableSegment2D readSerializableSegment2D(ObjectInputStream in) throws Exception
Parameters:
in - The ObjectInputStream object.
Returns:
The SerializableSegment2D object.
Processing:
∙ Reads the version to the file.
∙ Reads each field of the SerializableSegment2D object from the file.


5. Class SerializableAttributedString 戻る=>page top
public class SerializableAttributedString implements Serializable, Cloneable
This class provides the serializable class representing the java.text.AttributedString. This object is represented by the String object and the AttributedInterval object just like the AttributedStringUtil.
This object is created by the getSerializableAttributedString method of the CommittedTextContainer and set to the CommittedTextContainer object in the setSerializableAttributedString method.

Field
Description
string
private String string
Sets the string (plain text) of the AttributedString object.
attributedIntervalList
public ArrayList attributedIntervalList
The ArrayList storing the AttributedInterval object.
Just same as the arrayList of the AttributedStringUtil.
versions
public static final String[] versions
The array of the String objects representing versions of this class.

Method
Description
Constructor
public SerializableAttributedString(AttributedCharacterIterator iterator)
Creates a new AttributedStringUtil object and gets the string and the attributedIntervalList and sets them to the correnponding fields.
getString
public String getString()
Returns the string.
setString
public void setString(String str)
Sets the parameter the string.
getAttributedIntervalList
public ArrayList getAttributedIntervalList()
Returns the attributedIntervalList.
setAttributedIntervalList
public void setAttributedIntervalList(ArrayList list)
Sets the parameter to the attributedIntervalList.
getAttributedString
public AttributedString getAttributedString()
Returns the AttributedString object.
clone
public Object clone()
Returns the clone object.
toString
public String toString()
Returns the string representing this object.
writeSerializable
AttributedString

(static)
public static int writeSerializableAttributedString(ObjectOutputStream out, SerializableAttributedString sAttributedString) throws Exception
Parameters:
out - The ObjectOutputStream object.
sAttributedString - The SerializableAttributedString object.
Processing:
∙ Writes the version to the file.
∙ Writes each field of the SerializableAttributedString object to the file.
readSerializable
AttributedString

(static)
public static SerializableAttributedString readSerializableAttributedString(ObjectInputStream in) throws Exception
Parameters:
out - The ObjectOutputStream object.
Returns:
Returns SerializableAttributedString object.
Processing:
∙ Reads the version to the file.
∙ Reads each field of the SerializableAttributedString object from the file.


6. SerializableTextBox 戻る=>page top
public class SerializableTextBox implements Serializable
This class isn't used for writing to the file but used for setting an undo/redo object in the UndoDrawableEdit.ChangeTextBox object.

Field
Description
shapeId
public String shapeId
The shapeId field of the ShapeContainer object owning the TextBox.
textArea
public Rectangle2D textArea
The textArea field of the TextBox.
attributedString
public SerializableAttributedString attributedString
The attributed string which is got by the getSerializableAttributedString method of the CommittedTextContainer.
textBoxInsets
public Insets textBoxInsets
The textBoxInsets field of the TextBox.
textAlign
int textAlign
The textAlign field of the TextBox.
lineSpace
int lineSpace
The lineSpave field of the TextBox.

Method
Description
toString
public String toString()
Returns the string representing this object.


7. SerializablePaintStyle  戻る=>page top
public class SerializablePaintStyle implements Serializable
This class isn't used for writing to the file but used for setting an undo/redo object in the UndoDrawableEdit.ChangePaintStyle object.

Field
Description
shapeId
public String shapeId
The shapeId field of the ShapeContainer object owning the PaintStyle.
fillColor
public Color fillColor
The fillColor field of the PaintStyle.
lineColor
public Color lineColor
The lineColor field of the PaintStyle.
lineWidth
public float lineWidth
The lineWidth field of the PaintStyle.
dashedStyle
public String dashedStyle
The dashedStyle field of the PaintStyle.
dash
public float[] dash
The dash field of the PaintStyle.
arrowStyle
public int arrowStyle
The arrowStyle field of the PaintStyle.
startArrowType
public int startArrowType
The startArrowType field of the PaintStyle.
endArrowType
public int endArrowType
The endArrowType field of the PaintStyle.

Method
Description
toString
public String toString()
Returns the string representing this object.


8. Class SerializableElementUtil 戻る=>page top
public class SerializableElementUtil
This class provide the conversion/inversion methods between a ShapeContainer object and a SerializableElement object. This class is used for the followings.
Editing shape/text (cut/copy and caste)
Undo, Redo



(a) ShapeContainer objects of a group



(b) The SerializableElement objects
converted from the ShapeContainer of a group


Figure 8.1 The data format of a group of the ShapeContainer and SerializableElement


Field
Description
versions
public static final String[] versions
The array of the String objects representing versions of this class.

Method
Description
convertShapeContainer
(static)
public static SerializableElement convertShapeContainer(ShapeContainer container)
Parameters:
container - The ShapeContainer object to be converted to the SerializableElement object.
Returns:
The SerializableElement object.
Processing:
∙ If the container is a single shape object, calls the convertSingleContainer method.
∙ If the container is a group shape object, call the convertGroupContainer method

This method converts the (a) to (b) in Figure 8.1.

convertSingleContainer
(static)
public static SerializableElement convertSingleContainer(ShapeContainer container)
Parameters:
container - a single ShapeContainer object.
Retuns:
Returns SerializableElement object.
Processing:
Converts a single ShapeContainer to a SerializableElement object whichi is a writable to a file.
convertGroupeContainer
(static)
private static SerializableElement convertGroupToStructuredSElement(ShapeContainer container)
Parameters:
container - A group ShapeContainer object.
Returns:
The SerializableElement object (Group 0 in Figure 8.1 (c)).
Processing:
Converts child ShapeContainer objects of the container to SerializableElement objects by the convertShapeContainer method and stores them to the childrenList(ArrayList).
If a child ShapeConatiner is a group, the convertShapeContainer method calls this method recursively, so this method convers all the child ShapeContainers shown in Figure 8.1 (a) to SerializableElement objects
invertShapeContainer
(static)
public static ShapeContainer invertShapeContainer(SerializableElement sElement)
Parameters:
sElement - SerializableElement object
Returns:
ShapeContainer object
Processing:
∙ if the sElement is a single shape object:

Converts the sElement to the ShapeContainer object by the invertSingleContainer method.

∙ if the sElement is a group shape object:

Converts the sElement to the ShapeContainer object by the invertGroupContainer method.
Figure 8.1 (b) ->(a).

invertSingleContainer
(static)
public static ShapeContainer invertSingleContainer(SerializableElement sElement)
Parameters:
sElement - Single shape SerializableElement object.
Returns:
ShapeContainer object.
Processing:
Creates a ShapeContainer object and sets the field values of the sElement to the corresponding fields of the ShapeContainer and ShapeElement objects.

invertGroupContainer
(static)
public static ShapeContainer invertGroupContainer(SerializableElement sElement)
Parameters:
sElement - a group shape SerializableElement object
Returns:
A group ShapeContainer object.
Processing:
∙ Creates a ShapeContainer object.

Sets the field values of the sElement to the corresponding fields of the ShapeContainer and GroupElement objects.

∙ Converts child SerializableElement objects to ShapeContainer objects by invertShapeContainer method.

The invertShapeContainer method calls this method recursivly, so this method converts all the SerializableElement objects which are represented in the tree structue shown in Figure 8.1 (b).

setToShapeContainer
(static)
public static void setToShapeContainer(SerializableElement sElement, ShapeContainer container)
Parameters:
sElement - The SerializableElement object.
container - The ShapeContainer object.
Processing:
This method is calld by the UndoableDrawEdit.ChangeContainer object.
Replaces all the data of the container by the data of the sElement.
Calls the setToSingleContainer or setToGroupContainer
method.
setToSingleContainer
(static)
private static void setToSingleContainer(SerializableElement sElement, ShapeContainer container)
Parameters:
sElement - The SerializableElement object.
container - The ShapeContainer object.
Processing:
Performs the same operations as the DrawFileIo.invertShapeContainer without creating a new ShapeContainer object.
setToGroupContainer
(static)
private static void setToGroupContainer(SerializableElement sElement, ShapeContainer container)
Parameters:
sElement - The SerializableElement object.
container - The ShapeContainer object.
Processing:
Performs the same operations as the invertGroupContainer without creating a new ShapeContainer object.



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