File: /Users/shatabdi/Education/GitHub/se450_project/src/model/Ellipse.java

1     // The ellipse drawing is adopted from
2     // https://www.programcreek.com/java-api-examples/?api=java.awt.geom.Ellipse2D
3     
4     package model;
5     
6     import java.awt.BasicStroke;
7     import java.awt.Graphics;
8     import java.awt.Graphics2D;
9     import java.awt.Shape;
10     import java.awt.Stroke;
11     import java.awt.geom.Ellipse2D;
12     
13     import model.strategy.ShapeTypeStrategy;
14     import view.Enum.ShapeColor;
15     import view.Enum.ShapeShadingType;
16     import view.adapter.ColorAdapter;
17     
18     public class Ellipse extends ShapeTypeStrategy {
19     
20     	int height;
21     	ShapeColor primaryColor;
22     	ColorAdapter primaryColorAdapter;
23     	ShapeColor secondaryColor;
24     	ColorAdapter secondaryColorAdapter;
25     	ShapeShadingType shapeShadingType;
26     	Stroke stroke;
27     	int width;
28     	int x; // X coordinate
29     	int y; // Y coordinate
30     
31     	public Ellipse(int x, int y, int width, int height) {
32     
33     		this.x = x;
34     		this.y = y;
35     		this.width = width;
36     		this.height = height;
37     	}
38     
39     	public void draw(Graphics g) {
40     		Graphics2D g2 = (Graphics2D) g;
41     		if (shapeShadingType.equals(ShapeShadingType.OUTLINE)) {
42     			g2.setStroke(new BasicStroke(5));
43     			g.setColor(ColorAdapter.getColor(primaryColor));
44     			g.drawOval(x, y, width, height);
45     		} else if (shapeShadingType.equals(ShapeShadingType.FILLED_IN)) {
46     			g2.setStroke(new BasicStroke(5));
47     			g.setColor(ColorAdapter.getColor(secondaryColor));
48     			g.fillOval(x, y, width, height);
49     		} else if (shapeShadingType.equals(ShapeShadingType.OUTLINE_AND_FILLED_IN)) {
50     			g2.setStroke(new BasicStroke(5));
51     			g.setColor(ColorAdapter.getColor(primaryColor));
52     			g.drawOval(x, y, width, height);
53     			g.setColor(ColorAdapter.getColor(secondaryColor));
54     			g.fillOval(x, y, width, height);
55     		}
56     
57     	}
58     
59     	public Shape createShapeType() {
60     		Ellipse2D outerCircle = new Ellipse2D.Double(x, y, width, height);
61     		return outerCircle;
62     	}
63     
64     }
65