Skip to content

Commit 820f082

Browse files
authored
Merge pull request #52 from UCSDOalads/addBugsByXiaoquan
Remove undo redo methods in interpreter
2 parents b98205a + 051994d commit 820f082

File tree

6 files changed

+21
-188
lines changed

6 files changed

+21
-188
lines changed

src/script/InterpreterAddActions.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import javax.swing.JOptionPane;
44
import paintcomponents.TextPaintComponent;
5+
import actions.AddLazyJavaClassAction;
6+
import actions.AddTextBoxAction;
57
import actions.edit.undoredo.SharedUndoRedoActionManager;
68
import actions.edit.undoredo.UndoRedoableInterface;
79
import ui.PaintPanel;
@@ -56,27 +58,8 @@ public InterpreterAddActions(Tokenizer tokenizer, PaintPanel panel)
5658
}
5759

5860
private PaintComponent performAddTextBox() {
59-
String s = JOptionPane.showInputDialog("Please enter the text to display");
60-
TextPaintComponent comp = new TextPaintComponent(s, panel.getWidth() / 2,
61-
panel.getHeight() / 2);
62-
panel.addPaintComponent(comp);
63-
// push action to the manager
64-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(
65-
new UndoRedoableInterface() {
66-
67-
@Override
68-
public void undoAction() {
69-
comp.remove(panel);
70-
panel.repaint();
71-
}
72-
73-
@Override
74-
public void redoAction() {
75-
panel.addPaintComponent(comp);
76-
panel.repaint();
77-
}
78-
});
79-
panel.repaint();
80-
return comp;
61+
AddTextBoxAction action = new AddTextBoxAction(panel);
62+
action.performAction();
63+
return panel.getPaintComponents().get(panel.getPaintComponents().size() -1);
8164
}
8265
}

src/script/InterpreterAddData.java

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import paintcomponents.data.DataDisplayPaintComponent;
55
import paintcomponents.data.DataInputTextfieldPaintComponent;
66
import ui.PaintPanel;
7-
7+
import actions.AddDataDisplayBoxAction;
8+
import actions.AddDataInputBoxAction;
9+
import actions.AddTextBoxAction;
810
import actions.edit.undoredo.SharedUndoRedoActionManager;
911
import actions.edit.undoredo.UndoRedoableInterface;
1012

@@ -47,53 +49,14 @@ public InterpreterAddData(Tokenizer tokenizer, PaintPanel panel)
4749
}
4850

4951
private PaintComponent performAddDisplayBoxAction() {
50-
DataDisplayPaintComponent comp = new DataDisplayPaintComponent(
51-
"Data Display", panel.getWidth() / 2, panel.getHeight() / 2);
52-
panel.addPaintComponent(comp);
53-
54-
// push action to manager
55-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(
56-
new UndoRedoableInterface() {
57-
58-
@Override
59-
public void undoAction() {
60-
comp.remove(panel);
61-
panel.repaint();
62-
}
63-
64-
@Override
65-
public void redoAction() {
66-
panel.addPaintComponent(comp);
67-
panel.repaint();
68-
}
69-
});
70-
panel.repaint();
71-
return comp;
52+
AddDataDisplayBoxAction action = new AddDataDisplayBoxAction(panel);
53+
action.performAction();
54+
return panel.getPaintComponents().get(panel.getPaintComponents().size() -1);
7255
}
7356

7457
private PaintComponent performAddInputBoxAction() {
75-
DataInputTextfieldPaintComponent comp = new DataInputTextfieldPaintComponent(
76-
"Data Input", panel.getWidth() / 2, panel.getHeight() / 2);
77-
panel.addPaintComponent(comp);
78-
79-
// push action to the manager
80-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(
81-
new UndoRedoableInterface() {
82-
83-
@Override
84-
public void undoAction() {
85-
comp.remove(panel);
86-
panel.repaint();
87-
}
88-
89-
@Override
90-
public void redoAction() {
91-
panel.addPaintComponent(comp);
92-
panel.repaint();
93-
94-
}
95-
});
96-
panel.repaint();
97-
return comp;
58+
AddTextBoxAction action = new AddTextBoxAction(panel);
59+
action.performAction();
60+
return panel.getPaintComponents().get(panel.getPaintComponents().size() -1);
9861
}
9962
}

src/script/InterpreterAddLazy.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,7 @@ private PaintComponent performAddJavaClassAction() {
115115
Class classObj = Class.forName(className);
116116
ClassPaintComponent comp = new ClassPaintComponent(classObj, panel.getWidth() / 2, panel.getHeight() / 2);
117117
panel.addPaintComponent(comp);
118-
// add action to undo redo manager
119-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
120118

121-
@Override
122-
public void undoAction() {
123-
comp.remove(panel);
124-
panel.repaint();
125-
}
126-
127-
@Override
128-
public void redoAction() {
129-
panel.addPaintComponent(comp);
130-
panel.repaint();
131-
}
132-
});
133119
panel.repaint();
134120
return comp;
135121
} catch (ClassNotFoundException e) {
@@ -147,21 +133,7 @@ private PaintComponent performAddJavaConstructorAction() {
147133
ClassConstructorPaintComponent consComp = new ClassConstructorPaintComponent(cons[desiaredConstructorIndex],
148134
panel.getWidth() / 2, panel.getHeight() / 2);
149135
panel.addPaintComponent(consComp);
150-
// add action to undo redo manager
151-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
152136

153-
@Override
154-
public void undoAction() {
155-
consComp.remove(panel);
156-
panel.repaint();
157-
}
158-
159-
@Override
160-
public void redoAction() {
161-
panel.addPaintComponent(consComp);
162-
panel.repaint();
163-
}
164-
});
165137
panel.repaint();
166138
return consComp;
167139
}
@@ -179,20 +151,7 @@ private PaintComponent performAddJavaFieldsComponentAction() {
179151
FieldsPaintComponent fieldsComp = new FieldsPaintComponent(classComp.getDisplayingClass(), panel.getWidth() / 2,
180152
panel.getHeight() / 2);
181153
panel.addPaintComponent(fieldsComp);
182-
// push action to the manager
183-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
184154

185-
@Override
186-
public void undoAction() {
187-
fieldsComp.remove(panel);
188-
}
189-
190-
@Override
191-
public void redoAction() {
192-
panel.addPaintComponent(fieldsComp);
193-
194-
}
195-
});
196155
panel.repaint();
197156
return fieldsComp;
198157
}
@@ -205,21 +164,7 @@ private PaintComponent performAddJavaMethodComponentAction() {
205164
MethodPaintComponent methodComp = new MethodPaintComponent(methods[desiaredConstructorIndex], panel.getWidth() / 2,
206165
panel.getHeight() / 2);
207166
panel.addPaintComponent(methodComp);
208-
// add action to undo redo manager
209-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
210167

211-
@Override
212-
public void undoAction() {
213-
methodComp.remove(panel);
214-
panel.repaint();
215-
}
216-
217-
@Override
218-
public void redoAction() {
219-
panel.addPaintComponent(methodComp);
220-
panel.repaint();
221-
}
222-
});
223168
panel.repaint();
224169
return methodComp;
225170
}

src/script/InterpreterFileActions.java

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
import org.xml.sax.SAXException;
1111

12+
import actions.AddLazyJavaClassAction;
13+
import actions.FileOpen;
14+
import actions.FileSaveAs;
1215
import file.PanelIO;
1316
import ui.PaintPanel;
1417

@@ -50,29 +53,12 @@ public InterpreterFileActions(Tokenizer tokenizer, PaintPanel panel)
5053
}
5154

5255
private void performOpen(PaintPanel panel2) {
53-
String filePath = JOptionPane.showInputDialog("Please input file path");
54-
PanelIO io = new PanelIO();
55-
try {
56-
io.constructPanelFromDocument(panel, filePath, true);
57-
panel.repaint();
58-
} catch (ParserConfigurationException | SAXException | IOException
59-
| ClassNotFoundException | NoSuchMethodException
60-
| SecurityException | InstantiationException
61-
| IllegalAccessException | IllegalArgumentException
62-
| InvocationTargetException e) {
63-
e.printStackTrace();
64-
JOptionPane.showMessageDialog(panel, e.toString());
65-
}
56+
FileOpen action = new FileOpen(panel);
57+
action.performAction();
6658
}
6759

6860
private void performSaveAs(PaintPanel panel2) {
69-
String filePath = JOptionPane.showInputDialog("Please input file path");
70-
PanelIO io = new PanelIO();
71-
try {
72-
io.constructDocumentFromPanel(panel, filePath);
73-
} catch (ParserConfigurationException | TransformerException e) {
74-
e.printStackTrace();
75-
JOptionPane.showMessageDialog(panel, e.toString());
76-
}
61+
FileSaveAs action = new FileSaveAs(panel);
62+
action.performAction();
7763
}
7864
}

src/script/InterpreterRemoveAction.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,6 @@ private void performRemoveSelected() {
4646
}
4747
}
4848

49-
// push action to the manager
50-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
51-
52-
@Override
53-
public void undoAction() {
54-
for (PaintComponent comp : comps)
55-
panel.addPaintComponent(comp);
56-
}
57-
58-
@Override
59-
public void redoAction() {
60-
for (PaintComponent comp : comps)
61-
comp.remove(panel);
62-
}
63-
});
6449
panel.repaint();
6550
}
6651
}

src/script/InterpreterUpdateActions.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,7 @@ public InterpreterUpdateActions(Tokenizer tokenizer, PaintPanel panel) throws Ex
6767
private void performUpdateDataBox() {
6868
try {
6969
((DataDisplayPaintComponent) comp).updateDisplayText();
70-
// push action to the manager
71-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
7270

73-
public void undoAction() {
74-
comp.remove(panel);
75-
panel.repaint();
76-
if (ComponentMap.map.containsValue(comp)) {
77-
78-
}
79-
}
80-
81-
public void redoAction() {
82-
panel.addPaintComponent(comp);
83-
panel.repaint();
84-
}
85-
});
8671
panel.repaint();
8772
} catch (NoSuchElementException | NoConnectingLineSegmentException | DataFromPointNoDataProviderException
8873
| DataFromPointProviderCannotProvideDataException e) {
@@ -95,21 +80,7 @@ public void redoAction() {
9580
private void performUpdateinputBox() {
9681
String s = JOptionPane.showInputDialog("Please specify the message to push to the data input");
9782
((DataInputTextfieldPaintComponent) comp).inputData(s);
98-
// add action to undo redo manager
99-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
100-
101-
@Override
102-
public void undoAction() {
103-
comp.remove(panel);
104-
panel.repaint();
105-
}
10683

107-
@Override
108-
public void redoAction() {
109-
panel.addPaintComponent(comp);
110-
panel.repaint();
111-
}
112-
});
11384
panel.repaint();
11485
}
11586
}

0 commit comments

Comments
 (0)