Skip to content

Commit

Permalink
Merge pull request #23 from BradF-99/more-comments
Browse files Browse the repository at this point in the history
Added/updated comments
  • Loading branch information
BradF-99 authored Jun 2, 2019
2 parents 245bafc + a6895b5 commit 78c4659
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/main/java/components/ComponentsClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ public void Undo(ComponentsClass.undoListHelper helper, Integer position){
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g.create();
//polygons
//All drawn already drawn shapes are drawn first so that the dragged images are not underlapped.
for(int i = 0; i < undoList.size(); i++){
switch(undoList.get(i).component){
//in each case it grabs the shape from the correct list by using the index in undoList
case PLOT:
PlotComponent.Plot plot = plotComp.plots.get(undoList.get(i).index);
g2d.setColor(plot.color);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/components/LineComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class LineComponent {

//Line class
//inner line class
public static class Line{
public Float x1;
public Float y1;
Expand Down Expand Up @@ -36,21 +36,20 @@ public Line(Float x1, Float y1, Float x2, Float y2, Color color) {
public final LinkedList<Line> drawnLines = new LinkedList<>();

/**
* Adds new ellipse to the list of lines
* Adds new line to the list of lines
*
* @param x1 x-coordinate of first point
* @param y1 y-coordinate of first point
* @param x2 x-coordinate of second point
* @param y2 y-coordinate of second point
* @param color Color of the object
*/

public void addNewObject(Float x1, Float y1, Float x2, Float y2, Color color){
this.lines.add(new Line(x1,y1,x2,y2,color));
}

/**
* clears the list of ellipses
* clears the list of lines
*/
public void clearObjects(){
this.lines.clear();
Expand All @@ -65,7 +64,7 @@ public void clearObject(int index){
}

/**
* Adds new ellipse to the drawnlist of lines
* Adds new line to the drawnlist of lines
*
* @param x1 x-coordinate of first point
* @param y1 y-coordinate of first point
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/components/PlotComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class PlotComponent {

//Line class
//Inner Plot Class
public static class Plot{
public Float x;
public Float y;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/components/PolygonComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

public class PolygonComponent{

/**
* Helper class for the polygon list.
*/
//inner polygon class
public static class Polygon{
Object[] pointArray;
public Color borderColor;
Expand Down Expand Up @@ -49,8 +47,15 @@ public void addNewObject(Object[] pointArray,Color borderColor,boolean filled, C
polygon.add(new Polygon(pointArray,borderColor,filled,fillColor));
}


/**
* Creates a Path2D.Float (polygon) based on the point array and the screen size.
*
* @param pointArray array of points making up the polygon
* @param screenSize size of the area being drawn to
* @return
*/
public static Path2D.Float createScaledPolygon(Object[] pointArray, Dimension screenSize){
//create new Path2D.Float to simulate the polygon
Path2D.Float newPolygon = new Path2D.Float();
for (int i = 0; i < pointArray.length; i++) {
Point2D.Float point = ((Point2D.Float) pointArray[i]);
Expand Down Expand Up @@ -123,7 +128,7 @@ public void clearDrawObject(){
* @param starty y-co-ordinate of the start Point
* @param x1 x- co-ordinate of the point that is to be checked against
* @param y1 y- co-ordinate of the point that is to be checked against
* @return
* @return true if the point is close enough, false if it is not.
*/
public boolean checkPoly(int startx, int starty, int x1, int y1){
if((startx - x1 <= 5 && startx - x1 >= -5) && (starty - y1 <= 5 && starty - y1 >= -5)){
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/components/ShapeComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public class ShapeComponent implements ComponentInterface {

//Inner shape class
public static class Shape{
public float x;
public float y;
Expand All @@ -15,11 +16,12 @@ public static class Shape{
public Color fillColor;

/**
* Constructor for the Rectangle class
* Constructor for the shape class
*
* If the mouse is moved above or to the left of the starting position nothing would be drawn,
* if the mouse is above or left the Rectangle is now drawn from the current mouse position to the start position,
* if the mouse is below or right the Rectangle is drawn from the start position to the mouse.
* if the mouse is above or left the shape is now drawn from the current mouse position to the start position,
* if the mouse is below or right the shape is drawn from the start position to the mouse.
* if the mouse is below or right the shape is drawn from the start position to the mouse.
*
* @param x1 x-coordinate of first point
* @param y1 y-coordinate of first point
Expand All @@ -29,7 +31,7 @@ public static class Shape{
* @param filled true if object is filled
* @param fillColor Color the object will be filled in
*/
//constructor for the rectangle class
//constructor for the shape class
public Shape(Float x1, Float y1, Float x2, Float y2,Color borderColor, boolean filled, Color fillColor) {
this.x = x2 < x1 ? x2 : x1;
this.y = y2 < y1 ? y2 : y1;
Expand All @@ -41,13 +43,13 @@ public Shape(Float x1, Float y1, Float x2, Float y2,Color borderColor, boolean f
}
}

//create a LinkedList of Rectangles
//create a LinkedList of shapes
public final LinkedList<Shape> shapes = new LinkedList<>();
//LinkedList for the visual rectangle whilst mouse is pressed
//LinkedList for the visual shape whilst mouse is pressed
public final LinkedList<Shape> drawnShapes = new LinkedList<>();

/**
* Adds new ellipse to the list of rectangles
* Adds new ellipse to the list of shapes
*
* @param x1 x-coordinate of first point
* @param y1 y-coordinate of first point
Expand All @@ -62,7 +64,7 @@ public void addNewObject(Float x1, Float y1, Float x2, Float y2, Color borderCol
}

/**
* clears the list of rectangles
* clears the list of shapes
*/
public void clearObjects(){
this.shapes.clear();
Expand All @@ -76,7 +78,7 @@ public void clearObject(int index){
this.shapes.remove(index);
}
/**
* Adds new ellipse to the drawnlist of rectangles
* Adds new ellipse to the drawnlist of shapes
*
* @param x1 x-coordinate of first point
* @param y1 y-coordinate of first point
Expand All @@ -91,7 +93,7 @@ public void addDrawObject(Float x1, Float y1, Float x2, Float y2, Color borderCo
}

/**
* clears the list of drawn rectangles
* clears the list of drawn shapes
*/
public void clearDrawObject(){
this.drawnShapes.clear();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ else if (mainDisplay.getWidth() > 900){
}

/**
* ConfirmListenerFill handles the processng if the user accepts a change of fill colour.
* ConfirmListenerFill handles the processing if the user accepts a change of fill colour.
*/
class ConfirmListenerFill implements ActionListener{
/**
Expand All @@ -335,7 +335,7 @@ public void actionPerformed(ActionEvent actionEvent) {
}

/**
* ConfirmListenerPen handles the processng if the user accepts a change of pen colour.
* ConfirmListenerPen handles the processing if the user accepts a change of pen colour.
*/
class ConfirmListenerPen implements ActionListener{
/**
Expand Down

0 comments on commit 78c4659

Please sign in to comment.