codesimian
Class WindowCS

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.WindowCS
All Implemented Interfaces:
CodeSimian, java.awt.event.MouseListener, java.io.Serializable, java.util.EventListener

public class WindowCS
extends DefaultCS
implements java.awt.event.MouseListener

        a root gui component that displays 1 other
        gui component in a java.awt.JFrame.
        That other might contain many more gui objects.

        Param0 is a GUI CS object to display in the window.
        To disply multiple things, put them in a Layout and the Layout in this window.
        Param1 is window width in pixels. Param2 is window height in pixels.

        Location of window is similar to size.
        Param3 is X pixel position, and param4 is Y pixel position.
        If param3 is the last param, only X position is specified.

        These 4 default sizes are in static instance vars with type Number,
        and start as instances of NumberStack.
        Example in WindowCS: protected NumberWindowCS.defaultLocationX.
        NumberStack can contain CSs because Number is CS's superclass.

See Also:
Serialized Form

Field Summary
protected static java.lang.Number defaultHeight
           
protected static java.lang.Number defaultLocationX
           
protected static java.lang.Number defaultLocationY
           
protected static java.lang.Number defaultWidth
           
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
WindowCS()
           
WindowCS(javax.swing.JFrame window)
          JFrame 'window' will contain 1 JFrame from its 1 (type GUI.componentType) param.
 
Method Summary
 boolean combineIfParamIsMyClassType()
           
 double cost()
          cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively.
 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()
          tries to make the JFrame visible.
 boolean insertP(int index, CS insertMe)
          same as setP(int,CS) but inserts instead of overwriting.
 CS interpretAsGUI(CS graphRoot)
          some trees/graphs of CSs cant be converted to java.util.Component objects.
 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()".
 java.lang.Object L(java.lang.Class type)
          Optionally execute this CS, and definitely try to CAST it to the specified Java type.
 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.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 boolean needFuzzyType()
           
 int paramValueToPixelSize(double paramValue, int screenSizeInPixels)
          If paramValue is negative, use the absolute value.
 CS PType(int indexP)
          There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1.
 boolean setL(java.lang.Object window)
          setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.
 boolean setName(java.lang.String newName)
          window is any JFrame * public boolean setObject(Object window){ if (window==null || !(window instanceof JFrame)) return false; for (int p=0; p
 boolean setP(int index, CS setTo)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 boolean unknownCost()
           
protected  boolean updateObjectInWindow()
          checks if P(0).getObject() has changed since updateObjectInWindow() was called last.
 boolean updateWindowSize()
          returns true if window size changed to param1 x param2 pixels, false if it was already that size
 
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, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, P, prevD, prevL, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL1, setMyFuel, setObject, setPrevExec, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, 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, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultLocationX

protected static java.lang.Number defaultLocationX

defaultLocationY

protected static java.lang.Number defaultLocationY

defaultWidth

protected static java.lang.Number defaultWidth

defaultHeight

protected static java.lang.Number defaultHeight
Constructor Detail

WindowCS

public WindowCS(javax.swing.JFrame window)
JFrame 'window' will contain 1 JFrame from its 1 (type GUI.componentType) param. The window should not be visible yet. It should become visible when DForProxy() is called.


WindowCS

public WindowCS()
Method Detail

DForProxy

public double DForProxy()
tries to make the JFrame visible. Updates window size to param1 x param2.

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

updateWindowSize

public boolean updateWindowSize()
returns true if window size changed to param1 x param2 pixels, false if it was already that size


paramValueToPixelSize

public int paramValueToPixelSize(double paramValue,
                                 int screenSizeInPixels)
If paramValue is negative, use the absolute value. If less than 1, its a fraction of screen size. Else its the pixel size (wrapped around the screen size if too big).


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

combineIfParamIsMyClassType

public boolean combineIfParamIsMyClassType()

cost

public double cost()
Description copied from class: CS
cost() should be changed to return a float, and should be renamed to costToExecute()

cost of EXECUTING this CS, not including any CSs it executes recursively. The INTERNAL cost.

One unit of myFuel() costs cost() units of fuel(). Beware of CSs that counterfeit fuel.

Returns 1 by default.

Overrides:
cost in class CS

unknownCost

public boolean unknownCost()

PType

public CS PType(int indexP)
Description copied from class: CS
There is a TYPE for each Param.
A TYPE is a CS whose minP() is at least 1. When a TYPE executes, it MEASURES THE TYPE OF its first param CS. It returns a positive number if it is that type, else 0 or negative. Some TYPEs use only 2 numbers, while others can return any number on a continuous scale.

Types are optional. To not use types, return the default type: Static.defaultType(). The default type returns true for any CS. Most CSs do not need types therefore they use the default type.

Overrides:
PType in class DefaultCS

needFuzzyType

public boolean needFuzzyType()

setP

public boolean setP(int index,
                    CS setTo)
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

insertP

public boolean insertP(int index,
                       CS insertMe)
Description copied from class: CS
same as setP(int,CS) but inserts instead of overwriting. All higher params slide up 1 index.

Overrides:
insertP in class DefaultCS

updateObjectInWindow

protected boolean updateObjectInWindow()
checks if P(0).getObject() has changed since updateObjectInWindow() was called last. If so (or if this is the first call), then the new object appears in the window


L

public java.lang.Object L(java.lang.Class type)
Description copied from class: CS
Optionally execute this CS, and definitely try to CAST it to the specified Java type. If fail, throw a ClassCastException.

Should I change this from throwing a CSCastException to return null instead?

It is preferred not to return CSs from this function. If you have a CS to return, the standard is to put it in param0... setP(0,returnValue), where the function caller should get the output from... P(0).

The functions: V L Z B C S I J F and D, usually EXECUTE this CS and CAST its value to the specified type.
L does not have to execute this CS, but all the others do. The other difference is L can throw a CSCastException (extends ClassCastException), which is a RuntimeException so you do not have to use try/catch if you trust it.

No pattern of L()'s behavior is guaranteed.
The L's of some some CSs are more predictable than others, often written about in javadoc.
If it casts correctly, it could fail later. If it fails many times, and you try again, it could still succeed.

Example: new int[7][6][5].getClass().getName() returns "[[[I". These 9 function names (not 10 because excludes Void) are also used by a very important part of Java (but not as function names): java.lang.Class.name() .

EXAMPLES:
JButton b = (JButton) new ButtonCS().L(Component.class); //JButton inherits from Component
int fiveFiftyFive = new N(555).I();
double charValues[] = (double[]) new S("arraySize11").L(double[].class);

Overrides:
L in class CS
See Also:
CS.Z(), CS.B(), CS.C(), CS.S(), CS.I(), CS.J(), CS.F(), CS.D()

setL

public boolean setL(java.lang.Object window)
Description copied from class: CS
setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.

Overrides:
setL in class DefaultCS

setName

public boolean setName(java.lang.String newName)
window is any JFrame * public boolean setObject(Object window){ if (window==null || !(window instanceof JFrame)) return false; for (int p=0; p
Overrides:
setName in class DefaultCS

interpretAsGUI

public CS interpretAsGUI(CS graphRoot)
some trees/graphs of CSs cant be converted to java.util.Component objects. interpretAsGUI converts ANY tree/graph of CSs to GUI objects and returns the tree's root. Default implementation uses Layout and TreeOfCodeGUI objects.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener