package pipe.views;

import pipe.gui.Constants;
import pipe.models.component.ArcPoint;
import pipe.models.component.Connectable;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;

import static java.lang.Math.max;

public class TemporaryArcView<T extends Connectable> extends JComponent {
    private T source;
    private Point2D end;
    private List<ArcPoint> intermediatePoints = new ArrayList<ArcPoint>();

    public TemporaryArcView(T source) {
        super();
        this.source = source;
        Point2D centre = source.getCentre();
        end = new Point2D.Double(centre.getX(), centre.getY());
        //TODO: REPLACE WITH BETTER LOGIC
        setBounds(0,0, 500,500);
    }

    public void setEnd(Point2D end) {
        this.end = end;

        int x = (int) max(source.getCentre().getX(), end.getX());
        int y = (int) max(source.getCentre().getY(), end.getY());
        setBounds(0,0, x, y);
    }

    public void addIntermediatePoint(ArcPoint point) {
        intermediatePoints.add(point);
    }

    public T getSourceConnectable() {
        return source;
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g2 = (Graphics2D) g;

        g2.setPaint(Constants.ELEMENT_LINE_COLOUR);
        GeneralPath path = new GeneralPath();
        path.moveTo(source.getCentre().getX(), source.getCentre().getY());

        for(ArcPoint arcPoint : intermediatePoints) {
            path.lineTo(arcPoint.getX(), arcPoint.getY());
        }
        path.lineTo(end.getX(), end.getY());
        g2.draw(path);
    }

    public List<ArcPoint> getIntermediatePoints() {
        return intermediatePoints;
    }
}

@@ -202,37 +202,8 @@
 th;%0A
-import java.awt.geom.Line2D;%0A
 impo
@@ -407,24 +407,25 @@
 e T source;%0A
+%0A
     private 
@@ -437,16 +437,17 @@
 2D end;%0A
+%0A
     priv
@@ -510,24 +510,154 @@
 cPoint%3E();%0A%0A
+    /**%0A     * Maximum intermediate point for setting rectangle bounds%0A     */%0A    private double maxX;%0A    private double maxY;%0A%0A
     public T
@@ -906,15 +906,17 @@
 s(0,
+ 
 0, 500,
+ 
 500)
@@ -982,24 +982,47 @@
 .end = end;%0A
+        updateMax(end);
 %0A        int
@@ -1039,113 +1039,37 @@
  max
-(source.getCentre().getX(), end.getX());%0A        int y = (int) max(source.getCentre().getY(), end.getY())
+X;%0A        int y = (int) maxY
 ;%0A  
@@ -1086,16 +1086,17 @@
 ounds(0,
+ 
 0, x, y)
@@ -1198,16 +1198,241 @@
 point);%0A
+        updateMax(point.getPoint());%0A    %7D%0A%0A    /**%0A     * Updates max points based on point%0A     */%0A    private void updateMax(Point2D point) %7B%0A        maxX = max(maxX, point.getX());%0A        maxY = max(maxY, point.getY());%0A
     %7D%0A%0A 
@@ -1816,16 +1816,17 @@
      for
+ 
 (ArcPoin

Fix arc dissapearing logic