public void setNewImage(String imgFileName) throws IOException 
	{
		System.out.println("**** New Image ****");
		ImageBlocker blocker = new ImageBlocker(imgFileName);
		System.out.println("New image loaded: " + imgFileName);

		ArrayList<HashSet<Block>> parsedShapes = blocker.getLargeConnectedComponents(0.10);
		int shapesLeft = parsedShapes.size();
		System.out.println("# shapes left = " + shapesLeft);
		shapes = new ArrayList<Shape>();
		for (HashSet<Block> s: parsedShapes) {
			shapes.add(new Shape(s));
		}

		// Default values.
		imgWidth = 1.0;
		imgHeight = 1.0;

		double minX = Double.POSITIVE_INFINITY;
		double minY = minX;
		double maxX = Double.NEGATIVE_INFINITY;
		double maxY = maxX;
		for (Shape s: shapes) {
			BBox box = s.tree.getBox();
			if (box.lower.x < minX) minX = box.lower.x;
			if (box.lower.y < minY) minY = box.lower.y;
			if (box.upper.x > maxX) maxX = box.upper.x;
			if (box.upper.y > maxY) maxY = box.upper.y;
		}
		System.out.println("Area Covered: (" + minX + "," + minY + ") -- (" + maxX + "," + maxY + ")");
		imgWidth = maxX;
		imgHeight = maxY;
		
		// Calculate the scale.
		double canvasRatio = ((double) width) / ((double) height);
		double imgRatio = imgWidth / imgHeight;
		if (imgRatio <= canvasRatio) {
			// adjust according to height
			scale = ((double) height) / imgHeight;
		}
		else {
			// adjust according to width
			scale = ((double) width) / imgWidth;
		}

		repaint();
	}