#  $Id: layout.tk,v 4.9 2002/04/09 11:48:48 katie Exp $
# Copyright (c) 2001,2002                        RIPE NCC
#
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of the author not be
# used in advertising or publicity pertaining to distribution of the
# software without specific, written prior permission.
#
# THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
# AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
#  Copyright (c) 1994 by the University of Southern California
#  All rights reserved.
#
#  Permission to use, copy, modify, and distribute this software and its
#  documentation in source and binary forms for lawful non-commercial
#  purposes and without fee is hereby granted, provided that the above
#  copyright notice appear in all copies and that both the copyright
#  notice and this permission notice appear in supporting documentation,
#  and that any documentation, advertising materials, and other materials
#  related to such distribution and use acknowledge that the software was
#  developed by the University of Southern California, Information
#  Sciences Institute. The name of the USC may not be used to endorse or
#  promote products derived from this software without specific prior
#  written permission.
#
#  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
#  REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
#  PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
#  TITLE, AND NON-INFRINGEMENT.
#
#  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
#  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
#  OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
#  OR PERFORMANCE OF THIS SOFTWARE.
#
#  Questions concerning this software should be directed to
#  ratoolset@isi.edu.
#
#  Author(s): Cengiz Alaettinoglu <cengiz@ISI.EDU>


#source utils.tk

proc dkfBusyInternal {w d} {
    global dkfBusyStore
    if $d {
	$w config -cursor $dkfBusyStore($w)
    } else {
	set dkfBusyStore($w) [$w cget -cursor]
	$w config -cursor watch
    }
    foreach i [winfo children $w] {dkfBusyInternal $i $d}
}

proc dkfBusy_orig {w {d 0}} {
    dkfBusyInternal $w $d
    if $d {
	global dkfBusyStore
	unset dkfBusyStore
    }
    update idletasks
}

proc dkfBusy {w {d 0}} {
}

proc dkfNotBusy w {dkfBusy $w 1}

proc destroy_children {w} {
   set children [winfo children $w]
   foreach wc $children {
      destroy $wc
   }
}

proc popup_message {m} {
    if [winfo exists .message] {
        destroy .message
    } 

    toplevel .message
    wm title .message "ROE Message"
    focus .message
    
    message .message.text -text $m -aspect 1200
    button  .message.done -text {OK} -command { destroy .message }
    
    pack .message.text .message.done
    
    update
}

proc new_as_command {} {
    set new_as [GetValue {Please input a new AS:} {AS} ]
    update
    set new_as [string toupper $new_as]
    if [string compare $new_as ""] {
	if {[string compare [string range $new_as 0 1] "AS"] == 0} {
	    roe_file_new_as $new_as
	} else {
	    showError "AS number should start with \"AS\""
	}
    }
}

frame .menubar -relief raised -bd 2 
pack .menubar -side top -fill x

menubutton .menubar.file -text File -underline 0 -menu .menubar.file.menu
menu .menubar.file.menu
.menubar.file.menu add command -label {New AS} -command {
    roe_file_new_as
}
.menubar.file.menu add separator
.menubar.file.menu add command -label {Compare with BGP Dump} -command {
    set fname [ut:fsbox -prompt "BGP Dump File:" -grab 1]
    update
    if [string compare $fname ""] { roe_read_bgp_dump $fname } 
}
.menubar.file.menu add command -label {Quit} -command {destroy .}
   

menubutton .menubar.show -text Show -underline 0 -menu .menubar.show.menu
menu .menubar.show.menu
.menubar.show.menu add command -label {Show None} -command {
    set roe_show_reg_no            0 
    set roe_show_reg_single        0 
    set roe_show_reg_multi         0 
    set roe_show_reg_undet         0
    set roe_show_routed_no         0 
    set roe_show_routed_yes        0 
    set roe_show_routed_undet      0
    set roe_show_homed_you         0 
    set roe_show_homed_other       0 
    set roe_show_homed_multi_me    0 
    set roe_show_homed_multi_other 0 
    set roe_show_homed_undet       0
    roe_show_routes
}
.menubar.show.menu add command -label {Show All} -command {
    set roe_show_reg_no            1 
    set roe_show_reg_single        1 
    set roe_show_reg_multi         1 
    set roe_show_reg_undet         1
    set roe_show_routed_no         1 
    set roe_show_routed_yes        1 
    set roe_show_routed_undet      1
    set roe_show_homed_you         1 
    set roe_show_homed_other       1 
    set roe_show_homed_multi_me    1
    set roe_show_homed_multi_other 1
    set roe_show_homed_undet       1
    roe_show_routes
}
.menubar.show.menu add command -label {Show Again} -command roe_show_routes
.menubar.show.menu add separator
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Not Registered} -variable roe_show_reg_no
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Singly Registered} -variable roe_show_reg_single
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Multi Registered} -variable roe_show_reg_multi
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Undetermined} -variable roe_show_reg_undet
.menubar.show.menu add separator
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Routed} -variable roe_show_routed_yes
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Not Routed} -variable roe_show_routed_no
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Undetermined} -variable roe_show_routed_undet
.menubar.show.menu add separator
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Single Homed to Your AS} -variable roe_show_homed_you
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Single Homed to Other AS} -variable roe_show_homed_other
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Multi Homed with Your AS} -variable roe_show_homed_multi_me 
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Multi Homed w/o Your AS} -variable roe_show_homed_multi_other
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Undetermined} -variable roe_show_homed_undet
.menubar.show.menu add separator
.menubar.show.menu add checkbutton -command roe_show_routes \
   -label {Potential IBGP} -variable roe_show_potential_IBGP
.menubar.show.menu add separator
.menubar.show.menu add checkbutton \
   -label {Balloon hint} -variable roe_show_routes_hint

menubutton .menubar.selection -text Selection -underline 1 -menu .menubar.selection.menu
menu .menubar.selection.menu
.menubar.selection.menu add command -label {Select All} \
   -command {.routes.list selection set 0 end}
.menubar.selection.menu add command -label {UnSelect All} \
   -command {.routes.list selection clear 0 end}
.menubar.selection.menu add separator
.menubar.selection.menu add command -label {Add Selected Routes} \
   -command { roe_add_selected [.routes.list curselection] }
.menubar.selection.menu add command -label {Delete Selected Routes} \
   -command {roe_del_selected [.routes.list curselection] }
.menubar.selection.menu add cascade -label {Delete Selected Routes from} \
   -menu .menubar.selection.menu.sources
menu .menubar.selection.menu.sources
.menubar.selection.menu add separator
.menubar.selection.menu add command -label {Get More Specifics} \
   -command { roe_get_more_specifics [.routes.list curselection] }
.menubar.selection.menu add command -label {Get Less Specifics} \
   -command { roe_get_less_specifics [.routes.list curselection] }

menubutton .menubar.configure -text Configure -underline 0 \
   -menu .menubar.configure.menu
menu .menubar.configure.menu
.menubar.configure.menu add command -command {roe_config_tmpl} \
   -label {Templates} 
.menubar.configure.menu add command -command {roe_config_irr} \
   -label {IRR Update Commands} 
.menubar.configure.menu add command -command {roe_config_revert} \
   -label {Revert to Factory Settings} 
.menubar.configure.menu add command -command {roe_config_save} \
   -label {Save Options} 
.menubar.configure.menu add command -command {roe_config_load} \
   -label {Reload Options} 


pack .menubar.file     -in .menubar -side left
pack .menubar.show     -in .menubar -side left
pack .menubar.selection -in .menubar -side left
pack .menubar.configure  -in .menubar -side left

frame .routes
listbox .routes.list -yscrollcommand ".routes.scroll set" -selectmode extended \
   -font -misc-fixed-medium-r-semicondensed-*-13-*-75-75-*-*-iso8859-1
scrollbar .routes.scroll -command ".routes.list yview"
bind .routes.list <ButtonRelease-1> {
    roe_select_route [.routes.list curselection]
}
bind .routes.list <Enter> {
    roe_routes_hint_reset
}
bind .routes.list <Motion> {
    roe_routes_hint [%W nearest %y] [expr %X + 10] [expr %Y + 10]
}

pack .routes                    -side top  -expand 1 -fill both
pack .routes.list   -in .routes -side left -expand 1 -fill both
pack .routes.scroll -in .routes -side right           -fill y

frame .buttonbar -relief raised -bd 2
pack .buttonbar -side top -fill x

frame .statusbar -relief raised -bd 2
label .statusbar.left  -text {Connecting to server ...}
label .statusbar.right -justify right -text {Pending Replies: 0}
bind .statusbar.right <Enter> {
    roe_statusbar_hint
}

pack .statusbar -side bottom -fill x
pack .statusbar.left  -side left  -fill x
pack .statusbar.right -side right -fill x

frame .object -relief raised -bd 2 
text .object.text -wrap none -width 50 -height 12 \
   -yscrollcommand ".object.yscroll set" \
   -xscrollcommand ".object.xscroll set"
scrollbar .object.yscroll -command ".object.text yview"
scrollbar .object.xscroll -orient horizontal -command ".object.text xview"
frame .object.buttons
button .object.buttons.add    -text {Add Template}    \
   -command {roe_object_add [.routes.list curselection]}
button .object.buttons.delete -text {Delete Template} \
   -command {roe_object_delete [.routes.list curselection]}
button .object.buttons.update -text {Update Template} \
   -command {roe_object_update [.routes.list curselection]}
button .object.buttons.schedule -text {Schedule} -command roe_object_schedule

pack .object                     -side left   -expand 1 -fill both
pack .object.buttons        -in .object         -side bottom -fill x
pack .object.buttons.add    -in .object.buttons -side left
pack .object.buttons.delete -in .object.buttons -side left
pack .object.buttons.update -in .object.buttons -side left
pack .object.buttons.schedule -in .object.buttons -side right
pack .object.xscroll        -in .object -side bottom           -fill x
pack .object.text           -in .object -side left   -expand 1 -fill both
pack .object.yscroll        -in .object -side right            -fill y

frame .schedule -relief raised -bd 2 
listbox .schedule.list -width 45 \
   -yscrollcommand ".schedule.yscroll set" \
   -xscrollcommand ".schedule.xscroll set" \
   -font -misc-fixed-medium-r-semicondensed-*-13-*-75-75-*-*-iso8859-1
scrollbar .schedule.yscroll -command ".schedule.list yview"
scrollbar .schedule.xscroll -command ".schedule.list xview" -orient horizontal 
frame .schedule.buttons
button .schedule.buttons.update -text {Update IRR} -command roe_update_irr
button .schedule.buttons.cancel -text {Cancel} -command {roe_cancel_transaction [.schedule.list curselection]}
bind .schedule.list <ButtonRelease-1> {roe_select_transaction [.schedule.list curselection]}

pack .schedule -side right -expand 1 -fill both
pack .schedule.buttons        -in .schedule         -side bottom -fill x
pack .schedule.xscroll        -in .schedule -side bottom         -fill x
pack .schedule.buttons.cancel -in .schedule.buttons -side left
pack .schedule.buttons.update -in .schedule.buttons -side right
pack .schedule.list           -in .schedule -side left -expand 1 -fill both 
pack .schedule.yscroll        -in .schedule -side left           -fill y

# added by wlee@isi.edu
StatusLine:init .statusbar.left 
StatusLine:set .menubar.file "New AS, Compare with BGP Dump, Quit"
StatusLine:set .menubar.show "Show None/All/Again, Not/Singly/Multi Registered, various route status, balloon hint"
StatusLine:set .menubar.selection "Select/UnSelect All, Add/Delete Selected Routes, Get More/Less Specifics"
StatusLine:set .menubar.configure "Templates, IRR Update Commands, Revert to Factory Settings, Save/Reload Options"
StatusLine:set .object.buttons.add "Display a new route object from a template and prepare for editing"
StatusLine:set .object.buttons.delete "Prepare to delete an editing route object"
StatusLine:set .object.buttons.update "Prepare to update an editing route object"
StatusLine:set .object.buttons.schedule "Schedule the editing route object to be added/deleted/updated to/from IRR"
StatusLine:set .schedule.buttons.cancel "Cancel scheduled route objects once at a time from the list above"
StatusLine:set .schedule.buttons.update "Update scheduled route objects from the list above to IRR"
StatusLine:set .object.text "Route object editing area"
StatusLine:set .schedule.list "A list of scheduled route objects to be added/delete/updated"
StatusLine:set .statusbar "This is just a status line, move your mouse some places else, thanks"
