usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/control/Navigator.java
changeset 190 555203a2de79
parent 157 f4316b998c95
child 219 57841c113efe
--- a/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/control/Navigator.java	Fri Dec 12 13:48:52 2008 -0800
+++ b/usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/control/Navigator.java	Tue Dec 23 14:04:45 2008 -0500
@@ -45,7 +45,7 @@
 
     private Thread dispatchThread;
     private ThreadPoolExecutor threadPool;
-    private StackList<Control> stack = new StackList<Control>();
+    private LinkedList<Control> stack = new LinkedList<Control>();
     private NavigationListeners listeners = new NavigationListeners(false);
     private String name;
 
@@ -205,7 +205,7 @@
      */
     public Control getCurrentControl() {
 	synchronized (stack) {
-	    return StackUtil.getTop(stack);
+	    return stack.peekLast();
 	}
     }
 
@@ -214,7 +214,8 @@
     }
 
     /**
-     * Gets the current path.  This method is not thread-safe; it is up to
+     * Gets a list of the elements of the current path, with the root element at
+     * the beginning of the list.  This method is not thread-safe; it is up to
      * callers to ensure the that navigation is not currently modifying this
      * path.
      */
@@ -278,22 +279,22 @@
 
 	synchronized (stack) {
 	    // Last absolute path
-	    StackList<Navigable> laPath = new StackList<Navigable>();
+	    LinkedList<Navigable> laPath = new LinkedList<Navigable>();
 	    laPath.addAll(stack);
 
 	    while (true) {
 		// Current absolute path
-		StackList<Navigable> caPath = new StackList<Navigable>();
+		LinkedList<Navigable> caPath = new LinkedList<Navigable>();
 
 		if (relativeTo != null) {
 		    caPath.addAll(laPath);
 		    try {
 			// Remove path elements until relativeTo is at the top
-			while (!((HasControl)caPath.peek()).getControl().
+			while (!((HasControl)caPath.getLast()).getControl().
 			    equals(relativeTo)) {
-			    caPath.pop();
+			    caPath.removeLast();
 			}
-		    } catch (EmptyStackException e) {
+		    } catch (NoSuchElementException e) {
 			throw new IllegalArgumentException(String.format(
 			    "Control not in navigation path: %s (%s)",
 			    relativeTo.getClass().getName(),
@@ -317,12 +318,13 @@
 		// laPath as appropriate
 		for (Navigable nav : rPath) {
 		    if (nav.getId().equals(PARENT_ID)) {
-			if (laPath.isEmpty()) {
+			try {
+			    laPath.removeLast();
+			} catch (NoSuchElementException e) {
 			    throw new IllegalArgumentException(
-				"navigation stack has no root");
+				"\"..\" encountered with empty navigation " +
+				"stack");
 			}
-
-			laPath.pop();
 		    } else {
 			Control newControl;
 
@@ -337,7 +339,7 @@
 			    }
 			} else {
 			    String id = nav.getId();
-			    Object last = laPath.peek();
+			    Object last = laPath.getLast();
 
 			    // laPath elements are Controls or PendingControls
 			    Control curControl =
@@ -354,12 +356,14 @@
 			PendingControl pair =
 			    new PendingControl(newControl, nav.getParameters());
 
-			laPath.push(pair);
+			laPath.add(pair);
 		    }
 		}
 
 		try {
-		    Control control = ((HasControl)laPath.peek()).getControl();
+		    Control control =
+			((HasControl)laPath.getLast()).getControl();
+
 		    String forward = control.getForwardingPath();
 		    if (forward == null) {
 			break;
@@ -367,7 +371,7 @@
 
 		    path = toArray(forward);
 		    relativeTo = isAbsolute(forward) ? null : control;
-		} catch (EmptyStackException ignore) {
+		} catch (NoSuchElementException ignore) {
 		    // No root Control
 		}
 	    }
@@ -390,7 +394,7 @@
 
 			if (pend.getId().equals(PARENT_ID)) {
 			    curControl.stop();
-			    stack.pop();
+			    stack.removeLast();
 			    Control newCurControl = getCurrentControl();
 			    if (newCurControl != null) {
 				newCurControl.childStopped(curControl);
@@ -399,7 +403,7 @@
 			    Control newControl = pend.getControl();
 
 			    newControl.start(this, pend.getParameters());
-			    stack.push(newControl);
+			    stack.add(newControl);
 
 			    if (curControl != null) {
 				curControl.childStarted(newControl);