1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15  from __pyjamas__ import console 
 16  from pyjamas import Factory 
 17  from pyjamas import DOM 
 18   
 19  from CellPanel import CellPanel 
 20  from pyjamas.ui import HasHorizontalAlignment 
 21  from pyjamas.ui import HasVerticalAlignment 
 22   
 26   
 29          self.direction = direction 
 30          self.hAlign = "left" 
 31          self.height = "" 
 32          self.td = None 
 33          self.vAlign = "top" 
 34          self.width = "" 
   35   
 36   
 38   
 39      CENTER = "center" 
 40      EAST = "east" 
 41      NORTH = "north" 
 42      SOUTH = "south" 
 43      WEST = "west" 
 44   
 56   
 57 -    def add(self, widget, direction): 
  70   
 73   
 76   
 81   
 91   
 97   
103   
109   
115   
117          self.horzAlign = align 
 118   
120          self.vertAlign = align 
 121   
123          bodyElement = self.getBody() 
124   
125          while DOM.getChildCount(bodyElement) > 0: 
126              DOM.removeChild(bodyElement, DOM.getChild(bodyElement, 0)) 
127   
128          rowCount = 1 
129          colCount = 1 
130          for child in self.dock_children: 
131              dir = child.getLayoutData().direction 
132              if dir == self.NORTH or dir == self.SOUTH: 
133                  rowCount += 1 
134              elif dir == self.EAST or dir == self.WEST: 
135                  colCount += 1 
136   
137          rows = [] 
138          for i in range(rowCount): 
139              rows.append(DockPanelTmpRow()) 
140              rows[i].tr = DOM.createTR() 
141              DOM.appendChild(bodyElement, rows[i].tr) 
142   
143          westCol = 0 
144          eastCol = colCount - 1 
145          northRow = 0 
146          southRow = rowCount - 1 
147          centerTd = None 
148   
149          for child in self.dock_children: 
150              layout = child.getLayoutData() 
151   
152              td = DOM.createTD() 
153              layout.td = td 
154              DOM.setAttribute(layout.td, "align", layout.hAlign) 
155              DOM.setStyleAttribute(layout.td, "verticalAlign", layout.vAlign) 
156              DOM.setAttribute(layout.td, "width", layout.width) 
157              DOM.setAttribute(layout.td, "height", layout.height) 
158   
159              if layout.direction == self.NORTH: 
160                  DOM.insertChild(rows[northRow].tr, td, rows[northRow].center) 
161                  self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) 
162                  DOM.setIntAttribute(td, "colSpan", eastCol - westCol + 1) 
163                  northRow += 1 
164              elif layout.direction == self.SOUTH: 
165                  DOM.insertChild(rows[southRow].tr, td, rows[southRow].center) 
166                  self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) 
167                  DOM.setIntAttribute(td, "colSpan", eastCol - westCol + 1) 
168                  southRow -= 1 
169              elif layout.direction == self.WEST: 
170                  row = rows[northRow] 
171                  DOM.insertChild(row.tr, td, row.center) 
172                  row.center += 1 
173                  self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) 
174                  DOM.setIntAttribute(td, "rowSpan", southRow - northRow + 1) 
175                  westCol += 1 
176              elif layout.direction == self.EAST: 
177                  row = rows[northRow] 
178                  DOM.insertChild(row.tr, td, row.center) 
179                  self.appendAndMaybeAdopt(td, child.getElement(), beingAdded) 
180                  DOM.setIntAttribute(td, "rowSpan", southRow - northRow + 1) 
181                  eastCol -= 1 
182              elif layout.direction == self.CENTER: 
183                  centerTd = td 
184   
185          if self.center is not None: 
186              row = rows[northRow] 
187              DOM.insertChild(row.tr, centerTd, row.center) 
188              self.appendAndMaybeAdopt(centerTd, self.center.getElement(), beingAdded) 
 189   
 196   
197  Factory.registerClass('pyjamas.ui.DockPanel', DockPanel) 
198