Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Undo/redo is genctally implemented using stacks of objects that have redo and undo methods. These operations can be expressed by the following abstract data type:

image text in transcribed
image text in transcribed
image text in transcribed
Undo/redo is genctally implemented using stacks of objects that have redo and undo methods. These operations can be expressed by the following abstract data type: * An abstract data type to perform (redo) an edit action together with a method to undo the action. Bauthor dtsmith public interface EditAction { Perform some edit action public void redo(); Undo the effects of the edit action public void undo(); 3 The strategy is to modify methods that change the state of an object to first create an EditAction object with sufficient information to perform the change and to undo the change. These EditAction objects are pushed onto an undo stack. For example take the setX(int x) method The following is a SetXEditAction can perform the redo and undo actions: private class SetxEditAction implements EditAction int original; int news: public SetxEditAction(int originelx, int new) super) this.original originalX; this.neXheX; hp amat. Some content might be missing or displayed improperly. 3 private class SetxEditAction implements EditAction { int originalX; int newx; public SetxEditAction(int originalx, int newx) { super(); this.originalx = originalx; this.newX = new; 3 public void redo(){ PtrBrawobject. this.x - newX; } 1 public void undo) Ptr Drawobject. this.x - originalx; } 7 The redo will set the x of an object with its new value, the undo will set the x back to its original value. The setX method will now create a SetXEditAction object and then call a method to execute it, which is call the redo method: public void setX(int x) { editor.executeEditAction(new SetxEditAction(getX(), )); 3 The executeditAction will in addition to calling the EditAction's redo method, push the EditAction onto an undo stack of EditActions An undo method of the editor will pop EditActions from the undo stack, call the undo method on the EditAction and add the EditAction to the redo stack. A redo method of the editor does the reverse Tittain e. Pod ment's format. Some content might be missing or displayed improperly, 1 23 this.newx - new } public void redo) Project.this.x = newx; } public void undo) PtrOran Object.this.x - originalx; } The redo will set the x of an object with its new value, the mdo will set the x back to its original value. The setX method will now create a SetXEditAction object and then call a method to execute it, which is call the redo method public void setX(int x) { editor.executeEditAction(new SetxEditAction(getX(), x)); The executeditAction will in addition to calling the EditAction's redo method, push the EditAction onto an undo stack of EditActions An undo method of the editor will pop EditActions from the undo stack, call the undo method on the EditAction, and add the EditAction to the redo stack. A redo method of the editor does the reverse Updates in the editor may generate a number of EditActions that are pushed onto the stack To have these grouped together and processed as one unit, nulls are pushed and popped to delimit cach group of EditActions The painter program has been updated with some of the undo redo code Further steps are needed to complete this task Follow these steps carefully ew hp Undo/redo is genctally implemented using stacks of objects that have redo and undo methods. These operations can be expressed by the following abstract data type: * An abstract data type to perform (redo) an edit action together with a method to undo the action. Bauthor dtsmith public interface EditAction { Perform some edit action public void redo(); Undo the effects of the edit action public void undo(); 3 The strategy is to modify methods that change the state of an object to first create an EditAction object with sufficient information to perform the change and to undo the change. These EditAction objects are pushed onto an undo stack. For example take the setX(int x) method The following is a SetXEditAction can perform the redo and undo actions: private class SetxEditAction implements EditAction int original; int news: public SetxEditAction(int originelx, int new) super) this.original originalX; this.neXheX; hp amat. Some content might be missing or displayed improperly. 3 private class SetxEditAction implements EditAction { int originalX; int newx; public SetxEditAction(int originalx, int newx) { super(); this.originalx = originalx; this.newX = new; 3 public void redo(){ PtrBrawobject. this.x - newX; } 1 public void undo) Ptr Drawobject. this.x - originalx; } 7 The redo will set the x of an object with its new value, the undo will set the x back to its original value. The setX method will now create a SetXEditAction object and then call a method to execute it, which is call the redo method: public void setX(int x) { editor.executeEditAction(new SetxEditAction(getX(), )); 3 The executeditAction will in addition to calling the EditAction's redo method, push the EditAction onto an undo stack of EditActions An undo method of the editor will pop EditActions from the undo stack, call the undo method on the EditAction and add the EditAction to the redo stack. A redo method of the editor does the reverse Tittain e. Pod ment's format. Some content might be missing or displayed improperly, 1 23 this.newx - new } public void redo) Project.this.x = newx; } public void undo) PtrOran Object.this.x - originalx; } The redo will set the x of an object with its new value, the mdo will set the x back to its original value. The setX method will now create a SetXEditAction object and then call a method to execute it, which is call the redo method public void setX(int x) { editor.executeEditAction(new SetxEditAction(getX(), x)); The executeditAction will in addition to calling the EditAction's redo method, push the EditAction onto an undo stack of EditActions An undo method of the editor will pop EditActions from the undo stack, call the undo method on the EditAction, and add the EditAction to the redo stack. A redo method of the editor does the reverse Updates in the editor may generate a number of EditActions that are pushed onto the stack To have these grouped together and processed as one unit, nulls are pushed and popped to delimit cach group of EditActions The painter program has been updated with some of the undo redo code Further steps are needed to complete this task Follow these steps carefully ew hp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions