@Override
	public void mouseClicked(MouseEvent e) {
		int x = e.getX();
		int y = e.getY();
		
		if(mode == null) {
			
			if(search == null) return;
			Node n = getNodeAt(x, y);
			if(n == null) return;

			if(first == null) {
				first = n;
				first.setColor(Color.RED);
			} else {
				List<Node> path = search.search(first, n, nodes);
				if(path == null) {
					colored = true;
					revertColors();
					first = null;
					search = null;
					JOptionPane.showMessageDialog(this, "Path not found.");
					return;
				}
				Node last = null;
				for(Node node : path) {
					node.setColor(Color.RED);
					if(last != null) node.getEdgeWith(last).setColor(Color.RED);
					last = node;
				}
				
				first = null;
				search = null;
				colored = true;
			}
			
		} else {
		
			switch(mode) {
			case DESTINATION:
				Destination destin = new Destination(x, y);
				add(destin);
				nodes.add(destin);
				break;
			case WAYPOINT:
				Waypoint way = new Waypoint(x, y);
				add(way);
				nodes.add(way);
				break;
			default:
				break;
			}
			
		}
	}