# JStrack:  copyright 1997/2010 by Jim Graham, N5IAL, all rights reserved.
#

catch { destroy .file }         ;# set fmw .file
catch { destroy .opts }         ;# set omw .opts
catch { destroy .plotmenu }     ; set pmw .plotmenu
catch { destroy .warnframe }    ;# set wrnf .warnframe
catch { destroy .infomenu }     ;# set imw .infomenu

menubutton .file -text "File" -menu .file.m
menu .file.m -tearoff 0

.file.m add command -label Console -command { toggle_tkcon }
.file.m add command -label "Saffir-Simpson Scale" -command { tk_sschart }
.file.m add command -label "Save main window to a TIFF image" \
   -command { windump_ask . }
.file.m add command -label "PostScript output" -command { create_ps }
.file.m add command -label "Update Storm Data (From File)" \
   -command { update_data }

.file.m add command -label "Merge Tropical Depression/Named Storm Data" \
   -command { merge_data }

.file.m add command -label "Exit" -command { exit }

menubutton .opts -text "Options" -menu .opts.m
menu .opts.m -tearoff 0
.opts.m add command \
   -label "Plot City Names/Update Plotted Names" -command { plot_user_cities }
.opts.m add command -label "Remove City Names" -command { rmcities }

.opts.m add command -label "Default Map"
.opts.m add radiobutton -label "   Overall picture" \
   -variable defmap -value large_js
.opts.m add radiobutton -label "   East coast (north of FL)" \
   -variable defmap -value east_coast_js
.opts.m add radiobutton -label "   Caribbean, S. Gulf" \
   -variable defmap -value carib_js
.opts.m add radiobutton -label "   Gulf of Mexico, etc." \
   -variable defmap -value gulf_cab2_js
.opts.m add command -label " "
.opts.m add radiobutton -label "Miles/MPH" -variable units -value MPH
.opts.m add radiobutton -label "NM/KT" -variable units -value KT
.opts.m add checkbutton -label "Always plot latest wind radii" \
   -variable auto_radii -onvalue 1 -offvalue 0
.opts.m add checkbutton -label "Always plot latest forecast positions" \
   -variable auto_fc -onvalue 1 -offvalue 0
.opts.m add checkbutton -label "Watch for storm updates in background" \
   -variable auto_update -offvalue 0 -command {
      if {$auto_update} {
         test_st_files 1
      } else {
         catch { after cancel test_st_files }
      }
   }
.opts.m add checkbutton -label "Automatically load NEW storms" \
   -variable auto_load_new -onvalue 1 -offvalue 0
.opts.m add command -label "Home Coordinates" -command { mnu_home_coords }
.opts.m add command -label "Warnings (for when a storm gets too close)" \
   -command { mnu_warnings }
.opts.m add checkbutton -label "Display coordinates of mouse pointer" \
   -variable show_ptrloc -onvalue 1 -offvalue 0 -command {
      if {$show_ptrloc == 0} { set ptrlocstr "(not active)" }
   }

.opts.m add command -label "Save Config (user-specific)" \
   -command { save_config }
if {[file writable $trackdir/options.tcl]} {
   .opts.m add command -label "Save Config (GLOBAL config)" \
      -command { save_config 1 }
} elseif {![file exists $trackdir/options.tcl] && [file writable $trackdir]} {
   .opts.m add command -label "Save Config (GLOBAL config)" \
      -command { save_config 1 }
}

menubutton .maps -text "Maps (with/without satellite imagery)" -menu .maps.m
menu .maps.m -tearoff 0
.maps.m configure -disabledforeground red

# ####################################################################### #
# ###################  NORMAL (no satellite imagery)  ################### #
# ####################################################################### #
.maps.m add command -label "Normal (on-screen) Versions" \
   -state disabled -command {}
.maps.m add separator
.maps.m add command -label "Overall picture" \
   -command { set loadsat 0 ; set altprint 0 ; source $imgdir/large_js.tcl ; newmap }
.maps.m add command -label "US East coast (north of FL)" \
   -command { set loadsat 0 ; set altprint 0 ; source $imgdir/east_coast_js.tcl ; newmap }
.maps.m add command -label "Gulf coast + FL East coast" \
   -command { set loadsat 0 ; set altprint 0 ; source $imgdir/gulf_cab2_js.tcl ; newmap }
.maps.m add command -label "Caribbean, S. Gulf" \
   -command { set loadsat 0 ; set altprint 0 ; source $imgdir/carib_js.tcl ; newmap }
.maps.m add separator

# ####################################################################### #
# ##################  NORMAL plus GOES East (Visible)  ################## #
# ####################################################################### #
.maps.m add command -label "Normal Versions With GOES East (Visible)" \
   -state disabled -command {}
.maps.m add separator
.maps.m add command -label "Overall picture" \
   -command { set loadsat 1 ; set altprint 0 ; source $imgdir/large_js.tcl ; newmap }
.maps.m add command -label "US East coast (north of FL)" \
   -command { set loadsat 1 ; set altprint 0 ; source $imgdir/east_coast_js.tcl ; newmap }
.maps.m add command -label "Gulf coast + FL East coast" \
   -command { set loadsat 1 ; set altprint 0 ; source $imgdir/gulf_cab2_js.tcl ; newmap }
.maps.m add command -label "Caribbean, S. Gulf" \
   -command { set loadsat 1 ; set altprint 0 ; source $imgdir/carib_js.tcl ; newmap }
.maps.m add separator

# ####################################################################### #
# ##################  NORMAL plus GOES East (Infrared  ################## #
# ####################################################################### #
.maps.m add command -label "Normal Versions With GOES East (Infrared)" \
   -state disabled -command {}
.maps.m add separator
.maps.m add command -label "Overall picture" \
   -command { set loadsat 2 ; set altprint 0 ; source $imgdir/large_js.tcl ; newmap }
.maps.m add command -label "US East coast (north of FL)" \
   -command { set loadsat 2 ; set altprint 0 ; source $imgdir/east_coast_js.tcl ; newmap }
.maps.m add command -label "Gulf coast + FL East coast" \
   -command { set loadsat 2 ; set altprint 0 ; source $imgdir/gulf_cab2_js.tcl ; newmap }
.maps.m add command -label "Caribbean, S. Gulf" \
   -command { set loadsat 2 ; set altprint 0 ; source $imgdir/carib_js.tcl ; newmap }



.maps.m add separator
.maps.m configure -disabledforeground red
.maps.m add command -label "Printer (ink) Friendly Versions" \
   -state disabled -command {}
.maps.m add separator

.maps.m add command -label "Overall picture" \
   -command { set altprint 1 ; source $imgdir/large_js.tcl ; newmap }
.maps.m add command -label "US East coast (north of FL)" \
   -command { set altprint 1 ; source $imgdir/east_coast_js.tcl ; newmap }
.maps.m add command -label "Gulf coast + FL East coast" \
   -command { set altprint 1 ; source $imgdir/gulf_cab2_js.tcl ; newmap }
.maps.m add command -label "Caribbean, S. Gulf" \
   -command { set altprint 1 ; source $imgdir/carib_js.tcl ; newmap }


menubutton $pmw -text "Storm Data" -menu $pmw.m
menu $pmw.m -tearoff 0
$pmw.m add command -label "Load/reload storm(s)" -command { mnu_reload }
$pmw.m add command -label "Remove storm(s) from chart" -command {
   mnu_remove
}
$pmw.m add command -label "Update Storm Data (From File)" \
   -command { update_data }
$pmw.m add command -label "Input storm data manually" -command {
   tk_st_data
}
$pmw.m add command -label "History of storm" -command { mnu_hist }
$pmw.m add command -label "Plot all wind radii for storm" -command {
   mnu_radii
}
$pmw.m add command -label "Remove all wind radii for storm" -command {
   mnu_rm_radii
}
$pmw.m add command -label "Clean chart" -command { wipeclean }
$pmw.m add command -label "Saffir-Simpson Scale" -command { tk_sschart }

button .warnings -text "Watches/Warnings" -command {getww} -relief flat

label .spacer -text "  ||  " -relief flat
button .httpmenu -text "Update (from NHC via HTTP)" \
      -command { catch { update_http } } -relief flat


button .infomenu -text "Info" -command { jstrack_info } -relief flat

# I really hate having this ancient use of pack (as opposed to .mf.file,
# .mf.opts, etc.)...but as they say, "don't fix it if it ain't broke...."

pack .file .opts .maps $pmw .warnings .spacer .httpmenu -in .mf -side left -anchor w

# pack .exit -in .mf -side right -expand n

menubutton .imgmenu -text "Satellite Imagery" -menu .imgmenu.m
menu .imgmenu.m -tearoff 0
.imgmenu.m configure -disabledforeground blue
.imgmenu.m add command -label "GOES East Hurricane Sector Imagery" \
   -state disabled -command {} -font {Helvetica 14 bold}
.imgmenu.m add command -label {Links (for web browser use)} \
   -command { noaa_links }
foreach tlist $tagidx {
   foreach {tag idx} $tlist { break }
   .imgmenu.m add separator
   .imgmenu.m add command -label "   $tag" -state disabled -command {}
   .imgmenu.m add separator
   .imgmenu.m add command -label "      Overview" -command "
      goes_east_hurrsec \"$tag\" $goeslinks($idx,image) $goeslinks($idx,html)
   "
   .imgmenu.m add command -label "      Overview (loop)" -command "
      goes_east_hurrsec_loop \"$tag\" $idx $goeslinks($idx,loop,html)
   "
   set tmptag "$tag / Gulf of Mexico"
   .imgmenu.m add command -label "      Gulf of Mexico" -command "
      goes_east_hurrsec \"$tmptag\" $goeslinks($idx,gulf) $goeslinks(SSD_Home)
   "
   set tmptag "$tag / US East Coast"
   .imgmenu.m add command -label "      US East Coast" -command "
      goes_east_hurrsec \"$tmptag\" $goeslinks($idx,eastcoast) $goeslinks(SSD_Home)
   "
}

label .spacerb -text "  ||  " -relief flat
pack .imgmenu .spacerb -in .mf -side left -anchor w



button .georeset -text "\[ResetWinLoc]" -command {wm geometry . +0+0} \
   -relief flat
button .bexit -text "\[Exit]" -command {exit} -relief flat
label .spacerc -text "        " -relief flat
pack .spacerc .bexit .infomenu .georeset -in .mf -side right -anchor e

frame .warnframe
pack .warnframe -side top -anchor w -expand y -fill x

