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

Source Code for Module muntjac.ui.alignment

  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 a class containing information about alignment of a component.""" 
 17   
 18  from muntjac.terminal.gwt.client.ui.alignment_info import Bits 
 19   
 20   
21 -class Alignment(object):
22 """Class containing information about alignment of a component. Use 23 the pre-instantiated classes. 24 """ 25 26 TOP_RIGHT = None # see below 27 TOP_LEFT = None 28 TOP_CENTER = None 29 MIDDLE_RIGHT = None 30 MIDDLE_LEFT = None 31 MIDDLE_CENTER = None 32 BOTTOM_RIGHT = None 33 BOTTOM_LEFT = None 34 BOTTOM_CENTER = None 35
36 - def __init__(self, bitMask):
37 self._bitMask = bitMask
38 39
40 - def getBitMask(self):
41 """Returns a bitmask representation of the alignment value. Used 42 internally by terminal. 43 44 @return: the bitmask representation of the alignment value 45 """ 46 return self._bitMask
47 48
49 - def isTop(self):
50 """Checks if component is aligned to the top of the available space. 51 52 @return: true if aligned top 53 """ 54 return (self._bitMask & Bits.ALIGNMENT_TOP) == Bits.ALIGNMENT_TOP
55 56
57 - def isBottom(self):
58 """Checks if component is aligned to the bottom of the available 59 space. 60 61 @return: true if aligned bottom 62 """ 63 return (self._bitMask & Bits.ALIGNMENT_BOTTOM) == \ 64 Bits.ALIGNMENT_BOTTOM
65 66
67 - def isLeft(self):
68 """Checks if component is aligned to the left of the available 69 space. 70 71 @return: true if aligned left 72 """ 73 return (self._bitMask & Bits.ALIGNMENT_LEFT) == Bits.ALIGNMENT_LEFT
74 75
76 - def isRight(self):
77 """Checks if component is aligned to the right of the available space. 78 79 @return: true if aligned right 80 """ 81 return (self._bitMask & Bits.ALIGNMENT_RIGHT) == Bits.ALIGNMENT_RIGHT
82 83
84 - def isMiddle(self):
85 """Checks if component is aligned middle (vertically center) of the 86 available space. 87 88 @return: true if aligned bottom 89 """ 90 return (self._bitMask & Bits.ALIGNMENT_VERTICAL_CENTER) == \ 91 Bits.ALIGNMENT_VERTICAL_CENTER
92 93
94 - def isCenter(self):
95 """Checks if component is aligned center (horizontally) of the 96 available space. 97 98 @return: true if aligned center 99 """ 100 return (self._bitMask & Bits.ALIGNMENT_HORIZONTAL_CENTER) == \ 101 Bits.ALIGNMENT_HORIZONTAL_CENTER
102 103
104 - def getVerticalAlignment(self):
105 """Returns string representation of vertical alignment. 106 107 @return: vertical alignment as CSS value 108 """ 109 if self.isBottom(): 110 return 'bottom' 111 elif self.isMiddle(): 112 return 'middle' 113 return 'top'
114 115
116 - def getHorizontalAlignment(self):
117 """Returns string representation of horizontal alignment. 118 119 @return: horizontal alignment as CSS value 120 """ 121 if self.isRight(): 122 return 'right' 123 elif self.isCenter(): 124 return 'center' 125 return 'left'
126 127
128 - def __eq__(self, obj):
129 if self is obj: 130 return True 131 132 if (obj is None) or (obj.__class__ != self.__class__): 133 return False 134 135 return self._bitMask == obj.bitMask
136 137
138 - def __hash__(self):
139 return self._bitMask
140 141
142 - def __str__(self):
143 return str(self._bitMask)
144 145 146 Alignment.TOP_RIGHT = Alignment((Bits.ALIGNMENT_TOP + 147 Bits.ALIGNMENT_RIGHT)) 148 149 Alignment.TOP_LEFT = Alignment((Bits.ALIGNMENT_TOP + 150 Bits.ALIGNMENT_LEFT)) 151 152 Alignment.TOP_CENTER = Alignment((Bits.ALIGNMENT_TOP + 153 Bits.ALIGNMENT_HORIZONTAL_CENTER)) 154 155 Alignment.MIDDLE_RIGHT = Alignment((Bits.ALIGNMENT_VERTICAL_CENTER + 156 Bits.ALIGNMENT_RIGHT)) 157 158 Alignment.MIDDLE_LEFT = Alignment((Bits.ALIGNMENT_VERTICAL_CENTER + 159 Bits.ALIGNMENT_LEFT)) 160 161 Alignment.MIDDLE_CENTER = Alignment((Bits.ALIGNMENT_VERTICAL_CENTER + 162 Bits.ALIGNMENT_HORIZONTAL_CENTER)) 163 164 Alignment.BOTTOM_RIGHT = Alignment((Bits.ALIGNMENT_BOTTOM + 165 Bits.ALIGNMENT_RIGHT)) 166 167 Alignment.BOTTOM_LEFT = Alignment((Bits.ALIGNMENT_BOTTOM + 168 Bits.ALIGNMENT_LEFT)) 169 170 Alignment.BOTTOM_CENTER = Alignment((Bits.ALIGNMENT_BOTTOM + 171 Bits.ALIGNMENT_HORIZONTAL_CENTER)) 172