Skip to content

Commit 505439d

Browse files
committed
Merge branch 'develop' of https://github.com/UCSDOalads/JavaSketchPad into addGlobalFileActions
2 parents 75273af + 7c37f95 commit 505439d

25 files changed

Lines changed: 1904 additions & 267 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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public void undo() {
3333
UndoRedoableInterface undoableAction = undoStack.pop();
3434
undoableAction.undoAction();
3535
redoStack.add(undoableAction);
36-
delegate.didUndoAction(undoableAction);
36+
if (delegate != null) {
37+
delegate.didUndoAction(undoableAction);
38+
}
3739
}
3840
else {
3941
System.out.println("empty undo stack");
@@ -45,12 +47,13 @@ public void redo() {
4547
UndoRedoableInterface redoableAction = redoStack.pop();
4648
redoableAction.redoAction();
4749
undoStack.add(redoableAction);
48-
delegate.didRedoAction(redoableAction);
50+
if (delegate != null) {
51+
delegate.didRedoAction(redoableAction);
52+
}
4953
}
5054
else {
5155
System.out.println("empty redo stack");
5256
}
53-
5457
}
5558

5659
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+
}

src/painttools/toolbar/ToolBar.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,51 @@
11
package painttools.toolbar;
22

3-
import java.awt.Button;
4-
import java.awt.Component;
5-
import java.awt.Graphics;
63
import java.awt.event.ActionEvent;
74
import java.awt.event.ActionListener;
85
import java.util.ArrayList;
96

107
import javax.swing.BoxLayout;
11-
import javax.swing.Icon;
128
import javax.swing.JButton;
139
import javax.swing.JPanel;
14-
import javax.tools.Tool;
1510

16-
import painttools.tools.*;
11+
import painttools.tools.AddClassTool;
12+
import painttools.tools.AddInputBoxTool;
13+
import painttools.tools.AddOutputBoxTool;
14+
import painttools.tools.DotTool;
15+
import painttools.tools.LineTool;
16+
import painttools.tools.PaintTool;
17+
import painttools.tools.SelectTool;
1718
import ui.PaintPanel;
19+
import ui.ShortcutHandler;
1820

1921
public class ToolBar extends JPanel {
2022

2123
public ArrayList<ToolBarListener> listeners;
2224
private SelectTool selectTool;
23-
25+
private PaintPanel panel;
26+
2427
/**
2528
* Creates a default toolbar and add necessary tools
2629
*/
2730
public ToolBar(PaintPanel panel) {
2831
listeners = new ArrayList<>();
32+
this.panel = panel;
2933

3034
//sets the box layout
3135
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
3236

3337
selectTool = new SelectTool(panel);
3438
addTool(new DotTool());
3539
addTool(selectTool);
40+
41+
42+
addTool(new AddClassTool(panel));
43+
addTool(new AddInputBoxTool(panel));
44+
addTool(new AddOutputBoxTool(panel));
45+
3646
addTool(new LineTool());
47+
48+
this.addKeyListener(new ShortcutHandler(panel));
3749
}
3850

3951
/**
@@ -75,7 +87,6 @@ private void select(PaintTool tool) {
7587
public SelectTool getSelectTool() {
7688
return selectTool;
7789
}
78-
7990

80-
91+
8192
}

0 commit comments

Comments
 (0)