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 ## YadaDocument - embeddeable document. 00013 ## This class extends the YadaPlainDocument and offers all functionality to 00014 ## embed a document into the YadaMain widget. In parallel to this inheritance 00015 ## the YadaConfigDocument is not embeddeable into YadaMain but into YadaConfig, i.e. 00016 ## YadaGammars, YadaExperiments etc. 00017 ## \ingroup YadaDocuments 00018 ## 00019 ## \author Michael Daum 00020 ## 00021 ## $Id: YadaDocument.tcl,v 1.11 2004/05/11 14:30:47 ddreyer Exp $ 00022 ## ---------------------------------------------------------------------------- 00023 class YadaDocument { 00024 inherit ::itk::Widget YadaPlainDocument 00025 00026 # variables ---------------------------------------------------------------- 00027 00028 ## link to the previous YadaDocument registered to YadaMain 00029 public variable prevDocument ; ## \type YadaDocument 00030 00031 ## link to the next YadaDocument registered to YadaMain 00032 public variable nextDocument ; ## \type YadaDocument 00033 00034 ## flag indicating whether the toolbar of this document is shown. 00035 ## This information is kept in sync with YadaMain::_toolbarFlag whenever 00036 ## the document is activated. \see setToggle(), activationHandle(). 00037 private variable _toolbarFlag 1 00038 00039 ## flag indicating whether the status message of this document is shown. 00040 ## This information is kept in sync with YadaMain::_statusFlag whenever 00041 ## the document is activated. \see setToggle(), activationHandle(). 00042 private variable _statusFlag 1 00043 00044 00045 # methods ------------------------------------------------------------------ 00046 public method backward {} 00047 public method forward {} 00048 public method loadUpdatedWordgraphs {args} ;## \purevirtual \type TclList 00049 public method setToggle {name {value ""}} ;## \virtual \type TclString, TclRef 00050 public method activationHandle {}; ## \virtual 00051 public proc newDocument {className name}; ## \type TclString, TclString 00052 00053 constructor {} {} 00054 destructor {} 00055 00056 protected method askNewLoad {} 00057 00058 }; 00059 00060 ## ---------------------------------------------------------------------------- 00061 ## constructor 00062 ## ---------------------------------------------------------------------------- 00063 body YadaDocument::constructor {} { 00064 00065 # 00066 # file menu 00067 # 00068 set fileButton [.main component fileButton] 00069 for { 00070 set i 1 00071 set fileMenu $fileButton.menu$i 00072 } {[winfo exists $fileMenu]} {incr i} { 00073 set fileMenu $fileButton.menu$i 00074 } 00075 itk_component add fileMenu { 00076 menu $fileMenu 00077 } { 00078 keep -background -cursor 00079 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00080 } 00081 00082 itk_component add newMenu { 00083 menu $itk_component(fileMenu).newMenu 00084 } { 00085 keep -background -cursor 00086 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00087 } 00088 00089 $itk_component(fileMenu) add command \ 00090 -label "Load" \ 00091 -underline 0 \ 00092 -command [code $this load] 00093 $itk_component(fileMenu) add command \ 00094 -label "Save" \ 00095 -underline 0 \ 00096 -command [code $this save] 00097 $itk_component(fileMenu) add cascade \ 00098 -label "New" \ 00099 -underline 0 \ 00100 -menu $itk_component(newMenu) 00101 $itk_component(fileMenu) add separator 00102 $itk_component(fileMenu) add command \ 00103 -label "Close" \ 00104 -underline 0 \ 00105 -command [code itcl::delete object $this] 00106 $itk_component(fileMenu) add command \ 00107 -label "Quit" \ 00108 -underline 0 \ 00109 -command {.main quit} 00110 00111 $itk_component(newMenu) add command \ 00112 -label "Runner" \ 00113 -underline 0 \ 00114 -command {YadaDocument::newDocument YadaRunner Runner} 00115 $itk_component(newMenu) add command \ 00116 -label "Difference" \ 00117 -underline 0 \ 00118 -command {YadaDocument::newDocument YadaDifference Difference} 00119 $itk_component(newMenu) add command \ 00120 -label "Gls Statistics" \ 00121 -underline 0 \ 00122 -command {YadaDocument::newDocument YadaGlsStats GlsStatistics} 00123 $itk_component(newMenu) add command \ 00124 -label "Ranking" \ 00125 -underline 0 \ 00126 -command {YadaDocument::newDocument YadaRanking Ranking} 00127 # $itk_component(newMenu) add command \ 00128 # -label "Best per Wordgraph" \ 00129 # -underline 0 \ 00130 # -state disabled 00131 # $itk_component(newMenu) add command \ 00132 # -label "File Viewer" \ 00133 # -underline 0 \ 00134 # -state disabled 00135 00136 # 00137 # edit menu 00138 # 00139 set editButton [.main component editButton] 00140 for { 00141 set i 1 00142 set editMenu [subst $editButton.menu$i] 00143 } {[winfo exists $editMenu]} {incr i} { 00144 set editMenu [subst $editButton.menu$i] 00145 } 00146 00147 itk_component add editMenu { 00148 menu $editMenu 00149 } { 00150 keep -background -cursor 00151 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00152 } 00153 00154 # 00155 # view menu 00156 # 00157 set viewButton [.main component viewButton] 00158 for { 00159 set i 1 00160 set viewMenu [subst $viewButton.menu$i] 00161 } {[winfo exists $viewMenu]} {incr i} { 00162 set viewMenu [subst $viewButton.menu$i] 00163 } 00164 00165 itk_component add viewMenu { 00166 menu $viewMenu 00167 } { 00168 keep -background -cursor 00169 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00170 } 00171 00172 $itk_component(viewMenu) add checkbutton \ 00173 -label "Toolbar" \ 00174 -variable [scope _toolbarFlag] \ 00175 -command [code $this setToggle "toolbar"] 00176 $itk_component(viewMenu) add checkbutton \ 00177 -label "Status" \ 00178 -variable [scope _statusFlag] \ 00179 -command [code $this setToggle "status"] 00180 00181 # 00182 # toolbar 00183 # 00184 set toolbarArea [.main component toolbarArea] 00185 itk_component add toolbar { 00186 iwidgets::toolbar $toolbarArea#auto \ 00187 -balloonfont {-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*} \ 00188 -balloonbackground lightyellow 00189 } {} 00190 00191 $itk_component(toolbar) add FlatButton backButton \ 00192 -image [YadaImages::get backward] \ 00193 -command [code $this backward] \ 00194 -state disabled 00195 00196 $itk_component(toolbar) add FlatButton forwardButton \ 00197 -image [YadaImages::get forward] \ 00198 -command [code $this forward] \ 00199 -state disabled 00200 00201 $itk_component(toolbar) add FlatButton loadButton \ 00202 -image [YadaImages::get openFile] \ 00203 -command [code $this load] \ 00204 -balloonstr "load" 00205 00206 $itk_component(toolbar) add FlatButton saveButton \ 00207 -image [YadaImages::get floppy] \ 00208 -command [code $this save] \ 00209 -balloonstr "save" 00210 00211 # the childsite 00212 itk_component add childsite { 00213 frame $itk_interior.childsite 00214 } 00215 00216 # packing 00217 pack $itk_component(childsite) -fill both -expand 1 -side top -pady 2 00218 } 00219 00220 ## ---------------------------------------------------------------------------- 00221 ## destructor 00222 ## ---------------------------------------------------------------------------- 00223 body YadaDocument::destructor {} { 00224 ## unregister only, if document has been registered before 00225 if { $hasView == "true" } { 00226 .main unregisterDocument $this 00227 } 00228 } 00229 00230 ## ---------------------------------------------------------------------------- 00231 ## backward 00232 ## ---------------------------------------------------------------------------- 00233 body YadaDocument::backward {} { 00234 .main activateDocument $prevDocument 00235 } 00236 00237 ## ---------------------------------------------------------------------------- 00238 ## forward 00239 ## ---------------------------------------------------------------------------- 00240 body YadaDocument::forward {} { 00241 .main activateDocument $nextDocument 00242 } 00243 00244 ## ---------------------------------------------------------------------------- 00245 ## callback for prevDocument. 00246 ## ---------------------------------------------------------------------------- 00247 configbody YadaDocument::prevDocument { 00248 if {$prevDocument != ""} { 00249 $itk_component(toolbar) itemconfigure backButton\ 00250 -state normal \ 00251 -balloonstr "back to [$prevDocument cget -name]" 00252 } else { 00253 $itk_component(toolbar) itemconfigure backButton\ 00254 -state disabled \ 00255 -balloonstr "back" 00256 } 00257 } 00258 00259 ## ---------------------------------------------------------------------------- 00260 ## callback for nextDocument. 00261 ## ---------------------------------------------------------------------------- 00262 configbody YadaDocument::nextDocument { 00263 if {$nextDocument != ""} { 00264 $itk_component(toolbar) itemconfigure forwardButton\ 00265 -state normal \ 00266 -balloonstr "forward to [$nextDocument cget -name]" 00267 } else { 00268 $itk_component(toolbar) itemconfigure forwardButton\ 00269 -state disabled \ 00270 -balloonstr "forward" 00271 } 00272 } 00273 00274 ## ---------------------------------------------------------------------------- 00275 ## activationHandle 00276 ## ---------------------------------------------------------------------------- 00277 body YadaDocument::activationHandle {} { 00278 chain 00279 set _toolbarFlag [.main getToggle "toolbar"] 00280 set _statusFlag [.main getToggle "status"] 00281 00282 set fileButton [.main component fileButton] 00283 set editButton [.main component editButton] 00284 set viewButton [.main component viewButton] 00285 $fileButton configure -menu $itk_component(fileMenu) 00286 $editButton configure -menu $itk_component(editMenu) 00287 $viewButton configure -menu $itk_component(viewMenu) 00288 } 00289 00290 ## ---------------------------------------------------------------------------- 00291 ## toggle toolbar or status. 00292 ## This method switches the toolbar or the status bar on or off depending on 00293 ## its arguments. 00294 ## \param name the element to be toggled: toolbar or status 00295 ## \param value the value to which to switch to: 1 or 0 00296 ## ---------------------------------------------------------------------------- 00297 body YadaDocument::setToggle {name {value ""}} { 00298 switch $name { 00299 "toolbar" { 00300 set _toolbarFlag [.main setToggle "toolbar" $value] 00301 return $_toolbarFlag 00302 } 00303 "status" { 00304 set _statusFlag [.main setToggle "status" $value] 00305 return $_statusFlag 00306 } 00307 default { 00308 return [chain $name $value] 00309 } 00310 } 00311 } 00312 00313 ## ---------------------------------------------------------------------------- 00314 ## newDocument 00315 ## ---------------------------------------------------------------------------- 00316 proc YadaDocument::newDocument {className name} { 00317 set document [.main newDocument $className $name] 00318 $document init 00319 .main activateDocument $document 00320 } 00321 00322 00323 ## ---------------------------------------------------------------------------- 00324 ## Pops up a yes/no message dialog and returns the result 00325 ## (i.e. which button has been pressed) 00326 ## ---------------------------------------------------------------------------- 00327 body YadaDocument::askNewLoad {} { 00328 set msg [iwidgets::messagedialog .msg \ 00329 -text "File '[getPersistanceFileName].gz'\nhas been modified on disk. Do you want to reload?" \ 00330 -title "Yada - Caution" \ 00331 -image [YadaImages::get question] \ 00332 -modality application \ 00333 -master $itk_interior] 00334 $msg buttonconfigure OK -text "Yes" 00335 $msg buttonconfigure Cancel -text "No" 00336 $msg center . 00337 set result [$msg activate] 00338 destroy $msg 00339 return $result 00340 } 00341 00342