Skip to content

Commit 67a3b63

Browse files
author
lhwlyd
committed
Rewrote class search frame through input manager
1 parent 30cd5e0 commit 67a3b63

File tree

3 files changed

+58
-46
lines changed

3 files changed

+58
-46
lines changed

src/actions/AddLazyJavaClassAction.java

Lines changed: 28 additions & 36 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,40 @@ 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+
// TODO Auto-generated method stub
35+
ClassPaintComponent comp = new ClassPaintComponent(input,
36+
panel.getWidth() / 2, panel.getHeight() / 2);
37+
panel.addPaintComponent(comp);
38+
// add action to undo redo manager
39+
SharedUndoRedoActionManager.getSharedInstance().pushUndoableAction(new UndoRedoableInterface() {
40+
41+
@Override
42+
public void undoAction() {
43+
comp.remove(panel);
44+
panel.repaint();
45+
}
46+
47+
@Override
48+
public void redoAction() {
49+
panel.addPaintComponent(comp);
50+
panel.repaint();
51+
}
52+
});
53+
panel.repaint();
6154
}
62-
});
55+
} );
56+
57+
6358

6459

65-
classSearchFrame.setVisible(true);
66-
classSearchFrame.setSize(new Dimension(300, 200));
6760

6861

6962

70-
7163
}
7264

7365
@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)