public EffectiveSRUAreaGraphics(
      Position A, Position B, Position C, Position D, int id, String labelName) {
    super();

    verticalBearing = Calculator.bearing(A, C, Heading.RL);
    horizontalBearing = Calculator.bearing(A, B, Heading.RL);

    this.A = A;
    this.B = B;
    this.C = C;
    this.D = D;

    double width = Converter.metersToNm(A.distanceTo(B, CoordinateSystem.CARTESIAN));

    double height = Converter.metersToNm(A.distanceTo(C, CoordinateSystem.CARTESIAN));

    System.out.println("Width is " + width);
    System.out.println("Height is : " + height);

    effectiveArea =
        new AreaInternalGraphics(
            A, B, C, D, width, height, this, verticalBearing, horizontalBearing, labelName);

    topLine = new SarEffectiveAreaLines(A, B, LineType.TOP, this);
    bottomLine = new SarEffectiveAreaLines(C, D, LineType.BOTTOM, this);

    leftLine = new SarEffectiveAreaLines(A, C, LineType.LEFT, this);

    rightLine = new SarEffectiveAreaLines(B, D, LineType.RIGHT, this);

    add(effectiveArea);
    add(bottomLine);
    add(topLine);
    add(leftLine);
    add(rightLine);
  }
  public EffectiveSRUAreaGraphics(
      Double width, Double height, SARData data, int id, String labelName) {
    super();

    this.id = id;

    this.sarData = data;

    totalSize = width * height;

    // Find center point
    Position centerPosition = null;

    if (sarData instanceof RapidResponseData) {
      RapidResponseData rapidResponseData = (RapidResponseData) data;
      centerPosition = rapidResponseData.getDatum();

      verticalBearing =
          Calculator.bearing(rapidResponseData.getA(), rapidResponseData.getD(), Heading.RL);
      horizontalBearing =
          Calculator.bearing(rapidResponseData.getA(), rapidResponseData.getB(), Heading.RL);

      // Vertical and horizontal must be swapped since the direction has
      // been set to very east or very west
      if (verticalBearing < 280 && verticalBearing > 260
          || verticalBearing < 100 && verticalBearing > 70) {

        double newVer = verticalBearing;
        System.out.println("swapping");
        verticalBearing = horizontalBearing;
        horizontalBearing = newVer;
      }

      // Reversing if direction is opposite way of assumed, assumed to be
      // headed in 90 direction ie. right
      if (horizontalBearing > 180 || horizontalBearing < 0) {

        horizontalBearing = Calculator.reverseDirection(horizontalBearing);
      }

      if (verticalBearing > 270 || verticalBearing < 90) {
        verticalBearing = Calculator.reverseDirection(verticalBearing);
      }

      System.out.println("Vertical bearing is: " + verticalBearing);
      System.out.println("Horizontal bearing is: " + horizontalBearing);
    }

    if (sarData instanceof DatumPointData) {
      DatumPointData datumData = (DatumPointData) data;
      verticalBearing = Calculator.bearing(datumData.getA(), datumData.getD(), Heading.RL);
      horizontalBearing = Calculator.bearing(datumData.getA(), datumData.getB(), Heading.RL);
      centerPosition = datumData.getDatumDownWind();

      // Vertical and horizontal must be swapped since the direction has
      // been set to very east or very west
      if (verticalBearing < 280 && verticalBearing > 260
          || verticalBearing < 100 && verticalBearing > 70) {

        double newVer = verticalBearing;
        System.out.println("swapping");
        verticalBearing = horizontalBearing;
        horizontalBearing = newVer;
      }

      // Reversing if direction is opposite way of assumed, assumed to be
      // headed in 90 direction ie. right
      if (horizontalBearing > 180 || horizontalBearing < 0) {

        horizontalBearing = Calculator.reverseDirection(horizontalBearing);
      }

      if (verticalBearing > 270 || verticalBearing < 90) {
        verticalBearing = Calculator.reverseDirection(verticalBearing);
      }

      System.out.println("Vertical bearing is: " + verticalBearing);
      System.out.println("Horizontal bearing is: " + horizontalBearing);
    }

    // Find A position
    Position topCenter =
        Calculator.findPosition(
            centerPosition,
            Calculator.reverseDirection(verticalBearing),
            Converter.nmToMeters(height / 2));

    A =
        Calculator.findPosition(
            topCenter,
            Calculator.reverseDirection(horizontalBearing),
            Converter.nmToMeters(width / 2));

    B = Calculator.findPosition(A, horizontalBearing, Converter.nmToMeters(width));

    C = Calculator.findPosition(A, verticalBearing, Converter.nmToMeters(height));
    D = Calculator.findPosition(C, horizontalBearing, Converter.nmToMeters(width));

    sarData.getEffortAllocationData().get(id).setEffectiveAreaA(A);
    sarData.getEffortAllocationData().get(id).setEffectiveAreaB(B);
    sarData.getEffortAllocationData().get(id).setEffectiveAreaC(C);
    sarData.getEffortAllocationData().get(id).setEffectiveAreaD(D);

    effectiveArea =
        new AreaInternalGraphics(
            A, B, C, D, width, height, this, verticalBearing, horizontalBearing, labelName);

    topLine = new SarEffectiveAreaLines(A, B, LineType.TOP, this);
    bottomLine = new SarEffectiveAreaLines(C, D, LineType.BOTTOM, this);

    leftLine = new SarEffectiveAreaLines(A, C, LineType.LEFT, this);

    rightLine = new SarEffectiveAreaLines(B, D, LineType.RIGHT, this);

    add(effectiveArea);
    add(bottomLine);
    add(topLine);
    add(leftLine);
    add(rightLine);
  }
  public void updateLength(LineType type, Position newPos) {

    double height = 0;
    double width = 0;

    System.out.println(type);

    if (type == LineType.BOTTOM) {

      newPos = findIntersectionBottom(newPos);

      if (newPos != null) {

        // Check that we haven't moved the cursor to the "opposite" side
        // of the line ie. inversing
        double deltaValue = A.getLatitude() - (newPos.getLatitude() + deltaCorrection);

        // System.out.println(deltaValue);

        if (deltaValue > 0) {

          // if (Calculator.bearing(A, newPos, Heading.RL) > 0){

          // We update C point
          C = newPos;

          // New length
          height = Calculator.range(A, C, Heading.GC);

          // Recalculate width
          width = totalSize / height;

          // if (height > 1 && width > 1) {

          // Recalculate B and D
          B = Calculator.findPosition(A, horizontalBearing, Converter.nmToMeters(width));

          D = Calculator.findPosition(C, horizontalBearing, Converter.nmToMeters(width));

          effectiveArea.updatePosition(A, B, C, D, width, height);

          updateLines(A, B, C, D);
          // }
        }
      }
    }
    if (type == LineType.TOP) {

      newPos = findIntersectionTop(newPos);

      if (newPos != null) {

        double deltaValue = newPos.getLatitude() - (C.getLatitude() + deltaCorrection);
        // System.out.println(deltaValue);

        // Make sure it doesn\t go over and place A under C
        // if (newPos.getLatitude() - 0.001 > C.getLatitude()) {

        // C latitude must always be below As latitude
        if (deltaValue > 0) {

          // We update A point
          A = newPos;

          // New length
          height = Calculator.range(A, C, Heading.RL);

          // Recalculate width
          width = totalSize / height;

          // Recalculate B and D
          B = Calculator.findPosition(A, horizontalBearing, Converter.nmToMeters(width));

          D = Calculator.findPosition(C, horizontalBearing, Converter.nmToMeters(width));

          effectiveArea.updatePosition(A, B, C, D, width, height);

          updateLines(A, B, C, D);
        }
      }
    }

    if (type == LineType.LEFT) {

      newPos = findIntersectionLeft(newPos);

      if (newPos != null) {

        double deltaValue = B.getLongitude() - (newPos.getLongitude() + deltaCorrection);
        // System.out.println(deltaValue);

        if (deltaValue > 0) {

          // We update C point
          A = newPos;

          // New width

          // New length
          width = Calculator.range(A, B, Heading.RL);

          // Recalculate width
          height = totalSize / width;

          // Recalculate C and D
          C = Calculator.findPosition(A, verticalBearing, Converter.nmToMeters(height));

          D = Calculator.findPosition(C, horizontalBearing, Converter.nmToMeters(width));

          effectiveArea.updatePosition(A, B, C, D, width, height);

          updateLines(A, B, C, D);
        }
      }
    }

    if (type == LineType.RIGHT) {

      newPos = findIntersectionRight(newPos);

      if (newPos != null) {

        double deltaValue = newPos.getLongitude() - (A.getLongitude() + deltaCorrection);

        // System.out.println(deltaValue);

        if (deltaValue > 0) {

          // We update B point
          B = newPos;

          // New width

          // New length
          width = Calculator.range(A, B, Heading.RL);

          // Recalculate width
          height = totalSize / width;

          // Recalculate C and D
          C = Calculator.findPosition(A, verticalBearing, Converter.nmToMeters(height));

          D = Calculator.findPosition(C, horizontalBearing, Converter.nmToMeters(width));

          effectiveArea.updatePosition(A, B, C, D, width, height);

          updateLines(A, B, C, D);
        }
      } else {
        System.out.println("Its null");
      }
    }
  }