KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > part > DrillStack


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.part;
12
13 import java.util.Stack JavaDoc;
14
15 /* (non-Javadoc)
16  * A <code>DrillStack</code> manages a stack of DrillFrames.
17  * This class is not intended for use beyond the package.
18  */

19 /* package */class DrillStack {
20     Stack JavaDoc fStack = null;
21
22     /**
23      * Allocates a new DrillStack.
24      */

25     public DrillStack() {
26         reset();
27     }
28
29     /**
30      * Adds a drill frame to the stack.
31      *
32      * @param oRecord the new drill frame
33      */

34     public DrillFrame add(DrillFrame oRecord) {
35         fStack.push(oRecord);
36         return oRecord;
37     }
38
39     /**
40      * Returns true if backward navigation is possible. This is only true
41      * if the stack size is greater than 0.
42      *
43      * @return true if backward navigation is possible
44      */

45     public boolean canGoBack() {
46         return (fStack.size() > 0);
47     }
48
49     /**
50      * Returns true if "go home" is possible. This is only true
51      * if the stack size is greater than 0.
52      *
53      * @return true if "go home" is possible
54      */

55     public boolean canGoHome() {
56         return (fStack.size() > 0);
57     }
58
59     /**
60      * Navigate backwards one record.
61      */

62     public DrillFrame goBack() {
63         DrillFrame aFrame = (DrillFrame) fStack.pop();
64         return aFrame;
65     }
66
67     /**
68      * Navigate to the home record.
69      */

70     public DrillFrame goHome() {
71         DrillFrame aFrame = (DrillFrame) fStack.elementAt(0);
72         reset();
73         return aFrame;
74     }
75
76     /**
77      * Clears the navigation stack.
78      */

79     public void reset() {
80         fStack = new Stack JavaDoc();
81     }
82
83     /**
84      * Returns the stack size.
85      *
86      * @return the stack size
87      */

88     public int size() {
89         return fStack.size();
90     }
91
92     /**
93      * Returns the top element on the stack.
94      *
95      * @return the top element on the stack
96      */

97     public DrillFrame top() {
98         return (DrillFrame) fStack.peek();
99     }
100 }
101
Popular Tags