!******************************************************************************!
! @bug      <2888> <In LayerT5, selectColor is defaulted to Color.RED and there is no setter method>
! @author:  P. Quan / J. McCall
!******************************************************************************!
startmacro

  call setDatDir

  set instr "You should see a plot of the world with the cities in blue. Zoom in and select a specific city. \n&
                1) The selected city color should be green \n&
                2) Check the console to make sure the automated portion of this test passed \n\n&
             You should also not see a stack trace in the terminal prepended by a FAILED message. Bug 2911 is being &
             tested in this test case."

  invoke color_green nxm.sys.libg.MColor.getColor(0,100,0)

  pipe init 
    panel/setup/controls=gc
    plot/id=plot1/nice ^{datDir}.world.prm|^{datDir}.cities.prm{layer={AutoselectEnable="CLICK",AutoSelectMode="GreatArc",AutoSelectRange="750000.0",COLOR=BLUE, SELECTCOLOR=GREEN}} &
             type=line AXIS=+Grid SCALE=AUTOMIN|AUTOMAX AUTOL=4

    ! Test for Bug 2911: Prior to the fix, the line below this will cause a stack trace when the Legend is open (MMB -> LAYERS)
    layer "nxm.sys.libg.Layer" mylayer ,, plot1
    invoke ,, reg.plot1.showLegend("BR")

    gcontrol label macro  "MACRO"
    gcontrol menu  MAIN   "Exit with Status = " "PASS,FAIL" /tleft
    set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
    gcontrol text  idtext "Instructions" "^instr" 14 22 /title

    invoke selectColor reg.plot1.layers.cities.selectColor

    assert/text="^reg.main.name: getSelectColor" color_green oeq selectColor

  pipe off
endmacro


procedure processMessage m:msg
    if msg.name EQS "MAIN" then
        assert/text="^reg.main.name: Interactive tests" "PASS" SUBS msg.data
        pipe stop
    else
        say "^reg.main.name: Unhandled message name=^msg.name info=^msg.info data=^msg.data"
    endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  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
