!**************************************************************************************************!
! Purpose: test the Swing based FILECHOOSER COMMAND
!
! author : Neon Ngo
! version: $Id: test_filechooser.mm,v 1.3 2007/05/25 23:11:53 ntn Exp $
!**************************************************************************************************!
startmacro

switch INTERACTIVE interAct GET DEF=TRUE
if interAct then
  set commandName       "FILECHOOSER"
  set theTitle          "^commandName test dialog window Title"
  set filechooserResult "<^commandName not yet opened>"
  invoke optionsList    nxm.ucl.libg.MJFileChooser.optionList
  invoke pathOptionList nxm.ucl.libg.MJFileChooser.pathOptionList
  table aux getkeys/s   allauxes
  ! remove WRITE,READ, and HOMEPATH from all AUXes list
  sedit allauxes allauxes GSUB "WRITE,"
  sedit allauxes allauxes GSUB "READ,"
  sedit allauxes allauxes GSUB "HOMEPATH,"

  pipe on
    panel/msgid=MAIN/setup/controls=gc

    gcontrol label macro "MACRO"
      gcontrol/title TEXT instructions INSTRUCTIONS "" 24 4

    gcontrol label fileChoosersLab "FILE CHOOSER"
      set instruct "Click on 'Test ^commandName' and files with the specified 'Filename filter' &
                    for the 'Selected AUX list' should be listed. The 'Seed filename' should be &
                    shown as the current file. Then, select a file and click the Open button &
                    which should be be displayed in the 'User Input' text area."
      set gc.instructions.value "^instruct"

      ! file chooser options
      gcontrol PROMPT title   "Dialog Title     " "^theTitle"      /msg=f
      gcontrol PROMPT seedfn  "Seed filename    " "apenny.prm"     /msg=f
      gcontrol PROMPT filter  "Filename filter  " "*.prm|tmp|ext2" /msg=f /VBoxMO
      gcontrol CHOICE auxlist "Selected AUX list" "^allauxes" "DAT|RAM" /msg=f /flags="TLeft|Toggle|VBoxMO"
      gcontrol MENU   options "FLAGS options    " "^optionsList"     /msg=f /flags="TLeft|OneRow|ChkBox|Toggle"
      gcontrol CHOICE pathopt "Path option      " ",^pathOptionList" /msg=f /flags="TLeft"
      gcontrol MENU   testit  "Open ^commandName" "Test ^commandName"       /flags="Button|TLeft"

      ! to display user inputs
      gcontrol TEXT userInput "User Input" "^filechooserResult" 24 3 /title

    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemcolors {PASS=GREEN,FAIL=RED}

  pipe off
endif

endmacro

!**************************************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop

  elseif msg.name eqss "TESTIT"  then
    set title   "^gc.title.value"
    set seedfn  "^gc.seedfn.value"
    set filter  "^gc.filter.value"
    set auxlist "^gc.auxlist.value"
    set options "^gc.options.value"
    set pathopt "^gc.pathopt.value"
    set filechooserResult "<Waiting for ^commandName result or message>"
    ! display initial status message to user
    set gc.userInput.value "^filechooserResult"

    nxm.ucl.prim.filechooser RESULT=filechooserResult TITLE="^title" SEED="^seedfn" FILTER="^filter" &
                             AUXLIST="^auxlist" /FLAGS=^options /PATHOPTION=^pathopt /msgid=main
    ! display user file selection results
    set gc.userInput.value "RESULT: ^filechooserResult"
  else
    say "^reg.main.name: got message - name=^msg.name from=^msg.fid info=^msg.info data=^msg.data"
  endif

return
