Skip to content

Commit

Permalink
Merge pull request #12 from UCSDOalads/devBranchByUltimatePea
Browse files Browse the repository at this point in the history
Merge Java Class IOs from devBranchByUltimatePea
  • Loading branch information
Ultimate Pea authored Mar 1, 2017
2 parents 55ed6aa + fc1c76e commit f92065d
Show file tree
Hide file tree
Showing 31 changed files with 1,164 additions and 314 deletions.
2 changes: 1 addition & 1 deletion src/actions/AddDataDisplayBoxAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actions;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.DataDisplayPaintComponent;
import paintcomponents.data.DataDisplayPaintComponent;
import ui.PaintPanel;

public class AddDataDisplayBoxAction extends PaintAction {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/AddDataInputBoxAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package actions;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.DataInputTextfieldPaintComponent;
import paintcomponents.data.DataInputTextfieldPaintComponent;
import ui.PaintPanel;

public class AddDataInputBoxAction extends PaintAction {
Expand Down
43 changes: 43 additions & 0 deletions src/actions/AddLazyJavaClassAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package actions;

import javax.swing.JOptionPane;

import actions.menu.ActionsMenuBarTitles;
import actions.menu.PaintActionMenuItem;
import paintcomponents.java.lazy.ClassPaintComponent;
import ui.PaintPanel;

public class AddLazyJavaClassAction extends PaintAction {

public AddLazyJavaClassAction(PaintPanel panel) {
super(panel);
}

@Override
public boolean canPerformAction() {
return true;
}

@Override
public void performAction() {
String className = JOptionPane
.showInputDialog("Please specify the name of the Java Class");
try {
Class classObj = Class.forName(className);
panel.addPaintComponent(new ClassPaintComponent(classObj,
panel.getWidth() / 2, panel.getHeight() / 2));
panel.repaint();
} catch (ClassNotFoundException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(panel,
className + " :: Class Not Found");
}

}

@Override
public String locationString() {
return ActionsMenuBarTitles.Lazy().Add().Java_Class().toString();
}

}
63 changes: 63 additions & 0 deletions src/actions/AddLazyJavaConstructorAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package actions;

import java.lang.reflect.Constructor;

import javax.swing.JOptionPane;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
import paintcomponents.java.lazy.ClassPaintComponent;
import ui.PaintPanel;

public class AddLazyJavaConstructorAction extends PaintAction {

public AddLazyJavaConstructorAction(PaintPanel panel) {
super(panel);
}

@Override
public boolean canPerformAction() {
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
return false;
}
if (panel.getSelectTool().getSelectedComponents()
.get(0) instanceof ClassPaintComponent) {
return true;
}
return false;
}

@Override
public void performAction() {
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
.getSelectedComponents().get(0);
Constructor[] cons = comp.getDisplayingClass().getConstructors();

int desiaredConstructorIndex = Integer
.parseInt(JOptionPane.showInputDialog(
"Please enter the index of the constructor you would like to use: \n\n\n"
+ getConstructorsSelectionUI(cons)));
ClassConstructorPaintComponent consComp = new ClassConstructorPaintComponent(
cons[desiaredConstructorIndex], panel.getWidth() / 2,
panel.getHeight() / 2);
panel.addPaintComponent(consComp);
panel.repaint();

}

public String getConstructorsSelectionUI(Constructor[] cons) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < cons.length; i++) {
Constructor constructor = cons[i];
builder.append(i + " : " + constructor.toString() + "\n");
}
return builder.toString();

}

@Override
public String locationString() {
return ActionsMenuBarTitles.Lazy().Add().Java_Constructor().toString();
}

}
44 changes: 44 additions & 0 deletions src/actions/AddLazyJavaFieldsComponentAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package actions;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.java.lazy.ClassPaintComponent;
import paintcomponents.java.lazy.FieldsPaintComponent;
import ui.PaintPanel;

public class AddLazyJavaFieldsComponentAction extends PaintAction {

public AddLazyJavaFieldsComponentAction(PaintPanel panel) {
super(panel);
}
//TODO
//NOTE: I am copying from Constructor and Methods, consider refinement
@Override
public boolean canPerformAction() {
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
return false;
}
if (panel.getSelectTool().getSelectedComponents()
.get(0) instanceof ClassPaintComponent) {
return true;
}
return false;
}
@Override
public void performAction() {
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
.getSelectedComponents().get(0);

FieldsPaintComponent fieldsComp =
new FieldsPaintComponent(comp.getDisplayingClass(),
panel.getWidth() / 2,
panel.getHeight() / 2);
panel.addPaintComponent(fieldsComp);
panel.repaint();
}

@Override
public String locationString() {
return ActionsMenuBarTitles.Lazy().Add().Java_Fields().toString();
}

}
63 changes: 63 additions & 0 deletions src/actions/AddLazyJavaMethodComponentAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package actions;

import java.lang.reflect.Method;

import javax.swing.JOptionPane;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.java.lazy.ClassConstructorPaintComponent;
import paintcomponents.java.lazy.ClassPaintComponent;
import paintcomponents.java.lazy.MethodPaintComponent;
import ui.PaintPanel;

public class AddLazyJavaMethodComponentAction extends PaintAction {

public AddLazyJavaMethodComponentAction(PaintPanel panel) {
super(panel);
}

//TODO
//NOTE: I am copying from Constructor, consider refinement
@Override
public boolean canPerformAction() {
if (panel.getSelectTool().getSelectedComponents().size() != 1) {
return false;
}
if (panel.getSelectTool().getSelectedComponents()
.get(0) instanceof ClassPaintComponent) {
return true;
}
return false;
}

@Override
public void performAction() {
ClassPaintComponent comp = (ClassPaintComponent) panel.getSelectTool()
.getSelectedComponents().get(0);
Method[] methods = comp.getDisplayingClass().getMethods();

int desiaredConstructorIndex = Integer
.parseInt(JOptionPane.showInputDialog(
"Please enter the index of the constructor you would like to use: \n\n\n"
+ getMethodsSelectionUI(methods)));
MethodPaintComponent methodComp = new MethodPaintComponent(
methods[desiaredConstructorIndex], panel.getWidth() / 2,
panel.getHeight() / 2);
panel.addPaintComponent(methodComp);
panel.repaint();
}
public String getMethodsSelectionUI(Method[] methods) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < methods.length; i++) {
Method constructor = methods[i];
builder.append(i + " : " + constructor.toString() + "\n");
}
return builder.toString();

}
@Override
public String locationString() {
return ActionsMenuBarTitles.Lazy().Add().Java_Method().toString();
}

}
13 changes: 6 additions & 7 deletions src/actions/ConstructDataLineSegmentAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.ArrayList;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.DataFromPoint;
import paintcomponents.DataLineSegment;
import paintcomponents.DataToPoint;
import paintcomponents.PaintComponent;
import paintcomponents.data.DataFromPoint;
import paintcomponents.data.DataLineSegment;
import paintcomponents.data.DataToPoint;
import ui.PaintPanel;

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

ArrayList<PaintComponent> comps = this.panel.getSelectTool().getSelectedComponents();
@SuppressWarnings("rawtypes")
DataLineSegment<?> seg = new DataLineSegment((DataFromPoint<?>)comps.get(0), (DataToPoint<?>)comps.get(1));
DataLineSegment seg = new DataLineSegment((DataFromPoint)comps.get(0), (DataToPoint)comps.get(1));
addLineSegment(seg);
}

Expand Down
2 changes: 1 addition & 1 deletion src/actions/InputDataForDataInputBoxAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import javax.swing.JOptionPane;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.DataInputTextfieldPaintComponent;
import paintcomponents.PaintComponent;
import paintcomponents.data.DataInputTextfieldPaintComponent;
import ui.PaintPanel;

public class InputDataForDataInputBoxAction extends PaintAction {
Expand Down
8 changes: 5 additions & 3 deletions src/actions/UpdateDataDisplayBoxAction.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package actions;

import java.util.NoSuchElementException;
import java.util.logging.Logger;

import javax.swing.JOptionPane;

import actions.menu.ActionsMenuBarTitles;
import paintcomponents.DataDisplayPaintComponent;
import paintcomponents.DataFromPointNoDataProviderException;
import paintcomponents.DataFromPointProviderCannotProvideDataException;
import paintcomponents.NoConnectingLineSegmentException;
import paintcomponents.data.DataDisplayPaintComponent;
import paintcomponents.data.DataFromPointNoDataProviderException;
import paintcomponents.data.DataFromPointProviderCannotProvideDataException;
import ui.PaintPanel;

public class UpdateDataDisplayBoxAction extends PaintAction {
Expand Down Expand Up @@ -36,6 +37,7 @@ public void performAction() {
} catch (NoSuchElementException | NoConnectingLineSegmentException
| DataFromPointNoDataProviderException
| DataFromPointProviderCannotProvideDataException e) {
Logger.getGlobal().warning(e.toString());
e.printStackTrace();
JOptionPane.showMessageDialog(panel, e.toString());
}
Expand Down
10 changes: 10 additions & 0 deletions src/actions/menu/ActionsMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import ui.PaintPanel;
import actions.AddDataDisplayBoxAction;
import actions.AddDataInputBoxAction;
import actions.AddLazyJavaClassAction;
import actions.AddLazyJavaConstructorAction;
import actions.AddLazyJavaFieldsComponentAction;
import actions.AddLazyJavaMethodComponentAction;
import actions.AddTextBoxAction;
import actions.ConstructDataLineSegmentAction;
import actions.ConstructLineSegmentAction;
Expand All @@ -34,6 +38,12 @@ public ActionsMenuBar(PaintPanel panel){

//data segments
addAction(new ConstructDataLineSegmentAction(panel));

//java class
addAction(new AddLazyJavaClassAction(panel));
addAction(new AddLazyJavaConstructorAction(panel));
addAction(new AddLazyJavaMethodComponentAction(panel));
addAction(new AddLazyJavaFieldsComponentAction(panel));

}

Expand Down
24 changes: 24 additions & 0 deletions src/actions/menu/ActionsMenuBarTitles.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,30 @@ public ActionsMenuBarTitles Line_Segment(){
append("Line Segment");
return this;
}

public static ActionsMenuBarTitles Lazy() {
return new ActionsMenuBarTitles("Lazy");
}

public ActionsMenuBarTitles Java_Class() {
append("Java Class");
return this;
}

public ActionsMenuBarTitles Java_Constructor() {
append("Java Constructor");
return this;
}

public ActionsMenuBarTitles Java_Method() {
append("Java Method");
return this;
}

public ActionsMenuBarTitles Java_Fields() {
append("Java Fields");
return this;
}


}
Loading

0 comments on commit f92065d

Please sign in to comment.