00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaGenerals - stuff that didn't fit anywhere else til now. 00013 ## This class just offers a gui for some settings that we'd like to 00014 ## access but no special gui like the YadaExperiments or the YadaGrammars are 00015 ## done yet. That is there is no YadaConfigItems that we deal with here. Therefore 00016 ## The YadaGenerals don't inherit YadaConfigDocument. 00017 ## \ingroup YadaConfigDocument 00018 ## 00019 ## \author Michael Daum 00020 ## 00021 ## $Id: YadaGenerals.tcl,v 1.14 2004/09/06 13:41:13 micha Exp $ 00022 ## ---------------------------------------------------------------------------- 00023 class YadaGenerals { 00024 inherit itk::Widget YadaPlainDocument 00025 00026 00027 # variables ---------------------------------------------------------------- 00028 00029 ## percentage indicating a significant difference in a quotient of two numbers. 00030 public variable significance 1.1 00031 00032 ## tolerated time difference which isn't significant for a profiling distinction 00033 public variable timeTolerance 500 00034 00035 ## the name of an editor to launch when we want to edit something 00036 public variable editor "" 00037 00038 ## flag indicating how to compute weirdness in the YadaRunnableDocument s. 00039 public variable weirdness 1 00040 00041 # methods ------------------------------------------------------------------ 00042 public method init {} 00043 public method toDOM {} 00044 public method fromDOM {rootNode}; ## \type domNode 00045 public method displayTitle {} 00046 public method getPersistanceFileName {}; ## \virtual 00047 public method activationHandle {} 00048 00049 00050 constructor {args} {}; ## \type TclList 00051 00052 private method _commit {} 00053 }; 00054 00055 ## ---------------------------------------------------------------------------- 00056 ## constructor 00057 ## ---------------------------------------------------------------------------- 00058 body YadaGenerals::constructor {args} { 00059 global env 00060 00061 # 00062 # create custom file menu 00063 # 00064 set fileButton [.main component fileButton] 00065 for { 00066 set i 1 00067 set fileMenu $fileButton.menu$i 00068 } {[winfo exists $fileMenu]} {incr i} { 00069 set fileMenu $fileButton.menu$i 00070 } 00071 itk_component add fileMenu { 00072 menu $fileMenu 00073 } { 00074 keep -background -cursor 00075 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00076 } 00077 00078 ## create submenu entry "New" 00079 itk_component add newMenu { 00080 menu $itk_component(fileMenu).newMenu 00081 } { 00082 keep -background -cursor 00083 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00084 } 00085 00086 ## add file menu entries 00087 $itk_component(fileMenu) add command \ 00088 -label "Load" \ 00089 -underline 0 \ 00090 -command [code $this load] 00091 $itk_component(fileMenu) add command \ 00092 -label "Save" \ 00093 -underline 0 \ 00094 -command [code $this save] 00095 $itk_component(fileMenu) add cascade \ 00096 -label "New" \ 00097 -underline 0 \ 00098 -menu $itk_component(newMenu) 00099 $itk_component(fileMenu) add separator 00100 $itk_component(fileMenu) add command \ 00101 -label "Quit" \ 00102 -underline 0 \ 00103 -command {.main quit} 00104 00105 00106 $itk_component(newMenu) add command \ 00107 -label "Runner" \ 00108 -underline 0 \ 00109 -command {YadaDocument::newDocument YadaRunner Runner} 00110 $itk_component(newMenu) add command \ 00111 -label "Difference" \ 00112 -underline 0 \ 00113 -command {YadaDocument::newDocument YadaDifference Difference} 00114 $itk_component(newMenu) add command \ 00115 -label "Gls Statistics" \ 00116 -underline 0 \ 00117 -command {YadaDocument::newDocument YadaGlsStats GlsStatistics} 00118 $itk_component(newMenu) add command \ 00119 -label "Ranking" \ 00120 -underline 0 \ 00121 -command {YadaDocument::newDocument YadaRanking Ranking} 00122 00123 00124 set name "Generals" 00125 00126 itk_component add frame { 00127 frame $itk_interior.frame \ 00128 -borderwidth 0 00129 } 00130 00131 itk_component add significanceLabel { 00132 label $itk_component(frame).significanceLabel \ 00133 -text "Significance:" \ 00134 -anchor nw 00135 } 00136 00137 itk_component add significance { 00138 entry $itk_component(frame).significance \ 00139 -textvariable [scope significance] \ 00140 -borderwidth 2 \ 00141 -state normal \ 00142 -width 20 \ 00143 } {} 00144 00145 itk_component add timeToleranceLabel { 00146 label $itk_component(frame).timeToleranceLabel \ 00147 -text "Time Tolerance:" \ 00148 -anchor nw 00149 } 00150 00151 itk_component add timeTolerance { 00152 entry $itk_component(frame).timeTolerance \ 00153 -textvariable [scope timeTolerance] \ 00154 -borderwidth 2 \ 00155 -state normal \ 00156 -width 20 \ 00157 } {} 00158 00159 itk_component add editorLabel { 00160 label $itk_component(frame).editorLabel \ 00161 -text "Editor:" \ 00162 -anchor nw 00163 } 00164 00165 itk_component add editor { 00166 entry $itk_component(frame).editor \ 00167 -textvariable [scope editor] \ 00168 -borderwidth 2 \ 00169 -state normal \ 00170 -width 20 \ 00171 } {} 00172 00173 itk_component add weirdnessLabel { 00174 label $itk_component(frame).weirdnessLabel \ 00175 -text "Weirdness:" -anchor nw 00176 } {} 00177 00178 itk_component add weirdness { 00179 checkbutton $itk_component(frame).strictWeirdness \ 00180 -text "strict" \ 00181 -variable [scope weirdness] \ 00182 -command [code $this _commit] 00183 } {} 00184 00185 00186 # binding 00187 bind $itk_component(timeTolerance) <Return> [code $this _commit] 00188 bind $itk_component(significance) <Return> [code $this _commit] 00189 bind $itk_component(editor) <Return> [code $this _commit] 00190 00191 # packing + gridding 00192 pack $itk_component(frame) -fill both -expand 1 -padx 10 -pady 10 00193 grid columnconfigure $itk_component(frame) 0 -pad 10 00194 grid columnconfigure $itk_component(frame) 1 -weight 1 00195 grid rowconfigure $itk_component(frame) 4 -weight 1 00196 00197 grid $itk_component(editorLabel) -sticky nw -row 0 -column 0 -pady 10 00198 grid $itk_component(editor) -sticky nw -row 0 -column 1 -pady 10 00199 00200 grid $itk_component(significanceLabel) -sticky ew -row 1 -column 0 -pady 10 00201 grid $itk_component(significance) -sticky nw -row 1 -column 1 -pady 10 00202 00203 grid $itk_component(timeToleranceLabel) -sticky ew -row 2 -column 0 -pady 10 00204 grid $itk_component(timeTolerance) -sticky nw -row 2 -column 1 -pady 10 00205 00206 grid $itk_component(weirdnessLabel) -sticky ew -row 3 -column 0 -pady 10 00207 grid $itk_component(weirdness) -sticky nw -row 3 -column 1 -pady 10 00208 00209 00210 eval itk_initialize $args 00211 00212 } 00213 00214 ## ---------------------------------------------------------------------------- 00215 ## init 00216 ## ---------------------------------------------------------------------------- 00217 body YadaGenerals::init {} { 00218 if {$_isInitialized} { 00219 return 00220 } 00221 global env 00222 chain 00223 setModified 00224 configure -editor $editor; #$env(YADA_EDITOR) 00225 00226 00227 } 00228 00229 ## ---------------------------------------------------------------------------- 00230 ## _commit 00231 ## ---------------------------------------------------------------------------- 00232 body YadaGenerals::_commit {} { 00233 configure \ 00234 -significance $significance \ 00235 -timeTolerance $timeTolerance \ 00236 -editor $editor \ 00237 -weirdness $weirdness 00238 00239 setModified 00240 } 00241 00242 00243 ## ---------------------------------------------------------------------------- 00244 ## Serializes Object into a DOM-XML-Node 00245 ## @return root DOM node representing the YadaGenerals-Object (root tag <yada>) 00246 ## ---------------------------------------------------------------------------- 00247 body YadaGenerals::toDOM {} { 00248 set document [dom createDocument "yada"] 00249 set root [$document documentElement] 00250 00251 set nodeGenerals [$document createElement "yadaGenerals"] 00252 00253 $nodeGenerals setAttribute "significance" $significance 00254 00255 $nodeGenerals setAttribute "timeTolerance" $timeTolerance 00256 00257 $nodeGenerals setAttribute "editor" $editor 00258 00259 $nodeGenerals setAttribute "weirdness" $weirdness 00260 00261 $root appendChild $nodeGenerals 00262 00263 00264 return $root 00265 } 00266 00267 00268 00269 ## ---------------------------------------------------------------------------- 00270 ## Initialize Object with DOM node (that has saved the object state) 00271 ## @param rootNode root DOM-Node (Tag <yada>) 00272 ## ---------------------------------------------------------------------------- 00273 body YadaGenerals::fromDOM {rootNode} { 00274 set xpath "/yada/yadaGenerals" 00275 00276 set nodeGenerals [$rootNode selectNodes $xpath] 00277 set significance [$nodeGenerals getAttribute significance] 00278 00279 00280 set timeTolerance [$nodeGenerals getAttribute timeTolerance] 00281 set editor [$nodeGenerals getAttribute editor] 00282 set weirdness [$nodeGenerals getAttribute weirdness] 00283 00284 00285 } 00286 00287 00288 ## ---------------------------------------------------------------------------- 00289 ## Update toolbar, menubar and titlebar 00290 ## ---------------------------------------------------------------------------- 00291 body YadaGenerals::displayTitle {} { 00292 chain 00293 00294 set loadButton [[[.main getDocument Configure] component toolbar] component loadButton] 00295 set saveButton [[[.main getDocument Configure] component toolbar] component saveButton] 00296 00297 00298 if { [hasSavedState] } { 00299 $itk_component(fileMenu) entryconfigure 0 -state normal 00300 $loadButton configure -state normal 00301 } else { 00302 $itk_component(fileMenu) entryconfigure 0 -state disabled 00303 $loadButton configure -state disabled 00304 } 00305 00306 if { [isModified] } { 00307 $itk_component(fileMenu) entryconfigure 1 -state normal 00308 $saveButton configure -state normal 00309 } else { 00310 $itk_component(fileMenu) entryconfigure 1 -state disabled 00311 $saveButton configure -state disabled 00312 } 00313 } 00314 00315 ## ---------------------------------------------------------------------------- 00316 ## Getting unique file name from registry 00317 ## ---------------------------------------------------------------------------- 00318 body YadaGenerals::getPersistanceFileName {} { 00319 return [.main getPersistanceFileNameForMisc] 00320 } 00321 00322 ## ---------------------------------------------------------------------------- 00323 ## called whenever this document gets activated 00324 ## ---------------------------------------------------------------------------- 00325 body YadaGenerals::activationHandle {} { 00326 chain 00327 ## activate custom file menu 00328 set fileButton [.main component fileButton] 00329 $fileButton configure -menu $itk_component(fileMenu) 00330 } 00331 00332