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 ## VisFile - visualisation of a file or directory. 00013 ## This class is mainly used by VisDirectory. 00014 ## 00015 ## \author Michael Daum 00016 ## 00017 ## $Id: VisFile.tcl,v 1.9 2004/02/25 14:42:09 micha Exp $ 00018 ## ---------------------------------------------------------------------------- 00019 class VisFile { 00020 00021 # -- variables ------------------------------------------------------------- 00022 00023 ## name of the file 00024 public variable name "" 00025 00026 ## icon used to represent this file in a VisDirectory 00027 public variable icon "" 00028 00029 ## file type 00030 public variable type "" 00031 00032 ## link to the VisDirectory that displays this file. 00033 private variable _visDirectory "" 00034 00035 ## x position where this file is drawn 00036 private variable _xCoord -100 00037 00038 ## y position where this file is drawn 00039 private variable _yCoord -100 00040 00041 ## flag indicating whether this file is being selected in a VisDirectory 00042 private variable _isSelected 0 00043 00044 ## icon item tag in the drawing canvas 00045 private variable _iconTag "" 00046 00047 ## text item tag in the drawing canvas 00048 private variable _textTag "" 00049 00050 ## rectangular item tag in the drawing canvas 00051 private variable _recTag "" 00052 00053 # -- methods --------------------------------------------------------------- 00054 public method show {} 00055 public method hide {} 00056 public method setCoords {x y}; ## \type TclNumber, TclNumber 00057 public method getCoords {} 00058 public method getBBox {} 00059 public method getWidth {} 00060 public method getHeight {} 00061 public method setSelection {value}; ## \type TclNumber 00062 public method getSelection {} 00063 00064 constructor {visDir args} {}; ## \type VisDirectory, TclList 00065 destructor { hide } 00066 }; 00067 00068 ## ---------------------------------------------------------------------------- 00069 ## constructor 00070 ## ---------------------------------------------------------------------------- 00071 body VisFile::constructor {visDir args} { 00072 set _visDirectory $visDir 00073 eval configure $args 00074 00075 show 00076 } 00077 00078 ## ---------------------------------------------------------------------------- 00079 ## show 00080 ## ---------------------------------------------------------------------------- 00081 body VisFile::show {} { 00082 00083 if {$_recTag == ""} { 00084 set canvas [$_visDirectory component canvas] 00085 set background [$canvas cget -background] 00086 set _recTag \ 00087 [$_visDirectory create rectangle 0 0 0 0 \ 00088 -fill $background \ 00089 -outline "" \ 00090 -width 0 \ 00091 -tags "$this rec"] 00092 } 00093 00094 if {$_iconTag == ""} { 00095 set _iconTag \ 00096 [$_visDirectory create image 0 0 \ 00097 -image $icon \ 00098 -anchor nw \ 00099 -tags "$this icon"] 00100 } 00101 00102 if {$_textTag == ""} { 00103 set _textTag \ 00104 [$_visDirectory create text 0 0 \ 00105 -font {-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*} \ 00106 -anchor nw \ 00107 -text "$name" \ 00108 -tags "$this text"] 00109 } 00110 00111 setCoords $_xCoord $_yCoord 00112 } 00113 00114 ## ---------------------------------------------------------------------------- 00115 ## hide 00116 ## ---------------------------------------------------------------------------- 00117 body VisFile::hide {} { 00118 00119 if {$_iconTag != ""} { 00120 $_visDirectory delete $_iconTag 00121 set _iconTag "" 00122 } 00123 00124 if {$_textTag != ""} { 00125 $_visDirectory delete $_textTag 00126 set _textTag "" 00127 } 00128 00129 if {$_recTag != ""} { 00130 $_visDirectory delete $_recTag 00131 set _recTag "" 00132 } 00133 00134 } 00135 00136 ## ---------------------------------------------------------------------------- 00137 ## setCoords 00138 ## ---------------------------------------------------------------------------- 00139 body VisFile::setCoords {x y} { 00140 set _xCoord $x 00141 set _yCoord $y 00142 00143 if {$_recTag != ""} { 00144 set maxWidth [$_visDirectory getMaxFileWidth] 00145 set maxHeight [$_visDirectory getMaxFileHeight] 00146 set x2 [expr $x + $maxWidth] 00147 set y2 [expr $y + $maxHeight] 00148 $_visDirectory coords $_recTag $x $y $x2 $y2 00149 } 00150 00151 if {$_iconTag != ""} { 00152 $_visDirectory coords $_iconTag $x $y 00153 set iconBBox [$_visDirectory bbox $_iconTag] 00154 scan $iconBBox "%f %f %f %f" x1 y1 x2 y2 00155 set x [expr $x + $x2 - $x1 + 4] 00156 } 00157 00158 if {$_textTag != ""} { 00159 $_visDirectory coords $_textTag $x $y 00160 } 00161 00162 } 00163 00164 ## ---------------------------------------------------------------------------- 00165 ## getCoords 00166 ## ---------------------------------------------------------------------------- 00167 body VisFile::getCoords {} { 00168 return "$_xCoord $_yCoord" 00169 } 00170 00171 ## ---------------------------------------------------------------------------- 00172 ## getBBox 00173 ## ---------------------------------------------------------------------------- 00174 body VisFile::getBBox {} { 00175 return [eval $_visDirectory bbox $_iconTag $_textTag] 00176 } 00177 00178 ## ---------------------------------------------------------------------------- 00179 ## getWidth 00180 ## ---------------------------------------------------------------------------- 00181 body VisFile::getWidth {} { 00182 set bbox [getBBox] 00183 set x1 [lindex $bbox 0] 00184 set x2 [lindex $bbox 2] 00185 return [expr $x2 - $x1] 00186 } 00187 00188 ## ---------------------------------------------------------------------------- 00189 ## getHeight 00190 ## ---------------------------------------------------------------------------- 00191 body VisFile::getHeight {} { 00192 set bbox [getBBox] 00193 set y1 [lindex $bbox 1] 00194 set y2 [lindex $bbox 3] 00195 return [expr $y2 - $y1] 00196 } 00197 00198 ## ---------------------------------------------------------------------------- 00199 ## set the selection state. 00200 ## This method changes the _isSelected state and configures the item accordingly in 00201 ## the _visDirectory. 00202 ## \param value possible values are 00203 ## - 1: marks the VisFile in the _visDirectory 00204 ## - 0: unmarks the VisFile 00205 ## ---------------------------------------------------------------------------- 00206 body VisFile::setSelection {value} { 00207 if {$value} { 00208 $_visDirectory itemconfigure $_recTag \ 00209 -fill blue4 00210 $_visDirectory itemconfigure $_textTag \ 00211 -fill white 00212 } else { 00213 set canvas [$_visDirectory component canvas] 00214 set background [$canvas cget -background] 00215 00216 $_visDirectory itemconfigure $_recTag \ 00217 -fill $background 00218 $_visDirectory itemconfigure $_textTag \ 00219 -fill black 00220 } 00221 00222 set _isSelected $value 00223 } 00224 00225 ## ---------------------------------------------------------------------------- 00226 ## getSelection 00227 ## ---------------------------------------------------------------------------- 00228 body VisFile::getSelection {} { 00229 return $_isSelected 00230 }