1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
2 | # ---------------------------------------------------------------------- |
---|
3 | # COMPONENT: MapEntry - widget for viewing map as input control |
---|
4 | # |
---|
5 | # ====================================================================== |
---|
6 | # AUTHOR: Leif Delgass, Purdue University |
---|
7 | # Copyright (c) 2016 HUBzero Foundation, LLC |
---|
8 | # |
---|
9 | # See the file "license.terms" for information on usage and |
---|
10 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
11 | # ====================================================================== |
---|
12 | package require Itk |
---|
13 | |
---|
14 | itcl::class Rappture::MapEntry { |
---|
15 | inherit itk::Widget |
---|
16 | |
---|
17 | itk_option define -state state State "normal" |
---|
18 | |
---|
19 | constructor {owner path args} { |
---|
20 | # defined below |
---|
21 | } |
---|
22 | public method label {} |
---|
23 | public method tooltip {} |
---|
24 | public method value {args} |
---|
25 | |
---|
26 | private variable _owner "" ;# thing managing this control |
---|
27 | private variable _path "" ;# path in XML to this input |
---|
28 | private variable _xmlobj "" |
---|
29 | private variable _mapviewer "" ;# MapViewer widget |
---|
30 | } |
---|
31 | |
---|
32 | itk::usual MapEntry { |
---|
33 | } |
---|
34 | |
---|
35 | # ---------------------------------------------------------------------- |
---|
36 | # CONSTRUCTOR |
---|
37 | # ---------------------------------------------------------------------- |
---|
38 | itcl::body Rappture::MapEntry::constructor {owner path args} { |
---|
39 | if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { |
---|
40 | error "bad object \"$owner\": should be Rappture::ControlOwner" |
---|
41 | } |
---|
42 | set _owner $owner |
---|
43 | set _path $path |
---|
44 | set _xmlobj [$_owner xml object] |
---|
45 | |
---|
46 | itk_component add map { |
---|
47 | Rappture::MapViewer $itk_interior.map |
---|
48 | } |
---|
49 | pack $itk_component(map) -expand yes -fill both |
---|
50 | set _mapviewer $itk_component(map) |
---|
51 | |
---|
52 | eval itk_initialize $args |
---|
53 | |
---|
54 | value $_xmlobj |
---|
55 | } |
---|
56 | |
---|
57 | # ---------------------------------------------------------------------- |
---|
58 | # USAGE: value ?-check? ?<newval>? |
---|
59 | # |
---|
60 | # Clients use this to query/set the value for this widget. With |
---|
61 | # no args, it returns the current value for the widget. If the |
---|
62 | # <newval> is specified, it sets the value of the widget and |
---|
63 | # sends a <<Value>> event. If the -check flag is included, the |
---|
64 | # new value is not actually applied, but just checked for correctness. |
---|
65 | # ---------------------------------------------------------------------- |
---|
66 | itcl::body Rappture::MapEntry::value {args} { |
---|
67 | set onlycheck 0 |
---|
68 | set i [lsearch -exact $args -check] |
---|
69 | if {$i >= 0} { |
---|
70 | set onlycheck 1 |
---|
71 | set args [lreplace $args $i $i] |
---|
72 | } |
---|
73 | |
---|
74 | if {[llength $args] == 1} { |
---|
75 | set newval [lindex $args 0] |
---|
76 | |
---|
77 | if {!$onlycheck && $_xmlobj != "" && $_xmlobj != $newval} { |
---|
78 | # delete any existing object |
---|
79 | itcl::delete object $_xmlobj |
---|
80 | set _xmlobj "" |
---|
81 | } |
---|
82 | if {$newval != ""} { |
---|
83 | if {![Rappture::library isvalid $newval]} { |
---|
84 | error "bad value \"$newval\": should be Rappture::Library" |
---|
85 | } |
---|
86 | if {$onlycheck} { |
---|
87 | return |
---|
88 | } |
---|
89 | set _xmlobj $newval |
---|
90 | } |
---|
91 | set dataobjs [$_mapviewer get] |
---|
92 | $_mapviewer configure -map [Rappture::Map ::#auto $_xmlobj $_path] |
---|
93 | foreach dataobj $dataobjs { |
---|
94 | itcl::delete object $dataobj |
---|
95 | } |
---|
96 | event generate $itk_component(hull) <<Value>> |
---|
97 | } elseif {[llength $args] != 0} { |
---|
98 | error "wrong # args: should be \"value ?-check? ?newval?\"" |
---|
99 | } |
---|
100 | return "" |
---|
101 | } |
---|
102 | |
---|
103 | # ---------------------------------------------------------------------- |
---|
104 | # USAGE: label |
---|
105 | # |
---|
106 | # Clients use this to query the label associated with this widget. |
---|
107 | # Reaches into the XML and pulls out the appropriate label string. |
---|
108 | # ---------------------------------------------------------------------- |
---|
109 | itcl::body Rappture::MapEntry::label {} { |
---|
110 | set label [string trim [$_owner xml get $_path.about.label]] |
---|
111 | return $label |
---|
112 | } |
---|
113 | |
---|
114 | # ---------------------------------------------------------------------- |
---|
115 | # USAGE: tooltip |
---|
116 | # |
---|
117 | # Clients use this to query the tooltip associated with this widget. |
---|
118 | # Reaches into the XML and pulls out the appropriate description |
---|
119 | # string. Returns the string that should be used with the |
---|
120 | # Rappture::Tooltip facility. |
---|
121 | # ---------------------------------------------------------------------- |
---|
122 | itcl::body Rappture::MapEntry::tooltip {} { |
---|
123 | set str [string trim [$_owner xml get $_path.about.description]] |
---|
124 | return $str |
---|
125 | } |
---|
126 | |
---|
127 | # ---------------------------------------------------------------------- |
---|
128 | # CONFIGURATION OPTION: -state |
---|
129 | # ---------------------------------------------------------------------- |
---|
130 | itcl::configbody Rappture::MapEntry::state { |
---|
131 | set valid {normal disabled} |
---|
132 | if {[lsearch -exact $valid $itk_option(-state)] < 0} { |
---|
133 | error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" |
---|
134 | } |
---|
135 | #$_mapviewer configure -state $itk_option(-state) |
---|
136 | } |
---|