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 ## WordgraphTable - display a wordgaph in a table. 00013 ## 00014 ## \todo this class is so seldomly used and of such a limited usage that we 00015 ## might consider to remove it completely. 00016 ## 00017 ## $Id: wordgraph.tcl,v 1.23 2004/02/25 14:40:42 micha Exp $ 00018 ## ---------------------------------------------------------------------------- 00019 class WordgraphTable { 00020 inherit ::itk::Toplevel 00021 00022 00023 # public methods 00024 public method init_data {id}; ## \type TclString 00025 public method show {{id ""}}; ## \type TclString 00026 public method hide {} 00027 00028 constructor {id args} {}; ## \type TclString, TclList 00029 }; 00030 00031 ## ---------------------------------------------------------------------------- 00032 ## constructor 00033 ## ---------------------------------------------------------------------------- 00034 body WordgraphTable::constructor {id args} { 00035 wm iconname $itk_component(hull) "details" 00036 wm transient $itk_interior . 00037 wm resizable $itk_interior 1 0 00038 00039 configure -title "Xcdg - Details" 00040 00041 # the widget components 00042 itk_component add frame { 00043 frame $itk_interior.frame -borderwidth 8 -relief flat 00044 } {} 00045 00046 itk_component add info { 00047 MyTable $itk_component(frame).info \ 00048 -rows 3 \ 00049 -cols 2 \ 00050 -titlecols 1\ 00051 -titlerows 0\ 00052 -state disabled \ 00053 -colstretchmode last \ 00054 -vscrollmode none \ 00055 -hscrollmode none 00056 } {} 00057 $itk_component(info) tag config title \ 00058 -anchor w 00059 00060 itk_component add table { 00061 MyTable $itk_component(frame).table \ 00062 -rows 2 \ 00063 -vscrollmode none \ 00064 -hscrollmode none \ 00065 -colstretchmode last \ 00066 -state disabled 00067 } {} 00068 00069 $itk_component(table) tag config centered -anchor c 00070 $itk_component(table) tag col centered 0 1 2 00071 $itk_component(table) tag config words -anchor w 00072 $itk_component(table) tag col words 3 00073 $itk_component(table) tag config active \ 00074 -relief sunken \ 00075 -foreground black \ 00076 -background gray80 00077 00078 itk_component add hide { 00079 button $itk_component(frame).hide\ 00080 -text "Hide" \ 00081 -pady 3 \ 00082 -command [code $this hide] 00083 } { } 00084 00085 # register the helpmessages 00086 .cdgmain help sethelpstr \ 00087 $itk_component(hide) "Hide the Details-Window" 00088 00089 # packing 00090 pack $itk_component(frame) -fill both -expand 1 00091 pack $itk_component(info) -fill x 00092 pack $itk_component(table) -fill both -pady 5 -expand 1 00093 pack $itk_component(hide) -fill x -anchor s -side bottom -expand 1 00094 00095 # get the initial data 00096 init_data $id 00097 00098 eval itk_initialize $args 00099 } 00100 00101 ## ---------------------------------------------------------------------------- 00102 ## get the data from the C layer. 00103 ## \param id a lattice id to be loaded into the table. 00104 ## ---------------------------------------------------------------------------- 00105 body WordgraphTable::init_data {id} { 00106 set table $itk_component(table) 00107 set info $itk_component(info) 00108 $info configure -state normal 00109 $table configure -state normal 00110 00111 $table setCell 0,0 "From" \ 00112 0,1 "To" \ 00113 0,2 "Penalty" \ 00114 0,3 "Word" 00115 00116 set lattice [findLattice $id] 00117 if {$lattice == "NULL"} { 00118 return 00119 } 00120 00121 $info setCell 0,0 " Id" 0,1 $id \ 00122 1,0 " Filename" 1,1 [LatticeStruct_filename_get $lattice] \ 00123 3,0 " LineNo" 3,1 [LatticeStruct_lineNo_get $lattice] 00124 00125 set rmax [$table cget -rows] 00126 set r 1 00127 00128 for {set m [LatticeStruct_arcs_get $lattice]}\ 00129 {$m != "NULL"} \ 00130 {set m [listNext $m]} \ 00131 { 00132 set arc [listElement $m] 00133 set word [ArcStruct_word_get $arc] 00134 set from [ArcStruct_from_get $arc] 00135 set to [ArcStruct_to_get $arc] 00136 set penalty [ArcStruct_penalty_get $arc] 00137 $table setCell $r,0 $from $r,1 $to $r,2 $penalty $r,3 $word 00138 incr r 00139 } 00140 while {$r<$rmax} { 00141 $table setCell $r,0 "" $r,1 "" $r,2 "" $r,3 "" 00142 incr r 00143 } 00144 set rmax $r 00145 00146 $info configure -state disabled 00147 $table configure -state disabled 00148 $table configure -rows $rmax -cols 4 -titlecols 0 00149 } 00150 00151 ## ---------------------------------------------------------------------------- 00152 ## show the toplevel. 00153 ## \param id optional lattice id to initialize the table. 00154 ## ---------------------------------------------------------------------------- 00155 body WordgraphTable::show {{id ""}} { 00156 if {$id != ""} { 00157 init_data $id 00158 } 00159 wm deiconify $itk_interior 00160 } 00161 00162 ## ---------------------------------------------------------------------------- 00163 ## withdraw the toplevel 00164 ## ---------------------------------------------------------------------------- 00165 body WordgraphTable::hide {} { 00166 wm withdraw $itk_interior 00167 } 00168