File: /Users/shatabdi/Education/GitHub/se450_project/src/view/PaintCanvas.java

1     package view;
2     
3     import java.awt.Graphics;
4     import java.awt.Graphics2D;
5     import java.util.List;
6     
7     import model.commands.CommandHistory;
8     import model.interfaces.IObserver;
9     import model.interfaces.IShape;
10     import view.interfaces.PaintCanvasBase;
11     
12     public class PaintCanvas extends PaintCanvasBase implements IObserver {
13     
14     	/**
15     	 * 
16     	 */
17     	private static final long serialVersionUID = 1L;
18     
19     	public Graphics2D getGraphics2D() {
20     		return (Graphics2D) getGraphics();
21     	}
22     @Override
23     	protected void paintComponent(Graphics g) {
24     		super.paintComponent(g);
25     
26     		Graphics2D g2 = (Graphics2D) g;
27     		List<IShape> shapeCollectionList = CommandHistory.shapeCollection.getList();
28     		List<IShape> selectedCollectionList = CommandHistory.shapesSelected.getList();
29     
30     		for (IShape shapeItem : shapeCollectionList) {
31     			shapeItem.setGraphics2d(g2);
32     			shapeItem.paintShapeOnCanvas();
33     			if (selectedCollectionList.contains(shapeItem)) {
34     				shapeItem.highlightShape();
35     			}
36     		}
37     	}
38     
39     	public void update() {
40     		this.repaint();
41     	}
42     }
43