<repo_name>mbsuarezg/Proyecto<file_sep>/src/Model/Pentagon.java
package Model;

import java.awt.Color;
import java.awt.Graphics2D;

public class Pentagon extends ClosedFigure{

	public Pentagon(Color color, BoundBox bbox, int thickness, Color backcolor) {
		super(color, bbox, thickness, backcolor);
		// TODO Auto-generated constructor stub
	}

	private static final long serialVersionUID = 1L;
	int [] heightPoints = {getBoundBox().y,getBoundBox().y + getBoundBox().height/3,getBoundBox().y + getBoundBox().height,getBoundBox().y + getBoundBox().height,getBoundBox().y + getBoundBox().height/3};
	int [] weidthPoints = {getBoundBox().x + getBoundBox().width/2, getBoundBox().x + getBoundBox().width,getBoundBox().x + (2*getBoundBox().width)/3,getBoundBox().x + getBoundBox().width/3, getBoundBox().x};
	@Override
	public void endPaint(Graphics2D g) {
		// TODO Auto-generated method stub
		g.drawPolygon(weidthPoints,heightPoints,5);
	}

	@Override
	public void fillBackGround(Graphics2D g) {
		// TODO Auto-generated method stub
		g.fillPolygon(weidthPoints, heightPoints, 5);
	}

}
<file_sep>/src/View/LineCreationTool.java
package View;

import java.awt.Point;

import Controller.App;
import Model.BoundBox;
import Model.Figure;
import Model.Line;

public class LineCreationTool extends CreationTool {

	public Figure createFigure(Point ptPress, Point ptReleased) {

		Figure fig = new Line(App.getInstance().getThicknessColor(), new BoundBox(ptPress, ptReleased), 1);
		return fig;
	}

}
<file_sep>/src/View/MainFrame.java
package View;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class MainFrame extends JFrame {

	private static MainFrame mf;
	private MenuHelper mh;
	private Canvas cv;

	public static MainFrame getInstance() {
		if (mf == null) {
			mf = new MainFrame();
		}
		return mf;
	}

	private MainFrame() {
	}

	public void init() {

		mf.setTitle("Paint proyect");
		mf.setVisible(true);
		Toolkit screen = Toolkit.getDefaultToolkit();
		Dimension dimension = screen.getScreenSize();

		int widthD = dimension.width;
		int heightD = dimension.height;
		addMenuHelper();
		addCanvas();

		setBounds(widthD / 8, heightD / 8, widthD / 2, heightD / 2);

		mf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	}

	public void addCanvas() {
		cv = Canvas.getInstance();
		this.add(cv, BorderLayout.CENTER);
	}

	public void addMenuHelper() {

		mh = MenuHelper.getInstance();
		this.add(mh, BorderLayout.NORTH);
	}
	
	public void setActiveToolCanvas(int activeTool) {
		
		cv.setActiveTool(activeTool);
	}
}
<file_sep>/src/View/MenuHelper.java
package View;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import Controller.App;

public class MenuHelper extends JMenuBar{

	private static MenuHelper menu;

	public static MenuHelper getInstance() {
		if (menu == null) {
			menu = new MenuHelper();
		}
		return menu;
	}

	private MenuHelper() {
		super();
		this.add(setFile());
		this.add(setTool());
		this.add(setColor());
	}

	private JMenu setFile() {

		JMenu file = new JMenu("File");

		JMenuItem snew = new JMenuItem("New");
		JMenuItem sdelete = new JMenuItem("Delete");
		JMenuItem sclose = new JMenuItem("Close");

		file.add(snew);
		file.add(sdelete);
		file.add(sclose);
		
		sclose.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
		
		return file;
	}

	private JMenu setTool() {

		JMenu tool = new JMenu("Tool");

		JMenuItem circle = new JMenuItem("Circle");
		JMenuItem rectangle = new JMenuItem("Rectangle");
		JMenuItem phenta = new JMenuItem("Pentagon");
		JMenuItem line = new JMenuItem("Line");
		JMenuItem text = new JMenuItem("Text");
		
		tool.add(circle);
		tool.add(rectangle);
		tool.add(phenta);
		tool.add(line);
		tool.add(text);
		
		circle.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				App.getInstance().setActiveTool(Canvas.ELLIPSE_CREATION_TOOL);
			}
		});
		
		rectangle.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				App.getInstance().setActiveTool(Canvas.RECTANGLE_CREATION_TOOL);
			}
		});
		
		phenta.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				App.getInstance().setActiveTool(Canvas.PENTAGON_CREATION_TOOL);
			}
		});
		
		line.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				App.getInstance().setActiveTool(Canvas.LINE_CREATION_TOOL);
			}
		});
		
		text.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				App.getInstance().setActiveTool(Canvas.TEXT_CREATION_TOOL);
			}
		});
		return tool;
	}

	private JMenu setColor() {

		JMenu color = new JMenu("Color");

		JMenuItem bc = new JMenuItem("Background color");
		JMenuItem tc = new JMenuItem("Thickness color");

		color.add(bc);
		color.add(tc);

		bc.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				App.getInstance().setBackGroundColor();
			}
		});
		
		tc.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				App.getInstance().setThicknessColor();;
			}
		});
		return color;
	}
}
<file_sep>/src/View/Canvas.java
package View;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JPanel;

import Model.Drawing;
import Model.Figure;

public class Canvas extends JPanel implements CanvasListener {

	private static Canvas canvas;

	static final int LINE_CREATION_TOOL = 0;
	static final int ELLIPSE_CREATION_TOOL = 1;
	static final int RECTANGLE_CREATION_TOOL = 2;
	static final int TEXT_CREATION_TOOL = 3;
	static final int PENTAGON_CREATION_TOOL = 4;

	private Tools[] tools;
	private Tools activeTool;

	private List<CanvasListener> listeners = new LinkedList();

	public static Canvas getInstance() {
		if (canvas == null) {
			canvas = new Canvas();
		}
		return canvas;
	}

	private Canvas() {

		super();
		setBackground(Color.WHITE);

		tools = new Tools[PENTAGON_CREATION_TOOL + 1];

		tools[LINE_CREATION_TOOL] = new LineCreationTool();
		tools[ELLIPSE_CREATION_TOOL] = new EllipseCreationTool();
		tools[RECTANGLE_CREATION_TOOL] = new RectangleCreationTool();
		tools[TEXT_CREATION_TOOL] = new TextCreationTool();
		tools[PENTAGON_CREATION_TOOL] = new PentagonCreationTool();

		addMouseListener(new MouseAdapter() {

			@Override
			public void mousePressed(MouseEvent e) {

				activeTool.mousePressed(e);
			}

			@Override
			public void mouseReleased(MouseEvent e) {

				activeTool.mouseReleased(e);
			}

		});
	}

	public void notifyListeners(CanvasEvent e) {
		Iterator<CanvasListener> iterator = listeners.iterator();

		while (iterator.hasNext()) {
			iterator.next().update(e);
		}
	}

	public void setActiveTool(final int activeTool) {

		this.activeTool = tools[activeTool];

		notifyListeners(CanvasEvent.TOOL_CHANGED);
	}

	public void paint(Graphics g) {

		super.paint(g);
		Iterator<Figure> it = Drawing.getInstance().getIterator();
		while (it.hasNext()) {
		it.next().paint((Graphics2D) g);

		}
	}

	@Override
	public void update(CanvasEvent e) {
		this.repaint();
	}

}
<file_sep>/src/View/EllipseCreationTool.java
package View;

import java.awt.Point;

import Controller.App;
import Model.BoundBox;
import Model.Ellipse;
import Model.Figure;

public class EllipseCreationTool extends CreationTool {

	@Override
	public Figure createFigure(Point ptPress, Point ptReleased) {

		Figure fig = new Ellipse(App.getInstance().getThicknessColor(), new BoundBox(ptPress, ptReleased),1, App.getInstance().getBackGroundColor());
		return fig;
	}

}
<file_sep>/src/View/CanvasListener.java
package View;

import View.CanvasListener.CanvasEvent;

public interface CanvasListener {
	
	public enum CanvasEvent{
		TOOL_CHANGED;
	}
	public abstract void update(CanvasEvent e);

}