-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAddLazyJavaFieldsComponentAction.java
More file actions
65 lines (56 loc) · 1.62 KB
/
AddLazyJavaFieldsComponentAction.java
File metadata and controls
65 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package actions;
import actions.edit.undoredo.SharedUndoRedoActionManager;
import actions.edit.undoredo.UndoRedoableInterface;
import actions.menu.ActionsMenuBarTitles;
import paintcomponents.java.lazy.ClassPaintComponent;
import paintcomponents.java.lazy.FieldsPaintComponent;
import ui.PaintPanel;
/**
* Add a Java Fileds Component
* @author chenzb
*
*/
public class AddLazyJavaFieldsComponentAction extends PaintAction {
public AddLazyJavaFieldsComponentAction(PaintPanel panel) {
super(panel);
}
//TODO
//NOTE: I am copying from Constructor and Methods, consider refinement
@Override
public boolean canPerformAction() {
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
return false;
}
if (panel.getSelectTool().getSelectedComponents()
.get(0) instanceof ClassPaintComponent) {
return true;
}
return false;
}
@Override
public void performAction() {
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
.getSelectedComponents().get(0);
FieldsPaintComponent fieldsComp =
new FieldsPaintComponent(comp.getDisplayingClass(),
panel.getWidth() / 2,
panel.getHeight() / 2);
panel.addPaintComponent(fieldsComp);
//push action to the manager
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
@Override
public void undoAction() {
fieldsComp.remove(panel);
}
@Override
public void redoAction() {
panel.addPaintComponent(fieldsComp);
}
});
panel.repaint();
}
@Override
public String locationString() {
return ActionsMenuBarTitles.Lazy().Add().Java_Fields().toString();
}
}