Package library :: Package pyjamas :: Package ui :: Module CaptionPanel
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.ui.CaptionPanel

 1  # Copyright 2006 James Tauber and contributors 
 2  # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 
 3  # 
 4  # Licensed under the Apache License, Version 2.0 (the "License"); 
 5  # you may not use this file except in compliance with the License. 
 6  # You may obtain a copy of the License at 
 7  # 
 8  #     http://www.apache.org/licenses/LICENSE-2.0 
 9  # 
10  # Unless required by applicable law or agreed to in writing, software 
11  # distributed under the License is distributed on an "AS IS" BASIS, 
12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13  # See the License for the specific language governing permissions and 
14  # limitations under the License. 
15  from pyjamas import DOM 
16  from pyjamas import Factory 
17   
18  from pyjamas.ui.SimplePanel import SimplePanel 
19 20 -class CaptionPanel(SimplePanel):
21 """ 22 A panel that wraps its contents in a border with a caption that appears in 23 the upper left corner of the border. This is an implementation of the 24 fieldset HTML element. 25 """ 26 27 _props = [("caption", "Caption", "caption", None), 28 ] 29
30 - def __init__(self, caption, widget=None, **kwargs):
31 if kwargs.has_key('Element'): 32 element = kwargs.pop('Element') 33 else: 34 element = DOM.createElement("fieldset") 35 self.legend = DOM.createElement("legend") 36 DOM.appendChild(element, self.legend) 37 kwargs['Caption'] = caption 38 if widget is not None: 39 kwargs['Widget'] = widget 40 if not 'StyleName' in kwargs: 41 kwargs['StyleName'] = 'gwt-CaptionPanel' 42 SimplePanel.__init__(self, element, **kwargs)
43 44 @classmethod
45 - def _getProps(self):
46 return SimplePanel._getProps() + self._props
47
48 - def getCaption(self):
49 return self.caption
50
51 - def setCaption(self, caption):
52 self.caption = caption 53 if caption is not None and not caption == "": 54 DOM.setInnerHTML(self.legend, caption) 55 DOM.insertChild(self.getElement(), self.legend, 0) 56 elif DOM.getParent(self.legend) is not None: 57 DOM.removeChild(self.getElement(), self.legend)
58 59 Factory.registerClass('pyjamas.ui.CaptionPanel', 'CaptionPanel', CaptionPanel) 60