Skip to content

Commit 4a84caa

Browse files
authored
Merge pull request #98 from UCSDOalads/addRedobyDYB
Add redoby dyb, ignoring Travis Junit fail for now
2 parents 7c33c4b + 8451363 commit 4a84caa

8 files changed

Lines changed: 1016 additions & 9 deletions

?/.java/fonts/1.8.0_121/fcinfo-1-its-cseb260-18.ucsd.edu-null-null-en.properties

Lines changed: 834 additions & 0 deletions
Large diffs are not rendered by default.

src/actions/RedoActionTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package actions;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
import ui.PaintPanel;
9+
import actions.global.ActionName;
10+
import actions.global.GlobalPaintActionExecuter;
11+
import actions.global.globalactions.AddLazyJavaClassGlobalAction;
12+
13+
/**
14+
* RedoActionTest
15+
*
16+
* @author DYB Test the functionality of redo
17+
*/
18+
public class RedoActionTest {
19+
20+
@Test
21+
public void test() {
22+
PaintPanel panel = new PaintPanel();
23+
24+
// perform one action
25+
AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION
26+
.getAssiciatedAction();
27+
action.setClassToCreate(this.getClass());
28+
GlobalPaintActionExecuter.getSharedInstance().execute(action, panel);
29+
30+
// new redo action
31+
RedoAction action1 = new RedoAction(panel);
32+
33+
// determine whether can redo or not
34+
assertFalse(action1.canPerformAction());
35+
// do an undo action
36+
37+
new UndoAction(panel).performAction();
38+
// can redo now
39+
assertTrue(action1.canPerformAction());
40+
// do a redo
41+
action1.performAction();
42+
// cannot redo
43+
assertFalse(action1.canPerformAction());
44+
45+
46+
}
47+
48+
}

src/actions/UndoActionTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package actions;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
import ui.PaintPanel;
9+
import actions.global.ActionName;
10+
import actions.global.GlobalPaintActionExecuter;
11+
import actions.global.globalactions.AddLazyJavaClassGlobalAction;
12+
13+
/**
14+
* UndoActionTest
15+
*
16+
* @author DYB Test the functionality of undo
17+
*/
18+
public class UndoActionTest {
19+
20+
@Test
21+
public void test() {
22+
PaintPanel panel = new PaintPanel();
23+
24+
// perform one action
25+
AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION
26+
.getAssiciatedAction();
27+
action.setClassToCreate(this.getClass());
28+
GlobalPaintActionExecuter.getSharedInstance().execute(action, panel);
29+
30+
// new undo action
31+
UndoAction action1 = new UndoAction(panel);
32+
// determine whether can undo or not
33+
assertTrue(action1.canPerformAction());
34+
// perform one undo action
35+
action1.performAction();
36+
// determine again whether can undo or not
37+
assertFalse(action1.canPerformAction());
38+
39+
}
40+
41+
}

src/actions/edit/undoredo/SharedUndoRedoActionManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public void redo() {
5050
else {
5151
System.out.println("empty redo stack");
5252
}
53-
5453
}
5554

5655
public boolean canUndo() {
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package actions.global.globalactions;
22

3-
import actions.global.GlobalPaintAction;
43
import ui.PaintPanel;
4+
import actions.edit.undoredo.SharedUndoRedoActionManager;
5+
import actions.global.GlobalPaintAction;
56

67
public class EditRedoGlobalAction extends GlobalPaintAction {
7-
8+
SharedUndoRedoActionManager manager = SharedUndoRedoActionManager
9+
.getSharedInstance();
810
@Override
911
protected void execute(PaintPanel panel) {
10-
// TODO Auto-generated method stub
11-
12+
manager.redo();
1213
}
1314

1415
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package actions.global.globalactions;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
import ui.PaintPanel;
8+
import actions.global.ActionName;
9+
import actions.global.GlobalPaintActionExecuter;
10+
11+
/**
12+
* EditUndoActionTest
13+
*
14+
* @author cs30xsd Test the functionality of global undo
15+
*/
16+
public class EditUndoActionTest {
17+
18+
@Test
19+
public void test() {
20+
PaintPanel panel = new PaintPanel();
21+
22+
// perform one action
23+
AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION
24+
.getAssiciatedAction();
25+
action.setClassToCreate(this.getClass());
26+
GlobalPaintActionExecuter.getSharedInstance().execute(action, panel);
27+
28+
// new undo action
29+
EditRedoGlobalAction action1 = new EditRedoGlobalAction();
30+
EditUndoGlobalAction action2 = new EditUndoGlobalAction();
31+
32+
assertEquals(1, panel.getPaintComponents().size());
33+
// perform one undo action
34+
action2.execute(panel);
35+
assertEquals(0, panel.getPaintComponents().size());
36+
action1.execute(panel);
37+
assertEquals(1, panel.getPaintComponents().size());
38+
action2.execute(panel);
39+
assertEquals(0, panel.getPaintComponents().size());
40+
}
41+
42+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package actions.global.globalactions;
22

3-
import actions.global.GlobalPaintAction;
43
import ui.PaintPanel;
4+
import actions.edit.undoredo.SharedUndoRedoActionManager;
5+
import actions.global.GlobalPaintAction;
56

67
public class EditUndoGlobalAction extends GlobalPaintAction {
7-
8+
SharedUndoRedoActionManager manager = SharedUndoRedoActionManager
9+
.getSharedInstance();
810
@Override
911
protected void execute(PaintPanel panel) {
10-
// TODO Auto-generated method stub
11-
12+
manager.undo();
1213
}
1314

1415
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package actions.global.globalactions;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
import ui.PaintPanel;
8+
import actions.global.ActionName;
9+
import actions.global.GlobalPaintActionExecuter;
10+
11+
/**
12+
* RedoActionGlobalTest
13+
*
14+
* @author cs30xsd Test the functionality of global redo action
15+
*
16+
*/
17+
public class RedoActionGlobalTest {
18+
19+
@Test
20+
public void test() {
21+
PaintPanel panel = new PaintPanel();
22+
23+
// perform one action
24+
AddLazyJavaClassGlobalAction action = (AddLazyJavaClassGlobalAction) ActionName.ADD_LAZY_JAVA_CLASS_ACTION
25+
.getAssiciatedAction();
26+
action.setClassToCreate(this.getClass());
27+
GlobalPaintActionExecuter.getSharedInstance().execute(action, panel);
28+
29+
// new redo action
30+
EditRedoGlobalAction action1 = new EditRedoGlobalAction();
31+
EditUndoGlobalAction action2 = new EditUndoGlobalAction();
32+
33+
assertEquals(1, panel.getPaintComponents().size());
34+
// perform one redo action
35+
action2.execute(panel);
36+
assertEquals(0, panel.getPaintComponents().size());
37+
action1.execute(panel);
38+
assertEquals(1, panel.getPaintComponents().size());
39+
}
40+
41+
}

0 commit comments

Comments
 (0)