Java Drawing DrawTop

Language

JP  US  UK

 

 H. Jyounishi, Tokyo Japan
 Undo, Redo

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

Summary: This page describes the javax.swing.undo.UndoableEdit objects for the operations of creating, deleting and changing shape objects or text objects.

Classes on this page: UndoConstants, UndoDrawManager, UndoableDrawEdit
Sub classes of the UndoableDrawEditDelimiter, ChangeContainer, CreateContainer, DeleteContainer, ChangeTextBox, ChangePaintStyle, InsertText, DeleteText
Important issue: The undo setup for each command

1. Class UndoConstants return=>page top

public class UndoConstants

This class defines the type of a change.


Field

Description

ADD

public static final int ADD

This number represents that a new ShapeContainer object was created and registered in the ContainerList.

DELETE

public static final int DELETE

This number represents that an ShapeContainer object was removed from the ContainerList.

CONTAINER

public static final int CONTAINER

This number represents that some changes were done to an ShapeContainer.

SHAPE

public static final int SHAPE

This number represents that the shape data of an ShapeContainer was changed.

SIZE_POSITION

public static final int SIZE_POSITION

This number represents that the shape position or size of an ShapeContainer was changed.

TEXTBOX

public static final int TEXTBOX

This number represents that the TextBox object of an ShapeContainer was changed.

PAINTSTYLE

public static final int PAINTSTYLE

This number represents that the PaintStyle object of an ShapeContainer was changed.



2. Class UndoDrawManager return=>page top

public class UndoDrawManager extends UndoManager


Method

Description

Constructor

public UndoDrawManager(int id)

super();

addEdit

public boolean addEdit(UndoableEdit anEdit)

Calls the addEdit method of the super class and changeButtonState method.

canUndo

public boolean canUndo()

Returns true if edits may be undone.
This is the method of Java Standard Edition UndoManager class.

discardAllEdits

public void discardAllEdits()

Calls the discardAllEdits method of the super class and changeButtonState method.

undo

public void undo()

Calls the undo method of the super class until the Delimiter object appears.

redo

public void redo()

Calls the redo method of the super class until the Delimiter object appears.

changeButtonState

protected void changeButtonState()

Calls the setEnable method of the undo/redo button on the tool bar to change the appearance of the button.

If undoable/redoable edits remain, then calls the setEnable method with true, otherwise with false.



3. Class UndoableDrawEdit return=>page top

public class UndoableDrawEdit extends AbstractUndoableEdit


3.1 Subclass Delimiter return=>page top

public static class Delimiter extends AbstractUndoableEdit

The Delimiter object is prepared so that when the undo method is called, the UndoDrawManager executes multiple undoable edits between the current Delimiter and the next Delimiter.


Method

Description

Constructor

public Delimiter()

Creates a new object of this class.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "Delimiter".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "Delimiter".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

Calls the undo method of the super class.

redo

public void redo() throws CannotRedoException

Calls the redo method of the super class.

toString

public String toString()

Returns the "Delimiter".


3.2 Subclass ChangeContainer return=>page top

public static class ChangeContainer extends AbstractUndoableEdit

This object represents a change made to the shape object (ShapeContainer) by setting the shape data before the change and after the change to this object.


Field

Description

oldData

SerializableElement oldData

Sets the SerializableElement object before the ShapeContainer object is changed. The ShapeContainer can be a group.

newData

SerializableElement newData

Sets the SerializableElement object after the ShapeContainer object was changed. The ShapeContainer can be a group.


Method

Description

Constructor

public ChangeContainer(ShapeContainer oldContainer, ShapeContainer newContainer)

Converts the oldContainer and the newContainer to the SerializableElement objects by the SerializableElementUtil.convertShapeContainer method and sets them to the oldData and newData fields.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "ChangeContainer Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "ChangeContainer Undo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId of the oldData.

∙ Sets the newData to the ShapeContainer object by the SerializableElementUtil.setToShapeContainer method.

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId of the newData.

∙ Sets the oldData to the ShapeContainer object by the SerializableElementUtil.setToShapeContainer method.



3.3 Subclass CreateContainer return=>page top

public static class CreateContainer extends AbstractUndoableEdit

This object represents a edit of creating a shape object (ShapeContainer).


Field

Description

data

SerializableElement data

Sets the SerializableElement object representing the ShapeContainer which was created.


Method

Description

Constructor

public CreateContainer(ShapeContainer container)

Converts the container to the SerializableElement objects by the SerializableElementUtil.convertShapeContainer method and sets it to the data field.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "CreateContainer Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "CreateContainer Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId of the data.

∙ Removes the ShapeContainer object from the ContainerList by the ContainerManager.deleteContainer.

redo

public void redo() throws CannotRedoException

∙ Creates the new ShapeContainer object from the data by the SerializableElementUtil.invertShapeContainer method.

∙ Adds the new ShapeContainer object to the ContainerList by the ContainerManager.addContainer method.

manager.addContainer(container.getContainerIndex(), container);



3.4 Subclass DeleteContainer return=>page top

public static class DeleteContainer extends AbstractUndoableEdit

This object represents a edit of deleting a shape object (ShapeContainer).


Field

Description

data

SerializableElement data

Sets the SerializableElement object representing the ShapeContainer which was deleted. The ShapeContainer can be a group.


Method

Description

Constructor

public DeleteContainer (ShapeContainer container)

Converts the container to the SerializableElement objects by the SerializableElementUtil.convertShapeContainer method and sets it to the data field.

: Creates this object before delete the container from the ContainerList.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "DeleteContainer Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "DeleteContainer Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Creates the new ShapeContainer object from the data by the SerializableElementUtil.invertShapeContainer method.

∙ Adds the new ShapeContainer object to the ContainerList by the ContainerManager.addContainer method.

manager.addContainer(container.getContainerIndex(), container);

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId of the data.

∙ Removes the ShapeContainer object from the ContainerList by the ContainerManager.deleteContainer.



3.5 Subclass ChangeTextBox return=>page top
public static class ChangeTextBox extends AbstractUndoableEdit

This object represents a change made to a text box (TextBox).


Field

Description

shapeId

String shapeId

The shapeId of the ShapeContainer which owns the TextBox.

oldTextBox

public SerializableTextBox oldTextBox

Sets the SerializableTextBox object before the TextBox object is changed.

newTextBox

public SerializableTextBox newTextBox

Sets the SerializableTextBox object after the TextBox object was changed.


Method

Description

Constructor

public ChangeTextBox(String shapeId, TextBox oldTextBox, TextBox newTextBox)

Sets the parameters to the corresponding fields. Converts the TextBox objects to the the SerializableTextBox objects by the TextBox.getSerializableTextBox method.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Return the "ChangeTextBox Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Return the "ChangeTextBox Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Sets the the oldTextBox data to the to the TextBox of the ShapeContainer by the TextBox.setSerializableTextBox method.

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Sets the the newTextBox data to the to the TextBox of the ShapeContainer by the TextBox.setSerializableTextBox method.



3.6 ChangePaintStyle return=>page top
public static class ChangePaintStyle extends AbstractUndoableEdit

This object represents a change made to a shape drawing data (PaintStyle).


Field

Description

shapeId

String shapeId

The shapeId of the ShapeContainer which owns the PaintStyle.

oldPaintStyle

public SerializablePaintStyle oldPaintStyle

Sets the SerializablePaintStyle object before the PaintStyle object is changed.

newPaintStyle

public SerializablePaintStyle newPaintStyle

Sets the SerializablePaintStyle object after the PaintStyle object was changed.


Method

Description

Constructor

public ChangePaintStyle(String shapeId, PaintStyle oldPaintStyle, PaintStyle newPaintStylee)

Sets the parameters to the corresponding fields. Converts the PaintStyle objects to the the SerializablePaintStyle objects by the PaintStyle.getSerializablePaintStyle method.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "ChangePaintStyle Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "ChangePaintStyle Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Sets the the oldPaintStyle data to the to the PaintStyle of the ShapeContainer by the PaintStyle.setSerializablePaintStyle method.

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Sets the the newPaintStyle data to the to the PaintStyle of the ShapeContainer by the PaintStyle.setSerializablePaintStyle method.



3.7 Subclass ChangeText return=>page top

public static class ChangeText extends AbstractUndoableEdit

This object represents a change made to the committed text of the TextBox.


Field

Description

shapeId

String shapeId

The shapeId of the ShapeContainer which owns the TextBox.

oldStr

AttributedString oldStr

Sets the java.text.AttributedString object before the committed text in the TextBox is changed.

newStr

AttributedString newStr

Sets the java.text.AttributedString object after the committed text in the TextBox was changed.


Method

Description

Constructor

public ChangeText(String shapeId, AttributedString oldStr, AttributedString newStr)

Sets the parameters to the corresponding fields.

getContainer

public ShapeContainer getContainer()

Returns the ShapeContainer object whose shapeId equals shapeId field.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "ChangeText Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "ChangeText Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Calls the replaceText method of the TextBox.

shapeContainer.getTextBox().replaceText(TextBox.UNDO_REDO, this.oldStr)

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Calls the replaceText method of the TextBox.

shapeContainer.getTextBox().replaceText(TextBox.UNDO_REDO, this.newStr)



3.8 Subclass InsertText return=>page top

public static class InsertText extends AbstractUndoableEdit

This object represents the inserted characters to the committed text of the TextBox. Other characters can be added to the inserted characters by using the getContainer, getPosition, setPosition, getAttribString and setAttribString methods.
=> TextUndoSetup.InsertText


Field

Description

shapeId

String shapeId

The shapeId of the ShapeContainer which owns the TextBox.

attribStr

AttributedString attribStr

The inserted AttributedString to the TextBox.

position

int position

The inserted position.


Method

Description

Constructor

public InsertText(String shapeId, AttributedString attribStr, int position)

Sets the parameters to the corresponding fields.

getContainer

public ShapeContainer getContainer()

Returns the ShapeContainer object whose shapeId equals shapeId field.

getPosition

public int getPosition()

Return the position field.

setPosition

public void setPosition(int position)

Sets the parameter to the position field.

getAttribString

public AttributedString getAttribString()

Returns the attribStr field.

setAttribString

public void setAttribString(AttributedString attribStr)

Sets the parameter to the attribStr field.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "InsertText Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "InsertText Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Deletes the attribStr from theTextBox.

shapeContainer.getTextBox().deleteText(TextBox.UNDO_REDO, this.position, this.position+length)

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Inserts the attribStr to theTextBox.

shapeContainer.getTextBox().insertText(TextBox.UNDO_REDO, this.position, this.attribStr.getIterator())



3.9 Subclass DeleteText return=>page top
public static class DeleteText extends AbstractUndoableEdit

This object represents the deleted characters from the committed text of the TextBox. Other characters can be added to the deleted characters by using the getContainer, getPosition, setPosition, getAttribString and setAttribString methods.

=> TextUndoSetup.DeleteText


Field

Description

shapeId

String shapeId

The shapeId of the ShapeContainer which owns the TextBox.

attribStr

AttributedString attribStr

The deleted AttributedString.

position

int position

The deleted position.


Method

Description

Constructor

public DeleteText(String shapeId, AttributedString attribStr, int position)

Sets the parameters to the corresponding fields.

getContainer

public ShapeContainer getContainer()

Returns the ShapeContainer object whose shapeId equals shapeId field.

getPosition

public int getPosition()

Return the position field.

setPosition

public void setPosition(int position)

Sets the parameter to the position field.

getAttribString

public AttributedString getAttribString()

Returns the attribStr field.

setAttribString

public void setAttribString(AttributedString attribStr)

Sets the parameter to the attribStr field.

canUndo

public boolean canUndo()

Returns true always.

canRedo

public boolean canRedo()

Returns true always.

getUndoPresentation
Name

public String getUndoPresentationName()

Returns the "DeleteString Undo".

getRedoPresentation
Name

public String getRedoPresentationName()

Returns the "DeleteString Redo".

isSignificant

public boolean isSignificant()

Returns true always.

undo

public void undo() throws CannotUndoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Inserts the attribStr to theTextBox.

shapeContainer.getTextBox().insertText(TextBox.UNDO_REDO, this.position, this.attribStr.getIterator())

redo

public void redo() throws CannotRedoException

∙ Gets the ShapeContainer object by the getContainer method of the ContainerManager with the parameter of the shapeId.

∙ Deletes the attribStr from theTextBox.

shapeContainer.getTextBox().deleteText(TextBox.UNDO_REDO, this.position, this.position+length)



4. The undo setup for each command return=>page top

Command

Description

File

(NEW, OPEN, SAVE, SAVE, SAVEAS)

Undo setup is unnecessary.

Page setup

(NEXT_PAGE, PREVIOUS_PAGE, INSERT_NEW_PAGE, DELETE_PAGE, PAGE_SETUP, PAGE_LAYOUT)

Undo setup is unnecessary.

Print
(PRINT)

Undo setup is unnecessary.

Editing text

(CUT, COPY, PASTE, DELETE)

Undo setup is done in the deleteText method (CUT, DELETE) and insertText method (PASTE) of the TextBox.
Undo setup is unnecessary for COPY and SELECT_ALL.

Editing shape

(CUT, COPY, PASTE, DELETE, , SELECT_ALL)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the copyContainers(CUT), pasteContainers(PASTE) and delete(DELETE) methods of the Edit.

Undo setup is unnecessary for COPY.

Creating shape

(TEXT_BOX, RECTANGLE, ROUND_RECTANGLE, ELLIPSE, LINE, ARROW, DOUBLE_ARROW, POLYLINE, CUBIC_CURVE, COMPONENT_SHAPE)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the creatingEnd method of the CreateShapeLS.

Component library

(LIB)

Undo setup is unnecessary.

Moving/Resizing shape
(MOVE, RESIZE)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the start and end methods of the MoverResizeShapeLS.

If the resize command is called from the dialog (Shape format dialog), then the undo setup is done in the resizeContainer method of ConnectorUtil.

: Undo setup is done for connectors.

Add text box, Transforming/
Manipulating shape

(ADD_TEXT_BOX, TRANSLATE, ROTATE, FLIP, MODIFY_SHAPE, CUT_SHAPE, CONNECT_CURVES)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the following methods.

∙ ADD_TEXT_BOX: The exec method of the ExecCommand.

∙ TRANSLATE: The actionPerformed method of the TranslateAction.
∙ ROTATE: The actionPerformed method of the RotateAction.
∙ FLIP: The actionPerformed method of the FlipAction.
∙ MODIFY_SHAPE: The start and end methods of the ModifyShapeLS.
∙ CUT_SHAPE: The cutShapes method of the CutShapeAction.
∙ CONNECT_CURVES: The connect method of the ConnectCurvesAction.

Setting
(AUTO_ALIGN, CONNECTOR_ENABLE, DISPLAY_NODE_POINTS)
Undo setup is unnecessary.

Information

(SHAPE_FORMAT, DRAW_PANEL_INFORMATION)

Undo setup is unnecessary.

Font attribute
(FONT_FAMILY, FONT_SIZE, FONT_COLOR, BOLD, ITALIC, UNDERLINE, SUBSCRIPT/SUPERSCRIPT )

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the ExecCommandUtil.setFontStyle method.

Text box
(TEXTBOX_LAYOUT, TEXT_ALIGN)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the following methods.
∙TEXTBOX_LAYOUT: The ExecCommandUtil.setTextBoxLayout method.
∙TEXT_ALIGN: The ExecCommandUtil.setTextBoxLayout method.

Shape attribute

(FILL_COLOR, LINE_COLOR, LINE_WIDTH, LINE_STROKE, ARROW_STYLE)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the exec method of ExecCommand.

Z-order

(MOVE_TO_FRONT, MOVE_TO_BACK, MOVE_FORWARD, MOVE_BACKWARD)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the ExecCommandUtil.moveZorder method.

Align

(ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the ExecCommandUtil.align method.

Group
(GROUP, UNGROUP)

Undo setup is done by calling the undoSetupStart and undoSetupEnd methods of the ContainerManager (undo support function) in the exec method of ExecCommand.

Zoom

(ZOOM, ZOOM_TO)

Undo setup is unnecessary.



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