Package muntjac :: Package ui :: Module abstract_layout
[hide private]
[frames] | no frames]

Source Code for Module muntjac.ui.abstract_layout

  1  # Copyright (C) 2012 Vaadin Ltd.  
  2  # Copyright (C) 2012 Richard Lincoln 
  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   
 16  """Defines the default implementation of the ILayout interface.""" 
 17   
 18  from muntjac.ui.layout import ILayout, IMarginHandler, MarginInfo 
 19  from muntjac.ui.abstract_component_container import AbstractComponentContainer 
 20  from muntjac.terminal.gwt.client.mouse_event_details import MouseEventDetails 
 21  from muntjac.terminal.gwt.client.event_id import EventId 
 22  from muntjac.event.layout_events import ILayoutClickNotifier, LayoutClickEvent 
 23   
 24   
25 -class AbstractLayout(AbstractComponentContainer, ILayout, IMarginHandler):
26 """An abstract class that defines default implementation for the 27 L{ILayout} interface. 28 29 @author: Vaadin Ltd. 30 @author: Richard Lincoln 31 @version: 1.1.2 32 """ 33 34 _CLICK_EVENT = EventId.LAYOUT_CLICK 35
36 - def __init__(self):
37 super(AbstractLayout, self).__init__() 38 39 self.margins = MarginInfo(False)
40 41
42 - def setMargin(self, *args):
43 nargs = len(args) 44 if nargs == 1: 45 if isinstance(args[0], MarginInfo): 46 marginInfo, = args 47 self.margins.setMargins(marginInfo) 48 self.requestRepaint() 49 else: 50 enabled, = args 51 self.margins.setMargins(enabled) 52 self.requestRepaint() 53 elif nargs == 4: 54 topEnabled, rightEnabled, bottomEnabled, leftEnabled = args 55 self.margins.setMargins(topEnabled, rightEnabled, 56 bottomEnabled, leftEnabled) 57 self.requestRepaint() 58 else: 59 raise ValueError, 'invalid number of arguments'
60 61
62 - def getMargin(self):
63 return self.margins
64 65
66 - def paintContent(self, target):
67 # Add margin info. Defaults to false. 68 target.addAttribute('margins', int( self.margins.getBitMask() ))
69 70
71 - def changeVariables(self, source, variables):
72 super(AbstractLayout, self).changeVariables(source, variables) 73 # not all subclasses use these events 74 if (isinstance(self, ILayoutClickNotifier) 75 and self._CLICK_EVENT in variables): 76 self.fireClick( variables.get(self._CLICK_EVENT) )
77 78
79 - def fireClick(self, parameters):
80 """Fire a layout click event. 81 82 Note that this method is only used by the subclasses that 83 implement L{LayoutClickNotifier}, and can be overridden 84 for custom click event firing. 85 86 @param parameters: 87 The parameters received from the client side 88 implementation 89 """ 90 mouseDetails = MouseEventDetails.deSerialize( 91 parameters.get('mouseDetails')) 92 93 clickedComponent = parameters.get('component') 94 95 childComponent = clickedComponent 96 while (childComponent is not None 97 and childComponent.getParent() != self): 98 childComponent = childComponent.getParent() 99 100 self.fireEvent(LayoutClickEvent(self, mouseDetails, 101 clickedComponent, childComponent))
102