Skip to content

Commit badb174

Browse files
authored
Merge pull request #30 from UCSDOalads/addTESTbylhwlyd1
Integrate the search class frame to the add lazy class function
2 parents fd9874b + da40931 commit badb174

3 files changed

Lines changed: 47 additions & 28 deletions

File tree

src/actions/AddLazyJavaClassAction.java

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package actions;
22

3+
import java.awt.Dimension;
4+
35
import javax.swing.JOptionPane;
46

57
import actions.edit.undoredo.SharedUndoRedoActionManager;
@@ -8,6 +10,8 @@
810
import actions.menu.PaintActionMenuItem;
911
import paintcomponents.java.lazy.ClassPaintComponent;
1012
import ui.PaintPanel;
13+
import ui.helper.ClassSearchFrame;
14+
import ui.helper.ClassSearchFrameDelegateInterface;
1115

1216
public class AddLazyJavaClassAction extends PaintAction {
1317

@@ -19,37 +23,51 @@ public AddLazyJavaClassAction(PaintPanel panel) {
1923
public boolean canPerformAction() {
2024
return true;
2125
}
22-
26+
2327
@Override
2428
public void performAction() {
25-
String className = JOptionPane
26-
.showInputDialog("Please specify the name of the Java Class");
27-
try {
28-
Class classObj = Class.forName(className);
29-
ClassPaintComponent comp = new ClassPaintComponent(classObj,
30-
panel.getWidth() / 2, panel.getHeight() / 2);
31-
panel.addPaintComponent(comp);
32-
// add action to undo redo manager
33-
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
29+
30+
ClassSearchFrame classSearchFrame = new ClassSearchFrame();
31+
classSearchFrame.setDelegate(new ClassSearchFrameDelegateInterface() {
32+
33+
@Override
34+
public void didSelectClass(String classname) {
3435

35-
@Override
36-
public void undoAction() {
37-
comp.remove(panel);
38-
panel.repaint();
39-
}
40-
41-
@Override
42-
public void redoAction() {
36+
try {
37+
Class classObj = Class.forName(classname);
38+
ClassPaintComponent comp = new ClassPaintComponent(classObj,
39+
panel.getWidth() / 2, panel.getHeight() / 2);
4340
panel.addPaintComponent(comp);
41+
// add action to undo redo manager
42+
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
43+
44+
@Override
45+
public void undoAction() {
46+
comp.remove(panel);
47+
panel.repaint();
48+
}
49+
50+
@Override
51+
public void redoAction() {
52+
panel.addPaintComponent(comp);
53+
panel.repaint();
54+
}
55+
});
4456
panel.repaint();
57+
} catch (ClassNotFoundException e) {
58+
e.printStackTrace();
59+
JOptionPane.showMessageDialog(panel,
60+
classname + " :: Class Not Found");
4561
}
46-
});
47-
panel.repaint();
48-
} catch (ClassNotFoundException e) {
49-
e.printStackTrace();
50-
JOptionPane.showMessageDialog(panel,
51-
className + " :: Class Not Found");
52-
}
62+
}
63+
});
64+
65+
66+
classSearchFrame.setVisible(true);
67+
classSearchFrame.setSize(new Dimension(300, 200));
68+
69+
70+
5371

5472
}
5573

src/ui/helper/ClassSearchFrame.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ public void actionPerformed(ActionEvent e) {
142142

143143
// User cancel the class search
144144
if (e.getSource() == btnCancel) {
145-
System.exit(0);
145+
setVisible(false);
146+
dispose();
146147
} else if (e.getSource() == btnConfirm) {
147148

148149
System.out.println("btnConfirm pressed");
@@ -161,7 +162,8 @@ public void actionPerformed(ActionEvent e) {
161162

162163
}
163164

164-
System.exit(0);
165+
setVisible(false);
166+
dispose();
165167
}
166168
}
167169

src/ui/helper/ClassSearchFrameTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public void run() {
2121

2222
@Override
2323
public void didSelectClass(String classname) {
24-
// TODO Auto-generated method stub
2524

2625
}
2726
});

0 commit comments

Comments
 (0)