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

Source Code for Module pyjamas.ui.CellPanel

  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.ComplexPanel import ComplexPanel 
 19  from pyjamas.ui import HasHorizontalAlignment 
 20  from pyjamas.ui import HasVerticalAlignment 
21 22 23 -class CellPanel(ComplexPanel):
24 25 _props = [ 26 ("horzAlign", "Horizontal alignment", "HorizontalAlignment", None), 27 ("vertAlign", "Vertical alignment", "VerticalAlignment", None), 28 ("border", "Border width", "BorderWidth", int), 29 ("spacing", "Spacing", "Spacing", None), 30 ("padding", "Padding", "Padding", None) 31 ] 32
33 - def __init__(self, **kwargs):
34 35 kwargs['Spacing'] = kwargs.get('Spacing', 0) 36 kwargs['Padding'] = kwargs.get('Padding', 0) 37 kwargs['HorizontalAlignment'] = kwargs.get('HorizontalAlignment', 38 HasHorizontalAlignment.ALIGN_LEFT) 39 kwargs['VerticalAlignment'] = kwargs.get('VerticalAlignment', 40 HasVerticalAlignment.ALIGN_TOP) 41 42 element = kwargs.pop('Element', None) or DOM.createTable() 43 fc = DOM.getFirstChild(element) 44 if fc: 45 self.body = fc 46 else: 47 self.body = DOM.createTBody() 48 self.table = element 49 self.setElement(self.table) 50 DOM.appendChild(self.table, self.body) 51 52 ComplexPanel.__init__(self, **kwargs)
53 54 @classmethod
55 - def _getProps(self):
56 return ComplexPanel._getProps() + self._props
57
58 - def getTable(self):
59 return self.table
60
61 - def getBody(self):
62 return self.body
63
64 - def getBorderWidth(self):
65 return DOM.getAttribute(self.table, "border")
66
67 - def getCellHeight(self, widget):
68 td = DOM.getParent(widget.getElement()) 69 return DOM.getAttribute(td, "height")
70
71 - def getCellWidth(self, widget):
72 td = DOM.getParent(widget.getElement()) 73 return DOM.getAttribute(td, "width")
74
75 - def getSpacing(self):
76 return self.spacing
77
78 - def getPadding(self):
79 return self.padding
80
81 - def getCellHorizontalAlignment(self, widget):
82 td = self.getWidgetTd(widget) 83 if td is None: 84 return None 85 return DOM.getAttribute(td, "align")
86
87 - def getCellVerticalAlignment(self, widget):
88 td = self.getWidgetTd(widget) 89 if td is None: 90 return None 91 return DOM.getStyleAttribute(td, "verticalAlign")
92
93 - def getWidgetTd(self, widget):
94 if widget.getParent() != self: 95 return None 96 return DOM.getParent(widget.getElement())
97
98 - def setBorderWidth(self, width):
99 if width is None or width == "": 100 DOM.removeAttribute(self.table, "border") 101 else: 102 DOM.setAttribute(self.table, "border", "%d" % width)
103
104 - def setCellHeight(self, widget, height):
105 td = DOM.getParent(widget.getElement()) 106 if height is None: 107 DOM.removeAttribute(td, "height") 108 else: 109 DOM.setAttribute(td, "height", str(height))
110
111 - def setCellHorizontalAlignment(self, widget, align):
112 td = self.getWidgetTd(widget) 113 if td is not None: 114 if align is None: 115 DOM.removeAttribute(td, "align") 116 else: 117 DOM.setAttribute(td, "align", align)
118
119 - def setCellVerticalAlignment(self, widget, align):
120 td = self.getWidgetTd(widget) 121 if td is not None: 122 if align is None: 123 DOM.setStyleAttribute(td, "verticalAlign", "") 124 else: 125 DOM.setStyleAttribute(td, "verticalAlign", align)
126
127 - def setCellWidth(self, widget, width):
128 td = DOM.getParent(widget.getElement()) 129 if width is None: 130 DOM.removeAttribute(td, "width") 131 else: 132 DOM.setAttribute(td, "width", str(width))
133
134 - def setSpacing(self, spacing):
135 self.spacing = spacing 136 if spacing is None: 137 DOM.removeAttribute(self.table, "cellSpacing") 138 else: 139 DOM.setAttribute(self.table, "cellSpacing", str(spacing))
140
141 - def setPadding(self, padding):
142 self.padding = padding 143 if padding is None: 144 DOM.removeAttribute(self.table, "cellPadding") 145 else: 146 DOM.setAttribute(self.table, "cellPadding", str(padding))
147
148 - def setHorizontalAlignment(self, align):
149 self.horzAlign = align
150
151 - def setVerticalAlignment(self, align):
152 self.vertAlign = align
153
154 - def getHorizontalAlignment(self):
155 return self.horzAlign
156
157 - def getVerticalAlignment(self):
158 return self.vertAlign
159 160 161 Factory.registerClass('pyjamas.ui.CellPanel', 'CellPanel', CellPanel) 162