Index: ExtentHistory.java
===================================================================
--- ExtentHistory.java	(revision 42169)
+++ ExtentHistory.java	(revision 42170)
@@ -34,173 +34,255 @@
 import org.gvsig.tools.util.Callable;
 
 /**
- * <p><code>ExtentHistory</code> is designed for managing a history of extents.</p>
+ * <p>
+ * <code>ExtentHistory</code> is designed for managing a history of extents.
+ * </p>
+ * <p>
+ * Note: An <i>extent</i> is a rectangular area, with information of its
+ * top-left 2D corner.
+ * </p>
  *
- * <p>Note: An <i>extent</i> is a re.setMandatory(true)ctangular area, with information of its top-left 2D corner.</p>
- *
  * @author Vicente Caballero Navarro
  */
 public class ExtentHistory implements Persistent {
-	
-	/**
-	 * <p>Maximum number of extents that can store.</p>
-	 */
-	private int NUMREC;
 
-	/**
-	 * <p>Array with the extents.</p>
-	 *
-	 * @see #hasPrevious()
-	 * @see #put(Rectangle2D)
-	 * @see #get()
-	 * @see #removePrev()
-	 */
-	private Rectangle2D[] extents;
+  /**
+   * <p>
+   * Maximum number of extents that can store.
+   * </p>
+   */
+  private int NUMREC;
 
-	/**
-	 * <p>Number of extents stored.</p>
-	 *
-	 * @see #hasPrevious()
-	 * @see #put(Rectangle2D)
-	 * @see #get()
-	 * @see #removePrev()
-	 */
-	private int num = 0;
+  /**
+   * <p>
+   * Array with the extents.
+   * </p>
+   *
+   * @see #hasPrevious()
+   * @see #put(Rectangle2D)
+   * @see #get()
+   * @see #removePrev()
+   */
+  private Rectangle2D[] extents;
 
-	
-	/**
-	 * <p>Creates a new instance of <code>ExtentsHistory</code> with an history of 10 extents.</p>
-	 */
-	public ExtentHistory() {
-		this(10);
-	}
+  private Rectangle2D[] extentsNext;
 
-	
-	/**
-	 * <p>Creates a new instance of <code>ExtentsHistory</code> with an history of <code>numEntries</code> extents.</p>
-	 *
-	 * @param numEntries the maximum number of extents that will store the instance
-	 */
-	public ExtentHistory(int numEntries) {
-		NUMREC = numEntries;
-		extents = new Rectangle2D[NUMREC];
-	}
+  /**
+   * <p>
+   * Number of extents stored.
+   * </p>
+   *
+   * @see #hasPrevious()
+   * @see #put(Rectangle2D)
+   * @see #get()
+   * @see #removePrev()
+   */
+  private int num = 0;
 
-	/**
-	 * <p>Appends the specified extent to the end of this history.</p>
-	 *
-	 * @param ext the new extent
-	 *
-	 * @see #get()
-	 * @see #hasPrevious()
-	 */
-	public void put(Rectangle2D ext) {
-		if ((ext != null) && ((num < 1) || (ext != extents[num - 1]))) {
-			if (num < (NUMREC)) {
-				extents[num] = ext;
-				num = num + 1;
-			} else {
-				for (int i = 0; i < (NUMREC - 1); i++) {
-					extents[i] = extents[i + 1];
-				}
+  private int numNext = 0;
 
-				extents[num - 1] = ext;
-			}
-		}
-	}
+  /**
+   * <p>
+   * Creates a new instance of <code>ExtentsHistory</code> with an history of 10
+   * extents.
+   * </p>
+   */
+  public ExtentHistory() {
+    this(10);
+  }
 
-	/**
-	 * <p>Returns <code>true</code> if there are extents registered.</p>
-	 *
-	 * @return <code>true</code> if there are extents registered; <code>false</code> otherwise
-	 *
-	 * @see #put(Rectangle2D)
-	 * @see #removePrev()
-	 * @see #get()
-	 */
-	public boolean hasPrevious() {
-		return num > 0;
-	}
+  /**
+   * <p>
+   * Creates a new instance of <code>ExtentsHistory</code> with an history of
+   * <code>numEntries</code> extents.
+   * </p>
+   *
+   * @param numEntries the maximum number of extents that will store the
+   *          instance
+   */
+  public ExtentHistory(int numEntries) {
+    NUMREC = numEntries;
+    extents = new Rectangle2D[NUMREC];
+    extentsNext = new Rectangle2D[NUMREC];
+  }
 
-	/**
-	 * <p>Returns the last extent in the history.</p>
-	 *
-	 * @return the last extent in the history
-	 *
-	 * @see #put(Rectangle2D)
-	 * @see #getXMLEntity()
-	 */
-	public Rectangle2D get() {
-		if (num <= 0) {
-			return null;
-		}
-		Rectangle2D ext = extents[num - 1];
+  /**
+   * <p>
+   * Appends the specified extent to the end of this history.
+   * </p>
+   *
+   * @param ext the new extent
+   * @see #get()
+   * @see #hasPrevious()
+   */
+  public void put(Rectangle2D ext) {
+    if ((ext != null) && ((num < 1) || (ext != extents[num - 1]))) {
+      if (num < (NUMREC)) {
+        extents[num] = ext;
+        num = num + 1;
+      }
+      else {
+        for (int i = 0; i < (NUMREC - 1); i++) {
+          extents[i] = extents[i + 1];
+        }
+        extents[num - 1] = ext;
+      }
+    }
+  }
 
-		return ext;
-	}
+  /**
+   * <p>
+   * Returns <code>true</code> if there are extents registered.
+   * </p>
+   *
+   * @return <code>true</code> if there are extents registered;
+   *         <code>false</code> otherwise
+   * @see #put(Rectangle2D)
+   * @see #removePrev()
+   * @see #get()
+   */
+  public boolean hasPrevious() {
+    return num > 0;
+  }
 
-	/**
-	 * <p>Extracts (removing) the last extent from the history.</p>
-	 *
-	 * @return last extent in the history
-	 *
-	 * @see #hasPrevious()
-	 */
-	public Rectangle2D removePrev() {
-		if (num <= 0) {
-			return null;
-		}
-		Rectangle2D ext = extents[--num];
-		return ext;
-	}
+  public boolean hasNext() {
+    return numNext > 0;
+  }
 
-	public void loadFromState(PersistentState state)
-			throws PersistenceException {
-		
-		num = state.getInt("num");
-		NUMREC = state.getInt("numrec");
-		extents = (Rectangle2D[]) state.getArray("extents", Rectangle2D.class);
-	}
+  /**
+   * <p>
+   * Returns the last extent in the history.
+   * </p>
+   *
+   * @return the last extent in the history
+   * @see #put(Rectangle2D)
+   * @see #getXMLEntity()
+   */
+  public Rectangle2D get() {
+    if (num <= 0) {
+      return null;
+    }
+    Rectangle2D ext = extents[num - 1];
 
-	/**
-	 * <p>
-	 * Returns information of this object. All information is stored as
-	 * properties:<br>
-	 * </p>
-	 * <p>
-	 * <b>Properties:</b>
-	 * <ul>
-	 * <li><i>className</i>: name of this class.
-	 * <li><i>num</i>: number of extents registered.
-	 * <li><i>numrec</i>: maximum number of extents that can register.
-	 * <li><i>extents</i>: .
-	 * </ul>
-	 * </p>
-	 * 
-	 */
-	public void saveToState(PersistentState state) throws PersistenceException {
-		
-		state.set("num", num);
-		state.set("numrec", NUMREC);
-		state.set("extents", extents);
-	}
+    return ext;
+  }
+  
+  public Rectangle2D getNext() {
+    if (numNext <= 0) {
+      return null;
+    }
+    
+    Rectangle2D ext = extentsNext[numNext - 1];
+    
+    return ext;
+  }
 
+  /**
+   * <p>
+   * Extracts (removing) the last extent from the history.
+   * </p>
+   *
+   * @return last extent in the history
+   * @see #hasPrevious()
+   */
+  public Rectangle2D removePrev() {
+    if (num <= 0) {
+      return null;
+    }
+    if (numNext < (NUMREC)) {
+      extentsNext[numNext] = extents[num - 1];
+      numNext++;
+    }
+    else {
+      for (int i = 0; i < (NUMREC - 1); i++) {
+        extentsNext[i] = extentsNext[i + 1];
+      }
+      extentsNext[numNext - 1] = extents[num - 1];
+    }
 
-    public static class RegisterPersistence implements Callable {
+    Rectangle2D ext = extents[--num];
+    return ext;
+  }
 
-        public Object call() {
-		PersistenceManager manager = ToolsLocator.getPersistenceManager();
-		DynStruct definition = manager.addDefinition(
-				ExtentHistory.class,
-				"ExtentHistory",
-				"ExtentHistory Persistence definition",
-				null, 
-				null
-		);
-		definition.addDynFieldInt("num").setMandatory(true);
-		definition.addDynFieldInt("numrec").setMandatory(true);
-		definition.addDynFieldArray("extents").setClassOfItems(Rectangle2D.class).setMandatory(true);
-            return Boolean.TRUE;
-        }
+  /**
+   * <p>
+   * Extracts (removing) the last extent from the history.
+   * </p>
+   *
+   * @return last extent in the history
+   * @see #hasNext()
+   */
+  public Rectangle2D removeNext() {
+    if (numNext <= 0) {
+      return null;
     }
+
+    if (num < (NUMREC)) {
+      extents[num] = extentsNext[numNext - 1];
+    }
+    else {
+      for (int i = 0; i < (NUMREC - 1); i++) {
+        extents[i] = extents[i + 1];
+      }
+      extents[num - 1] = extentsNext[numNext - 1];
+    }
+
+    Rectangle2D ext = extentsNext[--numNext];
+    return ext;
+  }
+
+  
+  public void clear() {
+    num = 0;
+    numNext = 0;
+  }
+
+  
+  public void loadFromState(PersistentState state) throws PersistenceException {
+
+    num = state.getInt("num");
+    NUMREC = state.getInt("numrec");
+    extents = (Rectangle2D[]) state.getArray("extents", Rectangle2D.class);
+    extentsNext = (Rectangle2D[]) state.getArray("extentsNext",
+        Rectangle2D.class);
+  }
+
+  /**
+   * <p>
+   * Returns information of this object. All information is stored as
+   * properties:<br>
+   * </p>
+   * <p>
+   * <b>Properties:</b>
+   * <ul>
+   * <li><i>className</i>: name of this class.
+   * <li><i>num</i>: number of extents registered.
+   * <li><i>numrec</i>: maximum number of extents that can register.
+   * <li><i>extents</i>: .
+   * </ul>
+   * </p>
+   */
+  public void saveToState(PersistentState state) throws PersistenceException {
+
+    state.set("num", num);
+    state.set("numrec", NUMREC);
+    state.set("extents", extents);
+    state.set("extentsNext", extentsNext);
+  }
+
+  public static class RegisterPersistence implements Callable {
+
+    public Object call() {
+      PersistenceManager manager = ToolsLocator.getPersistenceManager();
+      DynStruct definition = manager.addDefinition(ExtentHistory.class,
+          "ExtentHistory", "ExtentHistory Persistence definition", null, null);
+      definition.addDynFieldInt("num").setMandatory(true);
+      definition.addDynFieldInt("numrec").setMandatory(true);
+      definition.addDynFieldArray("extents").setClassOfItems(Rectangle2D.class)
+          .setMandatory(true);
+      definition.addDynFieldArray("extentsNext")
+          .setClassOfItems(Rectangle2D.class).setMandatory(true);
+      return Boolean.TRUE;
+    }
+  }
 }
\ No newline at end of file
