/** Copyright 2012, Adam L. Davis, all rights reserved. */
package com.adamldavis.z.tasks;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Adam L. Davis
 * 
 */
public class ZTaskList implements Serializable {

	private static final long serialVersionUID = 42L;

	private ZTask task1, task2;

	private final List<ZTask> tasks = new LinkedList<ZTask>();

	private ZTask activeTask;

	public ZTaskList() {
		// TODO: remove
		task1 = new ZTask("Fix Tasks");
		task2 = new ZTask("Fix Editor");
		tasks.add(task1);
		tasks.add(task2);
		activeTask = task1;
	}

	public void clear() {
		tasks.clear();
	}

	public ZTask addTask(final ZTask task) {
		tasks.add(task);
		return task;
	}

	/**
	 * Gets ZTask at given x-position if any.
	 * 
	 * @param xPostn
	 *            X-position of mouse assuming y is within task area.
	 * @param height
	 *            Height of task area.
	 * @return ZTask clicked on.
	 */
	public ZTask getTaskAt(int xPostn, int height) {
		int x = 10;

		for (ZTask task : tasks) {
			int prevX = x;
			x += task.getName().length() * height / 2 + 2;
			if (xPostn >= prevX && xPostn <= x) {
				return task;
			}
		}
		return null;
	}

	public ZTask newTask() {
		final ZTask task = new ZTask();
		tasks.add(task);
		return task;
	}

	public List<ZTask> getTasks() {
		return tasks;
	}

	public ZTask getActiveTask() {
		return activeTask;
	}

	public void setActiveTask(ZTask activeTask) {
		this.activeTask = activeTask;
		if (activeTask != null) {
			activeTask.resetPositions();
		}
	}

}

@@ -310,38 +310,8 @@
 L;%0A%0A
-%09private ZTask task1, task2;%0A%0A
 %09pri
@@ -423,34 +423,18 @@
 %7B%0A%09%09
-// TODO: remove%0A%09%09task1 = 
+tasks.add(
 new 
@@ -444,116 +444,15 @@
 sk(%22
-Fix 
 Task
-s
 %22)
-;%0A%09%09task2 = new ZTask(%22Fix Editor%22);%0A%09%09tasks.add(task1);%0A%09%09tasks.add(task2);%0A%09%09activeTask = task1
+)
 ;%0A%09%7D

Remove fake tasks