package xml;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedList;

public class xml_image_register {
	
	private int nboxes;
	
	private String imageName;
	
	private int width;
	
	private int height;
	
	LinkedList<text_region_parameters> bParameters;

	public xml_image_register (){

	}

	public xml_image_register (String imageName, int width, int height, LinkedList<text_region_parameters> bParameters, int nboxes){
		this.imageName = imageName;
		this.width = width;
		this.height = height;
		this.bParameters = bParameters;
		this.nboxes = nboxes;
	}
	
	public int getNboxes() {
		return nboxes;
	}

	public void setNBoxes(int nboxes) {
		this.nboxes = nboxes;
	}
	
	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width =  width;
	}
	
	public int getHeight() {
		return height;
	}

	public void setHeight (int height) {
		this.height =  height;
	}
	
	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		this.imageName = imageName;
	}
	
	public text_region_parameters getBox (int pos) {
		return bParameters.get(pos);
	}
	
	public static void toXML ( 
			PrintStream out,
			String xml_header_name, 
			int width, 
			int height, 
			LinkedList<text_region_parameters> list )
	{
		int margin = 0;

		out.println("<image>");

		out.println("<imageName>" + xml_header_name + "</imageName>");

		out.println("<resolution x=\"" + width + "\" y=\"" + height + "\"/>");

		if (list.size() <= 0) {
			out.println("<taggedRectangles/>\n");
		}
		else {
			out.println("<taggedRectangles>");
			for (int b = 0; b < list.size(); b++) {
				text_region_parameters box = list.get(b);
				out.println("<taggedRectangle x=\"" + (box.getX() - margin) + "\" y=\"" + (box.getY()-margin) + "\" width=\"" + (box.getW()+margin) + "\" height=\"" + (box.getH()+margin) + "\" text=\"" + box.getText() + "\" id=\"" + box.getId() + "\" score=\"" + box.getScore() +"\" rotation=\"0.0\" offset=\"0.0\"/>");
			}
			out.println("</taggedRectangles>");
		}
		out.println("</image>");

	}
}
