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

1     package model.strategy;
2     
3     import java.awt.BasicStroke;
4     import java.awt.Color;
5     import java.awt.Graphics;
6     import java.awt.Graphics2D;
7     import java.awt.Shape;
8     
9     import view.Enum.ShapeColor;
10     import view.Enum.ShapeShadingType;
11     import view.adapter.ColorAdapter;
12     
13     public class ShapeShadingStrategy {
14     	ShapeColor color;
15     	ShapeColor primaryColor;
16     	ShapeColor secondaryColor;
17     	Shape shape;
18     	ShapeShadingType shapeShadingType = ShapeShadingType.OUTLINE;
19     	BasicStroke stroke = new BasicStroke(5.0f);
20     
21     	public ShapeShadingStrategy(ShapeShadingType shapeShadingType, ShapeColor primaryColor, ShapeColor secondaryColor,
22     			Shape shape, Graphics2D graphics2d, BasicStroke str) {
23     		this.shapeShadingType = shapeShadingType;
24     		this.shape = shape;
25     		this.color = primaryColor;
26     		this.stroke = str;
27     
28     		if (shapeShadingType.equals(ShapeShadingType.OUTLINE_AND_FILLED_IN)) {
29     			this.primaryColor = primaryColor;
30     			this.secondaryColor = secondaryColor;
31     			this.shape = shape;
32     		}
33     	}
34     
35     	public void draw(Graphics g) {
36     		Graphics2D graphics2d = (Graphics2D) g;
37     		graphics2d.setStroke(stroke);
38     
39     		if (shapeShadingType == (ShapeShadingType.OUTLINE)) {
40     			graphics2d.setPaint(ColorAdapter.getColor(color));
41     			graphics2d.draw(shape);
42     		} else if (shapeShadingType.equals(ShapeShadingType.FILLED_IN)) {
43     			Color color2 = ColorAdapter.getColor(color);
44     			graphics2d.setPaint(color2);
45     			graphics2d.fill(shape);
46     		} else {
47     			graphics2d.setPaint(ColorAdapter.getColor(secondaryColor));
48     			graphics2d.draw(shape);
49     
50     			graphics2d.setPaint(ColorAdapter.getColor(primaryColor));
51     			graphics2d.fill(shape);
52     		}
53     	}
54     
55     	public void setStoke(BasicStroke stroke) {
56     		this.stroke = stroke;
57     	}
58     
59     }
60