1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """Defines a component for embedding external objects."""
17
18 from muntjac.ui.abstract_component import AbstractComponent
19 from muntjac.event.mouse_events import IClickListener, ClickEvent
20 from muntjac.terminal.gwt.client.mouse_event_details import MouseEventDetails
21
22 from muntjac.terminal.gwt.client.ui.v_embedded import VEmbedded
23
24
26 """Component for embedding external objects.
27
28 @author: Vaadin Ltd.
29 @author: Richard Lincoln
30 @version: 1.1.2
31 """
32
33 CLIENT_WIDGET = None
34
35 _CLICK_EVENT = VEmbedded.CLICK_EVENT_IDENTIFIER
36
37
38 TYPE_OBJECT = 0
39
40
41 TYPE_IMAGE = 1
42
43
44 TYPE_BROWSER = 2
45
46 - def __init__(self, caption=None, source=None):
47 """Creates a new Embedded object whose contents is loaded from
48 given resource. The dimensions are assumed if possible. The
49 type is guessed from resource.
50
51 @param caption:
52 @param source:
53 the Source of the embedded object.
54 """
55 super(Embedded, self).__init__()
56
57
58 self._type = self.TYPE_OBJECT
59
60
61 self._source = None
62
63
64 self._mimeType = None
65 self._standby = None
66
67
68 self._parameters = dict()
69
70
71 self._codebase = None
72 self._codetype = None
73 self._classId = None
74 self._archive = None
75
76 if caption is not None:
77 self.setCaption(caption)
78
79 if source is not None:
80 self.setSource(source)
81
82
83 - def paintContent(self, target):
84 """Invoked when the component state should be painted."""
85
86 if self._type == self.TYPE_IMAGE:
87 target.addAttribute('type', 'image')
88 elif self._type == self.TYPE_BROWSER:
89 target.addAttribute('type', 'browser')
90
91
92 if self.getSource() is not None:
93 target.addAttribute('src', self.getSource())
94
95 if self._mimeType is not None and not ('' == self._mimeType):
96 target.addAttribute('mimetype', self._mimeType)
97
98 if self._classId is not None and not ('' == self._classId):
99 target.addAttribute('classid', self._classId)
100
101 if self._codebase is not None and not ('' == self._codebase):
102 target.addAttribute('codebase', self._codebase)
103
104 if self._codetype is not None and not ('' == self._codetype):
105 target.addAttribute('codetype', self._codetype)
106
107 if self._standby is not None and not ('' == self._standby):
108 target.addAttribute('standby', self._standby)
109
110 if self._archive is not None and not ('' == self._archive):
111 target.addAttribute('archive', self._archive)
112
113
114 for key in self.getParameterNames():
115 target.startTag('embeddedparam')
116 target.addAttribute('name', key)
117 target.addAttribute('value', self.getParameter(key))
118 target.endTag('embeddedparam')
119
120
122 """Sets an object parameter. Parameters are optional information,
123 and they are passed to the instantiated object. Parameters are are
124 stored as name value pairs. This overrides the previous value
125 assigned to this parameter.
126
127 @param name: the name of the parameter.
128 @param value: the value of the parameter.
129 """
130 self._parameters[name] = value
131 self.requestRepaint()
132
133
135 """Gets the value of an object parameter. Parameters are optional
136 information, and they are passed to the instantiated object.
137 Parameters are are stored as name value pairs.
138
139 @return: the Value of parameter or null if not found.
140 """
141 return self._parameters.get(name)
142
143
145 """Removes an object parameter from the list.
146
147 @param name:
148 the name of the parameter to remove.
149 """
150 if name in self._parameters:
151 del self._parameters[name]
152 self.requestRepaint()
153
154
156 """Gets the embedded object parameter names.
157
158 @return: the Iterator of parameters names.
159 """
160 return self._parameters.keys()
161
162
164 """This attribute specifies the base path used to resolve relative
165 URIs specified by the classid, data, and archive attributes. When
166 absent, its default value is the base URI of the current document.
167
168 @return: the code base.
169 """
170 return self._codebase
171
172
174 """Gets the MIME-Type of the code.
175
176 @return: the MIME-Type of the code.
177 """
178 return self._codetype
179
180
182 """Gets the MIME-Type of the object.
183
184 @return: the MIME-Type of the object.
185 """
186 return self._mimeType
187
188
190 """This attribute specifies a message that a user agent may render
191 while loading the object's implementation and data.
192
193 @return: The text displayed when loading
194 """
195 return self._standby
196
197
199 """This attribute specifies the base path used to resolve relative
200 URIs specified by the classid, data, and archive attributes. When
201 absent, its default value is the base URI of the current document.
202
203 @param codebase:
204 The base path
205 """
206 if (codebase != self._codebase
207 or (codebase is not None and codebase != self._codebase)):
208 self._codebase = codebase
209 self.requestRepaint()
210
211
213 """This attribute specifies the content type of data expected when
214 downloading the object specified by classid. This attribute is
215 optional but recommended when classid is specified since it allows
216 the user agent to avoid loading information for unsupported content
217 types. When absent, it defaults to the value of the type attribute.
218
219 @param codetype:
220 the codetype to set.
221 """
222 if (codetype != self._codetype
223 or (codetype is not None and codetype != self._codetype)):
224 self._codetype = codetype
225 self.requestRepaint()
226
227
229 """Sets the mimeType, the MIME-Type of the object.
230
231 @param mimeType: the mimeType to set.
232 """
233 if (mimeType != self._mimeType
234 or (mimeType is not None and mimeType != self._mimeType)):
235 self._mimeType = mimeType
236 if 'application/x-shockwave-flash' == mimeType:
237
238
239
240
241 if self.getParameter('wmode') is None:
242 self.setParameter('wmode', 'transparent')
243
244 self.requestRepaint()
245
246
248 """This attribute specifies a message that a user agent may render
249 while loading the object's implementation and data.
250
251 @param standby: The text to display while loading
252 """
253 if (standby != self._standby
254 or (standby is not None and standby != self._standby)):
255 self._standby = standby
256 self.requestRepaint()
257
258
260 """This attribute may be used to specify the location of an object's
261 implementation via a URI.
262
263 @return: the classid.
264 """
265 return self._classId
266
267
269 """This attribute may be used to specify the location of an object's
270 implementation via a URI.
271
272 @param classId:
273 the classId to set.
274 """
275 if (classId != self._classId
276 or (classId is not None and classId != self._classId)):
277 self._classId = classId
278 self.requestRepaint()
279
280
282 """Gets the resource contained in the embedded object.
283
284 @return: the Resource
285 """
286 return self._source
287
288
290 """Gets the type of the embedded object.
291
292 This can be one of the following:
293
294 - TYPE_OBJECT I{(This is the default)}
295 - TYPE_IMAGE
296
297 @return: the type.
298 """
299 return self._type
300
301
303 """Sets the object source resource. The dimensions are assumed
304 if possible. The type is guessed from resource.
305
306 @param source: the source to set.
307 """
308 if source is not None and source != self._source:
309 self._source = source
310 mt = source.getMIMEType()
311
312 if self._mimeType is None:
313 self._mimeType = mt
314
315 if mt == 'image/svg+xml':
316 self._type = self.TYPE_OBJECT
317 elif mt[:mt.find('/')].lower() == 'image':
318 self._type = self.TYPE_IMAGE
319 else:
320 pass
321
322 self.requestRepaint()
323
324
326 """Sets the object type.
327
328 This can be one of the following:
329
330 - TYPE_OBJECT I{(This is the default)}
331 - TYPE_IMAGE
332 - TYPE_BROWSER
333
334 @param typ: the type to set.
335 """
336 if (typ != self.TYPE_OBJECT and typ != self.TYPE_IMAGE
337 and typ != self.TYPE_BROWSER):
338 raise ValueError, 'Unsupported typ'
339
340 if typ != self._type:
341 self._type = typ
342 self.requestRepaint()
343
344
346 """This attribute may be used to specify a space-separated list of
347 URIs for archives containing resources relevant to the object, which
348 may include the resources specified by the classid and data
349 attributes. Preloading archives will generally result in reduced load
350 times for objects. Archives specified as relative URIs should be
351 interpreted relative to the codebase attribute.
352
353 @return: Space-separated list of URIs with resources relevant to the
354 object
355 """
356 return self._archive
357
358
360 """This attribute may be used to specify a space-separated list of
361 URIs for archives containing resources relevant to the object, which
362 may include the resources specified by the classid and data
363 attributes. Preloading archives will generally result in reduced load
364 times for objects. Archives specified as relative URIs should be
365 interpreted relative to the codebase attribute.
366
367 @param archive:
368 Space-separated list of URIs with resources relevant to
369 the object
370 """
371 if (archive != self._archive
372 or (archive is not None and archive != self._archive)):
373 self._archive = archive
374 self.requestRepaint()
375
376
378 """Add a click listener to the component. The listener is called
379 whenever the user clicks inside the component. Depending on the
380 content the event may be blocked and in that case no event is fired.
381
382 Use L{removeListener} to remove the listener.
383
384 @param listener:
385 The listener to add
386 """
387 if (isinstance(listener, IClickListener) and
388 (iface is None or issubclass(iface, IClickListener))):
389 self.registerListener(self._CLICK_EVENT, ClickEvent,
390 listener, IClickListener.clickMethod)
391
392 super(Embedded, self).addListener(listener, iface)
393
394
395 - def addCallback(self, callback, eventType=None, *args):
404
405
418
419
428
429
435
436
443