Skip to content

Commit

Permalink
Merge pull request #10 from UCSDOalads/develop
Browse files Browse the repository at this point in the history
Release v0.2 Merge develop into master
  • Loading branch information
Ultimate Pea authored Feb 28, 2017
2 parents 2c31ed7 + 491ee77 commit ddb951f
Show file tree
Hide file tree
Showing 28 changed files with 1,131 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.class
/bin/
6 changes: 6 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/actions/
/icons/
/paintcomponents/
/painttools/
/settings/
/ui/
29 changes: 29 additions & 0 deletions src/actions/AddDataDisplayBoxAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package actions;

import paintcomponents.DataDisplayPaintComponent;
import ui.PaintPanel;

public class AddDataDisplayBoxAction extends PaintAction {

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

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

@Override
public void performAction() {
DataDisplayPaintComponent comp = new DataDisplayPaintComponent("Data Display", panel.getWidth() /2, panel.getHeight()/2);
panel.addPaintComponent(comp);
panel.repaint();
}

@Override
public String locationString() {
return "Add/Data Display";
}

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

import paintcomponents.DataInputTextfieldPaintComponent;
import ui.PaintPanel;

public class AddDataInputBoxAction extends PaintAction {

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

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

@Override
public void performAction() {
DataInputTextfieldPaintComponent comp = new DataInputTextfieldPaintComponent("Data Input", panel.getWidth() /2, panel.getHeight()/2);
panel.addPaintComponent(comp);
panel.repaint();

}

@Override
public String locationString() {
return "Add/Data Input Box...";
}

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

import javax.swing.JOptionPane;

import paintcomponents.TextPaintComponent;
import ui.PaintPanel;

public class AddTextBoxAction extends PaintAction {

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

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

@Override
public void performAction() {
String s = JOptionPane.showInputDialog("Please enter the text to display");
panel.addPaintComponent(new TextPaintComponent(s, panel.getWidth() / 2, panel.getHeight()/2));
panel.repaint();
}

@Override
public String locationString() {
return "Add/Text Box...";
}

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

import java.util.ArrayList;

import paintcomponents.DataFromPoint;
import paintcomponents.DataLineSegment;
import paintcomponents.DataToPoint;
import paintcomponents.PaintComponent;
import ui.PaintPanel;

public class ConstructDataLineSegmentAction extends ConstructLineSegmentAction {

public ConstructDataLineSegmentAction(PaintPanel panel) {
super(panel);
// TODO Auto-generated constructor stub
}

@Override
public boolean canPerformAction() {
if( super.canPerformAction() == false) return false;
//we must connect from a DataFromPoint to DataToPoint
//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<?>){
//allow connection only when no segment has no existing connections to the data
if(((DataToPoint<?>)comps.get(1)).getLineSegment() == null){
return true;
}
}
return false;
}

@Override
public void performAction() {

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

@Override
public String locationString() {
// TODO Auto-generated method stub
return "Data/Construct/Line Segment";
}

}
37 changes: 34 additions & 3 deletions src/actions/ConstructLineSegmentAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package actions;

import java.awt.Component;
import java.util.ArrayList;

import paintcomponents.LineSegment;
Expand All @@ -20,12 +21,32 @@ public boolean canPerformAction() {
//only two points can be selected
if(items.size() != 2) return false;
//selected component must be of type point

for (PaintComponent paintComponent : items) {
if(!(paintComponent instanceof SimplePoint)){
return false;
}
}
//TODO If line segment already exists, do not add again!!!

//check if line segment already exist
// if exists, then it will not form a new line segment
ArrayList<PaintComponent> components = panel.getPaintComponents();
LineSegment line = null;

//get all paintComponents
for(PaintComponent paintComponent : components) {
if( paintComponent instanceof LineSegment ) {
line = (LineSegment) paintComponent;
//check front point and to point similarities
if(items.get(0) == line.getFromPoint() &&
items.get(1) == line.getToPoint())
return false;
if(items.get(1) == line.getFromPoint() &&
items.get(0) == line.getToPoint())
return false;
}
}

//TODO Do not allow adding two line segments connecting the same point
return true;

Expand All @@ -38,15 +59,25 @@ public void performAction() {

//construct line segment
LineSegment lineSegment = new LineSegment((SimplePoint)(items.get(0)), (SimplePoint)(items.get(1)));


addLineSegment(lineSegment);
}
/**
* This method updates the panel's list of paint components and selection after a line segment is added
* Subclasses should call this method to update the panel when customizing the addition of a line segment
*
* @param lineSegment the lineSegment to be added to the painting panel
*/
protected void addLineSegment(LineSegment lineSegment) {

//add to panel
panel.addPaintComponent(lineSegment);

//change selection
panel.getSelectTool().clearSelection();
panel.getSelectTool().selectComponent(lineSegment);
panel.repaint();


}

@Override
Expand Down
40 changes: 40 additions & 0 deletions src/actions/InputDataForDataInputBoxAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package actions;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import paintcomponents.DataInputTextfieldPaintComponent;
import paintcomponents.PaintComponent;
import ui.PaintPanel;

public class InputDataForDataInputBoxAction extends PaintAction {

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

@Override
public boolean canPerformAction() {
ArrayList<PaintComponent> comps = panel.getSelectTool().getSelectedComponents();
if(comps.size()!= 1) return false;
if(comps.get(0) instanceof DataInputTextfieldPaintComponent){
return true;
}
return false;
}

@Override
public void performAction() {
DataInputTextfieldPaintComponent inputComp = (DataInputTextfieldPaintComponent) panel.getSelectTool().getSelectedComponents().get(0);
String s = JOptionPane.showInputDialog("Please specify the message to push to the data input");
inputComp.inputData(s);
panel.repaint();
}

@Override
public String locationString() {
return "Input/Input into Data Panel";
}

}
37 changes: 34 additions & 3 deletions src/actions/PaintAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,47 @@

import ui.PaintPanel;

/**
* Paint Action abstracts a particular menu action
*
* Override this class to create a new Action.
*
* Perfrom action will only be called when can perform action returns true.
*
* Most of the cases, you have to call panel.repaint() as the last statement of
* perform action
*
* @author chenzb
*
*/
public abstract class PaintAction {

protected PaintPanel panel;

public PaintAction(PaintPanel panel){
public PaintAction(PaintPanel panel) {
this.panel = panel;
}


/**
* Whether this action can perform. Subclasses generally base the return
* value on the current selection on screen
* <code>panel.getSelectTool().getSelectedComponents</code>
*
* @return true if the action can be performed
*/
public abstract boolean canPerformAction();

/**
* Performs this action Subclassess must invoke panel.repaint if the action
* changes the panel
*/
public abstract void performAction();

/**
* The location of this item in the menu bar.
* For example, "File/Save As..", "File/Open Recent/Clear Menu"
* @return
*/
public abstract String locationString();

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

import java.util.NoSuchElementException;

import javax.swing.JOptionPane;

import paintcomponents.DataDisplayPaintComponent;
import paintcomponents.DataFromPointNoDataProviderException;
import paintcomponents.DataFromPointProviderCannotProvideDataException;
import paintcomponents.NoConnectingLineSegmentException;
import ui.PaintPanel;

public class UpdateDataDisplayBoxAction extends PaintAction {

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

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

@Override
public void performAction() {
DataDisplayPaintComponent comp = (DataDisplayPaintComponent) panel.getSelectTool().getSelectedComponents().get(0) ;
try {
comp.updateDisplayText();
panel.repaint();
} catch (NoSuchElementException | NoConnectingLineSegmentException
| DataFromPointNoDataProviderException
| DataFromPointProviderCannotProvideDataException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(panel, e.toString());
}

}

@Override
public String locationString() {
return "Data/Display Box/Update";
}

}
Loading

0 comments on commit ddb951f

Please sign in to comment.