Skip to content

Commit f31943e

Browse files
authored
Merge pull request #45 from UCSDOalads/addTESTbylhwlyd1
Rewrote class search frame through input manager
2 parents 29161f6 + 5804361 commit f31943e

3 files changed

Lines changed: 56 additions & 51 deletions

File tree

src/actions/AddLazyJavaClassAction.java

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
import actions.menu.ActionsMenuBarTitles;
1010
import paintcomponents.java.lazy.ClassPaintComponent;
1111
import ui.PaintPanel;
12+
import ui.general.InputManager;
13+
import ui.general.InputManagerDelegate;
1214
import ui.helper.classsearch.ClassSearchFrame;
1315
import ui.helper.classsearch.ClassSearchFrameDelegateInterface;
14-
1516
public class AddLazyJavaClassAction extends PaintAction {
1617

1718
public AddLazyJavaClassAction(PaintPanel panel) {
@@ -25,49 +26,33 @@ public boolean canPerformAction() {
2526

2627
@Override
2728
public void performAction() {
28-
29-
ClassSearchFrame classSearchFrame = new ClassSearchFrame();
30-
classSearchFrame.setDelegate(new ClassSearchFrameDelegateInterface() {
29+
InputManager im = new InputManager();
30+
im.askForClass(panel,new InputManagerDelegate<Class>() {
3131

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

7358
@Override

src/paintcomponents/java/interactive/MethodPaintComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void evaluate(){
9393
Object[] args = new Object[toPoints.size()];
9494

9595
//Get the input data from each the input points
96-
for (int i = 0; i < toPoints.size() ; i++) {
96+
for (int i = 0; i < toPoints.size(); i++) {
9797
DataToPoint toPoint = toPoints.get(i);
9898
try {
9999
args[i] = toPoint.fetchData();

src/ui/general/InputManager.java

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package ui.general;
22

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

57
import ui.PaintPanel;
8+
import ui.helper.classsearch.ClassSearchFrame;
9+
import ui.helper.classsearch.ClassSearchFrameDelegateInterface;
610

711
/**
812
* Ask for things from user.
@@ -69,15 +73,31 @@ public void askForInt(PaintPanel panel, InputManagerDelegate<Integer> delegate)
6973
}
7074

7175
// TODO askForClass
72-
public void askForClass(PaintPanel panel, InputManagerDelegate<Integer> delegate) {
73-
String input = JOptionPane.showInputDialog("Please Input A Class");
74-
try{
75-
//TODO Class
76-
//delegate.didFinishInput(inputInt);
77-
} catch (NumberFormatException exp){
78-
exp.printStackTrace();
79-
askForClass(panel, delegate);
80-
}
76+
public void askForClass(PaintPanel panel, InputManagerDelegate<Class> delegate) {
77+
ClassSearchFrame classSearchFrame = new ClassSearchFrame();
78+
classSearchFrame.setDelegate(new ClassSearchFrameDelegateInterface() {
79+
80+
@Override
81+
public void didSelectClass(String classname) {
82+
83+
try {
84+
Class classInput = Class.forName(classname);
85+
delegate.didFinishInput(classInput);
86+
} catch (ClassNotFoundException e) {
87+
e.printStackTrace();
88+
JOptionPane.showMessageDialog(panel,
89+
classname + " :: Class Not Found");
90+
}
91+
92+
}
93+
});
94+
95+
96+
classSearchFrame.setVisible(true);
97+
classSearchFrame.setSize(new Dimension(300, 200));
98+
8199
}
100+
101+
82102

83103
}

0 commit comments

Comments
 (0)