1 # ui-nsdr.tcl --
2 #
3 # Defines the primary nsdr UI
4 #
5 # Copyright (c) 1997-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 import notebook NewList SDPEditWindow ProgramWindow HelpWindow
32
33 # Implements the main user interface for the Nsdr session
34 # directory tool.
35 Class NsdrUI
36
37 # Builds the main user interface in the window <i>w</i>
38 NsdrUI public init {w app} {
39 $self set app_ $app
40 $self set w_ $w
41
42 $self instvar notebook_
43 set notebook_ [notebook $w.n -tabheight 27 -tabpadx 2 -bd 2 ]
44 $self set sources_ {}
45
46 set helpWindow [new NsdrHelpWindow .help]
47
48 set b "$w.bar"
49 frame $b -relief ridge -bd 2
50 label $b.title -text "nsdr v[version]" -relief flat -justify left
51 button $b.new -relief raised -highlightthickness 1 \
52 -text "New" -command "$self new-program"
53 button $b.help -relief raised -highlightthickness 1 \
54 -text "Help" -command "$helpWindow toggle"
55 button $b.quit -relief raised -highlightthickness 1 \
56 -text "Quit" -command "$app exit"
57 pack $b.title -side left -fill both -expand yes
58 pack $b.new $b.help $b.quit -side left -padx 1 -pady 1
59
60 pack $b -side bottom -fill x -expand no
61 pack $notebook_ -fill both -expand yes -padx 2 -pady 2
62 }
63
64 # Creates a new tab for this source. Returns an integer that can
65 # be used in subsequent calls to the UI to add/remove programs.
66 NsdrUI public addsource s {
67 $self instvar sources_
68 set n [llength $sources_]
69 lappend sources_ $s
70 $self set orders_($n) {}
71
72 $self instvar notebook_
73 $notebook_ addTab [$s name]
74 set f [frame $notebook_.f$n]
75 $notebook_ addFrame $f $n -expand yes -fill both -pady 2
76
77 $self set lists_($n) [new NewList $f]
78
79 if {$n == 0} {
80 $notebook_ tabPress 0
81 }
82 }
83
84 #
85 NsdrUI private lookup {src} {
86 $self instvar sources_ progs_
87
88 set n [lsearch -exact $sources_ $src]
89 if {$n == -1} {
90 $self fatal "NsdrUI inconsistency in sources_"
91 }
92 return $n
93 }
94
95 # Adds the Program <i>prog</i> to the user interface in the frame
96 # corresponding to the ProgramSource <i>src</i>.
97 NsdrUI public addprog {src prog} {
98 $self instvar sources_ progs_ orders_ lists_
99
100 set n [$self lookup $src]
101
102 # create the new Program object and update local state
103 set o [$prog unique_key]
104 set p [new ProgramWindow $prog]
105 set progs_($n:$o) $p
106
107 # update the user interface
108 set title [string tolower [$p title]]
109 set order $orders_($n)
110 set i 0
111 set pr [lindex $order 0]
112 while {$pr != ""} {
113 set title2 [string tolower [$pr title]]
114 if {[string compare $title $title2] <= 0} break
115 incr i
116 set pr [lindex $order $i]
117 }
118 if {$pr == ""} {set i "end" }
119 set orders_($n) [linsert $order $i $p]
120 $self instvar lists_
121 $lists_($n) insert $i [$p title] "$p toggle-window"
122 }
123
124 # Removes the Program object <i>prog</i> from the user interface
125 # frame corresponding to the ProgramSource <i>src</i>.
126 NsdrUI public removeprog {src prog} {
127 $self instvar sources_ progs_ orders_ lists_
128
129 set n [$self lookup $src]
130
131 # find the corresponding program
132 set o [$prog unique_key]
133 if ![info exists progs_($n:$o)] {
134 $self fatal "NsdrUI::removeprog: inconsistency in progs_!"
135 }
136
137 set p $progs_($n:$o)
138
139 set i [lsearch -exact $orders_($n) $p]
140 if {$i < 0} {
141 $self fatal "NsdrUI::removeprog: insconsistency in orders_!"
142 }
143
144 set orders_($n) [lreplace $orders_($n) $i $i]
145 $lists_($n) delete $i
146
147 delete $p
148 }
149
150 # describe
151 NsdrUI public updateprog {src prog} {
152 $self instvar sources_ progs_
153
154 set n [$self lookup $src]
155 set o [$prog unique_key]
156 if ![info exists progs_($n:$o)] {
157 $self fatal "NsdrUI inconsistency in progs_"
158 }
159
160 $progs_($n:$o) updateprog $prog
161 }
162
163 # describe
164 NsdrUI public current-source {} {
165 $self instvar notebook_ sources_
166 set i [$notebook_ index]
167 return [lindex $sources_ $i]
168 }
169
170 # describe
171 NsdrUI private new-program {} {
172 new SDPEditWindow "" [$self current-source]
173 }
174
175 #
176 # A toggle-able dismissable toplevel window for displaying a
177 # bulleted list of tips to help the user.
178 #
179 Class NsdrHelpWindow -superclass HelpWindow
180
181 #
182 # Instantiate, but do not yet display or iconify, a dismissable toplevel
183 # window using the provided widgetpath, <i>w</i>. Within <i>w</i>,
184 # create a bulleted list of tips to help the vic user. (This method is
185 # called when the user toggles this window for the first time.)
186 #
187 NsdrHelpWindow instproc build w {
188
189 $self create-window $w "nsdr: Help" {
190
191 "Click on a program name to display detailed information \
192 and launch media tools."
193
194 "Use ``New'' button to create new session announcements."
195
196 "If the user interface looks peculiar, you might \
197 have X resources that conflict with tk. A common problem is \
198 defining ``*background'' and/or ``*foreground''."
199
200 "Bugs and suggestions to openmash-users@openmash.org. Thanks."
201 }
202 }
203
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.