<s> """<STR_LIT>""" <EOL> import re <EOL> from muntjac . ui . abstract_layout import AbstractLayout <EOL> from muntjac . terminal . gwt . client . event_id import EventId <EOL> from muntjac . terminal . sizeable import ISizeable <EOL> from muntjac . event . layout_events import LayoutClickEvent , ILayoutClickListener , ILayoutClickNotifier <EOL> from muntjac . util import OrderedSet <EOL> class AbsoluteLayout ( AbstractLayout , ILayoutClickNotifier ) : <EOL> """<STR_LIT>""" <EOL> CLIENT_WIDGET = None <EOL> _CLICK_EVENT = EventId . LAYOUT_CLICK <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( AbsoluteLayout , self ) . __init__ ( ) <EOL> self . _components = OrderedSet ( ) <EOL> self . _componentToCoordinates = dict ( ) <EOL> self . setSizeFull ( ) <EOL> def getComponentIterator ( self ) : <EOL> """<STR_LIT>""" <EOL> return iter ( self . _components ) <EOL> def getComponentCount ( self ) : <EOL> """<STR_LIT>""" <EOL> return len ( self . _components ) <EOL> def replaceComponent ( self , oldComponent , newComponent ) : <EOL> """<STR_LIT>""" <EOL> position = self . getPosition ( oldComponent ) <EOL> self . removeComponent ( oldComponent ) <EOL> self . addComponent ( newComponent ) <EOL> self . _componentToCoordinates [ newComponent ] = position <EOL> def addComponent ( self , c , cssPosition = None ) : <EOL> """<STR_LIT>""" <EOL> if cssPosition is not None : <EOL> position = ComponentPosition ( self ) <EOL> position . setCSSString ( cssPosition ) <EOL> self . _componentToCoordinates [ c ] = position <EOL> self . _components . add ( c ) <EOL> try : <EOL> super ( AbsoluteLayout , self ) . addComponent ( c ) <EOL> self . requestRepaint ( ) <EOL> except ValueError , e : <EOL> self . _components . remove ( c ) <EOL> if cssPosition is not None : <EOL> del self . _componentToCoordinates [ c ] <EOL> raise e <EOL> def removeComponent ( self , c ) : <EOL> if c in self . _components : <EOL> self . _components . remove ( c ) <EOL> if c in self . _componentToCoordinates : <EOL> del self . _componentToCoordinates [ c ] <EOL> super ( AbsoluteLayout , self ) . removeComponent ( c ) <EOL> self . requestRepaint ( ) <EOL> def getPosition ( self , component ) : <EOL> """<STR_LIT>""" <EOL> if component . getParent ( ) != self : <EOL> return None <EOL> elif component in self . _componentToCoordinates : <EOL> return self . _componentToCoordinates . get ( component ) <EOL> else : <EOL> coords = ComponentPosition ( self ) <EOL> self . _componentToCoordinates [ component ] = coords <EOL> return coords <EOL> def paintContent ( self , target ) : <EOL> super ( AbsoluteLayout , self ) . paintContent ( target ) <EOL> for component in self . _components : <EOL> target . startTag ( '<STR_LIT>' ) <EOL> css = self . getPosition ( component ) . getCSSString ( ) <EOL> target . addAttribute ( '<STR_LIT>' , css ) <EOL> component . paint ( target ) <EOL> target . endTag ( '<STR_LIT>' ) <EOL> def addListener ( self , listener , iface = None ) : <EOL> if ( isinstance ( listener , ILayoutClickListener ) and <EOL> ( iface is None or issubclass ( iface , ILayoutClickListener ) ) ) : <EOL> self . registerListener ( self . _CLICK_EVENT , LayoutClickEvent , <EOL> listener , ILayoutClickListener . clickMethod ) <EOL> super ( AbsoluteLayout , self ) . addListener ( listener , iface ) <EOL> def addCallback ( self , callback , eventType = None , * args ) : <EOL> if eventType is None : <EOL> eventType = callback . _eventType <EOL> if issubclass ( eventType , LayoutClickEvent ) : <EOL> self . registerCallback ( LayoutClickEvent , callback , <EOL> self . _CLICK_EVENT , * args ) <EOL> else : <EOL> super ( AbsoluteLayout , self ) . addCallback ( callback , eventType , * args ) <EOL> def removeListener ( self , listener , iface = None ) : <EOL> if ( isinstance ( listener , ILayoutClickListener ) and <EOL> ( iface is None or issubclass ( iface , ILayoutClickListener ) ) ) : <EOL> self . withdrawListener ( self . _CLICK_EVENT , LayoutClickEvent , <EOL> listener ) <EOL> super ( AbsoluteLayout , self ) . removeListener ( listener , iface ) <EOL> def removeCallback ( self , callback , eventType = None ) : <EOL> if eventType is None : <EOL> eventType = callback . _eventType <EOL> if issubclass ( eventType , LayoutClickEvent ) : <EOL> self . withdrawCallback ( LayoutClickEvent , callback , <EOL> self . _CLICK_EVENT ) <EOL> else : <EOL> super ( AbsoluteLayout , self ) . removeCallback ( callback , eventType ) <EOL> class ComponentPosition ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , layout ) : <EOL> self . _zIndex = - <NUM_LIT:1> <EOL> self . _topValue = None <EOL> self . _rightValue = None <EOL> self . _bottomValue = None <EOL> self . _leftValue = None <EOL> self . _topUnits = <NUM_LIT:0> <EOL> self . _rightUnits = <NUM_LIT:0> <EOL> self . _bottomUnits = <NUM_LIT:0> <EOL> self . _leftUnits = <NUM_LIT:0> <EOL> self . _layout = layout <EOL> def setCSSString ( self , css ) : <EOL> """<STR_LIT>""" <EOL> self . _topValue = self . _bottomValue = None <EOL> self . _rightValue = self . _leftValue = None <EOL> self . _topUnits = self . _bottomUnits = <NUM_LIT:0> <EOL> self . _rightUnits = self . _leftUnits = <NUM_LIT:0> <EOL> self . _zIndex = - <NUM_LIT:1> <EOL> if css is None : <EOL> return <EOL> cssProperties = css . split ( '<STR_LIT:;>' ) <EOL> for i in range ( len ( cssProperties ) ) : <EOL> keyValuePair = cssProperties [ i ] . split ( '<STR_LIT::>' ) <EOL> key = keyValuePair [ <NUM_LIT:0> ] . strip ( ) <EOL> if key == '<STR_LIT>' : <EOL> continue <EOL> if key == '<STR_LIT>' : <EOL> self . _zIndex = int ( keyValuePair [ <NUM_LIT:1> ] . strip ( ) ) <EOL> else : <EOL> if len ( keyValuePair ) > <NUM_LIT:1> : <EOL> value = keyValuePair [ <NUM_LIT:1> ] . strip ( ) <EOL> else : <EOL> value = '<STR_LIT>' <EOL> unit = re . sub ( '<STR_LIT>' , '<STR_LIT>' , value ) <EOL> if not ( unit == '<STR_LIT>' ) : <EOL> value = value [ : value . find ( unit ) ] . strip ( ) <EOL> v = float ( value ) <EOL> unitInt = self . parseCssUnit ( unit ) <EOL> if key == '<STR_LIT>' : <EOL> self . _topValue = v <EOL> self . _topUnits = unitInt <EOL> elif key == '<STR_LIT:right>' : <EOL> self . _rightValue = v <EOL> self . _rightUnits = unitInt <EOL> elif key == '<STR_LIT>' : <EOL> self . _bottomValue = v <EOL> self . _bottomUnits = unitInt <EOL> elif key == '<STR_LIT:left>' : <EOL> self . _leftValue = v <EOL> self . _leftUnits = unitInt <EOL> self . _layout . requestRepaint ( ) <EOL> def parseCssUnit ( self , string ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( len ( ISizeable . UNIT_SYMBOLS ) ) : <EOL> if ISizeable . UNIT_SYMBOLS [ i ] == string : <EOL> return i <EOL> return <NUM_LIT:0> <EOL> def getCSSString ( self ) : <EOL> """<STR_LIT>""" <EOL> s = '<STR_LIT>' <EOL> if self . _topValue is not None : <EOL> symbol = ISizeable . UNIT_SYMBOLS [ self . _topUnits ] <EOL> s += '<STR_LIT>' + str ( self . _topValue ) + symbol + '<STR_LIT:;>' <EOL> if self . _rightValue is not None : <EOL> symbol = ISizeable . UNIT_SYMBOLS [ self . _rightUnits ] <EOL> s += '<STR_LIT>' + str ( self . _rightValue ) + symbol + '<STR_LIT:;>' <EOL> if self . _bottomValue is not None : <EOL> symbol = ISizeable . UNIT_SYMBOLS [ self . _bottomUnits ] <EOL> s += '<STR_LIT>' + str ( self . _bottomValue ) + symbol + '<STR_LIT:;>' <EOL> if self . _leftValue is not None : <EOL> symbol = ISizeable . UNIT_SYMBOLS [ self . _leftUnits ] <EOL> s += '<STR_LIT>' + str ( self . _leftValue ) + symbol + '<STR_LIT:;>' <EOL> if self . _zIndex >= <NUM_LIT:0> : <EOL> s += '<STR_LIT>' + str ( self . _zIndex ) + '<STR_LIT:;>' <EOL> return s <EOL> def setTop ( self , topValue , topUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _topValue = topValue <EOL> self . _topUnits = topUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def setRight ( self , rightValue , rightUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _rightValue = rightValue <EOL> self . _rightUnits = rightUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def setBottom ( self , bottomValue , bottomUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _bottomValue = bottomValue <EOL> self . _bottomUnits = bottomUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def setLeft ( self , leftValue , leftUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _leftValue = leftValue <EOL> self . _leftUnits = leftUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def setZIndex ( self , zIndex ) : <EOL> """<STR_LIT>""" <EOL> self . _zIndex = zIndex <EOL> self . _layout . requestRepaint ( ) <EOL> def setTopValue ( self , topValue ) : <EOL> """<STR_LIT>""" <EOL> self . _topValue = topValue <EOL> self . _layout . requestRepaint ( ) <EOL> def getTopValue ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _topValue <EOL> def getRightValue ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _rightValue <EOL> def setRightValue ( self , rightValue ) : <EOL> """<STR_LIT>""" <EOL> self . _rightValue = rightValue <EOL> self . _layout . requestRepaint ( ) <EOL> def getBottomValue ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _bottomValue <EOL> def setBottomValue ( self , bottomValue ) : <EOL> """<STR_LIT>""" <EOL> self . _bottomValue = bottomValue <EOL> self . _layout . requestRepaint ( ) <EOL> def getLeftValue ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _leftValue <EOL> def setLeftValue ( self , leftValue ) : <EOL> """<STR_LIT>""" <EOL> self . _leftValue = leftValue <EOL> self . _layout . requestRepaint ( ) <EOL> def getTopUnits ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _topUnits <EOL> def setTopUnits ( self , topUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _topUnits = topUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def getRightUnits ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _rightUnits <EOL> def setRightUnits ( self , rightUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _rightUnits = rightUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def getBottomUnits ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _bottomUnits <EOL> def setBottomUnits ( self , bottomUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _bottomUnits = bottomUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def getLeftUnits ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _leftUnits <EOL> def setLeftUnits ( self , leftUnits ) : <EOL> """<STR_LIT>""" <EOL> self . _leftUnits = leftUnits <EOL> self . _layout . requestRepaint ( ) <EOL> def getZIndex ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _zIndex <EOL> def toString ( self ) : <EOL> return self . getCSSString ( ) </s>
