BBjInputNSpinner Example

USE java.util.HashMap

REM Obtain the instance of the BBjAPI object
LET myAPI!=BBjAPI()

REM Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI)"X0"

REM Obtain the instance of the BBjSysGui object
LET mySysGui!=myAPI!.getSysGui()

REM Set addWindow param values
X=200
Y=200
WIDTH=350
HEIGHT=250
TITLE$="Event Simulation"

REM Set the current context
mySysGui!.setContext(0)

REM Create a window
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$,$00010083$)

REM Create fields for time
myHourSpinner! = myWindow!.addInputNSpinner(101, 10, 10, 35, 25, $$, "##", $$, 1, 1)
testInputN! = myWindow!.addInputN(201, 190, 10, 35, 25, $$, "##", $$, 1, 1)
testInputN!.setCallback(myAPI!.ON_EDIT_MODIFY, "ED_MOD")
myHourSpinner!.setCallback(myAPI!.ON_EDIT_MODIFY, "ED_MOD")

min! = myHourSpinner!.getMinimum()
IF (min! = NULL() OR min! <> 1)
    myHourSpinner!.setMinimum(1)
ENDIF

max! = myHourSpinner!.getMaximum()
IF (max! = NULL() OR max! <> 12)
    myHourSpinner!.setMaximum(12)
ENDIF

myMinuteSpinner! = myWindow!.addInputNSpinner(102, 55, 10, 35, 25, $$, "00")
origColor! = myMinuteSpinner!.getBackColor()

min! = myMinuteSpinner!.getMinimum()
IF (min! = NULL() OR min! <> 0)
    myMinuteSpinner!.setMinimum(0)
ENDIF

max! = myMinuteSpinner!.getMinimum()
IF (max! = NULL() OR max! <> 55)
    myMinuteSpinner!.setMaximum(55)
ENDIF

IF (myMinuteSpinner!.getStepSize() <> 5)
    myMinuteSpinner!.setStepSize(5)
ENDIF

myHalfVec! = myAPI!.makeVector()
myHalfVec!.add("AM")
myHalfVec!.add("PM")
myHalfSpinner! = myWindow!.addInputESpinner(103, 100, 10, 35, 25, myHalfVec!)
myHalfSpinner!.setMask("AA")

myEditBox! = myWindow!.addEditBox(104, 10, 45, 120, 25, $$)
myCEdit! = myWindow!.addCEdit(105, 10, 80, 200, 50, $$)
myCEdit!.setLineWrap(1)
myCEdit!.setIgnoreTabs(0)

myList! = myWindow!.addListBox(106, 10, 140, 140, 100, $$)

REM Create a button for adding new languages
myAddButton! = myWindow!.addButton(107, 230, 80, 110, 25, "Add Event")

REM Create a button for deleting existing languages
myRemoveButton! = myWindow!.addButton(108, 230, 115, 110, 25, "Remove Event")

REM Set callbacks
myWindow!.setCallback(myWindow!.ON_CLOSE,"APP_CLOSE")
myMinuteSpinner!.setCallback(myMinuteSpinner!.ON_SPIN, "MINUTE_SPIN")
myAddButton!.setCallback(myAddButton!.ON_BUTTON_PUSH, "ADD_EVENT")
myRemoveButton!.setCallback(myRemoveButton!.ON_BUTTON_PUSH, "REMOVE_EVENT")
myList!.setCallback(myList!.ON_LIST_DOUBLE_CLICK, "SELECT_EVENT")

myEventTimes! = new HashMap()
myEventDescs! = new HashMap()

PROCESS_EVENTS

REM Callback for myMinuteSpinner! ON_SPIN
MINUTE_SPIN:
    next! = myMinuteSpinner!.getNextNumber()
    prev! = myMinuteSpinner!.getPreviousNumber()
    myMinuteSpinner!.setBackColor(origColor!)
    IF (next! = NULL())
        myMinuteSpinner!.setBackColor(mySysGui!.makeColor(255, 0, 0))
    ENDIF
    IF (prev! = NULL())
        myMinuteSpinner!.setBackColor(mySysGui!.makeColor(255, 0, 0))
    ENDIF
    
    RETURN

REM Callback for myAddButton! ON_BUTTON_PUSH
ADD_EVENT:
    eventName$ = myEditBox!.getText()
    eventDesc$ = myCEdit!.getText()
    hour = myHourSpinner!.getValue()
    minute = myMinuteSpinner!.getValue()
    half$ = myHalfSpinner!.getText()
    myEventTimes!.put(eventName$, STR(hour:"00") + ":" + STR(minute:"00") + " " + half$)
    myEventDescs!.put(eventName$, eventDesc$)
    myList!.addItem(eventName$)
    RETURN

REMOVE_EVENT:
    eventName$ = myEditBox!.getText()
    list! = myList!.getAllItems()
    index = list!.indexOf(eventName$)
    IF (index >= 0)
        myList!.removeItemAt(index)
    ENDIF
    myEventTimes!.remove(eventName$)
    myEventDescs!.remove(eventName$)
    RETURN

SELECT_EVENT:
    index = myList!.getSelectedIndex()
    eventName$ = myList!.getItemAt(index)
    timeStr! = myEventTimes!.get(eventName$)
    list! = java.util.Arrays.asList(timeStr!.split("[: ]"))
    hour = NUM(list!.get(0))
    minute = NUM(list!.get(1))
    half$ = list!.get(2)
    desc$ = myEventDescs!.get(eventName$)

    myEditBox!.setText(eventName$)
    myCEdit!.setText(desc$)
    myHourSpinner!.setValue(hour)
    myMinuteSpinner!.setValue(minute)
    myHalfSpinner!.setText(half$)
    RETURN

APP_CLOSE:
    RELEASE

ED_MOD:
    PRINT "Got here"
    RETURN