package tropicalescape.physics;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import org.newdawn.slick.geom.Rectangle;

public class CompositeRectangleFactory {
	public static CompositeRectangle loadFromTXT(String path)
			throws IOException {
		CompositeRectangle cr = new CompositeRectangle();
		File file = new File(path);
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(file));
			String text = null;
			while ((text = reader.readLine()) != null) {
				String[] array = text.split(" ", -1);
				System.out.println(array);
				if (array.length < 4) {
					throw new IOException("Need 4 rectangles");
				}
				try {
					float x = Float.parseFloat(array[0]);
					float y = Float.parseFloat(array[1]);
					float w = Float.parseFloat(array[2]);
					float h = Float.parseFloat(array[3]);
					cr.addRectangle(new Rectangle(x, y, w, h));
				} catch (NumberFormatException e) {
					throw new IOException(e);
				}
			}
		} finally {
			if (reader != null) {
				reader.close();
			}
		}
		return cr;
	}
	
	public static void main(String [] args) {
		try {
			CompositeRectangle cr = CompositeRectangleFactory.loadFromTXT("res/rects/test.txt");
			System.out.println(cr.getRectangles());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

@@ -1104,249 +1104,6 @@
 %0A%09%7D%0A
-%09%0A%09public static void main(String %5B%5D args) %7B%0A%09%09try %7B%0A%09%09%09CompositeRectangle cr = CompositeRectangleFactory.loadFromTXT(%22res/rects/test.txt%22);%0A%09%09%09System.out.println(cr.getRectangles());%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

remove main