Skip to content

Commit ddb951f

Browse files
author
Ultimate Pea
authored
Merge pull request #10 from UCSDOalads/develop
Release v0.2 Merge develop into master
2 parents 2c31ed7 + 491ee77 commit ddb951f

28 files changed

+1131
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.class
2+
/bin/

bin/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/actions/
2+
/icons/
3+
/paintcomponents/
4+
/painttools/
5+
/settings/
6+
/ui/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package actions;
2+
3+
import paintcomponents.DataDisplayPaintComponent;
4+
import ui.PaintPanel;
5+
6+
public class AddDataDisplayBoxAction extends PaintAction {
7+
8+
public AddDataDisplayBoxAction(PaintPanel panel) {
9+
super(panel);
10+
}
11+
12+
@Override
13+
public boolean canPerformAction() {
14+
return true;
15+
}
16+
17+
@Override
18+
public void performAction() {
19+
DataDisplayPaintComponent comp = new DataDisplayPaintComponent("Data Display", panel.getWidth() /2, panel.getHeight()/2);
20+
panel.addPaintComponent(comp);
21+
panel.repaint();
22+
}
23+
24+
@Override
25+
public String locationString() {
26+
return "Add/Data Display";
27+
}
28+
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package actions;
2+
3+
import paintcomponents.DataInputTextfieldPaintComponent;
4+
import ui.PaintPanel;
5+
6+
public class AddDataInputBoxAction extends PaintAction {
7+
8+
public AddDataInputBoxAction(PaintPanel panel) {
9+
super(panel);
10+
}
11+
12+
@Override
13+
public boolean canPerformAction() {
14+
return true;
15+
}
16+
17+
@Override
18+
public void performAction() {
19+
DataInputTextfieldPaintComponent comp = new DataInputTextfieldPaintComponent("Data Input", panel.getWidth() /2, panel.getHeight()/2);
20+
panel.addPaintComponent(comp);
21+
panel.repaint();
22+
23+
}
24+
25+
@Override
26+
public String locationString() {
27+
return "Add/Data Input Box...";
28+
}
29+
30+
}

src/actions/AddTextBoxAction.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package actions;
2+
3+
import javax.swing.JOptionPane;
4+
5+
import paintcomponents.TextPaintComponent;
6+
import ui.PaintPanel;
7+
8+
public class AddTextBoxAction extends PaintAction {
9+
10+
public AddTextBoxAction(PaintPanel panel) {
11+
super(panel);
12+
}
13+
14+
@Override
15+
public boolean canPerformAction() {
16+
return true;
17+
}
18+
19+
@Override
20+
public void performAction() {
21+
String s = JOptionPane.showInputDialog("Please enter the text to display");
22+
panel.addPaintComponent(new TextPaintComponent(s, panel.getWidth() / 2, panel.getHeight()/2));
23+
panel.repaint();
24+
}
25+
26+
@Override
27+
public String locationString() {
28+
return "Add/Text Box...";
29+
}
30+
31+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package actions;
2+
3+
import java.util.ArrayList;
4+
5+
import paintcomponents.DataFromPoint;
6+
import paintcomponents.DataLineSegment;
7+
import paintcomponents.DataToPoint;
8+
import paintcomponents.PaintComponent;
9+
import ui.PaintPanel;
10+
11+
public class ConstructDataLineSegmentAction extends ConstructLineSegmentAction {
12+
13+
public ConstructDataLineSegmentAction(PaintPanel panel) {
14+
super(panel);
15+
// TODO Auto-generated constructor stub
16+
}
17+
18+
@Override
19+
public boolean canPerformAction() {
20+
if( super.canPerformAction() == false) return false;
21+
//we must connect from a DataFromPoint to DataToPoint
22+
//assume ConstructLineSegment is doing correctly, there is two corrently selected points
23+
ArrayList<PaintComponent> comps = this.panel.getSelectTool().getSelectedComponents();
24+
//TODO IMPORTANT Generic Argument is erased, may cause unexpected behavior when types dont match in the future
25+
if(comps.get(0) instanceof DataFromPoint<?> && comps.get(1) instanceof DataToPoint<?>){
26+
//allow connection only when no segment has no existing connections to the data
27+
if(((DataToPoint<?>)comps.get(1)).getLineSegment() == null){
28+
return true;
29+
}
30+
}
31+
return false;
32+
}
33+
34+
@Override
35+
public void performAction() {
36+
37+
ArrayList<PaintComponent> comps = this.panel.getSelectTool().getSelectedComponents();
38+
@SuppressWarnings("rawtypes")
39+
DataLineSegment<?> seg = new DataLineSegment((DataFromPoint<?>)comps.get(0), (DataToPoint<?>)comps.get(1));
40+
addLineSegment(seg);
41+
}
42+
43+
@Override
44+
public String locationString() {
45+
// TODO Auto-generated method stub
46+
return "Data/Construct/Line Segment";
47+
}
48+
49+
}

src/actions/ConstructLineSegmentAction.java

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

3+
import java.awt.Component;
34
import java.util.ArrayList;
45

56
import paintcomponents.LineSegment;
@@ -20,12 +21,32 @@ public boolean canPerformAction() {
2021
//only two points can be selected
2122
if(items.size() != 2) return false;
2223
//selected component must be of type point
24+
2325
for (PaintComponent paintComponent : items) {
2426
if(!(paintComponent instanceof SimplePoint)){
2527
return false;
2628
}
2729
}
28-
//TODO If line segment already exists, do not add again!!!
30+
31+
//check if line segment already exist
32+
// if exists, then it will not form a new line segment
33+
ArrayList<PaintComponent> components = panel.getPaintComponents();
34+
LineSegment line = null;
35+
36+
//get all paintComponents
37+
for(PaintComponent paintComponent : components) {
38+
if( paintComponent instanceof LineSegment ) {
39+
line = (LineSegment) paintComponent;
40+
//check front point and to point similarities
41+
if(items.get(0) == line.getFromPoint() &&
42+
items.get(1) == line.getToPoint())
43+
return false;
44+
if(items.get(1) == line.getFromPoint() &&
45+
items.get(0) == line.getToPoint())
46+
return false;
47+
}
48+
}
49+
2950
//TODO Do not allow adding two line segments connecting the same point
3051
return true;
3152

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

3960
//construct line segment
4061
LineSegment lineSegment = new LineSegment((SimplePoint)(items.get(0)), (SimplePoint)(items.get(1)));
62+
63+
64+
addLineSegment(lineSegment);
65+
}
66+
/**
67+
* This method updates the panel's list of paint components and selection after a line segment is added
68+
* Subclasses should call this method to update the panel when customizing the addition of a line segment
69+
*
70+
* @param lineSegment the lineSegment to be added to the painting panel
71+
*/
72+
protected void addLineSegment(LineSegment lineSegment) {
73+
4174
//add to panel
4275
panel.addPaintComponent(lineSegment);
4376

4477
//change selection
4578
panel.getSelectTool().clearSelection();
4679
panel.getSelectTool().selectComponent(lineSegment);
4780
panel.repaint();
48-
49-
5081
}
5182

5283
@Override
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package actions;
2+
3+
import java.util.ArrayList;
4+
5+
import javax.swing.JOptionPane;
6+
7+
import paintcomponents.DataInputTextfieldPaintComponent;
8+
import paintcomponents.PaintComponent;
9+
import ui.PaintPanel;
10+
11+
public class InputDataForDataInputBoxAction extends PaintAction {
12+
13+
public InputDataForDataInputBoxAction(PaintPanel panel) {
14+
super(panel);
15+
}
16+
17+
@Override
18+
public boolean canPerformAction() {
19+
ArrayList<PaintComponent> comps = panel.getSelectTool().getSelectedComponents();
20+
if(comps.size()!= 1) return false;
21+
if(comps.get(0) instanceof DataInputTextfieldPaintComponent){
22+
return true;
23+
}
24+
return false;
25+
}
26+
27+
@Override
28+
public void performAction() {
29+
DataInputTextfieldPaintComponent inputComp = (DataInputTextfieldPaintComponent) panel.getSelectTool().getSelectedComponents().get(0);
30+
String s = JOptionPane.showInputDialog("Please specify the message to push to the data input");
31+
inputComp.inputData(s);
32+
panel.repaint();
33+
}
34+
35+
@Override
36+
public String locationString() {
37+
return "Input/Input into Data Panel";
38+
}
39+
40+
}

src/actions/PaintAction.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,47 @@
22

33
import ui.PaintPanel;
44

5+
/**
6+
* Paint Action abstracts a particular menu action
7+
*
8+
* Override this class to create a new Action.
9+
*
10+
* Perfrom action will only be called when can perform action returns true.
11+
*
12+
* Most of the cases, you have to call panel.repaint() as the last statement of
13+
* perform action
14+
*
15+
* @author chenzb
16+
*
17+
*/
518
public abstract class PaintAction {
6-
19+
720
protected PaintPanel panel;
821

9-
public PaintAction(PaintPanel panel){
22+
public PaintAction(PaintPanel panel) {
1023
this.panel = panel;
1124
}
12-
25+
26+
/**
27+
* Whether this action can perform. Subclasses generally base the return
28+
* value on the current selection on screen
29+
* <code>panel.getSelectTool().getSelectedComponents</code>
30+
*
31+
* @return true if the action can be performed
32+
*/
1333
public abstract boolean canPerformAction();
34+
35+
/**
36+
* Performs this action Subclassess must invoke panel.repaint if the action
37+
* changes the panel
38+
*/
1439
public abstract void performAction();
40+
41+
/**
42+
* The location of this item in the menu bar.
43+
* For example, "File/Save As..", "File/Open Recent/Clear Menu"
44+
* @return
45+
*/
1546
public abstract String locationString();
1647

1748
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package actions;
2+
3+
import java.util.NoSuchElementException;
4+
5+
import javax.swing.JOptionPane;
6+
7+
import paintcomponents.DataDisplayPaintComponent;
8+
import paintcomponents.DataFromPointNoDataProviderException;
9+
import paintcomponents.DataFromPointProviderCannotProvideDataException;
10+
import paintcomponents.NoConnectingLineSegmentException;
11+
import ui.PaintPanel;
12+
13+
public class UpdateDataDisplayBoxAction extends PaintAction {
14+
15+
public UpdateDataDisplayBoxAction(PaintPanel panel) {
16+
super(panel);
17+
}
18+
19+
@Override
20+
public boolean canPerformAction() {
21+
if(panel.getSelectTool().getSelectedComponents().size() == 1){
22+
if(panel.getSelectTool().getSelectedComponents().get(0) instanceof DataDisplayPaintComponent){
23+
return true;
24+
}
25+
}
26+
return false;
27+
}
28+
29+
@Override
30+
public void performAction() {
31+
DataDisplayPaintComponent comp = (DataDisplayPaintComponent) panel.getSelectTool().getSelectedComponents().get(0) ;
32+
try {
33+
comp.updateDisplayText();
34+
panel.repaint();
35+
} catch (NoSuchElementException | NoConnectingLineSegmentException
36+
| DataFromPointNoDataProviderException
37+
| DataFromPointProviderCannotProvideDataException e) {
38+
e.printStackTrace();
39+
JOptionPane.showMessageDialog(panel, e.toString());
40+
}
41+
42+
}
43+
44+
@Override
45+
public String locationString() {
46+
return "Data/Display Box/Update";
47+
}
48+
49+
}

0 commit comments

Comments
 (0)