Skip to content

Commit 30cd5e0

Browse files
author
lhwlyd
committed
add two interactive execute actions
1 parent 74c87c2 commit 30cd5e0

File tree

5 files changed

+72
-8
lines changed

5 files changed

+72
-8
lines changed

src/actions/menu/ActionsMenuBar.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import actions.RemoveAnnotationAction;
3333
import actions.RemovePaintComponent;
3434
import actions.UpdateDataDisplayBoxAction;
35+
import actions.singleinstanceoperations.ExecuteJavaInteractiveConstructor;
36+
import actions.singleinstanceoperations.ExecuteJavaInteractiveMethod;
3537
import actions.singleinstanceoperations.SetPointSizeOperation;
3638
import actions.singleinstanceoperations.UpdateFontSizeOperation;
3739
import actions.ZoomInAction;
@@ -69,7 +71,8 @@ public ActionsMenuBar(PaintPanel panel){
6971
//interactive
7072
addAction(new AddInteractiveConstructorAction(panel));
7173
addAction(new AddInteractiveJavaMethodComponentAction(panel));
72-
74+
addAction(new ExecuteJavaInteractiveConstructor(panel));
75+
addAction(new ExecuteJavaInteractiveMethod(panel));
7376

7477
//edit
7578
addAction(new EditRedoAction(panel));
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package actions.singleinstanceoperations;
2+
3+
import actions.menu.ActionsMenuBarTitles;
4+
import paintcomponents.java.interactive.ClassConstructorPaintComponent;
5+
import ui.PaintPanel;
6+
7+
public class ExecuteJavaInteractiveConstructor extends SingleInstanceOperation<ClassConstructorPaintComponent> {
8+
9+
public ExecuteJavaInteractiveConstructor(PaintPanel panel) {
10+
super(panel);
11+
// TODO Auto-generated constructor stub
12+
}
13+
14+
@Override
15+
protected void performActionOnInstance(ClassConstructorPaintComponent instance) {
16+
17+
instance.evaluate();
18+
}
19+
20+
@Override
21+
protected Class<ClassConstructorPaintComponent> getGenericClassType() {
22+
return ClassConstructorPaintComponent.class;
23+
}
24+
25+
@Override
26+
public String locationString() {
27+
// TODO Auto-generated method stub
28+
return ActionsMenuBarTitles.Developer("Interactive/Constructor Evaluate").toString();
29+
}
30+
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package actions.singleinstanceoperations;
2+
3+
import actions.menu.ActionsMenuBarTitles;
4+
import paintcomponents.java.interactive.ClassConstructorPaintComponent;
5+
import paintcomponents.java.interactive.MethodPaintComponent;
6+
import ui.PaintPanel;
7+
8+
public class ExecuteJavaInteractiveMethod extends SingleInstanceOperation<MethodPaintComponent>{
9+
10+
public ExecuteJavaInteractiveMethod(PaintPanel panel) {
11+
super(panel);
12+
}
13+
14+
@Override
15+
protected void performActionOnInstance(MethodPaintComponent instance) {
16+
// TODO Auto-generated method stub
17+
instance.evaluate();
18+
}
19+
20+
@Override
21+
protected Class<MethodPaintComponent> getGenericClassType() {
22+
// TODO Auto-generated method stub
23+
return MethodPaintComponent.class;
24+
}
25+
26+
@Override
27+
public String locationString() {
28+
// TODO Auto-generated method stub
29+
return ActionsMenuBarTitles.Developer("Interactive/Method Evaluate").toString();
30+
}
31+
32+
}

src/paintcomponents/java/interactive/ClassConstructorPaintComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void init() {
6868
/**
6969
* Calculate the input data and store it.
7070
*/
71-
public void evaluate(DataFromPoint dataFromPoint){
71+
public void evaluate(){
7272
// prepare argument list
7373
ArrayList<DataToPoint> toPoints = getToPoints();
7474
Object[] args = new Object[toPoints.size()];

src/paintcomponents/java/interactive/MethodPaintComponent.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public MethodPaintComponent(Method displayingMethod, Object instance, int x, int
5555

5656
private void init() {
5757

58-
// line 0 is signature
59-
addToPoint(1, new JavaType(this.displayingMethod.getDeclaringClass()));
6058
// parameters take place from line 2 to length+1
6159
Class[] paramTypes = displayingMethod.getParameterTypes();
6260
for (int i = 0; i < paramTypes.length ; i++) {
@@ -83,7 +81,7 @@ private void init() {
8381
/**
8482
* Calculate the input data and store it.
8583
*/
86-
public void evaluate(DataFromPoint dataFromPoint){
84+
public void evaluate(){
8785

8886
// prepare argument list
8987
ArrayList<DataToPoint> toPoints = getToPoints();
@@ -92,11 +90,11 @@ public void evaluate(DataFromPoint dataFromPoint){
9290

9391

9492
// args takes toPoint 1 to size
95-
Object[] args = new Object[toPoints.size() - 1];
93+
Object[] args = new Object[toPoints.size()];
9694

9795
//Get the input data from each the input points
98-
for (int i = 0; i < toPoints.size() - 1; i++) {
99-
DataToPoint toPoint = toPoints.get(i+1);
96+
for (int i = 0; i < toPoints.size() ; i++) {
97+
DataToPoint toPoint = toPoints.get(i);
10098
try {
10199
args[i] = toPoint.fetchData();
102100
} catch (NoSuchElementException | NoConnectingLineSegmentException

0 commit comments

Comments
 (0)