Class VALIIParser

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.TextComponent
              |
              +--java.awt.TextArea
                    |
                    +--VALIIParser

public class VALIIParser
extends java.awt.TextArea

This class is the culmination of all of these other classes. It is an extension of TextArea and when the processProgram() method is called the contents of of the textArea sre processed and events are thrown to any registered listeners.

See Also:
Serialized Form

Field Summary
protected  MovementRequestListener listener
          The listener for any events generated
 
Fields inherited from class java.awt.TextArea
SCROLLBARS_BOTH, SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE, SCROLLBARS_VERTICAL_ONLY
 
Fields inherited from class java.awt.TextComponent
textListener
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
VALIIParser()
          By default a TextArea of height 30 and width 20 is created with only vertical scroll bars and no text.
VALIIParser(int rows, int cols)
          Creates a TextArea of height rows and width cols and only vertical scrool bars.
 
Method Summary
 void addMovementRequestListener(MovementRequestListener l)
          Adds a listener to the events generated by processProgram().
 void clear()
          Clears the contents of the text box.
 void processProgram()
          Very simply this method does the processing of the text and generates the appropriate events.
 void removeMovementRequestListener(MovementRequestListener l)
          Removes a listener to the events generated by processProgram().
 
Methods inherited from class java.awt.TextArea
addNotify, append, appendText, getColumns, getMinimumSize, getMinimumSize, getPreferredSize, getPreferredSize, getRows, getScrollbarVisibility, insert, insertText, minimumSize, minimumSize, paramString, preferredSize, preferredSize, replaceRange, replaceText, setColumns, setRows
 
Methods inherited from class java.awt.TextComponent
addTextListener, getCaretPosition, getSelectedText, getSelectionEnd, getSelectionStart, getText, isEditable, processEvent, processTextEvent, removeNotify, removeTextListener, select, selectAll, setCaretPosition, setEditable, setSelectionEnd, setSelectionStart, setText
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listener

protected MovementRequestListener listener
The listener for any events generated
Constructor Detail

VALIIParser

public VALIIParser()
By default a TextArea of height 30 and width 20 is created with only vertical scroll bars and no text.

VALIIParser

public VALIIParser(int rows,
                   int cols)
Creates a TextArea of height rows and width cols and only vertical scrool bars.
Parameters:
rows - the number of rows
cols - the number of columns
Method Detail

processProgram

public void processProgram()
Very simply this method does the processing of the text and generates the appropriate events. The algorithm at this point is extremely simple:

The recognized keywords are:

All that his function is this:
  • tokenize the entire program using StringTokenizer with '\n' as the delimiter thereby processing the program line by line
  • while there are strings remaining in the tokenizer
    • remove whitespace from the begninning and end of the string
    • change the string to lowercase
    • check to see if the string begins with any of the keywords
    • if the string begins with one of the keywords
      • intialize the appropriate event with the remainder of the string other than the keyword
      • throw the event; that is send it to movementRequested in the registered listener (which may in fact be more than one listener through the use of MovementRequestEventMulticaster.
    • otherwise print an error messge to System#out (this will become a throw of anInvalidProgramElement


The method of the processing makes it so that each line of the program is one command (tokenizing according to '\n') and it is case insensitive (calling String#toLowercase before checking for any keywords.


clear

public void clear()
Clears the contents of the text box.

addMovementRequestListener

public void addMovementRequestListener(MovementRequestListener l)
Adds a listener to the events generated by processProgram().
Parameters:
l - a listener

removeMovementRequestListener

public void removeMovementRequestListener(MovementRequestListener l)
Removes a listener to the events generated by processProgram().
Parameters:
l - a listener