@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		JViewport jv = (JViewport) this.getParent();
		Point jvp = jv.getViewPosition();
		
		int xStart = (int) jvp.getX();
		xStart /= tileSize;
		if (xStart - 1 >= 0)
			xStart -= 1;
		
		int yStart = (int) jvp.getY();
		yStart /= tileSize;
		if (yStart - 1 >= 0)
			yStart -= 1;
		
		int xEnd = (int) (jvp.getX() + jv.getWidth());
		xEnd /= tileSize;
		if (xEnd + 1 < map.getMapWidth())
			xEnd += 1;
		else
			xEnd = map.getMapWidth();
		
		int yEnd = (int) (jvp.getY() + jv.getHeight());
		yEnd /= tileSize;
		if (yEnd + 1 < map.getMapHeight())
			yEnd += 1;
		else
			yEnd = map.getMapHeight();
		
		if (saveToImage) {
			xStart = 0;
			yStart = 0;
			xEnd = map.getMapWidth();
			yEnd = map.getMapHeight();
		}
		
		int halfTileSize = tileSize / 2;
		FontMetrics fm = g.getFontMetrics();
		
		/*
		 * Terrain and grid.
		 */
		g.setColor(Color.BLACK);
		for (int i = xStart; i < xEnd; i++) {
			for (int j = yStart; j < yEnd; j++) {
				Tile t = map.getTile(i, j, false);
				
				g.drawRect(i * tileSize, j * tileSize, tileSize, tileSize);
			}
		}
	}