org.gannacademy.cdf.graphics.geom.Ellipse   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
rs 10
eloc 14
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setShape(Shape) 0 6 2
A Ellipse(double,double,double,double,DrawingPanel) 0 7 2
1
package org.gannacademy.cdf.graphics.geom;
2
3
import org.gannacademy.cdf.graphics.Drawable2D;
4
import org.gannacademy.cdf.graphics.DrawableException;
5
import org.gannacademy.cdf.graphics.ui.DrawingPanel;
6
7
import java.awt.*;
8
import java.awt.geom.Ellipse2D;
9
10
/**
11
 * <p>Draw an ellipse</p>
12
 *
13
 * <p><img src="doc-files/Ellipse.png" alt="Ellipse diagram"></p>
14
 *
15
 * <p>Ellipses are drawn inscribed within their rectangular bounding box.</p>
16
 *
17
 * @author <a href="https://github.com/gann-cdf/graphics/issues" target="_blank">Seth Battis</a>
18
 */
19
public class Ellipse extends Drawable2D {
20
  /**
21
   * <p>Construct a new ellipse</p>
22
   *
23
   * <p><img src="doc-files/Ellipse.png" alt="Diagram of Ellipse parameters"></p>
24
   *
25
   * <p>All window coordinates are measured in pixels, with the X-axis increasing from left to right and the Y-axis
26
   * increasing from top to bottom. All window coordinates exist in the first quadrant.</p>
27
   *
28
   * <p><img src="../doc-files/window-coordinates.png" alt="Diagram of window coordinates"></p>
29
   *
30
   * @param x            coordinate of origin
31
   * @param y            coordinate of origin
32
   * @param width        in pixels
33
   * @param height       in pixels
34
   * @param drawingPanel on which to draw
35
   */
36
  public Ellipse(double x, double y, double width, double height, DrawingPanel drawingPanel) {
37
    try {
38
      setShape(new Ellipse2D.Double(x, y, width, height));
39
      setDrawingPanel(drawingPanel);
40
    } catch (DrawableException e) {
41
        System.err.println(e.getMessage());
42
      e.printStackTrace();
0 ignored issues
show
Best Practice introduced by
Throwable.printStackTrace writes to the console which might not be available at runtime. Using a logger is preferred.
Loading history...
43
    }
44
  }
45
46
  @Override
47
  public void setShape(Shape shape) throws DrawableException {
48
    if (shape instanceof Ellipse2D) {
49
      super.setShape(shape);
50
    } else {
51
      throw new DrawableException("Attempt to set Ellipse's underlying shape to a non-Ellipse2D instance");
52
    }
53
  }
54
}
55