@Override
	public void mouseClicked(MouseEvent arg0)
	{
		Point2D.Float position = new Point2D.Float(arg0.getX() - offset, arg0.getY() - offset);
		EditorObjectInformation object = null;
		switch (frame.getSelectedTool())
		{
		case CURSOR:
			boolean insideBorder = false;
			for (EditorObjectInformation object2 : map.getGameObjects())
			{
				if (object2.isInsideBorder(position) != DragDirection.OUTSIDE)
					insideBorder = true;
				if (object2.isInside(position))
				{
					selectedObject = object2;
					frame.toolPanel.update();
					break;
				}
			}
			if (!insideBorder)
			{
				selectedObject = null;
				frame.toolPanel.update();
			}
			break;
		case WALL:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 40, 40, position, null, null, 0, EditorObjectType.WALL, frame.getControl().getNext(EditorObjectType.WALL));
			map.getGameObjects().add(object);
			selectedObject = object;
			break;
		case BLOCK:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 40, 40, position, new Point2D.Float(40, 40), null, 0, EditorObjectType.BLOCK, frame.getControl().getNext(
					EditorObjectType.BLOCK));
			map.getGameObjects().add(object);
			selectedObject = object;
			break;
		case DEADLYBLOCK:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 40, 40, position, new Point2D.Float(40, 40), null, 0, EditorObjectType.DEADLYBLOCK, frame.getControl()
					.getNext(EditorObjectType.DEADLYBLOCK));
			map.getGameObjects().add(object);
			selectedObject = object;
			break;
		case SPIKE:
			if (arg0.isControlDown() && arg0.getButton() == MouseEvent.BUTTON1)
			{
				position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
				object = new EditorObjectInformation((float) (Math.PI / 2 * 3), 20, 20, position, null, null, 0, EditorObjectType.SPIKE, frame.getControl()
						.getNext(EditorObjectType.SPIKE));
				map.getGameObjects().add(object);
			}
			else if (arg0.getButton() == MouseEvent.BUTTON1)
			{
				position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
				object = new EditorObjectInformation(0, 20, 20, position, null, null, 0, EditorObjectType.SPIKE, frame.getControl().getNext(
						EditorObjectType.SPIKE));
				map.getGameObjects().add(object);
			}
			if (arg0.isControlDown() && arg0.getButton() == MouseEvent.BUTTON3)
			{
				position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
				object = new EditorObjectInformation((float) (Math.PI / 2), 20, 20, position, null, null, 0, EditorObjectType.SPIKE, frame.getControl()
						.getNext(EditorObjectType.SPIKE));
				map.getGameObjects().add(object);
			}
			else if (arg0.getButton() == MouseEvent.BUTTON3)
			{
				position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
				object = new EditorObjectInformation((float) Math.PI, 20, 20, position, null, null, 0, EditorObjectType.SPIKE, frame.getControl().getNext(
						EditorObjectType.SPIKE));
				map.getGameObjects().add(object);
			}
			selectedObject = object;
			break;
		case PLATFORM:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 40, 40, position, position, position, 1, EditorObjectType.PLATFORM, frame.getControl().getNext(
					EditorObjectType.PLATFORM));
			map.getGameObjects().add(object);
			selectedObject = object;
			break;
		case DEADLYPLATFORM:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 40, 40, position, position, position, 1, EditorObjectType.DEADLYPLATFORM, frame.getControl().getNext(
					EditorObjectType.DEADLYPLATFORM));
			map.getGameObjects().add(object);
			selectedObject = object;
			break;
		case DELETE:
			selectedObject = null;
			Iterator<EditorObjectInformation> it = map.getGameObjects().iterator();
			while (it.hasNext())
			{
				object = it.next();
				if (object.isInside(position))
				{
					if (object.getObjectType() == EditorObjectType.INTERACTION)
					{
						map.setInteractLine1(null);
						map.setInteractLine2(null);
					}
					else if (object.getObjectType() == EditorObjectType.PC)
					{
						frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().get(object.toString()).clear();
						frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().remove(object.toString());
					}
					it.remove();
					break;
				}
			}
			break;
		case OMRU:
			Iterator<EditorObjectInformation> it2 = map.getGameObjects().iterator();
			while (it2.hasNext())
			{
				object = it2.next();
				if (object.getObjectType() == EditorObjectType.OMRU)
				{
					it2.remove();
					break;
				}
			}
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 160, 160, position, null, null, 0, EditorObjectType.OMRU, frame.getControl().getNext(EditorObjectType.OMRU));
			map.getGameObjects().add(object);
			selectedObject = object;
			frame.setSelectedTool(SelectedTool.CURSOR);
			break;
		case INTERACTION:
			Iterator<EditorObjectInformation> it3 = map.getGameObjects().iterator();
			while (it3.hasNext())
			{
				object = it3.next();
				if (object.getObjectType() == EditorObjectType.INTERACTION)
				{
					it3.remove();
					map.setInteractLine1(null);
					map.setInteractLine2(null);
					break;
				}
			}
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 100, 100, position, null, null, 0, EditorObjectType.INTERACTION, frame.getControl().getNext(
					EditorObjectType.INTERACTION));
			map.getGameObjects().add(object);
			selectedObject = object;
			frame.setSelectedTool(SelectedTool.CURSOR);
			new LinesDialog(frame, map);
			break;
		case PC:
			Iterator<EditorObjectInformation> it4 = map.getGameObjects().iterator();
			while (it4.hasNext())
			{
				object = it4.next();
				if (object.getObjectType() == EditorObjectType.PC)
				{
					frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().get(object.toString()).clear();
					frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().remove(object.toString());
					it4.remove();
					break;
				}
			}
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			object = new EditorObjectInformation(0, 80, 80, position, null, null, 0, EditorObjectType.PC, frame.getControl().getNext(EditorObjectType.PC));
			map.getGameObjects().add(object);
			selectedObject = object;
			frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().put(object.toString(), new ArrayList<EditorObjectInformation>());
			frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().get(object.toString()).add(object);
			frame.getLevels().get("level " + frame.getCurrentLevel()).getActivatedComps().put(object.toString(), true);
			break;
		case DOOR:
			if (frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().isEmpty())
			{
				JOptionPane.showMessageDialog(new JFrame(), "No PC created to link this door.", "Error 2407", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				tempEOI = null;
				position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
				object = new EditorObjectInformation(0, 20, 200, position, position, position, 1, EditorObjectType.DOOR, frame.getControl().getNext(
						EditorObjectType.DOOR));
				EditorObjectInformation selectedPC = getPcSelection();
				if (tempEOI != null)
				{
					frame.getLevels().get("level " + frame.getCurrentLevel()).getComps().get(selectedPC.toString()).add(object);
					map.getGameObjects().add(object);
				}
				else
					JOptionPane.showMessageDialog(new JFrame(), "No PC selected.", "Error 2408", JOptionPane.WARNING_MESSAGE);
			}
			break;
		case LINE:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			if (secondClickLine)
			{
				Line2D.Float newLine = new Line2D.Float(firstPointLine, position);
				map.getLines().add(newLine);
				secondClickLine = false;
				firstPointLine = null;
			}
			else
			{
				secondClickLine = true;
				firstPointLine = position;
			}
			break;
		case NEXTLEVEL:
			position = getGridPoint(new Point2D.Float(arg0.getPoint().x - offset, arg0.getPoint().y - offset));
			if (secondClickNextLevel)
			{
				map.setNextLevelStep(getRectangle(firstPointNextLevel, position));
				secondClickNextLevel = false;
				firstPointNextLevel = null;
			}
			else
			{
				secondClickNextLevel = true;
				firstPointNextLevel = position;
			}
			break;
		default:
			break;
		}
	}