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 - def __init__(self, outer, **kwargs):
22 self.outer = outer 23 Applier.__init__(self, **kwargs)
24
25 - def addStyleName(self, row, column, styleName):
26 self.outer.prepareCell(row, column) 27 self.outer.setStyleName(self.getElement(row, column), styleName, True)
28
29 - def getElement(self, row, column):
30 self.outer.checkCellBounds(row, column) 31 return DOM.getChild(self.outer.rowFormatter.getRow(self.outer.bodyElem, row), column)
32
33 - def getStyleName(self, row, column):
34 return DOM.getAttribute(self.getElement(row, column), "className")
35
36 - def isVisible(self, row, column):
37 element = self.getElement(row, column) 38 return self.outer.isVisible(element)
39
40 - def removeStyleName(self, row, column, styleName):
41 self.outer.checkCellBounds(row, column) 42 self.outer.setStyleName(self.getElement(row, column), styleName, False)
43
44 - def setAlignment(self, row, column, hAlign, vAlign):
45 self.setHorizontalAlignment(row, column, hAlign) 46 self.setVerticalAlignment(row, column, vAlign)
47
48 - def setHeight(self, row, column, height):
49 self.outer.prepareCell(row, column) 50 element = self.getCellElement(self.outer.bodyElem, row, column) 51 DOM.setStyleAttribute(element, "height", height)
52
53 - def setHorizontalAlignment(self, row, column, align):
54 self.outer.prepareCell(row, column) 55 element = self.getCellElement(self.outer.bodyElem, row, column) 56 DOM.setAttribute(element, "align", align)
57
58 - def setStyleName(self, row, column, styleName):
59 self.outer.prepareCell(row, column) 60 self.setAttr(row, column, "className", styleName)
61
62 - def setVerticalAlignment(self, row, column, align):
63 self.outer.prepareCell(row, column) 64 DOM.setStyleAttribute(self.getCellElement(self.outer.bodyElem, row, column), "verticalAlign", align)
65
66 - def setVisible(self, row, column, visible):
67 element = self.ensureElement(row, column) 68 self.outer.setVisible(element, visible)
69
70 - def setWidth(self, row, column, width):
71 self.outer.prepareCell(row, column) 72 DOM.setStyleAttribute(self.getCellElement(self.outer.bodyElem, row, column), "width", width)
73
74 - def setWordWrap(self, row, column, wrap):
75 self.outer.prepareCell(row, column) 76 if wrap: 77 wrap_str = "" 78 else: 79 wrap_str = "nowrap" 80 81 DOM.setStyleAttribute(self.getElement(row, column), "whiteSpace", wrap_str)
82
83 - def getCellElement(self, table, row, col):
84 length = table.rows.length 85 if row >= length: 86 return None 87 cols = table.rows.item(row).cells 88 length = cols.length 89 if col >= length: 90 return None 91 item = cols.item(col) 92 return item
93
94 - def getRawElement(self, row, column):
95 return self.getCellElement(self.outer.bodyElem, row, column)
96
97 - def ensureElement(self, row, column):
98 self.outer.prepareCell(row, column) 99 return DOM.getChild(self.outer.rowFormatter.ensureElement(row), column)
100
101 - def getStyleAttr(self, row, column, attr):
102 elem = self.getElement(row, column) 103 return DOM.getStyleAttribute(elem, attr)
104
105 - def setStyleAttr(self, row, column, attrName, value):
106 elem = self.getElement(row, column) 107 DOM.setStyleAttribute(elem, attrName, value)
108
109 - def getAttr(self, row, column, attr):
110 elem = self.getElement(row, column) 111 return DOM.getAttribute(elem, attr)
112
113 - def setAttr(self, row, column, attrName, value):
114 elem = self.getElement(row, column) 115 DOM.setAttribute(elem, attrName, value)
116