!------------------------------------------------------------------------------!
! Test the plotting of Shape (.shp) files and modifications to the border color
! while the mouse is moved over the plot.
!
! Author:  J. Hallam
!------------------------------------------------------------------------------!
startmacro

  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE

  call setDatDir

  set instructions &
      "Should see:\n&
      1) a plot of the world\n&
      2) nations of the world should be colored.\n\n&
      Click on [CycleColors] then move the mouse over the plot.\n&
      -> should not see graphical glitches while moving the mouse."

  if interAct then
    pipe init

    panel/msgid=MAIN/setup/controls=gc
    plot/id=idplot/READOUT="+OnAxis" ^{datDir}.world.shp{LAYER={LABEL=NAME}} view=latlon

    set shapeLayer reg.idplot.layers.world   ! Handle to world Shape file layer

    gcontrol label mainLabel "Main"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol text idtext "Instructions" "^instructions" 24 12 /title

    gcontrol LABEL optionsLabel "Options"
      gcontrol button borderColor "" "CycleColors"

    pipe off

  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="Plot border tests" msg.data eqss "PASS" 
    pipe stop
  elseif msg.name EQS "BORDERCOLOR" then
    if msg.data EQS "CycleColors" then
      foreach bColor INLIST "#000000,#0000FF,#00FF00,#FF0000,#00FFFF,#FF00FF,#FFFF00,#FFFFFF, &
                                     #000033,#003300,#330000,#003333,#330033,#333300,#333333, &
                                     #000066,#006600,#660000,#006666,#660066,#666600,#666666, &
                                     #000099,#009900,#990000,#009999,#990099,#999900,#999999 "
        set shapeLayer.colorTable {border=^bColor}
        pause (.5)
      endfor 
    endif
  else
    ! do nothing
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
