package Debrief.Wrappers.DynamicTrackShapes;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.Arc2D;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;

public class AWTDemoDonuts extends JFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
		private int xDestination;
    private int yDestination;

    private double innerRadius;
    private double outerRadius;

    private double minAngle;
    private double maxAngle;

    private int leftCornerShift;

    private Shape fullDonut;
    private Shape sectorDonut;

    public AWTDemoDonuts() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400,700);
        setLayout(null);
    }

    /**
     * Method to show shapes.
     * @param x of upper left corner of donut sector
     * @param y of upper left corner of donut sector
     * @param innerR radius of inner circle in donut
     * @param outerR raius of outer circle in donut
     * @param minA start angle of donut sector
     * @param maxA end angle of donut sector
     */
    public void setParameters(int x, int y,
                           double innerR, double outerR,
                           double minA, double maxA) {
        xDestination = x;
        yDestination = y;
        innerRadius = innerR;
        outerRadius = outerR;
        minAngle =  minA;
        maxAngle =  maxA;
        leftCornerShift = (int) (outerRadius - innerRadius) / 2;
    }

    public void showShapes() {
        setVisible(true);
    }

    public void createFullDonut() {
        Ellipse2D circleOuter = new Ellipse2D.Double();
        Ellipse2D circleInner= new Ellipse2D.Double();
        circleOuter.setFrame(xDestination, yDestination, outerRadius, outerRadius);
        circleInner.setFrame(xDestination + leftCornerShift, yDestination + leftCornerShift, innerRadius, innerRadius);

        fullDonut = subtract(circleOuter, circleInner);
    }

    public void createSectorDonut() {
        Ellipse2D circleOuter = new Ellipse2D.Double();
        circleOuter.setFrame(xDestination, yDestination, outerRadius, outerRadius);

        Ellipse2D circleInner= new Ellipse2D.Double();
        circleInner.setFrame(xDestination + leftCornerShift, yDestination + leftCornerShift, innerRadius, innerRadius);

        /**
         * Create circle sector from maxAngle to minAngle.
         */
        Arc2D circleSector = new Arc2D.Double(xDestination - 1, yDestination - 1, outerRadius + 2, outerRadius + 2, minAngle, - 360 + (maxAngle - minAngle), Arc2D.PIE);

        /**
         * Subtract inner circle from outer thus creating needed donut.
         * Subtract circle sector from maxAngle to minAngle from created donut.
         */
        sectorDonut = subtract(subtract(circleOuter,circleInner), circleSector);
    }

    @Override
    public void paint(Graphics graphics) {
        if (sectorDonut == null || fullDonut == null) {
            System.out.println("PLease create full and sector donuts first.");
        }
        Graphics2D graphics2D = (Graphics2D) graphics;

        graphics2D.setPaint(Color.green);
        graphics2D.fill(sectorDonut);

        graphics2D.setPaint(Color.green);
        graphics2D.fill(fullDonut);
        
        // @TODO:  Peco, here's a class that lets us plot an AWT shape object in SWT:
        // http://www.java2s.com/Tutorial/Java/0280__SWT/DrawGraphics2Dstuffonaswtcomposite.htm
        // So, we'll need to extend our CanvasType object with the fill(Shape) method, and incldue
        // the above shape-conversion code in the SWT rendering
        
        
    }

    /**
     * Helper method to create shapes by subtracting some two of them
     * @param shape1 minuend
     * @param shape2 subtrahend
     * @return new shape
     */
    private Shape subtract(Shape shape1, Shape shape2) {
        Shape result = new Area(shape1);
        ((Area) result).subtract(new Area(shape2));
        return result;
    }

    public static void main(String[] args) {
        AWTDemoDonuts awtDemoDonuts = new AWTDemoDonuts();
        awtDemoDonuts.setParameters(100,400,150,200,45,135);
        awtDemoDonuts.createFullDonut();
        awtDemoDonuts.setParameters(100,100,150,200,45,135);
        awtDemoDonuts.createSectorDonut();
        awtDemoDonuts.showShapes();
    }
}
@@ -453,24 +453,27 @@
  double 
-maxAngle
+angleExtent
 ;%0A%0A    p
@@ -1206,24 +1206,240 @@
 ble maxA) %7B%0A
+        setParameters(x,y,innerR,outerR);%0A        minAngle = minA;%0A        angleExtent = maxA - minA;%0A%0A    %7D%0A%0A    public void setParameters(int x, int y,%0A                              double innerR, double outerR) %7B%0A
         xDes
@@ -1542,60 +1542,8 @@
 rR;%0A
-        minAngle =  minA;%0A        maxAngle =  maxA;%0A
     
@@ -2643,24 +2643,26 @@
 us + 2, 
+-(
 minAngle
 , - 360 
@@ -2657,39 +2657,33 @@
 ngle
-,
  - 
-360 + (maxAngle - minAngle)
+90), 360 - angleExtent
 , Ar
@@ -3213,16 +3213,124 @@
 raphics;
+%0A        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,    RenderingHints.VALUE_ANTIALIAS_ON);
 %0A%0A      
@@ -3402,16 +3402,54 @@
 rDonut);
+%0A        graphics2D.draw(sectorDonut);
 %0A%0A      
@@ -3532,371 +3532,35 @@
     
-%0A        // @TODO:  Peco, here's a class that lets us plot an AWT shape object in SWT:%0A        // http://www.java2s.com/Tutorial/Java/0280__SWT/DrawGraphics2Dstuffonaswtcomposite.htm%0A        // So, we'll need to extend our CanvasType object with the fill(Shape) method, and incldue%0A        // the above shape-conversion code in the SWT rendering%0A        %0A        
+graphics2D.draw(fullDonut);
 %0A   
@@ -4015,24 +4015,24 @@
 moDonuts();%0A
+
         awtD
@@ -4062,39 +4062,32 @@
 (100,400,150,200
-,45,135
 );%0A        awtDe

fix for angle orientation