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

Source Code for Module pyjamas.ui.CellFormatter

  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  from pyjamas.ui import Applier 
 18   
19 -class CellFormatter(Applier):
20 21 _elem_props = [ 22 ("wordwrap", "Word Wrap", "WordWrap", None, True), 23 ("stylename", "Style Name", "StyleName", None, ""), 24 ("height", "Height", "Height", None, None), 25 ("width", "Width", "Width", None, None), 26 ("halign", "Horizontal Alignment", "HorizontalAlignment", str, ""), 27 ("valign", "Vertical Alignment", "VerticalAlignment", str, ""), 28 ] 29
30 - def _getElementProps(self):
31 return self._elem_props
32
33 - def __init__(self, outer, **kwargs):
34 self.outer = outer 35 Applier.__init__(self, **kwargs)
36
37 - def _setStyleName(self, row, column, styleName, add):
38 self.outer.prepareCell(row, column) 39 self.outer.setStyleName(self.getElement(row, column), styleName, add)
40
41 - def addStyleName(self, row, column, styleName):
42 self._setStyleName(row, column, styleName, True)
43
44 - def getElement(self, row, column):
45 self.outer.checkCellBounds(row, column) 46 return DOM.getChild(self.outer.rowFormatter.getRow(self.outer.bodyElem, row), column)
47
48 - def getStyleName(self, row, column):
49 return DOM.getAttribute(self.getElement(row, column), "className")
50
51 - def isVisible(self, row, column):
52 """ DEPRECATED: please use getVisible 53 """ 54 return self.getVisible(row, column)
55
56 - def getVisible(self, row, column):
57 element = self.getElement(row, column) 58 return self.outer.isVisible(element)
59
60 - def removeStyleName(self, row, column, styleName):
61 self._setStyleName(row, column, styleName, False)
62
63 - def setAlignment(self, row, column, hAlign, vAlign):
64 self.setHorizontalAlignment(row, column, hAlign) 65 self.setVerticalAlignment(row, column, vAlign)
66
67 - def setHeight(self, row, column, height):
68 self.outer.prepareCell(row, column) 69 element = self.getCellElement(self.outer.bodyElem, row, column) 70 DOM.setStyleAttribute(element, "height", height)
71
72 - def setHorizontalAlignment(self, row, column, align):
73 self.outer.prepareCell(row, column) 74 element = self.getCellElement(self.outer.bodyElem, row, column) 75 DOM.setAttribute(element, "align", align)
76
77 - def setStyleName(self, row, column, styleName, add=None):
78 if add is None: 79 self.outer.prepareCell(row, column) 80 self.setAttr(row, column, "className", styleName) 81 else: 82 self._setStyleName(row, column, styleName, add)
83
84 - def setVerticalAlignment(self, row, column, align):
85 self.outer.prepareCell(row, column) 86 DOM.setStyleAttribute(self.getCellElement(self.outer.bodyElem, 87 row, column), 88 "verticalAlign", align)
89
90 - def setVisible(self, row, column, visible):
91 element = self.ensureElement(row, column) 92 self.outer.setVisible(element, visible)
93
94 - def setWidth(self, row, column, width):
95 self.outer.prepareCell(row, column) 96 DOM.setStyleAttribute(self.getCellElement(self.outer.bodyElem, 97 row, column), 98 "width", width)
99
100 - def setWordWrap(self, row, column, wrap):
101 self.outer.prepareCell(row, column) 102 if wrap: 103 wrap_str = "" 104 else: 105 wrap_str = "nowrap" 106 107 DOM.setStyleAttribute(self.getElement(row, column), 108 "whiteSpace", wrap_str)
109
110 - def getCellElement(self, table, row, col):
111 length = table.rows.length 112 if row >= length: 113 return None 114 cols = table.rows.item(row).cells 115 length = cols.length 116 if col >= length: 117 return None 118 item = cols.item(col) 119 return item
120
121 - def getRawElement(self, row, column):
122 return self.getCellElement(self.outer.bodyElem, row, column)
123
124 - def ensureElement(self, row, column):
125 self.outer.prepareCell(row, column) 126 return DOM.getChild(self.outer.rowFormatter.ensureElement(row), column)
127
128 - def getStyleAttr(self, row, column, attr):
129 elem = self.getElement(row, column) 130 return DOM.getStyleAttribute(elem, attr)
131
132 - def setStyleAttr(self, row, column, attrName, value):
133 elem = self.getElement(row, column) 134 DOM.setStyleAttribute(elem, attrName, value)
135
136 - def getAttr(self, row, column, attr):
137 elem = self.getElement(row, column) 138 return DOM.getAttribute(elem, attr)
139
140 - def setAttr(self, row, column, attrName, value):
141 elem = self.getElement(row, column) 142 DOM.setAttribute(elem, attrName, value)
143