KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > blueprints > ui > BrowseHistory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.blueprints.ui;
21
22 import java.util.Stack JavaDoc;
23
24 /**
25  * Keeps track of which pages the user was browsing
26  *
27  * @author Mark Roth
28  */

29 public class BrowseHistory {
30
31     private Stack JavaDoc backStack = new Stack JavaDoc();
32     private Stack JavaDoc forwardStack = new Stack JavaDoc();
33
34     public BrowseHistory() {
35     }
36
37     public void clear() {
38         backStack.clear();
39         forwardStack.clear();
40     }
41
42     /**
43      * Pushes the back stack and erases all forward history.
44      */

45     public void pushBackStack(BrowseHistoryToken token) {
46         backStack.push(token);
47         forwardStack.clear();
48     }
49     
50     public boolean isBackStackEmpty() {
51         return backStack.isEmpty();
52     }
53     
54     public boolean isForwardStackEmpty() {
55         return forwardStack.isEmpty();
56     }
57     
58     /**
59      * Go back one page, saving the current token in the forward stack
60      */

61     public BrowseHistoryToken back(BrowseHistoryToken currentToken) {
62         BrowseHistoryToken result = null;
63         if(!backStack.isEmpty()) {
64             result = (BrowseHistoryToken)backStack.pop();
65             forwardStack.push(currentToken);
66         }
67         return result;
68     }
69
70     /**
71      * Go forward one page, saving the current token in the back stack
72      */

73     public BrowseHistoryToken forward(BrowseHistoryToken currentToken) {
74         BrowseHistoryToken result = null;
75         if(!forwardStack.isEmpty()) {
76             result = (BrowseHistoryToken)forwardStack.pop();
77             backStack.push(currentToken);
78         }
79         return result;
80     }
81 }
82
Popular Tags