org.gannacademy.cdf.graphics.geom.Rectangle   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 Rectangle(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.Rectangle2D;
9
10
/**
11
 * <p>Draw a rectangle</p>
12
 *
13
 * <p><img src="doc-files/Rectangle.png" alt="Rectangle diagram"></p>
14
 *
15
 * @author <a href="https://github.com/gann-cdf/graphics/issues" target="_blank">Seth Battis</a>
16
 */
17
public class Rectangle extends Drawable2D {
18
  /**
19
   * <p>Construct a new rectangle</p>
20
   *
21
   * <p><img src="doc-files/Rectangle.png" alt="Diagram of Rectangle parameters"></p>
22
   *
23
   * <p>All window coordinates are measured in pixels, with the X-axis increasing from left to right and the Y-axis
24
   * increasing from top to bottom. All window coordinates exist in the first quadrant.</p>
25
   *
26
   * <p><img src="../doc-files/window-coordinates.png" alt="Diagram of window coordinates"></p>
27
   *
28
   * @param x            coordinate of origin
29
   * @param y            coordinate of origin
30
   * @param width        in pixels
31
   * @param height       in pixels
32
   * @param drawingPanel on which to draw
33
   */
34
  public Rectangle(double x, double y, double width, double height, DrawingPanel drawingPanel) {
35
    try {
36
      setShape(new Rectangle2D.Double(x, y, width, height));
37
      setDrawingPanel(drawingPanel);
38
    } catch (DrawableException e) {
39
        System.err.println(e.getMessage());
40
      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...
41
    }
42
  }
43
44
  @Override
45
  public void setShape(Shape shape) throws DrawableException {
46
    if (shape instanceof Rectangle2D) {
47
      super.setShape(shape);
48
    } else {
49
      throw new DrawableException("Attempt to set Rectangles's underlying shape to a non-Rectangle2D instance");
50
    }
51
  }
52
}
53