-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from UCSDOalads/addIOComponentsbyUltimatePea
Add io componentsby ultimate pea, Complete DataInput and DataDisplay PaintComponent
- Loading branch information
Showing
11 changed files
with
305 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package paintcomponents; | ||
|
||
import java.awt.Graphics; | ||
import java.util.NoSuchElementException; | ||
|
||
import painttools.tools.SelectTool; | ||
|
||
/** | ||
* The data display paint component displays the data with a asoociated DataToPoint | ||
* @author chenzb | ||
* | ||
*/ | ||
//TODO THIS class is a copy of DataInputTextfieldPaintComponent class, please consider abstraction | ||
public class DataDisplayPaintComponent extends DataTextPaintComponent { | ||
|
||
private static final int HORIZONTAL_OFFSET = 10; | ||
private DataToPoint<String> toPoint; | ||
|
||
public DataDisplayPaintComponent(String displayingText, int x, int y) { | ||
super(displayingText, x, y); | ||
this.toPoint = new DataToPoint<>(x, y); | ||
} | ||
|
||
@Override | ||
protected void paintSelected(Graphics g) { | ||
super.paintSelected(g); | ||
updateFromPointPosition(); | ||
toPoint.paint(g); | ||
} | ||
|
||
@Override | ||
protected void paintNotSelected(Graphics g) { | ||
super.paintNotSelected(g); | ||
updateFromPointPosition(); | ||
toPoint.paint(g); | ||
} | ||
|
||
/** | ||
* This method will use the protected bounds, which will be updated in | ||
* super.paint[Not]Selected. Make sure you've already invoked super's | ||
* paintNotSelectedMethod before invoking this one. | ||
*/ | ||
private void updateFromPointPosition() { | ||
this.toPoint.setX( | ||
(int) (getX() - HORIZONTAL_OFFSET)); | ||
this.toPoint.setY((int) (getY() + this.bounds.getHeight() / 2)); | ||
} | ||
|
||
@Override | ||
public void translate(int i, int j) { | ||
super.translate(i, j); | ||
this.toPoint.translate(i, j); | ||
} | ||
|
||
@Override | ||
public boolean contains(int x, int y) { | ||
|
||
return toPoint.contains(x, y) || super.contains(x, y); | ||
} | ||
|
||
|
||
@Override | ||
public void select(SelectTool selectTool) { | ||
int x = selectTool.getLastMouseEvent().getX(); | ||
int y = selectTool.getLastMouseEvent().getY(); | ||
if (toPoint.contains(x, y)) { | ||
toPoint.select(selectTool); | ||
} else { | ||
super.select(selectTool); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void deselect(SelectTool selectTool) { | ||
int x = selectTool.getLastMouseEvent().getX(); | ||
int y = selectTool.getLastMouseEvent().getY(); | ||
if (toPoint.contains(x, y)) { | ||
toPoint.deselect(selectTool); | ||
} else { | ||
super.deselect(selectTool); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isSelected() { | ||
//if the from point is selected, this components is considered selected | ||
if(this.toPoint.isSelected()) return true; | ||
return super.isSelected(); | ||
} | ||
|
||
/** | ||
* Update the current display. | ||
* | ||
* This class will try to fetch the data from the toPointClass | ||
* @throws DataFromPointProviderCannotProvideDataException | ||
* @throws DataFromPointNoDataProviderException | ||
* @throws NoConnectingLineSegmentException | ||
* @throws NoSuchElementException | ||
* @see DataToPoint.fetchData for exception details | ||
*/ | ||
public void updateDisplayText() throws NoSuchElementException, NoConnectingLineSegmentException, DataFromPointNoDataProviderException, DataFromPointProviderCannotProvideDataException{ | ||
this.setDisplayingText(toPoint.fetchData()); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,4 +60,5 @@ public void setProvider(DataFromPointDataProvider<T> provider) { | |
this.provider = provider; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.