
#-------------------------------------------------------------------------------
# Module:     layoutMeasures.tk
# Activation: Dynamically loaded on user request
# Scope:      Size and alignment of the parts of graph display
#-------------------------------------------------------------------------------



proc ShowLayoutOptions {} {
    global WDMeasures InternalWindowing DialogFrame DefPadX DefPadY ActiveDialog 

    if {$ActiveDialog=="Measures & Alignments"} {return}

    if {$InternalWindowing} {
        set WDMeasures $DialogFrame.optlevel
        if {![winfo exists $WDMeasures]} {
            frame $WDMeasures
        }
        
        RegisterDialog "Measures & Alignments" $WDMeasures ShowLayoutOptions {}
    } else {
        set WDMeasures .optlevel
        if {![winfo exists $WDMeasures]} {
            toplevel $WDMeasures
            wm title $WDMeasures "Measures & Alignments"
            wm resizable $WDMeasures 0 0
        } else {return}
    }
    

    frame $WDMeasures.buttons
    pack $WDMeasures.buttons -padx 3m -pady 3m -side bottom

    button $WDMeasures.buttons.apply -text "Apply" -command { \
        if {[QualifiedInt $goblinLegenda 0 50000] && \
            [QualifiedInt $goblinNodeSize 1 50000] && \
            [QualifiedInt $goblinNodeSep 1 50000] && \
            [QualifiedInt $goblinArrowSize 1 50000]} {
            InitDisplay
        }
    }
    
    button $WDMeasures.buttons.done -text "Done" -command { \
        if {[QualifiedInt $goblinLegenda 0 50000] && \
            [QualifiedInt $goblinNodeSize 1 50000] && \
            [QualifiedInt $goblinNodeSep 1 50000] && \
            [QualifiedInt $goblinArrowSize 1 50000]} {
            if {$InternalWindowing} {
                DestroyActiveDialog
            } else {
                destroy $WDMeasures
            }
            InitDisplay
        }
    }    
    
    pack $WDMeasures.buttons.apply \
    	$WDMeasures.buttons.done -side left -fill x -padx 3m


    frame $WDMeasures.frame3
    pack $WDMeasures.frame3 -padx 5m -pady 3m -side bottom -anchor w

    
    frame $WDMeasures.frame
    pack $WDMeasures.frame -padx 5m -pady 3m -side left -anchor w
    
    label $WDMeasures.frame.x -text "x" -anchor n
    grid $WDMeasures.frame.x -in $WDMeasures.frame \
        -row 0 -column 1 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    label $WDMeasures.frame.y -text "y" -anchor n
    grid $WDMeasures.frame.y -in $WDMeasures.frame \
        -row 0 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    
    label $WDMeasures.frame.zoomText -text "Zoom Factor:" -anchor w
    grid $WDMeasures.frame.zoomText -in $WDMeasures.frame \
        -row 1 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.xZoom -textvariable goblinXZoom -bg white -width 5
    grid $WDMeasures.frame.xZoom -in $WDMeasures.frame \
        -row 1 -column 1 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.yZoom -textvariable goblinYZoom -bg white -width 5
    grid $WDMeasures.frame.yZoom -in $WDMeasures.frame \
        -row 1 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    
    label $WDMeasures.frame.shiftText -text "Shift:" -anchor w
    grid $WDMeasures.frame.shiftText -in $WDMeasures.frame \
        -row 2 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.xShift -textvariable goblinXShift -bg white -width 5
    grid $WDMeasures.frame.xShift -in $WDMeasures.frame \
        -row 2 -column 1 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.yShift -textvariable goblinYShift -bg white -width 5
    grid $WDMeasures.frame.yShift -in $WDMeasures.frame \
        -row 2 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m

    label $WDMeasures.frame.nodeText -text "Node Size:" -anchor w
    grid $WDMeasures.frame.nodeText -in $WDMeasures.frame \
        -row 1 -column 4 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.nodeSize -textvariable goblinNodeSize -bg white -width 5
    grid $WDMeasures.frame.nodeSize -in $WDMeasures.frame \
        -row 1 -column 5 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    
    label $WDMeasures.frame.arrowText -text "Arrow Size:" -anchor w
    grid $WDMeasures.frame.arrowText -in $WDMeasures.frame \
        -row 2 -column 4 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.arrowSize -textvariable goblinArrowSize -bg white -width 5
    grid $WDMeasures.frame.arrowSize -in $WDMeasures.frame \
        -row 2 -column 5 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
	
    frame $WDMeasures.frame.dummy 
    grid $WDMeasures.frame.dummy -in $WDMeasures.frame \
        -row 3 -column 3 -rowspan 1 -columnspan 1 -sticky news -padx 20

    label $WDMeasures.frame.sepText2 -text "Node Separator: " -anchor w
    grid $WDMeasures.frame.sepText2 -in $WDMeasures.frame \
        -row 3 -column 4 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.sepNode -textvariable goblinNodeSep -bg white -width 5
    grid $WDMeasures.frame.sepNode -in $WDMeasures.frame \
        -row 3 -column 5 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m

    label $WDMeasures.frame.legendaText -text "Legenda:    " -anchor w
    grid $WDMeasures.frame.legendaText -in $WDMeasures.frame \
        -row 4 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    radiobutton $WDMeasures.frame.legenda -text "Hidden" \
        -variable goblinLegenda -value 0 -anchor w
    grid $WDMeasures.frame.legenda -in $WDMeasures.frame \
        -row 4 -column 1 -rowspan 1 -columnspan 2 -sticky news -padx 1m -pady 1m
    label $WDMeasures.frame.sepText -text "Separator: " -anchor w
    grid $WDMeasures.frame.sepText -in $WDMeasures.frame \
        -row 4 -column 4 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    entry $WDMeasures.frame.sepLegenda -textvariable goblinLegenda -bg white -width 5
    grid $WDMeasures.frame.sepLegenda -in $WDMeasures.frame \
        -row 4 -column 5 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m

    if {$InternalWindowing} {
        button $WDMeasures.frame.fit -text "Fit Into Window" \
            -command FitIntoWindow
        grid $WDMeasures.frame.fit -in $WDMeasures.frame \
            -row 3 -column 0 -rowspan 1 -columnspan 3 -sticky ns -pady 10m

        grid $WDMeasures.frame.dummy -in $WDMeasures.frame \
            -row 4 -column 1 -rowspan 1 -columnspan 1 -sticky news -pady 0m

        grid $WDMeasures.frame.nodeText -in $WDMeasures.frame \
            -row 5 -column 0 -rowspan 1 -columnspan 2 -sticky news -padx 1m -pady 1m
        grid $WDMeasures.frame.nodeSize -in $WDMeasures.frame \
            -row 5 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    
        grid $WDMeasures.frame.arrowText -in $WDMeasures.frame \
            -row 6 -column 0 -rowspan 1 -columnspan 2 -sticky news -padx 1m -pady 1m
        grid $WDMeasures.frame.arrowSize -in $WDMeasures.frame \
            -row 6 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
	
        grid $WDMeasures.frame.sepText2 -in $WDMeasures.frame \
            -row 7 -column 0 -rowspan 1 -columnspan 2 -sticky news -padx 1m -pady 1m
        grid $WDMeasures.frame.sepNode -in $WDMeasures.frame \
            -row 7 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m

        frame $WDMeasures.frame.dummy2
        grid $WDMeasures.frame.dummy2 -in $WDMeasures.frame \
            -row 8 -column 1 -rowspan 1 -columnspan 1 -sticky news -pady 10

        grid $WDMeasures.frame.legendaText -in $WDMeasures.frame \
            -row 9 -column 0 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
        grid $WDMeasures.frame.legenda -in $WDMeasures.frame \
            -row 9 -column 1 -rowspan 1 -columnspan 2 -sticky news -padx 1m -pady 1m
        grid $WDMeasures.frame.sepText -in $WDMeasures.frame \
            -row 10 -column 0 -rowspan 1 -columnspan 2 -sticky news -padx 1m -pady 1m
        grid $WDMeasures.frame.sepLegenda -in $WDMeasures.frame \
            -row 10 -column 2 -rowspan 1 -columnspan 1 -sticky news -padx 1m -pady 1m
    }

    grid rowconfig    $WDMeasures.frame 0 -weight 1 -minsize 0
    grid columnconfig $WDMeasures.frame 0 -weight 1 -minsize 0


    bind $WDMeasures.frame.xZoom <Return> {focus $WDMeasures.frame.yZoom}
    bind $WDMeasures.frame.yZoom <Return> {focus $WDMeasures.frame.xShift}
    bind $WDMeasures.frame.xShift <Return> {focus $WDMeasures.frame.yShift}
    bind $WDMeasures.frame.yShift <Return> {focus $WDMeasures.frame.nodeSize}
    bind $WDMeasures.frame.nodeSize <Return> {
        if {[QualifiedInt $goblinNodeSize 1 50000]} {
            focus $WDMeasures.frame.arrowSize
        }
    }
    bind $WDMeasures.frame.arrowSize <Return> {
        if {[QualifiedInt $goblinArrowSize 1 50000]} {
            focus $WDMeasures.frame.sepNode
        }
    }
    bind $WDMeasures.frame.sepNode <Return> {
        if {[QualifiedInt $goblinNodeSep 0 50000] && \
            focus $WDMeasures.frame.sepLegenda
        }
    }
    bind $WDMeasures.frame.sepLegenda <Return> {
        if {[QualifiedInt $goblinLegenda 0 50000] && \
            [QualifiedInt $goblinNodeSize 1 50000] && \
            [QualifiedInt $goblinNodeSep 1 50000] && \
            [QualifiedInt $goblinArrowSize 1 50000]} {
            destroy .measures
            InitDisplay
        }
    }
    
    focus $WDMeasures.frame.xZoom

    if {$InternalWindowing} {
        pack $WDMeasures -anchor nw
        AlignActiveDialog
    }
}

if {![info exists WDMeasures] || ![winfo exists $WDMeasures]} {ShowLayoutOptions}
