Index: /branches/uiuc_vtk_viewers/gui/scripts/gauge.tcl
===================================================================
--- /branches/uiuc_vtk_viewers/gui/scripts/gauge.tcl	(revision 5032)
+++ /branches/uiuc_vtk_viewers/gui/scripts/gauge.tcl	(revision 5033)
@@ -42,4 +42,5 @@
     itk_option define -sampleheight sampleHeight SampleHeight 0
     itk_option define -log log Log ""
+    itk_option define -validatecommand validateCommand ValidateCommand ""
 
     constructor {args} { # defined below }
@@ -290,4 +291,13 @@
         }
 
+        #
+        # If there's a -validatecommand option, then invoke the code
+        # now to check the new value.
+        #
+        if {[string length $itk_option(-validatecommand)] > 0} {
+            set cmd "uplevel #0 [list $itk_option(-validatecommand) [list $newval]]"
+            set result [eval $cmd]
+        }
+
         if {$onlycheck} {
             return
Index: /branches/uiuc_vtk_viewers/gui/scripts/vtkisosurfaceviewer.tcl
===================================================================
--- /branches/uiuc_vtk_viewers/gui/scripts/vtkisosurfaceviewer.tcl	(revision 5032)
+++ /branches/uiuc_vtk_viewers/gui/scripts/vtkisosurfaceviewer.tcl	(revision 5033)
@@ -94,6 +94,8 @@
     private method LegendProbeSingleContour { x y }
     private method LegendRangeAction { option args }
+    private method LegendRangeValidate { widget which value }
     private method LegendTitleAction { option }
     private method MotionLegend { x y }
+    private method MouseOver2Which {}
     private method Pan {option x y}
     private method PanCamera {}
@@ -258,6 +260,4 @@
         -colormapvisible            1
         -customrange                0
-        -customrangevmin            0
-        -customrangevmax            1
         -cutplaneedges              0
         -cutplanelighting           1
@@ -775,10 +775,6 @@
                 # customrangevmin and customrangevmax
                 foreach {min max} $lim break
-                if { ![info exists _settings(-customrangevmin)] } {
-                    set _settings(-customrangevmin) $min
-                }
-                if { ![info exists _settings(-customrangevmax)] } {
-                    set _settings(-customrangevmax) $max
-                }
+                $itk_component(min) value $min
+                $itk_component(max) value $max
 
                 continue
@@ -786,8 +782,7 @@
             foreach {min max} $lim break
             foreach {fmin fmax} $_limits($fname) break
-#            if { $fname == $_curFldName && ! $_settings(-customrange) } {}
             if { ! $_settings(-customrange) } {
-                set _settings(-customrangevmin) $fmin
-                set _settings(-customrangevmax) $fmax
+                $itk_component(min) value $fmin
+                $itk_component(max) value $fmax
             }
             if { $fmin > $min } {
@@ -1493,9 +1488,9 @@
                 foreach { vmin vmax } $_limits($_curFldName) break
                 if { $_settings(-customrange) } {
-                    if { $_settings(-customrangevmin) > $vmin } {
-                        set vmin $_settings(-customrangevmin)
+                    if { [$itk_component(min) value] > $vmin } {
+                        set vmin [$itk_component(min) value]
                     }
-                    if { $_settings(-customrangevmax) < $vmax } {
-                        set vmax $_settings(-customrangevmax)
+                    if { [$itk_component(max) value] < $vmax } {
+                        set vmax [$itk_component(max) value]
                     }
                 }
@@ -1582,23 +1577,9 @@
                 $itk_component(l_max) configure -state normal
                 $itk_component(max) configure -state normal
-#                foreach { vmin vmax } $_limits($_curFldName) break
-#                if { $_settings(-customrangevmin) < $vmin } {
-#                    set _settings(-customrangevmin) $vmin
-#                }
-#                if { $_settings(-customrangevmin) > $vmax } {
-#                    set _settings(-customrangevmin) $vmax
-#                }
-#                if { $_settings(-customrangevmax) < $vmin } {
-#                    set _settings(-customrangevmax) $vmin
-#                }
-#                if { $_settings(-customrangevmax) > $vmax } {
-#                    set _settings(-customrangevmax) $vmax
-#                }
-#
-                if { $_settings(-customrangevmin) > $vmin } {
-                    set vmin $_settings(-customrangevmin)
-                }
-                if { $_settings(-customrangevmax) < $vmax } {
-                    set vmax $_settings(-customrangevmax)
+                if { [$itk_component(min) value] > $vmin } {
+                    set vmin [$itk_component(min) value]
+                }
+                if { [$itk_component(max) value] < $vmax } {
+                    set vmax [$itk_component(max) value]
                 }
             } else {
@@ -1845,12 +1826,8 @@
     }
     itk_component add min {
-        entry $inner.min -font "Arial 9" -bg white \
-            -textvariable [itcl::scope _settings(-customrangevmin)]
-    } {
-        ignore -font -background
-    }
-    bind $inner.min <Return> \
-        [itcl::code $this AdjustSetting -range]
-    bind $inner.min <KP_Enter> \
+        Rappture::Gauge $inner.min \
+            -validatecommand [itcl::code $this LegendRangeValidate "" vmin]
+    }
+    bind $itk_component(min) <<Value>> \
         [itcl::code $this AdjustSetting -range]
 
@@ -1859,12 +1836,8 @@
     }
     itk_component add max {
-        entry $inner.max -font "Arial 9" -bg white \
-            -textvariable [itcl::scope _settings(-customrangevmax)]
-    } {
-        ignore -font -background
-    }
-    bind $inner.max <Return> \
-        [itcl::code $this AdjustSetting -range]
-    bind $inner.max <KP_Enter> \
+        Rappture::Gauge $inner.max \
+            -validatecommand [itcl::code $this LegendRangeValidate "" vmax]
+    }
+    bind $itk_component(max) <<Value>> \
         [itcl::code $this AdjustSetting -range]
 
@@ -2468,6 +2441,6 @@
     if { [info exists _limits($fname)] } {
         if { $_settings(-customrange) } {
-            set vmin $_settings(-customrangevmin)
-            set vmax $_settings(-customrangevmax)
+            set vmin [$itk_component(min) value]
+            set vmax [$itk_component(max) value]
         } else {
             foreach { vmin vmax } $_limits($fname) break
@@ -2685,6 +2658,6 @@
 
         if { $_settings(-customrange) } {
-            set vmin $_settings(-customrangevmin)
-            set vmax $_settings(-customrangevmax)
+            set vmin [$itk_component(min) value]
+            set vmax [$itk_component(max) value]
         } else {
             foreach { vmin vmax } $_limits($_curFldName) break
@@ -2717,6 +2690,6 @@
     if { [info exists _limits($_curFldName)] } {
         if { $_settings(-customrange) } {
-            set vmin $_settings(-customrangevmin)
-            set vmax $_settings(-customrangevmax)
+            set vmin [$itk_component(min) value]
+            set vmax [$itk_component(max) value]
         } else {
             foreach { vmin vmax } $_limits($_curFldName) break
@@ -2792,11 +2765,88 @@
 
 # ----------------------------------------------------------------------
+# USAGE: LegendRangeValidate <widget> <which> <value>
+#
+# Used internally to validate a legend range min/max value.
+# Returns a boolean value telling if <value> was accepted (1) or rejected (0)
+# If the value is rejected, a tooltip/warning message is popped up
+# near the widget that asked for the validation, specified by <widget>
+#
+# <widget> is the widget where a tooltip/warning message should show up on
+# <which> is either "vmin" or "vmax".
+# <value> is the value to be validated.
+#
+# ----------------------------------------------------------------------
+itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeValidate {widget which value} {
+
+    #check for a valid value
+    if {[string is double $value] != 1} {
+        set msg "should be valid number"
+        if {$widget != ""} {
+            Rappture::Tooltip::cue $widget $msg
+        } else {
+            # error "bad value \"$value\": $msg"
+            error $msg
+        }
+        return 0
+    }
+
+    switch -- $which {
+        vmin {
+            # check for min > max
+            if {$value > [$itk_component(max) value]} {
+                set msg "min > max, change max first"
+                if {$widget != ""} {
+                    Rappture::Tooltip::cue $widget $msg
+                } else {
+                    # error "bad value \"$value\": $msg"
+                    error $msg
+                }
+                return 0
+            }
+        }
+        vmax {
+            # check for max < min
+            if {$value < [$itk_component(min) value]} {
+                set msg "max < min, change min first"
+                if {$widget != ""} {
+                    Rappture::Tooltip::cue $widget $msg
+                } else {
+                    # error "bad value \"$value\": $msg"
+                    error $msg
+                }
+                return 0
+            }
+        }
+        default {
+            error "bad option \"$which\": should be vmin, vmax"
+        }
+    }
+}
+
+
+itcl::body Rappture::VtkIsosurfaceViewer::MouseOver2Which {} {
+    switch -- $_mouseOver {
+        vmin {
+            set which min
+        }
+        vmax {
+            set which max
+        }
+        default {
+            error "bad _mouseOver \"$_mouseOver\": should be vmin, vmax"
+        }
+    }
+    return $which
+}
+
+
+# ----------------------------------------------------------------------
 # USAGE: LegendRangeAction enter <which>
 # USAGE: LegendRangeAction leave <which>
 #
-# USAGE: LegendTitleAction popup <which>
-# USAGE: LegendTitleAction activate
-# USAGE: LegendTitleAction validate <value>
-# USAGE: LegendTitleAction apply <value>
+# USAGE: LegendRangeAction popup <which>
+# USAGE: LegendRangeAction activate
+# USAGE: LegendRangeAction validate <value>
+# USAGE: LegendRangeAction apply <value>
 #
 # Used internally to handle the mouseover and popup entry for the field range
@@ -2814,5 +2864,5 @@
 itcl::body Rappture::VtkIsosurfaceViewer::LegendRangeAction {option args} {
     set c $itk_component(view)
-# FIXME: check $which for valid values
+
     switch -- $option {
         enter {
@@ -2832,5 +2882,6 @@
         activate {
             foreach { x1 y1 x2 y2 } [$c bbox $_mouseOver] break
-            set info(text) $_settings(-customrange$_mouseOver)
+            set which [MouseOver2Which]
+            set info(text) [$itk_component($which) value]
             set info(x) [expr $x1 + [winfo rootx $c]]
             set info(y) [expr $y1 + [winfo rooty $c]]
@@ -2843,4 +2894,12 @@
                 error "wrong # args: should be \"editor validate value\""
             }
+
+            set value [lindex $args 0]
+            if {[LegendRangeValidate $itk_component(editor) $_mouseOver $value] == 0} {
+                return 0
+            }
+
+            # value was good, apply it
+            # reset the mouse rotation bindings
             SetupMouseRotationBindings
         }
@@ -2849,6 +2908,13 @@
                 error "wrong # args: should be \"editor apply value\""
             }
-            set _settings(-customrange$_mouseOver) [lindex $args 0]
-            $itk_component(crange) select
+            set value [string trim [lindex $args 0]]
+
+            set which [MouseOver2Which]
+
+            # only set custom range if value changed
+            if {[$itk_component($which) value] != $value} {
+                $itk_component($which) value $value
+                $itk_component(crange) select
+            }
             AdjustSetting -range
         }
@@ -2858,4 +2924,5 @@
     }
 }
+
 
 #
@@ -2927,9 +2994,9 @@
         # range, use the custom min and max to generate contour list values
         if { $_settings(-customrange) } {
-            if { $_settings(-customrangevmin) > $vmin } {
-                set vmin $_settings(-customrangevmin)
-            }
-            if { $_settings(-customrangevmax) < $vmax } {
-                set vmax $_settings(-customrangevmax)
+            if { [$itk_component(min) value] > $vmin } {
+                set vmin [$itk_component(min) value]
+            }
+            if { [$itk_component(max) value] < $vmax } {
+                set vmax [$itk_component(max) value]
             }
         }
