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

1     //adopted from project starter code
2     //this is builder pattern, add in PDF report
3     package model;
4     
5     import java.awt.BasicStroke;
6     import java.awt.Color;
7     import java.awt.Graphics;
8     import java.awt.Graphics2D;
9     import java.awt.Point;
10     import java.awt.Shape;
11     import java.awt.Stroke;
12     import java.util.List;
13     
14     import model.interfaces.IShape;
15     import view.Enum.ShapeColor;
16     import view.Enum.ShapeShadingType;
17     import view.Enum.ShapeType;
18     import view.adapter.ColorAdapter;
19     
20     /* shape class implementing IShape
21     The class could be named as Shape, but since we are using java.awt.Shape class,
22     this class is named as GeometricShape */
23     public class GeometricShape implements IShape {
24     	private Point endPoint;
25     	private int height;
26     	private ShapeColor primaryColor;
27     	ColorAdapter primaryColorAdapter;
28     	private ShapeColor secondaryColor;
29     	ColorAdapter secondaryColorAdapter;
30     
31     	ShapeShadingType shapeShadingType;
32     
33     	private ShapeType shapeType;
34     
35     	private Point startPoint;
36     	Stroke stroke;
37     
38     	// moved the properties from Triangle, Rectangle, Ellipse classes
39     	private int width;
40     	private int x;
41     	private int y;
42     
43     
44     	public GeometricShape(Point mousePressed, Point mouseReleased, ShapeColor primaryColor, ShapeColor secondaryColor,
45     			ShapeShadingType shapeShadingType) {
46     		selectMaxandMin(mousePressed, mouseReleased);
47     		this.primaryColor = primaryColor;
48     		this.secondaryColor = secondaryColor;
49     		this.shapeShadingType = shapeShadingType;
50     		primaryColorAdapter = new ColorAdapter(primaryColor);
51     		secondaryColorAdapter = new ColorAdapter(secondaryColor);
52     		this.stroke = new BasicStroke(5);
53     	}
54     	public GeometricShape(Point startPoint, Point endPoint) {
55     		this.startPoint = startPoint;
56     		this.endPoint = endPoint;
57     
58     		// Set default property values
59     		this.primaryColor = primaryColor;
60     		this.secondaryColor = secondaryColor;
61     		this.shapeShadingType = shapeShadingType;
62     		primaryColorAdapter = new ColorAdapter(primaryColor);
63     		secondaryColorAdapter = new ColorAdapter(secondaryColor);
64     		this.stroke = new BasicStroke(5);
65     
66     		selectMaxandMin();
67     	}
68     	@Override
69     	public void addX(int x) {
70     		// TODO Auto-generated method stub
71     
72     	}
73     
74     	@Override
75     	public void addY(int y) {
76     		// TODO Auto-generated method stub
77     
78     	}
79     
80     	@Override
81     	public Boolean contain(Point startpoint) {
82     		// TODO Auto-generated method stub
83     		return null;
84     	}
85     
86     	@Override
87     	public IShape copyShape() {
88     		// TODO Auto-generated method stub
89     		return null;
90     	}
91     
92     	@Override
93     	public void create() {
94     		// TODO Auto-generated method stub
95     
96     	}
97     
98     	@Override
99     	public void deleteShape() {
100     		// TODO Auto-generated method stub
101     
102     	}
103     
104     	@Override
105     	public void draw(Graphics g) {
106     		// TODO Auto-generated method stub
107     
108     	}
109     
110     	@Override
111     	public Shape getBoundingBox() {
112     		// TODO Auto-generated method stub
113     		return null;
114     	}
115     
116     	public Point getEndPoint() {
117     		return endPoint;
118     	}
119     
120     	public int getHeight() {
121     		return height;
122     	}
123     
124     	@Override
125     	public List<IShape> getNodeList() {
126     		// TODO Auto-generated method stub
127     		return null;
128     	}
129     
130     	@Override
131     	public ShapeColor getPrimaryColor() {
132     		return primaryColor;
133     	}
134     
135     	@Override
136     	public ShapeColor getSecondaryColor() {
137     		return secondaryColor;
138     	}
139     
140     	public ShapeShadingType getShadingType() {
141     		return shapeShadingType;
142     	}
143     
144     	public ShapeType getShapeType() {
145     		return shapeType;
146     	}
147     
148     	public int getShapeXcoord() {
149     		return x;
150     	}
151     
152     	public int getShapeYcoord() {
153     		return y;
154     	}
155     
156     	public Point getStartPoint() {
157     		return startPoint;
158     	}
159     
160     	@Override
161     	public Stroke getStroke() {
162     		// TODO Auto-generated method stub
163     		return this.getStroke();
164     	}
165     
166     	public int getWidth() {
167     		return width;
168     	}
169     
170     	@Override
171     	public void highlightShape() {
172     		// TODO Auto-generated method stub
173     
174     	}
175     
176     	@Override
177     	public void moveShape(int transformOffsetX, int transformOffsetY) {
178     		// TODO Auto-generated method stub
179     
180     	}
181     
182     	@Override
183     	public void paintShapeOnCanvas() {
184     		// TODO Auto-generated method stub
185     
186     	}
187     
188     	@Override
189     	public IShape pasteShape() {
190     		// TODO Auto-generated method stub
191     		return null;
192     	}
193     
194     	public void selectMaxandMin() {
195     		this.x = Math.min(startPoint.x, endPoint.x);
196     		
197     		if (endPoint.x >= startPoint.x)
198     			this.width = endPoint.x - startPoint.x;
199     		else
200     			this.width = startPoint.x - endPoint.x;
201     		
202     		this.y = Math.min(startPoint.y, endPoint.y);
203     		
204     		if (endPoint.y >= startPoint.y)
205     			this.height = endPoint.y - startPoint.y ;
206     		else
207     			this.height = startPoint.y - endPoint.y;
208     	}
209     
210     	@Override
211     	public void selectMaxandMin(Point start, Point end) {
212     		// TODO Auto-generated method stub
213     
214     	}
215     
216     	public GeometricShape setEndPoint(Point endPoint) {
217     		this.endPoint = endPoint;
218     		return this;
219     	}
220     
221     	@Override
222     	public void setGraphics2d(Graphics2D graphics2d) {
223     		// TODO Auto-generated method stub
224     
225     	}
226     
227     	public GeometricShape setHeight(int ht) {
228     		this.height = ht;
229     		return this;
230     	}
231     
232     	public GeometricShape setPrimaryColor(Color primaryColor2) {
233     		// TODO Auto-generated method stub
234     		this.primaryColor = ColorAdapter.getShapeColor(primaryColor2);
235     		return this;
236     	}
237     
238     	@Override
239     	public void setPrimaryColor(ShapeColor primaryColor) {
240     		this.primaryColor = primaryColor;
241     	}
242     
243     	public GeometricShape setSecondaryColor(Color secondaryColor2) {
244     		this.secondaryColor = ColorAdapter.getShapeColor(secondaryColor2);
245     		return this;
246     
247     	}
248     
249     	@Override
250     	public void setSecondaryColor(ShapeColor secondaryColor) {
251     		this.secondaryColor = secondaryColor;
252     	}
253     
254     	@Override
255     	public void setShadingColor(ShapeShadingType shapeShadingType) {
256     		this.shapeShadingType = shapeShadingType;
257     	}
258     
259     	public GeometricShape setShadingType(ShapeShadingType shadingType) {
260     		this.shapeShadingType = shadingType;
261     		return this;
262     	}
263     
264     	public GeometricShape setShapeType(ShapeType shapeType) {
265     		this.shapeType = shapeType;
266     		return this;
267     	}
268     
269     	public GeometricShape setShapeXcoord(int shapeXcoord) {
270     		this.x = shapeXcoord;
271     		return this;
272     	}
273     
274     	public GeometricShape setShapeYcoord(int shapeYcoord) {
275     		this.y = shapeYcoord;
276     		return this;
277     	}
278     
279     	public GeometricShape setStartPoint(Point startPoint) {
280     		this.startPoint = startPoint;
281     		return this;
282     	}
283     
284     	@Override
285     	public void setStroke(Stroke stroke) {
286     		this.stroke = stroke;
287     
288     	}
289     
290     	public GeometricShape setWidth(int width) {
291     		this.width = width;
292     		return this;
293     	}
294     
295     }
296