Package muntjac :: Package terminal :: Package gwt :: Package client :: Package ui :: Module v_margin_info
[hide private]
[frames] | no frames]

Source Code for Module muntjac.terminal.gwt.client.ui.v_margin_info

 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   
17 -class VMarginInfo(object):
18 19 _TOP = 1 20 _RIGHT = 2 21 _BOTTOM = 4 22 _LEFT = 8 23
24 - def __init__(self, *args):
25 self._bitMask = None 26 27 args = args 28 nargs = len(args) 29 if nargs == 1: 30 bitMask, = args 31 self._bitMask = bitMask 32 elif nargs == 4: 33 top, right, bottom, left = args 34 self.setMargins(top, right, bottom, left) 35 else: 36 raise ValueError, 'invalid number of arguments'
37 38
39 - def setMargins(self, *args):
40 args = args 41 nargs = len(args) 42 if nargs == 1: 43 if isinstance(args[0], VMarginInfo): 44 marginInfo, = args 45 self._bitMask = marginInfo.bitMask 46 else: 47 enabled, = args 48 if enabled: 49 self._bitMask = \ 50 self._TOP + self._RIGHT + self._BOTTOM + self._LEFT 51 else: 52 self._bitMask = 0 53 elif nargs == 4: 54 top, right, bottom, left = args 55 self._bitMask = self._TOP if top else 0 56 self._bitMask += self._RIGHT if right else 0 57 self._bitMask += self._BOTTOM if bottom else 0 58 self._bitMask += self._LEFT if left else 0 59 else: 60 raise ValueError, 'invalid number of arguments'
61 62
63 - def hasLeft(self):
64 return self._bitMask & self._LEFT == self._LEFT
65 66
67 - def hasRight(self):
68 return self._bitMask & self._RIGHT == self._RIGHT
69 70
71 - def hasTop(self):
72 return self._bitMask & self._TOP == self._TOP
73 74
75 - def hasBottom(self):
76 return self._bitMask & self._BOTTOM == self._BOTTOM
77 78
79 - def getBitMask(self):
80 return self._bitMask
81 82
83 - def equals(self, obj):
84 if not isinstance(obj, VMarginInfo): 85 return False 86 return obj.bitMask == self._bitMask
87
88 - def __eq__(self, obj):
89 return self.equals(obj)
90 91
92 - def hashCode(self):
93 return self._bitMask
94
95 - def __hash__(self):
96 return self.hashCode()
97