Index: trunk/src/org/expeditee/gui/FreeItems.java
===================================================================
--- trunk/src/org/expeditee/gui/FreeItems.java	(revision 919)
+++ trunk/src/org/expeditee/gui/FreeItems.java	(revision 1102)
@@ -19,5 +19,4 @@
 package org.expeditee.gui;
 
-import java.awt.Polygon;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -29,4 +28,5 @@
 import java.util.Map;
 
+import org.expeditee.core.bounds.PolygonBounds;
 import org.expeditee.items.Dot;
 import org.expeditee.items.Item;
@@ -42,17 +42,22 @@
 	private static FreeItems _cursor = new FreeItems();
 
-	private FreeItems() {
-	}
-
-	public static FreeItems getCursor() {
+	public static FreeItems getCursor()
+	{
 		return _cursor;
 	}
 	
-	public static FreeItems getInstance() {
+	public static FreeItems getInstance()
+	{
 		return _instance;
 	}
 
-	@Override
-	public void clear() {
+	/** Singleton class (although there are two of them). */
+	private FreeItems()
+	{
+	}
+	
+	@Override
+	public void clear()
+	{
 		for (Item i : this) {
 			i.invalidateAll();
@@ -63,5 +68,6 @@
 
 	@Override
-	public Item remove(int index) {
+	public Item remove(int index)
+	{
 		Item i = get(index);
 		remove(i);
@@ -70,9 +76,11 @@
 
 	@Override
-	public boolean remove(Object o) {
+	public boolean remove(Object o)
+	{
 		if (o instanceof Item) {
 			((Item) o).invalidateAll();
 			((Item) o).invalidateFill();
 		}
+		
 		return super.remove(o);
 	}
@@ -84,5 +92,6 @@
 	 * @return true if at least one item is attached to the cursor.
 	 */
-	public static boolean itemsAttachedToCursor() {
+	public static boolean hasItemsAttachedToCursor()
+	{
 		return getInstance().size() > 0;
 	}
@@ -94,24 +103,26 @@
 	 *         attached are text items.
 	 */
-	public static boolean textOnlyAttachedToCursor() {
-		if (!itemsAttachedToCursor())
-			return false;
-		for (Item i : getInstance()) {
-			if (!(i instanceof Text)) {
-				return false;
-			}
-		}
+	public static boolean textOnlyAttachedToCursor()
+	{
+		if (!hasItemsAttachedToCursor()) return false;
+		
+		for (Item i : getInstance()) {
+			if (!(i instanceof Text)) return false;
+		}
+		
 		return true;
 	}
 
-	public static Item getItemAttachedToCursor() {
-		if (itemsAttachedToCursor())
-			return getInstance().get(0);
+	public static Item getItemAttachedToCursor()
+	{
+		if (hasItemsAttachedToCursor()) return getInstance().get(0);
+		
 		return null;
 	}
 
-	public static Text getTextAttachedToCursor() {
-		if (textOnlyAttachedToCursor())
-			return (Text) getInstance().get(0);
+	public static Text getTextAttachedToCursor()
+	{
+		if (textOnlyAttachedToCursor()) return (Text) getInstance().get(0);
+		
 		return null;
 	}
@@ -121,10 +132,10 @@
 	 * @return the list of free text items
 	 */
-	public static Collection<Text> getTextItems() {
+	public static Collection<Text> getTextItems()
+	{
 		Collection<Text> textItems = new LinkedList<Text>();
-		for (Item i : getInstance()) {
-			if (i instanceof Text) {
-				textItems.add((Text) i);
-			}
+		
+		for (Item i : getInstance()) {
+			if (i instanceof Text) textItems.add((Text) i);
 		}
 
@@ -132,12 +143,13 @@
 	}
 
-	public static Map<String, Collection<String>> getGroupedText() {
+	public static Map<String, Collection<String>> getGroupedText()
+	{
 		Map<String, Collection<String>> groupedText = new HashMap<String, Collection<String>>();
+		
 		// Go throught the lineEnds
 		Collection<Item> addedItems = new HashSet<Item>();
 		for (Item i : getInstance()) {
-			if (!(i instanceof Text) || !i.isLineEnd()) {
-				continue;
-			}
+			if (!(i instanceof Text) || !i.isLineEnd()) continue;
+			
 			// Check for text inside the box
 			Collection<String> textList = new LinkedList<String>();
@@ -146,8 +158,10 @@
 				addedItems.add(enclosed);
 			}
+			
 			if (textList.size() > 0) {
 				groupedText.put(i.getText(), textList);
 			}
 		}
+		
 		// Now add the items that were not contained in any of the boxes
 		Collection<String> outsideList = new LinkedList<String>();
@@ -157,4 +171,5 @@
 			}
 		}
+		
 		groupedText.put("", outsideList);
 
@@ -169,6 +184,8 @@
 	 * @return
 	 */
-	private Collection<Text> getTextWithin(Item lineEnd) {
-		Polygon poly = lineEnd.getEnclosedShape();
+	private Collection<Text> getTextWithin(Item lineEnd)
+	{
+		PolygonBounds poly = lineEnd.getEnclosedShape();
+		
 		Collection<Text> results = new LinkedHashSet<Text>();
 		for (Item i : this) {
@@ -177,18 +194,23 @@
 			}
 		}
+		
 		return results;
 	}
 
-	public static boolean hasCursor() {
+	public static boolean hasCursor()
+	{
 		return getCursor().size() > 0;
 	}
 
-	public static void setCursor(Collection<Item> cursor) {
+	public static void setCursor(Collection<Item> cursor)
+	{
 		_cursor.clear();
 		_cursor.addAll(cursor);
 	}
 	
-	public static boolean hasMultipleVisibleItems() {
+	public static boolean hasMultipleVisibleItems()
+	{
 		List<Item> toCount = new LinkedList<Item>(getInstance());
+		
 		int c = 0;
 		while(!toCount.isEmpty()) {
@@ -199,10 +221,44 @@
 			}
 		}
+		
 		return false;
 	}
 	
-	public static boolean isDrawingPolyLine() {
+	public static boolean isDrawingPolyLine()
+	{
 		List<Item> tmp = getInstance();
+		
 		return tmp.size() == 2 && tmp.get(0) instanceof Dot && tmp.get(1) instanceof Line;
 	}
+
+	/**
+	 * Checks if lines are being rubber banded.
+	 * 
+	 * @return true if the user is rubberBanding one or more lines
+	 */
+	public static boolean rubberBanding()
+	{
+		if (getInstance().size() != 2) return false;
+
+		// if rubber-banding, there will be 1 line end and the rest will be lines
+		boolean foundLineEnd = false;
+		for (Item i : getInstance()) {
+			if (i.isLineEnd()) {
+				if (foundLineEnd) return false;
+				foundLineEnd = true;
+			} else if (!(i instanceof Line) || !i.isVisible()) {
+				return false;
+			}
+		}
+		
+		return true;
+	}
+	
+	@Override
+	public FreeItems clone()
+	{
+		FreeItems ret = new FreeItems();
+		ret.addAll(this);
+		return ret;
+	}
 }
