Skip to content

Commit f92065d

Browse files
author
Ultimate Pea
authored
Merge pull request #12 from UCSDOalads/devBranchByUltimatePea
Merge Java Class IOs from devBranchByUltimatePea
2 parents 55ed6aa + fc1c76e commit f92065d

31 files changed

+1164
-314
lines changed

src/actions/AddDataDisplayBoxAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package actions;
22

33
import actions.menu.ActionsMenuBarTitles;
4-
import paintcomponents.DataDisplayPaintComponent;
4+
import paintcomponents.data.DataDisplayPaintComponent;
55
import ui.PaintPanel;
66

77
public class AddDataDisplayBoxAction extends PaintAction {

src/actions/AddDataInputBoxAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package actions;
22

33
import actions.menu.ActionsMenuBarTitles;
4-
import paintcomponents.DataInputTextfieldPaintComponent;
4+
import paintcomponents.data.DataInputTextfieldPaintComponent;
55
import ui.PaintPanel;
66

77
public class AddDataInputBoxAction extends PaintAction {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package actions;
2+
3+
import javax.swing.JOptionPane;
4+
5+
import actions.menu.ActionsMenuBarTitles;
6+
import actions.menu.PaintActionMenuItem;
7+
import paintcomponents.java.lazy.ClassPaintComponent;
8+
import ui.PaintPanel;
9+
10+
public class AddLazyJavaClassAction extends PaintAction {
11+
12+
public AddLazyJavaClassAction(PaintPanel panel) {
13+
super(panel);
14+
}
15+
16+
@Override
17+
public boolean canPerformAction() {
18+
return true;
19+
}
20+
21+
@Override
22+
public void performAction() {
23+
String className = JOptionPane
24+
.showInputDialog("Please specify the name of the Java Class");
25+
try {
26+
Class classObj = Class.forName(className);
27+
panel.addPaintComponent(new ClassPaintComponent(classObj,
28+
panel.getWidth() / 2, panel.getHeight() / 2));
29+
panel.repaint();
30+
} catch (ClassNotFoundException e) {
31+
e.printStackTrace();
32+
JOptionPane.showMessageDialog(panel,
33+
className + " :: Class Not Found");
34+
}
35+
36+
}
37+
38+
@Override
39+
public String locationString() {
40+
return ActionsMenuBarTitles.Lazy().Add().Java_Class().toString();
41+
}
42+
43+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package actions;
2+
3+
import java.lang.reflect.Constructor;
4+
5+
import javax.swing.JOptionPane;
6+
7+
import actions.menu.ActionsMenuBarTitles;
8+
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
9+
import paintcomponents.java.lazy.ClassPaintComponent;
10+
import ui.PaintPanel;
11+
12+
public class AddLazyJavaConstructorAction extends PaintAction {
13+
14+
public AddLazyJavaConstructorAction(PaintPanel panel) {
15+
super(panel);
16+
}
17+
18+
@Override
19+
public boolean canPerformAction() {
20+
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
21+
return false;
22+
}
23+
if (panel.getSelectTool().getSelectedComponents()
24+
.get(0) instanceof ClassPaintComponent) {
25+
return true;
26+
}
27+
return false;
28+
}
29+
30+
@Override
31+
public void performAction() {
32+
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
33+
.getSelectedComponents().get(0);
34+
Constructor[] cons = comp.getDisplayingClass().getConstructors();
35+
36+
int desiaredConstructorIndex = Integer
37+
.parseInt(JOptionPane.showInputDialog(
38+
"Please enter the index of the constructor you would like to use: \n\n\n"
39+
+ getConstructorsSelectionUI(cons)));
40+
ClassConstructorPaintComponent consComp = new ClassConstructorPaintComponent(
41+
cons[desiaredConstructorIndex], panel.getWidth() / 2,
42+
panel.getHeight() / 2);
43+
panel.addPaintComponent(consComp);
44+
panel.repaint();
45+
46+
}
47+
48+
public String getConstructorsSelectionUI(Constructor[] cons) {
49+
StringBuilder builder = new StringBuilder();
50+
for (int i = 0; i < cons.length; i++) {
51+
Constructor constructor = cons[i];
52+
builder.append(i + " : " + constructor.toString() + "\n");
53+
}
54+
return builder.toString();
55+
56+
}
57+
58+
@Override
59+
public String locationString() {
60+
return ActionsMenuBarTitles.Lazy().Add().Java_Constructor().toString();
61+
}
62+
63+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package actions;
2+
3+
import actions.menu.ActionsMenuBarTitles;
4+
import paintcomponents.java.lazy.ClassPaintComponent;
5+
import paintcomponents.java.lazy.FieldsPaintComponent;
6+
import ui.PaintPanel;
7+
8+
public class AddLazyJavaFieldsComponentAction extends PaintAction {
9+
10+
public AddLazyJavaFieldsComponentAction(PaintPanel panel) {
11+
super(panel);
12+
}
13+
//TODO
14+
//NOTE: I am copying from Constructor and Methods, consider refinement
15+
@Override
16+
public boolean canPerformAction() {
17+
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
18+
return false;
19+
}
20+
if (panel.getSelectTool().getSelectedComponents()
21+
.get(0) instanceof ClassPaintComponent) {
22+
return true;
23+
}
24+
return false;
25+
}
26+
@Override
27+
public void performAction() {
28+
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
29+
.getSelectedComponents().get(0);
30+
31+
FieldsPaintComponent fieldsComp =
32+
new FieldsPaintComponent(comp.getDisplayingClass(),
33+
panel.getWidth() / 2,
34+
panel.getHeight() / 2);
35+
panel.addPaintComponent(fieldsComp);
36+
panel.repaint();
37+
}
38+
39+
@Override
40+
public String locationString() {
41+
return ActionsMenuBarTitles.Lazy().Add().Java_Fields().toString();
42+
}
43+
44+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package actions;
2+
3+
import java.lang.reflect.Method;
4+
5+
import javax.swing.JOptionPane;
6+
7+
import actions.menu.ActionsMenuBarTitles;
8+
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
9+
import paintcomponents.java.lazy.ClassPaintComponent;
10+
import paintcomponents.java.lazy.MethodPaintComponent;
11+
import ui.PaintPanel;
12+
13+
public class AddLazyJavaMethodComponentAction extends PaintAction {
14+
15+
public AddLazyJavaMethodComponentAction(PaintPanel panel) {
16+
super(panel);
17+
}
18+
19+
//TODO
20+
//NOTE: I am copying from Constructor, consider refinement
21+
@Override
22+
public boolean canPerformAction() {
23+
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
24+
return false;
25+
}
26+
if (panel.getSelectTool().getSelectedComponents()
27+
.get(0) instanceof ClassPaintComponent) {
28+
return true;
29+
}
30+
return false;
31+
}
32+
33+
@Override
34+
public void performAction() {
35+
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
36+
.getSelectedComponents().get(0);
37+
Method[] methods = comp.getDisplayingClass().getMethods();
38+
39+
int desiaredConstructorIndex = Integer
40+
.parseInt(JOptionPane.showInputDialog(
41+
"Please enter the index of the constructor you would like to use: \n\n\n"
42+
+ getMethodsSelectionUI(methods)));
43+
MethodPaintComponent methodComp = new MethodPaintComponent(
44+
methods[desiaredConstructorIndex], panel.getWidth() / 2,
45+
panel.getHeight() / 2);
46+
panel.addPaintComponent(methodComp);
47+
panel.repaint();
48+
}
49+
public String getMethodsSelectionUI(Method[] methods) {
50+
StringBuilder builder = new StringBuilder();
51+
for (int i = 0; i < methods.length; i++) {
52+
Method constructor = methods[i];
53+
builder.append(i + " : " + constructor.toString() + "\n");
54+
}
55+
return builder.toString();
56+
57+
}
58+
@Override
59+
public String locationString() {
60+
return ActionsMenuBarTitles.Lazy().Add().Java_Method().toString();
61+
}
62+
63+
}

src/actions/ConstructDataLineSegmentAction.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import java.util.ArrayList;
44

55
import actions.menu.ActionsMenuBarTitles;
6-
import paintcomponents.DataFromPoint;
7-
import paintcomponents.DataLineSegment;
8-
import paintcomponents.DataToPoint;
96
import paintcomponents.PaintComponent;
7+
import paintcomponents.data.DataFromPoint;
8+
import paintcomponents.data.DataLineSegment;
9+
import paintcomponents.data.DataToPoint;
1010
import ui.PaintPanel;
1111

1212
public class ConstructDataLineSegmentAction extends ConstructLineSegmentAction {
@@ -23,9 +23,9 @@ public boolean canPerformAction() {
2323
//assume ConstructLineSegment is doing correctly, there is two corrently selected points
2424
ArrayList<PaintComponent> comps = this.panel.getSelectTool().getSelectedComponents();
2525
//TODO IMPORTANT Generic Argument is erased, may cause unexpected behavior when types dont match in the future
26-
if(comps.get(0) instanceof DataFromPoint<?> && comps.get(1) instanceof DataToPoint<?>){
26+
if(comps.get(0) instanceof DataFromPoint && comps.get(1) instanceof DataToPoint){
2727
//allow connection only when no segment has no existing connections to the data
28-
if(((DataToPoint<?>)comps.get(1)).getLineSegment() == null){
28+
if(((DataToPoint)comps.get(1)).getLineSegment() == null){
2929
return true;
3030
}
3131
}
@@ -36,8 +36,7 @@ public boolean canPerformAction() {
3636
public void performAction() {
3737

3838
ArrayList<PaintComponent> comps = this.panel.getSelectTool().getSelectedComponents();
39-
@SuppressWarnings("rawtypes")
40-
DataLineSegment<?> seg = new DataLineSegment((DataFromPoint<?>)comps.get(0), (DataToPoint<?>)comps.get(1));
39+
DataLineSegment seg = new DataLineSegment((DataFromPoint)comps.get(0), (DataToPoint)comps.get(1));
4140
addLineSegment(seg);
4241
}
4342

src/actions/InputDataForDataInputBoxAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import javax.swing.JOptionPane;
66

77
import actions.menu.ActionsMenuBarTitles;
8-
import paintcomponents.DataInputTextfieldPaintComponent;
98
import paintcomponents.PaintComponent;
9+
import paintcomponents.data.DataInputTextfieldPaintComponent;
1010
import ui.PaintPanel;
1111

1212
public class InputDataForDataInputBoxAction extends PaintAction {

src/actions/UpdateDataDisplayBoxAction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package actions;
22

33
import java.util.NoSuchElementException;
4+
import java.util.logging.Logger;
45

56
import javax.swing.JOptionPane;
67

78
import actions.menu.ActionsMenuBarTitles;
8-
import paintcomponents.DataDisplayPaintComponent;
9-
import paintcomponents.DataFromPointNoDataProviderException;
10-
import paintcomponents.DataFromPointProviderCannotProvideDataException;
119
import paintcomponents.NoConnectingLineSegmentException;
10+
import paintcomponents.data.DataDisplayPaintComponent;
11+
import paintcomponents.data.DataFromPointNoDataProviderException;
12+
import paintcomponents.data.DataFromPointProviderCannotProvideDataException;
1213
import ui.PaintPanel;
1314

1415
public class UpdateDataDisplayBoxAction extends PaintAction {
@@ -36,6 +37,7 @@ public void performAction() {
3637
} catch (NoSuchElementException | NoConnectingLineSegmentException
3738
| DataFromPointNoDataProviderException
3839
| DataFromPointProviderCannotProvideDataException e) {
40+
Logger.getGlobal().warning(e.toString());
3941
e.printStackTrace();
4042
JOptionPane.showMessageDialog(panel, e.toString());
4143
}

src/actions/menu/ActionsMenuBar.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import ui.PaintPanel;
1212
import actions.AddDataDisplayBoxAction;
1313
import actions.AddDataInputBoxAction;
14+
import actions.AddLazyJavaClassAction;
15+
import actions.AddLazyJavaConstructorAction;
16+
import actions.AddLazyJavaFieldsComponentAction;
17+
import actions.AddLazyJavaMethodComponentAction;
1418
import actions.AddTextBoxAction;
1519
import actions.ConstructDataLineSegmentAction;
1620
import actions.ConstructLineSegmentAction;
@@ -34,6 +38,12 @@ public ActionsMenuBar(PaintPanel panel){
3438

3539
//data segments
3640
addAction(new ConstructDataLineSegmentAction(panel));
41+
42+
//java class
43+
addAction(new AddLazyJavaClassAction(panel));
44+
addAction(new AddLazyJavaConstructorAction(panel));
45+
addAction(new AddLazyJavaMethodComponentAction(panel));
46+
addAction(new AddLazyJavaFieldsComponentAction(panel));
3747

3848
}
3949

0 commit comments

Comments
 (0)