package com.grorogue.uilanterna;

import java.util.Iterator;

import com.jrle.std.ui.WidgetStdTextarea;

public class WidgetStdTextareaAscii extends WidgetStdTextarea<UiStdAscii> {

	public WidgetStdTextareaAscii(UiStdAscii ui, int y, int x, int height, int width) {
		super(ui, y, x, height, width);
	}

	@Override
	public void clear() {
		int y = this.getClientY();
		int x = this.getClientX();
		this.ui.clearZone(y,  x, this.getClientHeight(), this.getClientWidth());
	}

	@Override
	protected int computeLinesCapacity() {
		return Math.max(0, this.getClientHeight());
	}

	@Override
	protected int computeLinesLength() {
		return Math.max(0, this.getClientWidth() - 2);
	}

	@Override
	public void render() {
		int y = this.getClientY();
		int x = this.getClientX();
		int i;

		String line;
		Iterator<String> lines;

		this.clear();

		i = 0;
		lines = this.getPageElements().iterator();
		while(lines.hasNext()) {
			line = lines.next();
			ui.display(line, y+i, x, this.computeLinesLength());
			i++;
		}
	}
}
