kiwi.ui
Class StackView

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JList
                          |
                          +--kiwi.ui.StackView

public class StackView
extends JList

A component that displays the contents of a Stack data structure. This is an MVC class that uses a StackModel as its data model.

Version:
2.0 (10/98)
Author:
Mark Lindner, PING Software Group
See Also:
StackModel, java.util.Stack, Serialized Form

Inner classes inherited from class javax.swing.JList
JList.AccessibleJList
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
StackView()
          Construct a new StackView with a default stack model.
StackView(StackModel model)
          Construct a new StackView with the given stack model.
 
Method Summary
 void append(Object obj)
          Append an item to the stack.
 void drop()
          Drop the top item off the stack.
 int getDepth()
          Return the depth of the stack.
 StackModel getStackModel()
          Get the model used by this StackView.
 boolean isEmpty()
          Check if the stack is empty.
 Object peek()
          Peek at the top item on the stack.
 Object pick(int index)
          Remove an item from the stack.
 Object pop()
          Pop an item off the stack.
 void push(Object obj)
          Push a new item on the stack.
 void replace(Object obj)
          Replace the top item on the stack.
 void swap()
          Swap the positions of the top two items on the stack.
 
Methods inherited from class javax.swing.JList
addListSelectionListener, addSelectionInterval, clearSelection, createSelectionModel, ensureIndexIsVisible, fireSelectionValueChanged, getAccessibleContext, getAnchorSelectionIndex, getCellBounds, getCellRenderer, getFirstVisibleIndex, getFixedCellHeight, getFixedCellWidth, getLastVisibleIndex, getLeadSelectionIndex, getMaxSelectionIndex, getMinSelectionIndex, getModel, getPreferredScrollableViewportSize, getPrototypeCellValue, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedIndex, getSelectedIndices, getSelectedValue, getSelectedValues, getSelectionBackground, getSelectionForeground, getSelectionMode, getSelectionModel, getUI, getUIClassID, getValueIsAdjusting, getVisibleRowCount, indexToLocation, isSelectedIndex, isSelectionEmpty, locationToIndex, paramString, removeListSelectionListener, removeSelectionInterval, setCellRenderer, setFixedCellHeight, setFixedCellWidth, setListData, setListData, setModel, setPrototypeCellValue, setSelectedIndex, setSelectedIndices, setSelectedValue, setSelectionBackground, setSelectionForeground, setSelectionInterval, setSelectionMode, setSelectionModel, setUI, setValueIsAdjusting, setVisibleRowCount, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StackView

public StackView()
Construct a new StackView with a default stack model.

StackView

public StackView(StackModel model)
Construct a new StackView with the given stack model.
Parameters:
model - The StackModel to use.
Method Detail

getStackModel

public StackModel getStackModel()
Get the model used by this StackView.

push

public void push(Object obj)
Push a new item on the stack.
Parameters:
obj - The object to push on the stack.

pop

public Object pop()
           throws EmptyStackException
Pop an item off the stack. Pops the top item off the stack.
Returns:
The popped item.
Throws:
EmptyStackException - If the stack is empty.

drop

public void drop()
          throws EmptyStackException
Drop the top item off the stack. Pops and discards the top item off the stack.
Throws:
EmptyStackException - If the stack is empty.

peek

public Object peek()
Peek at the top item on the stack.
Returns:
The top item on the stack. The item is not removed from the stack.

swap

public void swap()
          throws EmptyStackException
Swap the positions of the top two items on the stack. If there is only one item in the stack, this method has no effect.
Throws:
EmptyStackException - If the stack is empty.

getDepth

public int getDepth()
Return the depth of the stack.
Returns:
The number of items on the stack.

isEmpty

public boolean isEmpty()
Check if the stack is empty.
Returns:
true if the stack is empty, false otherwise.

pick

public Object pick(int index)
            throws ArrayIndexOutOfBoundsException
Remove an item from the stack. Removes the item at the specified index from the stack. Index position 0 refers to the top of the stack.
Parameters:
index - The index of the item to remove.
Returns:
The removed item.
Throws:
ArrayIndexOutOfBoundsException - If index is out of range.

append

public void append(Object obj)
Append an item to the stack.
Parameters:
obj - The item to add to the bottom of the stack.

replace

public void replace(Object obj)
Replace the top item on the stack. The top item on the stack is replaced with the item obj. If the stack is empty, the item is merely pushed on the stack.
Parameters:
obj - The new item.