#
#  Module Preferences.tcl
#
# $Log: Preferences.tcl,v $
# Revision 1.2  2006/10/26 09:39:17  vfom
# Added code for netstate server query
#
# Revision 1.1.1.1  2006/09/21 10:57:02  vfom
# Loading TkNetmon to CVS
#
#
namespace eval ::Prefs {
variable editPrefs_exitFlag	0	\
	snmp_ver		$::node_SnmpVer \
	objPreftextJust		center
}
#
proc editPrefs_GUIconstructor {} {
    set w .commonPrefs
    set t $w.tnb
    set pf $t.pathsFrame
    set pfg $pf.grid
    set cf $t.commonFrame
    set cfg $cf.grid
    set nf $t.nodeFrame
    set nfg $nf.grid
    set tf $t.txtFrame
    set tfg $tf.grid
    set lf $t.lineFrame
    set lfg $lf.grid
    set kf $t.linkFrame
    set kfg $kf.grid
    set b $w.buttons

    toplevel $w -class Dialog
    wm transient $w [winfo toplevel [winfo parent $w]]
    wm title $w [ msgcat::mc "Default Settings" ]
    wm withdraw $w

    blt::tabset $t -tiers 2
    pack $t -side top -fill both -expand on

    $t insert end [msgcat::mc "Paths"]
    $t insert end [msgcat::mc "Common"]	
    $t insert end [msgcat::mc "Node"]
    $t insert end [msgcat::mc "Text"]
    $t insert end [msgcat::mc "Line"]	
    $t insert end [msgcat::mc "Link"]	
#
#   Закладка "Пути"
#
    frame $pf 
    frame $pfg
    pack $pfg -side top -anchor nw -padx 15 -pady 5
    $t tab configure [msgcat::mc "Paths"] -window $pf -fill both -anchor n -padx 5 -pady 5
    set curr_row 0

    label $pf.lbbrw -text [msgcat::mc "Browser Programm:"]
    grid $pf.lbbrw -in $pfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $pf.epfilebrw -width 60 
    grid $pf.epfilebrw -in $pfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $pf.browsebrw -text [msgcat::mc "..."]  \
	-command {  browseFile .commonPrefs.tnb.pathsFrame.epfilebrw [msgcat::mc "Find Browser programm"]}
    grid $pf.browsebrw -in $pfg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $pf.lbsnd -text [msgcat::mc "Sound Playing Programm:"]
    grid $pf.lbsnd -in $pfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $pf.epfilesnd -width 60 
    grid $pf.epfilesnd -in $pfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $pf.browsesnd -text [msgcat::mc "..."]  \
	-command {  browseFile .commonPrefs.tnb.pathsFrame.epfilesnd [msgcat::mc "Find Sound Playing programm"]}
    grid $pf.browsesnd -in $pfg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $pf.lblog -text [msgcat::mc "Logfile:"]
    grid $pf.lblog -in $pfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $pf.epfilelog -width 60 
    grid $pf.epfilelog -in $pfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $pf.browselog -text [msgcat::mc "..."]  \
	-command {browseFile .commonPrefs.tnb.pathsFrame.epfilelog [msgcat::mc "Find Logfile"]}
    grid $pf.browselog -in $pfg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $pf.lbpre -text [msgcat::mc "Pred Include file:"]
    grid $pf.lbpre -in $pfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $pf.epfilepre -width 60 
    grid $pf.epfilepre -in $pfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $pf.browsepre -text [msgcat::mc "..."]  \
	-command {browseFile .commonPrefs.tnb.pathsFrame.epfilepre [msgcat::mc "Find Pred Include file"]}
    grid $pf.browsepre -in $pfg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $pf.lbpost -text [msgcat::mc "Post Include file:"]
    grid $pf.lbpost -in $pfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $pf.epfilepost -width 60 
    grid $pf.epfilepost -in $pfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $pf.browsepost -text [msgcat::mc "..."]  \
	-command {browseFile .commonPrefs.tnb.pathsFrame.epfilepost [msgcat::mc "Find Post Include file"]}
    grid $pf.browsepost -in $pfg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
#
#   Закладка "Общие"
#
    frame $cf 
    frame $cfg
    pack $cfg -side top -anchor nw -padx 15 -pady 5
    $t tab configure [msgcat::mc "Common"] -window $cf -fill both -anchor n -padx 5 -pady 5
    set curr_row 0
    label $cf.lbtimestr -text [msgcat::mc "TimeString Format:"]
    grid $cf.lbtimestr -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e    
    entry $cf.etimestr -width 40 
    grid $cf.etimestr -in $cfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row    
    label $cf.lbsavtm -text [msgcat::mc "Data Saving Interval:"]
    grid $cf.lbsavtm -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e    
    entry $cf.esavtm -width 10 
    grid $cf.esavtm -in $cfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $cf.lbd1 -text " "
    grid $cf.lbd1 -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e            
    incr curr_row
    label $cf.lbuname -text [msgcat::mc "User Name:"]
    grid $cf.lbuname -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e    
    entry $cf.euname -width 40 
    grid $cf.euname -in $cfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row    
    label $cf.lbgname -text [msgcat::mc "Group Name:"]
    grid $cf.lbgname -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e    
    entry $cf.egname -width 40 
    grid $cf.egname -in $cfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row    
    label $cf.lbchroot -text [msgcat::mc "ChRoot Directory:"]
    grid $cf.lbchroot -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e    
    entry $cf.echroot -width 40 
    grid $cf.echroot -in $cfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row
    label $cf.lbd2 -text " "
    grid $cf.lbd2 -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e            
    incr curr_row    
    label $cf.lglobalFG -text [msgcat::mc "Foreground color:"]
    grid $cf.lglobalFG -in $cfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $cf.eglobalFG -width 16
    grid $cf.eglobalFG -in $cfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $cf.bglobalFG -text [msgcat::mc "..."] -command "tk_chooseColor2 $cf.eglobalFG"
    grid $cf.bglobalFG -in $cfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $cf.lglobalBG -text [msgcat::mc "Background color:"]
    grid $cf.lglobalBG -in $cfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $cf.eglobalBG -width 16
    grid $cf.eglobalBG -in $cfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $cf.bglobalBG -text [msgcat::mc "..."] -command "tk_chooseColor2 $cf.eglobalBG"
    grid $cf.bglobalBG -in $cfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $cf.lbbgr -text [msgcat::mc "Background Image:"]
    grid $cf.lbbgr -in $cfg \
	-row $curr_row -column 0 -columnspan 1 -rowspan 1 -sticky e
    entry $cf.epfilebgr -width 40 
    grid $cf.epfilebgr -in $cfg \
	-row $curr_row -column 1 -columnspan 1 -rowspan 1 -sticky w
    button $cf.browsebgr -text [msgcat::mc "..."]  \
	-command {  browseFile .commonPrefs.tnb.commonFrame.epfilebgr [msgcat::mc "Find Background Image"]}
    grid $cf.browsebgr -in $cfg \
	-row $curr_row -column 2 -columnspan 1 -rowspan 1 -sticky w
    incr curr_row    
#
#   Закладка "Хост"
#
    frame $nf 
    frame $nfg
    pack $nfg -side top -anchor nw -padx 15 -pady 5
    $t tab configure [msgcat::mc "Node"] -window $nf -fill both -anchor n -padx 5 -pady 5
    set curr_row 0
    label $nf.lnodeicon -text [msgcat::mc "Default node icon:"]
    grid $nf.lnodeicon -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodeicon -width 16
    grid $nf.enodeicon -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $nf.bnodeicon -text [msgcat::mc "..."]  -command "tk_chooseIcon $w $nf.enodeicon"
    grid $nf.bnodeicon -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodeupsound -text [msgcat::mc "Default node UP sound:"]
    grid $nf.lnodeupsound -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodeupsound -width 16
    grid $nf.enodeupsound -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $nf.bnodeupsound -text [msgcat::mc "..."]  -command "tk_chooseSound $w $nf.enodeupsound"
    grid $nf.bnodeupsound -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodednsound -text [msgcat::mc "Default node Down sound:"]
    grid $nf.lnodednsound -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodednsound -width 16
    grid $nf.enodednsound -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $nf.bnodednsound -text [msgcat::mc "..."]  -command "tk_chooseSound $w $nf.enodednsound"
    grid $nf.bnodednsound -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodetextcolor -text [msgcat::mc "Default node text color:"]
    grid $nf.lnodetextcolor -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodetextcolor -width 16
    grid $nf.enodetextcolor -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $nf.bnodetextcolor -text [msgcat::mc "..."] -command "tk_chooseColor2 $nf.enodetextcolor"
    grid $nf.bnodetextcolor -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodetextfont -text [msgcat::mc "Default node text font:"]
    grid $nf.lnodetextfont -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodetextfont -width 48
    grid $nf.enodetextfont -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $nf.bnodetextfont -text [msgcat::mc "..."] -command "tk_chooseFont $nf.enodetextfont"
    grid $nf.bnodetextfont -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.laction -text [msgcat::mc "Default node DoubleClick Action:"]
    grid $nf.laction -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.eaction -width 48
    grid $nf.eaction -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodeaddr -text [msgcat::mc "Default node IP address:"]
    grid $nf.lnodeaddr -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodeaddr -width 15
    grid $nf.enodeaddr -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lsrcaddr -text [msgcat::mc "Default Source IP address:"]
    grid $nf.lsrcaddr -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.esrcaddr -width 15
    grid $nf.esrcaddr -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    $nf.esrcaddr delete 0 end
    $nf.esrcaddr insert 0 $::node_SrcIP
    incr curr_row
    label $nf.lsnmpget -text [msgcat::mc "Default SNMP Get Community:"]
    grid $nf.lsnmpget -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.esnmpget -width 15
    grid $nf.esnmpget -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    radiobutton $nf.rbv1 -text "v1" -variable ::Prefs::snmp_ver -value ""
    grid $nf.rbv1 -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lsnmptrap -text [msgcat::mc "Default SNMP Trap Community:"]
    grid $nf.lsnmptrap -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.esnmptrap -width 15
    grid $nf.esnmptrap -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    radiobutton $nf.rbv2 -text "v2" -variable ::Prefs::snmp_ver -value "v2"
    grid $nf.rbv2 -in $nfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodepoll -text [msgcat::mc "Default node poll interval:"]
    grid $nf.lnodepoll -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodepoll -width 4
    grid $nf.enodepoll -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnoderetr -text [msgcat::mc "Default node retry count:"]
    grid $nf.lnoderetr -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enoderetr -width 4
    grid $nf.enoderetr -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $nf.lnodetmo -text [msgcat::mc "Default node retry timeout:"]
    grid $nf.lnodetmo -in $nfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $nf.enodetmo -width 10
    grid $nf.enodetmo -in $nfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
#
#   Закладка "Текст"
#
    frame $tf 
    frame $tfg
    pack $tfg -side top -anchor nw -padx 15 -pady 5
    $t tab configure [msgcat::mc "Text"] -window $tf -fill both -anchor n -padx 5 -pady 5
    set curr_row 0
    label $tf.ltextcolor -text [msgcat::mc "Default text color:"]
    grid $tf.ltextcolor -in $tfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $tf.etextcolor -width 16
    grid $tf.etextcolor -in $tfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $tf.btextcolor -text [msgcat::mc "..."] -command "tk_chooseColor2 $tf.etextcolor"
    grid $tf.btextcolor -in $tfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $tf.ltextfont -text [msgcat::mc "Default text font:"]
    grid $tf.ltextfont -in $tfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $tf.etextfont -width 48
    grid $tf.etextfont -in $tfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w

    button $tf.btextfont -text [msgcat::mc "..."] -command "tk_chooseFont $tf.etextfont"
    grid $tf.btextfont -in $tfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $tf.ltextaj -text [msgcat::mc "Default text ajustment:"]
    grid $tf.ltextaj -in $tfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    set s $tf.btextaj
    frame $s
    radiobutton $s.left -text [msgcat::mc "Left"] \
	-variable ::Prefs::objPreftextJust -value "left"
    radiobutton $s.center -text [msgcat::mc "Center"] \
	-variable ::Prefs::objPreftextJust -value "center"
    radiobutton $s.right -text [msgcat::mc "Right"] \
	-variable ::Prefs::objPreftextJust -value "right"
    pack $s.left $s.center $s.right  -side left -padx 5
    grid $tf.btextaj -in $tfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky e
#
#   Закладка "Line"
#
    frame $lf 
    frame $lfg
    pack $lfg -side top -anchor nw -padx 15 -pady 5
    $t tab configure [msgcat::mc "Line"] -window $lf -fill both -anchor n -padx 5 -pady 5
    set curr_row 0
    label $lf.llinecolor -text [msgcat::mc "Default line color:"]
    grid $lf.llinecolor -in $lfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $lf.elinecolor -width 16
    grid $lf.elinecolor -in $lfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $lf.blinecolor -text [msgcat::mc "..."] -command "tk_chooseColor2 $lf.elinecolor"
    grid $lf.blinecolor -in $lfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $lf.llinewidth -text [msgcat::mc "Default line width:"]
    grid $lf.llinewidth -in $lfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $lf.elinewidth -width 2
    grid $lf.elinewidth -in $lfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
#
#   Закладка "Link"
#
    frame $kf 
    frame $kfg
    pack $kfg -side top -anchor nw -padx 15 -pady 5
    $t tab configure [msgcat::mc "Link"] -window $kf -fill both -anchor n -padx 5 -pady 5
    set curr_row 0

    label $kf.llinkcolor -text [msgcat::mc "Default link color:"]
    grid $kf.llinkcolor -in $kfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $kf.elinkcolor -width 16
    grid $kf.elinkcolor -in $kfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
    button $kf.blinkcolor -text [msgcat::mc "..."] -command "tk_chooseColor2 $kf.elinkcolor"
    grid $kf.blinkcolor -in $kfg \
	-row $curr_row -column 2 -rowspan 1 -columnspan 1 -sticky w
    incr curr_row
    label $kf.llinkwidth -text [msgcat::mc "Default link width:"]
    grid $kf.llinkwidth -in $kfg \
	-row $curr_row -column 0 -rowspan 1 -columnspan 1 -sticky e
    entry $kf.elinkwidth -width 2
    grid $kf.elinkwidth -in $kfg \
	-row $curr_row -column 1 -rowspan 1 -columnspan 1 -sticky w
#
    frame $b
    pack $b -side bottom -padx 10 -pady 10
    button $b.apply -text [msgcat::mc "Apply"]   -command "validatePrefs"
    button $b.cans  -text [msgcat::mc "Cancel"]  -command "set ::Prefs::editPrefs_exitFlag  2"
    pack $b.apply $b.cans -side left -padx 5 -pady 5
    update idletasks

    set x [expr {[winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
	- [winfo vrootx [winfo parent $w]]}]
    set y [expr {[winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
	- [winfo vrooty [winfo parent $w]]}]
    wm geom $w +$x+$y
    
    bind $w <Destroy> "set ::Node::nodeProperties_exitFlag  2"

}
#
proc editPrefs {} {
    set w .commonPrefs
    set t $w.tnb
    set pf $t.pathsFrame
    set pfg $pf.grid
    set cf $t.commonFrame
    set cfg $cf.grid
    set nf $t.nodeFrame
    set nfg $nf.grid
    set tf $t.txtFrame
    set tfg $tf.grid
    set lf $t.lineFrame
    set lfg $lf.grid
    set kf $t.linkFrame
    set kfg $kf.grid
    set b $w.buttons

    if { ![winfo exists $w ] } {
	editPrefs_GUIconstructor
    }
#
#  Load actual  data:
#
    $t select	0
    $t focus	0
    $t see	0
#   .......
    $pf.epfilebrw insert 0 $::browserProg
    $pf.epfilesnd insert 0 $::soundPlayCmd
    $pf.epfilelog insert 0 $::myLogFile
    $pf.epfilepre insert 0 $::predIncludeFile
    $pf.epfilepost insert 0 $::postIncludeFile

    $cf.etimestr insert 0 $::timeFmt
    $cf.esavtm insert 0 $::dataSaveInterval
    $cf.euname insert 0 $::userName
    $cf.egname insert 0 $::groupName
    $cf.echroot insert 0 $::chRootDir
    
    $cf.eglobalFG insert 0 $::globalFG
    $cf.eglobalBG insert 0 $::globalBG
    $cf.epfilebgr insert 0 $::background
    
    $nf.enodeicon insert 0 $::nodeIcon
    $nf.enodeupsound insert 0 $::nodeUpSound
    $nf.enodednsound insert 0 $::nodeDownSound
    $nf.enodetextcolor insert 0 $::nodeFontColor
    $nf.enodetextfont insert 0 $::nodeFont
    $nf.enodeaddr insert 0 $::nodeIP
    $nf.eaction insert 0 $::node_dblClickCmd
    $nf.esnmpget insert 0 $::node_getCommunity
    $nf.esnmptrap insert 0 $::node_trapCommunity
    set ::Prefs::snmp_ver $::node_SnmpVer
    $nf.enodepoll insert 0 $::nodePoll
    $nf.enoderetr insert 0 $::nodeRetr
    $nf.enodetmo insert 0 $::nodeTmo
    $tf.etextcolor insert 0 $::textFontColor
    $tf.etextfont insert 0 $::textFont
    set ::Prefs::objPreftextJust $::textJust
    $lf.elinecolor insert 0 $::lineColor
    $lf.elinewidth insert 0 $::lineWidth
    $kf.elinkcolor insert 0 $::linkColor
    $kf.elinkwidth insert 0 $::linkWidth

    if { [string equal [wm state $w] withdrawn] } {
        wm deiconify $w
    }
    raise $w 
    set ::Prefs::editPrefs_exitFlag  0
#
#
#
    update idletasks
    
    set oldFocus [focus]
    set oldGrab [grab current $w]
    if {[string compare $oldGrab ""]} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w
    focus $w.buttons.apply

    tkwait variable ::Prefs::editPrefs_exitFlag
    catch { focus $oldFocus }
    if {[winfo exists $w ]} {
	grab release $w
	wm withdraw $w
	if { $::Prefs::editPrefs_exitFlag == 1 } {	
	    # update gloabal variables
	    set tmpLogFile        [string trim [ $pf.epfilelog get ]]
	    #
	    # ReOpen logfiles if needed
	    #
	    if {[string compare $::myLogFile $tmpLogFile ]} {
		set ::myLogFile $tmpLogFile
    		close stdout
    		set fd stdout
	        if { [catch { open $::myLogFile "CREAT WRONLY APPEND" 0640  } fd ] } {
    		    error "Can't open logfile! : $fd "
    		    exit    
    		} else {
		    fconfigure stdout -buffering none
	    	    set t [ clock format [clock seconds] ]
    		    set u $::tcl_platform(user)
    		    puts "$t Started by $u"
    		}
    		close stderr
    		set fd stderr
    		if { [catch { open $::myLogFile "CREAT WRONLY APPEND" 0640  } fd ] } {
    		    error "Can't open logfile! : $fd "
    		    exit    
    		} else {
		    fconfigure stderr -buffering none
    		}
	    }
	    set ::browserProg     [string trim [ $pf.epfilebrw	get ]]
            set ::soundPlayCmd    [string trim [ $pf.epfilesnd	get ]]
	    set ::predIncludeFile [string trim [ $pf.epfilepre	get ]]
            set ::postIncludeFile [string trim [ $pf.epfilepost	get ]]
            set ::timeFmt 	  [string trim [$cf.etimestr	get ]]
            set ::dataSavingInterval [string trim [$cf.esavtm	get ]]
            set ::userName	  [string trim [$cf.euname	get ]]
            set ::groupName	  [string trim [$cf.egname	get ]]
            set ::chRootDir	  [string trim [$cf.echroot	get ]]
            set ::globalFG 	  [string trim [$cf.eglobalFG	get ]]
            set ::globalBG	  [string trim [$cf.eglobalBG	get ]]
	    .canvas configure -background $::globalBG
	    set ::background      [string trim [ $cf.epfilebgr get ]]
    	    set img_id [ .canvas find withtag bgimage ]
	    .canvas delete $img_id
	    image create  photo new_background_image -width 1 -heigh 1
	    new_background_image blank	    
	    if { [file readable $::background ] } {
		if { [catch { image create  photo new_background_image -file $::background } ] } {
		    puts stderr "Can't create background image from \"$::background\"!"
    		}
	    }    
	    .canvas create image 0 0 -image new_background_image -anchor nw -tags bgimage
#    
	    set ::nodeIcon 	[string trim [ $nf.enodeicon get ]]
	    set ::nodeUpSound	[string trim [ $nf.enodeupsound get ]]
	    set ::nodeDownSound [string trim [ $nf.enodednsound get ]]
	    set ::nodeFont	[string trim [ $nf.enodetextfont get ]]
	    set ::nodeFontColor	[string trim [ $nf.enodetextcolor get ]]
	    set ::nodeIP 	[string trim [ $nf.enodeaddr get ]]
	    set ::node_dblClickCmd [string trim [ $nf.eaction get ]]
#
	    set tmp_SrcIP 	[string trim [ $nf.esrcaddr  get ]]
	    foreach { node ip } [array get node_srcip] {
		if {[string equal $ip $::node_SrcIP ] } {
	    	    set node_srcip($node)  $tmp_SrcIP
		}
	    }
	    set ::node_SrcIP $tmp_SrcIP
#
	    set tmp_getCommunity [string trim [$nf.esnmpget get ]]
	    foreach { node comm } [array get node_snmpget ] {
		if {[string equal $comm $::node_getCommunity ] } {
    		    set node_snmpget($node)  $tmp_getCommunity
		}
	    }
	    set ::node_getCommunity $tmp_getCommunity
	    set ::node_SnmpVer $::Prefs::snmp_ver 
#
	    set tmp_trapCommunity [string trim [$nf.esnmptrap get ]]
	    foreach { node comm } [array get node_snmptrap ] {
		if {[string equal $comm $::node_trapCommunity ] } {
    		    set node_snmptrap($node)  $tmp_trapCommunity
		}
	    }
	    set ::node_trapCommunity $tmp_trapCommunity
#
	    set ::nodePoll [string trim [$nf.enodepoll get]]
	    set ::nodeRetr [string trim [$nf.enoderetr get]]
	    set ::nodeTmo  [string trim [$nf.enodetmo  get]]
#
	    set ::textFont 	[string trim [$tf.etextfont get ]]
	    set ::textFontcolor [string trim [$tf.etextcolor get ]]
	    set ::textJust $::Prefs::objPreftextJust 
#
	    set ::lineColor [string trim [$lf.elinecolor get ]]
	    set ::lineWidth [string trim [$lf.elinewidth get ]]
#
	    set ::linkColor [string trim [$kf.elinkcolor get ]]
	    set ::linkWidth [string trim [$kf.elinkwidth get ]]
	}
	# cleanup ........... 
	$pf.epfilebrw delete 0 end
	$pf.epfilesnd delete 0 end
	$pf.epfilelog delete 0 end
	$pf.epfilepre delete 0 end
	$pf.epfilepost delete 0 end

	$cf.etimestr delete 0 end
        $cf.esavtm delete 0 end
        $cf.euname delete 0 end
        $cf.egname delete 0 end
        $cf.echroot delete 0 end
	$cf.eglobalFG delete 0 end
	$cf.eglobalBG delete 0 end
	$cf.epfilebgr delete 0 end

	$nf.enodeicon delete 0 end
	$nf.enodeupsound delete 0 end
	$nf.enodednsound delete 0 end
	$nf.enodetextcolor delete 0 end
	$nf.enodetextfont delete 0 end
	$nf.enodeaddr delete 0 end
	$nf.eaction delete 0 end
	$nf.esnmpget delete 0 end
	$nf.esnmptrap delete 0 end
	$nf.enodepoll delete 0 end
	$nf.enoderetr delete 0 end
	$nf.enodetmo delete 0 end
	$tf.etextcolor delete 0 end
	$tf.etextfont  delete 0 end
	$lf.elinecolor delete 0 end
	$lf.elinewidth delete 0 end
	$kf.elinkcolor delete 0 end
	$kf.elinkwidth delete 0 end
    }
    if {[string compare $oldGrab ""]} {
	if {![string compare $grabStatus "global"]} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    }
    return 

}
#
proc 	validatePrefs {} {
    set w .commonPrefs
    set t $w.tnb
    set pf $t.pathsFrame
    set pfg $pf.grid
    set cf $t.commonFrame
    set cfg $cf.grid
    set nf $t.nodeFrame
    set nfg $nf.grid
    set tf $t.txtFrame
    set tfg $tf.grid
    set lf $t.lineFrame
    set lfg $lf.grid
    set kf $t.linkFrame
    set kfg $kf.grid
    set b $w.buttons

# node icon
    set tmp_icon [string trim [$nf.enodeicon get]]
    if { ![ info exists ::arIcons($tmp_icon) ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Node Icon: \"$tmp_icon\"." error 0 [msgcat::mc "Approve" ]
	  return
    } 
# node up sound
    set tmp_sound [string trim [ $nf.enodeupsound get ]]
    if { ![string match $tmp_sound "" ]  } {
	 if {  ![info exists ::arSounds($tmp_sound) ] } {
    	    tk_dialog $w.dlg "ObjectPreferences" \
	     "Invalid Node UP sound: \"$tmp_sound\"." error 0 [msgcat::mc "Approve" ]
	    return
	}
    }
# node down sound
    set tmp_sound [string trim [ $nf.enodednsound get ]]
    if { ![string match $tmp_sound "" ] } {
	 if {  ![info exists ::arSounds($tmp_sound) ] } {
    	    tk_dialog $w.dlg "ObjectPreferences" \
	     "Invalid Node Down sound: \"$tmp_sound\"." error 0 [msgcat::mc "Approve" ]
	    return
	}
    }
# node src ip
    set tmp_ip [string trim [$nf.esrcaddr  get ]]
    if { ![ IsValidIpAddr $tmp_ip ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Default Source IP: \"$tmp_ip\"." error 0 [msgcat::mc "Approve" ]
	  return
    } 
# node ip
    set tmp_ip [string trim [$nf.enodeaddr  get ]]
    if { ![IsValidIpAddr $tmp_ip ] }  {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Default Node IP: \"$tmp_ip\"." error 0 [msgcat::mc "Approve" ]
	  return
    } 
# node font
    set tmp_font [string trim [ $nf.enodetextfont get ]]    
    if { ![IsValidFont $tmp_font] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Default Node Font: \"$tmp_font\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# text font
    set tmp_font [string trim [ $tf.etextfont get ]]    
    if { ![IsValidFont $tmp_font] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Default TEXT Font: \"$tmp_font\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# bgcolor
    set tmp_color [string trim [ $cf.eglobalBG get ]]    
    if { ![IsValidColor $tmp_color ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid background color: \"$tmp_color\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# fgcolor
    set tmp_color [string trim [ $cf.eglobalFG get ]]    
    if { ![IsValidColor $tmp_color ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid foreground color: \"$tmp_color\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# node color
    set tmp_color [string trim [ $nf.enodetextcolor get ]]    
    if { ![IsValidColor $tmp_color ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Node color: \"$tmp_color\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# text color
    set tmp_color [string trim [ $tf.etextcolor get ]]    
    if { ![IsValidColor $tmp_color ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Text color: \"$tmp_color\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# line color
    set tmp_color [string trim [ $lf.elinecolor get ]]    
    if { ![IsValidColor $tmp_color ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Line color: \"$tmp_color\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
# link color
    set tmp_color [string trim [ $kf.elinkcolor get ]]    
    if { ![IsValidColor $tmp_color ] } {
    	tk_dialog $w.dlg "ObjectPreferences" \
	  "Invalid Link color: \"$tmp_color\"." error 0 [msgcat::mc "Approve" ]
	  return
    }
#
    set ::Prefs::editPrefs_exitFlag 1
}
#
#  add dialog for pregeneration
#
lappend ::GUI_pregenerate_list [list {editPrefs_GUIconstructor} {Loading Common Preferences dialog...}]
#
