Java Drawing DrawTop

Language

JP  US  UK

 

Container Manager

 H. Jyounishi, Tokyo Japan
 

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

Summary:
ContainerManager:This class manages the ContainerList storing the drawings of a page. Multiple pages are managed by the PageManager.
Class on this page: ContainerManager

1. Overview

Figure 1.1 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.


Figure 1.2 Components - Group shapes


Figure 1.3 The Structure of ContainerList.
∙ Group shape and single shape:

The Group(No-0), Group(No-1) and so on 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 Figure 1.3, links from childrenList to child elements are represented by arrows.


Item
Description
Usage of the ContainerManager
In the usual case, the only one ContainerManager object exists in this application for managing the shapes on the canvas. However, in the case of executing the page layout command or the component library command, the another ContainerManager object is created temporarily during the execution of the command.
Creating the serial number for the shape identifier
The shape identifier is stored to the shapeId field of the ShapeContainer. The serial number part of the shapeId is created by the getUniqueSerialNumber method of this class.
The serial number is added by 1 whenever it is created. If the shape is removed, the serial number of the shapeId will be a unused number, but we don't care.
Managing shape elements and group elements
The shape elements are classified into two types. The first type is a shape element with a single shape. The second type a shape element with a link table to the child ShapeContainer objects.
We call the first type as "a single shape element", the second type as "a group element".
A single shape element or a group element is stored in the ShapeContainer object and the ShapeContainer object is stored in the ContainerList(ArrayList) and managed by the ContainerManager.
Single shape element

This element is registered to the ContainerList.

∙ Group element

A group element can has a group element as a child element. So only the top group element in the group hierarchy is registered to the to the ContainerList. The child single shape element or a child group element isn't registered to the to the ContainerList. It is linked by the parent element.
=>Figure 1

Z-order of shapes
The shapes (ShapeContainer objects) are drawn from the head of the ContainerList. So if two shapes are overlapped, the shape positioned backward in the ContainerList is drawn forward in the canvas.
To change the z - order of a shape, only the location of the shape is moved in the ContainerList.
The index in the ContainerList It is desirable to return removed shapes at the former z - positions in the canvas, when the undo command is specified. This implies to return them at the former positions in the ContainerList. To do this, each shape should have the index in the ContainerList. If the index of a shape is changed, the indices of all the shapes should be updated.
Editable(active)
text box
Multiple text boxes can't be edited at the same time. The method to search a ShapeContainer with an editable (active) text box is implemented as the getEditableTextBox method to ensure that the editable text box is always one.
Undo support function
The undo setup for creating/deleting/changing a ShapeContainer object and changing TextBox, PaintStyle object is performed as follow.
(1) Declaration of starting undo setup

Calls undoSetupStart method of this class to declare starting undo setup. Hereafter, whenever the getContainer or its family method of this class is called, the ContainerManager creates a clone of the ShapeContainer and saves the clone to the BackupContainerList. This is done to save the shape object before it is changed.

(2) Undo setup for creating/deleting a shape

When the addContainer or deleteContainer method is called, the ContainerManager calls the undoSetupOfAddOrDelete method to add an UndoableDrawEdit object representing "created" or "deleted" to the UndoDrawManager.

(3) Reporting the change of a shape, a text box or a paint style

When an ShapeContainer object including its TextBox or PaintStyle object is changed, the ShapeContainer.changeCode must be called to report its change to the ContainerManager. If the ShapeContainer.changeCode is called, then undoSetupEnd method checks its change and sets an undo data (UndoableDrawEdit object) to the UndoDrawManager.

: If the shape is changed several times in a single command processing, the set of undoSetupStart - setChangeCode - undoSetupEnd can be called any number of times. The undo setting is registered as much as the number of the calls.

(4) Declaration of ending undo setup

Calls the undoSetupEnd method of this class to declare ending undo setup.
If an ShapeContainer object (including its TextBox or PaintStyle object) is changed, then gets the old state of the ShapeContainer from the BackupContainerList and creates an UndoableDrawEdit object using the old state and the current state of the ShapeContainer, and adds it to the UndoDrawManager.


: Calling the undoSetupStart and undoSetupEnd methods
(a) If an undoSetupStart method is called twice or more, it occurs nothing bad. The last call is effective. Also, if the undoSetupEnd method can be called twice or more, the first call is effective.
(b)If nothing changes to ShapeContainer object in the ContainermMnager during undoSetupStart - undoSetupEnd calls, no UndoableDrawEdit object is added to the UndoDrawManager.
=> Undo setup for each command


2. Class ContainerManager return=>page top
public class ContainerManager

Field
Description
ContainerList ArrayList ContainerList
The ArrayList which stores all the ShapeContainer objects displayed on the screen (Figure 1).
: Multiple pages are managed by the PageManager.
workVector Vector workVector=new Vector()
Work Vector object.
undoSetup private boolean undoSetup
The undoSetupStart method sets true and the undoSetupEnd method sets false.
undoEdit private boolean undoEdit
True if the UndoableDrawEdit objects are added to the UndoDrawManager.
If undoEdit is true, then the undoSetupEnd method adds an UndoableDrawEdit.Delimiter object to the UndoDrawManager.
BackupContainerList private ArrayList BackupContainerList
The ArrayList to back up ShapeContainer objects before changing.
=> Undo support function

Method
Description
getUniqueSerialNumber public int getUniqueSerialNumber()
Return the serial number used for creating the shapeId of a ShapeContainer. The serial number is given by adding 1 to the return value of the getMaxSerialNumber method below.
getMaxSerialNumber public int getMaxSerialNumber()
Returns the max value among the serial numbers which are retrieve from the ShapeContainer objects stored in the ContainerList. The serial number can be retrieved by the ShapeContainer.getSerialNumber method.
: The shapeId is an 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, for example "Rectangle (No-1)".
getContainerList public ArrayList getContainerList()
Returns the ContainerList.
setContainerList public void setContainerList(ArrayList containerList)
Parameters:
containerList - The ArrayList object.
Processing:
Sets the containerList to the ContainerList.
This method is called by the PageManager to change the page to be displayed.
size public int size()
Return the size of the ContainerList.
clear public void clear()
Clears the ContainerList.
setContainerIndex> private void setContainerIndex(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Calls the getContainerIndex method of this class and calls the ShapeContainer.setContainerIndex method of the container.
=> Index of ContainerList on this page.
getContainerIndex private int getContainerIndex(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Returns the index of the container in ContainerList.
addContainer public void addContainer(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Adds the container to the ContainerList. This method calls the setContainerIndex methods.
If the undoSetup field is true, then calls the undoSetupOfAddOrDelete method of this class.
addContainer public void addContainer(int index, ShapeContainer container)
Parameters:
index - The index of the ContainerList.
container - The ShapeContainer object.
Processing:
Adds the ontainer at the position of the index in the ContainerList. This method calls the setContainerIndex methods.
If the undoSetup field is true, then calls the undoSetupOfAddOrDelete method of this class.
deleteContainer public void deleteContainer(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Removes the container from the ContainerList. This method calls the setContainerIndex method before removing.
If the undoSetup field is true, then calls the undoSetupOfAddOrDelete method of this class.
deleteContainer public void deleteContainer(int index)
Parameters:
index - The index of the ContainerList.
Processing:
Removes the ShapeContainer object specified by the index from the ContainerList. This method calls the setContainerIndex method before removing.
If the undoSetup field is true, then calls the undoSetupOfAddOrDelete method of this class.
deleteContainer public void deleteContainer(String shapeId)
Parameters:
shapeId - The shapeId of an ShapeContainer object
Processing:
Removes the ShapeContainer object specified by the shapeId from the ContainerList. This method calls the setContainerIndex method before removing.
If the undoSetup field is true, then calls the undoSetupOfAddOrDelete method of this class.
getContainer public ShapeContainer getContainer(int index)
Parameters:
index - The index of the ContainerList.
Processing:
Returns the ShapeContainer object at the index in the ContainerList.
This method calls the setContainerIndex method and if the undoSetup field is true, calls the backup method.
getContainer public ShapeContainer getContainer(String shapeId)
Parameters:
shapeId - The shapeId of an ShapeContainer object
Processing:
Returns the ShapeContainer object specified by the shapeId. This method searches child ShapeContainers of the ShapeContainer in the ContainerList by the shapeId.
This method calls the setContainerIndex method and if the undoSetup field is true, calls the backup method.
getContainers public ShapeContainer[] getContainers()
Returns the array of all the ShapeContainer objects in the ContainerList.
This method calls the setContainerIndex method and if the undoSetup field is true, calls the backup method.
getSelectedContainers public ShapeContainer[] getSelectedContainers()
Returns the array of the selected ShapeContainer objects in the ContainerList.
This method calls the setContainerIndex method and if the undoSetup field is true, calls the backup method.
getAllShapeContainers public Vector getAllShapeContainers()
Returns all ShapeContainers to a Vector.
In the Figure 1.1, 1.2, 1.3 described above, for example, the sequence of Round_Rectangle(No-0), Group(No-1), Group(No-2), Rectangle(No-3), Rectangle(No-4), Group(No-5), Rectangle(No-6), Rectangle(No-7),Line(No-8), Line(No-9), Rectangle(No-10), Rectangle(No-11), Line(No-12) and Line(No-13) are returned in this order. This order is related to the z-order, that is, the Round_Rectangle(No-0) is backmost and the Line(No-13)is in front.
: the z-order => user's guide z-order of shapes
getAllSigleShapeContainers public ShapeContainer[] getAllSigleShapeContainers(boolean selectedOnly)
Parameters:
selectedOnly - If true, then returns the selected single shape objects, otherwise returns the all the single shape objects.
Returns:
Returns the array of the (selected) ShapeContainer objects each of which has a single shape element.
Processing:
To get all the child ShapeContainer objects in a group, t he getGroupedSingleShapeContainers method of the ShapeContainer is used.
This method calls the setContainerIndex method and if the undoSetup field is true, calls the backup method.
Example: Returns Round_Rectangle(No-0), Rectangle(No-3), Rectangle(No-4), Rectangle(No-6), Rectangle(No-7), Line(No-8), Line(No-9), Rectangle(No-10), Rectangle(No-11), Line(No-12) and Line(No-13), if the selectedOnly is false in Figure 1.1, 1.2, 1.3.
renumberContainerList public void renumberContainerList()
Renumber the serial number in ShapeContainer.shapeId
getEditableTextBox public ShapeContainer getEditableTextBox()
Returns the ShapeContainer object with an editable (active) TextBox.
makeAllTextBoxesUneditable public void makeAllTextBoxesUneditable()
Makes all the TextBox objects uneditable.
swapContainers public void swapContainers(ShapeContainer container1, ShapeContainer container2)
Exchanges the positions of the container1 and container2 in the ContainerList.
This method is used for changing the z -orders of two shapes.
group public ShapeContainer group(ShapeContainer[] containers)
Parameters:
containers - The ShapeContainer objects to be grouped.
Returns:
∙ Creates a new ShapeContainer object and a new GroupElement object.
∙ Registers the containers to the new GroupElement.
∙ Adds the new ShapeContainer object to the ContainerList by the addContainer method.

The position in ContainerList is the same as the maximum position of the ShapeContainer objects specified by the parameter.

∙ Deletes the containers from the ContainrList.
ungroup public void unGroup(ShapeContainer groupContainer)
Parameters:
groupContainer - The ShapeContainer objects of a group..
Returns:
∙ Checks that the groupContainer has a GroupElement. If not, then this method returns, otherwise executes the following steps.
∙ Retrieves the child ShapeContainer objects which are registered in the GroupElement and adds them to the ContainerList by the addContainer method. The position in ContainerList is the same as the groupContainer.
∙ Sets "selected" to the the child ShapeContainer objects.
∙ Deletes the groupContainer from the ContainerList.
undoSetupStart public void undoSetupStart()
Sets true to the undoSetup field to declare starting undo setup. Hereafter, whenever the getContainer or its family method is called, the ContainerManager creates a clone of the ShapeContainer to be returned and stores the clone to the BackupContainerList by the backup method. This action is to save the backup of the shape before changed.
For all the ShapeContainer objects in the ContainerList and all their child ShapeContainer objects, calls the resetChangeCode method.
=> Undo support function
undoSetupStart public void undoSetupStart(ShapeContainer[] containers)
Parameters:
containers - The ShapeContainer objects.
Processing:
Performs the same processing as the above method.
In addition, calls the backup method to save the clones of the containers to the BackupContainerList.
backup private void backup(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Saves the clone of the container to the BackupContainerList.
backup private void backup(ShapeContainer[] containers)
Parameters:
containers - The ShapeContainer objects.
Processing:
Saves the clones of the containers to the BackupContainerList.
getBackup private ShapeContainer getBackup(String shapeId)
Parameters:
shapeId - The shapeId of an ShapeContainer object
Returns the ShapeContainer object in the BackupContainerList whose shapeId matches to the given shapeId.
undoSetupOfAddOrDelete public void undoSetupOfAddOrDelete(int type, ShapeContainer container)
Parameters:
type - UndoConstants.ADD or UndoConstants.DELETE.
container - The ShapeContainer object.
Processing:
This method performs the operation of the undo setup for adding the container to the ContainerList and for deleting container from the ContainerList. The details are as follow.
This method is called by the addContainer method, the deleteContainer method and their family methods if the undoSetup field is true.
If this method is called by the addContainer method and its family method, this method creates a new UndoableDrawEdit.CreateContainer object and registers it to the UndoDrawManager.
And if this method is called by the deleteContainer method and its family method, this method creates a new UndoableDrawEdit.DeleteContainer object and registers it to the UndoDrawManager.
undoSetupEnd public void undoSetupEnd()
This method declares ending undo setup and performs the operation of the undo setup for an changed ShapeContainer object. The undo setup for adding or deleting and ShapeContainer is done by the undoSetupOfAddOrDelete method, therefore this method sets up other types of changes. The types of changes are defined in the UndoConstants class. If a change occurs in an ShapeContainer, a TextBox or a PaintStyle, then the corresponding method sets the change code by using the setChangeCode method of the ShapeContainer. Then this method calls the appropriate method according to the change code.
∙ If the change is UndoConstants.CONTAINER, SHAPE, or SIZE_POSITION, then calls the undoSetupEndOfContainer method.
∙ If the change is UndoConstants.TEXTBOX, then calls the undoSetupEndOfTextBox method.
∙ If the change is UndoConstants.PAINTSTYLE, then calls the undoSetupEndOfPaintStyle method.
Finally, this method clears the undoSetup field, undoEdit field and the BackupContainerList.
undoSetupEndOfContainer private boolean undoSetupEndOfContainer(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Gets the clone of the container - the ShapeContainer object before changed - rom the BackupContainerList. Then creates a new UndoableDrawEdit.ChangeContainer object for the container and its clone, and adds it to the UndoDrawManager.
: The container allows to be a group object.
undoSetupEndOfTextBox private boolean undoSetupEndOfTextBox(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Gets the clone of the container from the BackupContainerList and gets all the TextBox objects of the child ShapeContainer objects of the container by the getGroupedTextBoxes method. Also gets the clones of the TextBox objects by the getGroupedTextBox method of the clone of the container.
Then creates a new UndoableDrawEdit.ChangeTextBox object for all the TextBox objects and their clones, and adds them to the UndoDrawManager.
: The container allows to be a group object.
undoSetupEndOfPaintStyle private boolean undoSetupEndOfPaintStyle(ShapeContainer container)
Parameters:
container - The ShapeContainer object.
Processing:
Gets the clone of the container from the BackupContainerList and gets all the TextBox objects of the child ShapeContainer objects of the container by the getGroupedPaintStyles method. Also gets the clones of the TextBox objects by the getGroupedPaintStyle method of the clone of the container.
Then creates a new UndoableDrawEdit.ChangePaintStyle object for all the PaintStyle objects and their clones, and adds them to the UndoDrawManager.
: The container allows to be a group object.
printContainers public void printContainers()
This method is for debug. Prints out all the ShapeContainer object in the ContainerList.
toString public String toString()
Returns the string representing this object. The string is the print out of the printContainers methods.


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