-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAddLazyJavaClassAction.java
More file actions
84 lines (64 loc) · 1.94 KB
/
AddLazyJavaClassAction.java
File metadata and controls
84 lines (64 loc) · 1.94 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package actions;
import java.awt.Dimension;
import javax.swing.JOptionPane;
import actions.edit.undoredo.SharedUndoRedoActionManager;
import actions.edit.undoredo.UndoRedoableInterface;
import actions.menu.ActionsMenuBarTitles;
import actions.menu.PaintActionMenuItem;
import paintcomponents.java.lazy.ClassPaintComponent;
import ui.PaintPanel;
import ui.helper.ClassSearchFrame;
import ui.helper.ClassSearchFrameDelegateInterface;
/**
* Add a lazily evaluated java class component
* @author chenzb
*
*/
public class AddLazyJavaClassAction extends PaintAction {
public AddLazyJavaClassAction(PaintPanel panel) {
super(panel);
}
@Override
public boolean canPerformAction() {
return true;
}
@Override
public void performAction() {
ClassSearchFrame classSearchFrame = new ClassSearchFrame();
classSearchFrame.setDelegate(new ClassSearchFrameDelegateInterface() {
@Override
public void didSelectClass(String classname) {
try {
Class classObj = Class.forName(classname);
ClassPaintComponent comp = new ClassPaintComponent(classObj,
panel.getWidth() / 2, panel.getHeight() / 2);
panel.addPaintComponent(comp);
// add action to undo redo manager
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
@Override
public void undoAction() {
comp.remove(panel);
panel.repaint();
}
@Override
public void redoAction() {
panel.addPaintComponent(comp);
panel.repaint();
}
});
panel.repaint();
} catch (ClassNotFoundException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(panel,
classname + " :: Class Not Found");
}
}
});
classSearchFrame.setVisible(true);
classSearchFrame.setSize(new Dimension(300, 200));
}
@Override
public String locationString() {
return ActionsMenuBarTitles.Lazy().Add().Java_Class().toString();
}
}