codesimian
Class KeyListenerOnComponent

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.KeyListenerOnComponent
All Implemented Interfaces:
CodeSimian, java.awt.event.KeyListener, java.util.EventListener

public class KeyListenerOnComponent
extends DefaultCS
implements java.awt.event.KeyListener

THIS CLASS NEEDS TO BE TESTED.

Adds a KeyListner, defined by P(1) - P(3), to the java.awt.Component inside P(0). P(4) P(5) and P(6) are optional.

keyPressed(KeyEvent) causes P(1).setC(charTyped). keyReleased(KeyEvent) causes P(2).setC(charTyped). keyTyped(KeyEvent) causes P(3).setC(charTyped).

If P(4) exists, its a list of 128 numbers describing the keyboard right now, 0 for key up, 1 for key down.

When P(0) is replaced, the KeyListener is removed from P(0).L(java.awt.Component.class)

If there is a P(5), it is the number of seconds (can be a fraction) to wait after the last key event, before delivering all events. This lets the user type a whole string before being interrupted.

If there is a P(6), its the max queued key events. Set this to 1 to only do the last event. If an other event occurs while waiting, it would replace the currently waiting event, and it is delayed from that point in time. If its 5, you get up to the last 5 events when the wait is over.


Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
Constructor Summary
KeyListenerOnComponent()
           
 
Method Summary
 void delayEvents()
          P(5).D() number of seconds after the last call of this, doLater is executed then emptied.
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
 double DForProxy()
          Execute this CS and cast to double.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 int maxP()
          Maximum quantity of Params
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 char nameToChar(java.lang.String name)
          example: nameToChar("\n") returns '\n', but maybe later exceptions like "HOME" will also work.
 CS[] reorderByName128(CS[] keyList)
          This function lets you select a small quantity of keys to watch.
 void reorderP4()
          calls reorderByName128 and forces P(4) to update itself.
 boolean setP(int index, CS value)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
static void tellListener(CS listener, char input)
           
 void tellListenerLater(CS listener, char input)
          TODO: this function needs to be tested.
 void updateKeyInP4(char key, boolean down)
           
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, PType, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setPrevExec, setPType, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, JForProxy, L, L, L, L, L, maxD, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, SETZ, SForProxy, tester, toJavaCode, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeyListenerOnComponent

public KeyListenerOnComponent()
Method Detail

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Overrides:
description in class DefaultCS

DForProxy

public double DForProxy()
Description copied from class: CS
Execute this CS and cast to double.

D() and DForProxy() are the 2 most important functions in CS. They execute this CS. All other execute functions, by default, return DForProxy cast to their own type.

For example, J() calls the proxy which calls JForProxy() which calls DForProxy(). D() calls the proxy which calls DForProxy().

By default, all other primitive EXECUTE functions defer to D.
Functions that EXECUTE this CS: L(Class) L(int,Class,int) Z() B() C() S() I() J() F() D() V()

Specified by:
DForProxy in class DefaultCS

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

maxP

public int maxP()
Description copied from class: CS
Maximum quantity of Params

Overrides:
maxP in class CS

setP

public boolean setP(int index,
                    CS value)
Description copied from class: CS
Every CS is a list of other CSs, between size minP() and maxP() inclusive. setP overwrites one of those CSs or adds a new one at the end, depending on the index. If index is between 0 and countP()-1, overwrites. If it equals countP(), adds at end.

Overrides:
setP in class DefaultCS

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

updateKeyInP4

public void updateKeyInP4(char key,
                          boolean down)

reorderByName128

public CS[] reorderByName128(CS[] keyList)
This function lets you select a small quantity of keys to watch. Those keys are repositioned by their name to their correct position from 0 to 127, and empty indexs are filled in with new N(0).

Parameters:
keyList - a list of CSs that each represent a key on the keyboard. That list can be any size between 0 and 128.

Returns:
list size 128, with keys moved if their CS.name() equals the name of a key, like "a", "A", ";", etc.

reorderP4

public void reorderP4()
calls reorderByName128 and forces P(4) to update itself. If it refuses, it is replaced.


nameToChar

public char nameToChar(java.lang.String name)
example: nameToChar("\n") returns '\n', but maybe later exceptions like "HOME" will also work. Returns (char)0 if there is no char with that name.


tellListener

public static void tellListener(CS listener,
                                char input)

tellListenerLater

public void tellListenerLater(CS listener,
                              char input)
TODO: this function needs to be tested. I dont think it allows enough queued key events. its limiting them all to 1, which is all I need right now.


delayEvents

public void delayEvents()
P(5).D() number of seconds after the last call of this, doLater is executed then emptied.