kiwi.ui.model
Class DefaultStackModel

java.lang.Object
  |
  +--javax.swing.AbstractListModel
        |
        +--javax.swing.DefaultListModel
              |
              +--kiwi.ui.model.DefaultStackModel

public class DefaultStackModel
extends DefaultListModel
implements StackModel

This class is a default implementation of the StackModel interface. It inherits its base functionality from DefaultListModel, and adds only methods for dealing with stack operations.

Version:
1.0 (10/98)
Author:
Mark Lindner, PING Software Group
See Also:
Serialized Form

Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
DefaultStackModel()
           
 
Method Summary
 void addStackDataListener(ListDataListener listener)
          Add a ListDataListener to this model's list of listeners.
 void append(Object obj)
          Append an object to the bottom of the stack.
 void drop()
          Drop an item off the stack.
 int getDepth()
          Get the depth of the stack.
 boolean isEmpty()
          Determine if the stack is empty.
 Object peek()
          Retrieve the topmost item from the stack (without removing the item from the stack).
 Object pick(int index)
          Remove an object from the stack.
 Object pop()
          Pop an object off the stack.
 void push(Object obj)
          Push an object on the stack.
 void removeStackDataListener(ListDataListener listener)
          Remove a ListDataListener from this model's list of listeners.
 void swap()
          Swap the topmost items on the stack.
 
Methods inherited from class javax.swing.DefaultListModel
add, addElement, capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, setSize, size, toArray, toString, trimToSize
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultStackModel

public DefaultStackModel()
Method Detail

push

public void push(Object obj)
Push an object on the stack. The object becomes the topmost item on the stack.
Specified by:
push in interface StackModel
Parameters:
obj - The object to push.

pop

public Object pop()
           throws EmptyStackException
Pop an object off the stack. Pulls the topmost item off the stack.
Specified by:
pop in interface StackModel
Returns:
The popped object.

drop

public void drop()
          throws EmptyStackException
Drop an item off the stack. Pops and discards the topmost item on the stack.
Specified by:
drop in interface StackModel
Throws:
EmptyStackException - If the stack is empty.

peek

public Object peek()
            throws EmptyStackException
Retrieve the topmost item from the stack (without removing the item from the stack).
Specified by:
peek in interface StackModel
Returns:
The topmost item on the stack.
Throws:
EmptyStackException - If the stack is empty.

getDepth

public int getDepth()
Get the depth of the stack.
Specified by:
getDepth in interface StackModel
Returns:
The number of items in the stack.

swap

public void swap()
          throws EmptyStackException
Swap the topmost items on the stack. If the stack contains only one item, calling this method has no effect.
Specified by:
swap in interface StackModel
Throws:
EmptyStackException - If the stack is empty.

isEmpty

public boolean isEmpty()
Determine if the stack is empty.
Specified by:
isEmpty in interface StackModel
Returns:
true if there are no items in the stack, and false otherwise.
Overrides:
isEmpty in class DefaultListModel

pick

public Object pick(int index)
            throws ArrayIndexOutOfBoundsException,
                   EmptyStackException
Remove an object from the stack. Retrieves (and removes) an object from the given offset in the stack.
Specified by:
pick in interface StackModel
Parameters:
index - The offset (from the top of the stack) of the item to remove.
Returns:
The object that was removed.
Throws:
EmptyStackException - If the stack is empty.
ArrayIndexOutOfBoundsException - If the value of index is out of range.

append

public void append(Object obj)
Append an object to the bottom of the stack.
Specified by:
append in interface StackModel
Parameters:
obj - The object to append.

addStackDataListener

public void addStackDataListener(ListDataListener listener)
Add a ListDataListener to this model's list of listeners. Since a stack is essentially a list with some special semantics, ListDataListeners are used.
Specified by:
addStackDataListener in interface StackModel
Parameters:
listener - The listener to add.

removeStackDataListener

public void removeStackDataListener(ListDataListener listener)
Remove a ListDataListener from this model's list of listeners. Since a stack is essentially a list with some special semantics, ListDataListeners are used.
Specified by:
removeStackDataListener in interface StackModel
Parameters:
listener - The listener to add.