<s> from pyjamas import DOM <EOL> from pyjamas import Factory <EOL> from pyjamas . ui . PopupPanel import PopupPanel <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . FlexTable import FlexTable <EOL> from pyjamas . ui import HasHorizontalAlignment <EOL> from pyjamas . ui import HasVerticalAlignment <EOL> from pyjamas . ui import GlassWidget <EOL> class DialogBox ( PopupPanel ) : <EOL> _props = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ] <EOL> def __init__ ( self , autoHide = None , modal = True , ** kwargs ) : <EOL> self . dragging = False <EOL> self . dragStartX = <NUM_LIT:0> <EOL> self . dragStartY = <NUM_LIT:0> <EOL> self . child = None <EOL> self . panel = FlexTable ( <EOL> Height = "<STR_LIT>" , <EOL> BorderWidth = "<STR_LIT:0>" , <EOL> CellPadding = "<STR_LIT:0>" , <EOL> CellSpacing = "<STR_LIT:0>" , <EOL> ) <EOL> cf = self . panel . getCellFormatter ( ) <EOL> cf . setHeight ( <NUM_LIT:1> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> cf . setWidth ( <NUM_LIT:1> , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> cf . setAlignment ( <EOL> <NUM_LIT:1> , <NUM_LIT:0> , <EOL> HasHorizontalAlignment . ALIGN_CENTER , <EOL> HasVerticalAlignment . ALIGN_MIDDLE , <EOL> ) <EOL> self . modal = modal <EOL> self . caption = HTML ( ) <EOL> self . panel . setWidget ( <NUM_LIT:0> , <NUM_LIT:0> , self . caption ) <EOL> self . caption . setStyleName ( "<STR_LIT>" ) <EOL> self . caption . addMouseListener ( self ) <EOL> kwargs [ '<STR_LIT>' ] = kwargs . get ( '<STR_LIT>' , "<STR_LIT>" ) <EOL> PopupPanel . __init__ ( self , autoHide , modal , ** kwargs ) <EOL> PopupPanel . setWidget ( self , self . panel ) <EOL> @ classmethod <EOL> def _getProps ( self ) : <EOL> return PopupPanel . _getProps ( ) + self . _props <EOL> def onEventPreview ( self , event ) : <EOL> type = DOM . eventGetType ( event ) <EOL> if type == '<STR_LIT>' : <EOL> target = DOM . eventGetTarget ( event ) <EOL> elem = self . caption . getElement ( ) <EOL> event_targets_popup = target and DOM . isOrHasChild ( elem , target ) <EOL> if event_targets_popup : <EOL> DOM . eventPreventDefault ( event ) <EOL> return PopupPanel . onEventPreview ( self , event ) <EOL> def getHTML ( self ) : <EOL> return self . caption . getHTML ( ) <EOL> def getText ( self ) : <EOL> return self . caption . getText ( ) <EOL> def setHTML ( self , html ) : <EOL> self . caption . setHTML ( html ) <EOL> def setText ( self , text ) : <EOL> self . caption . setText ( text ) <EOL> def onMouseDown ( self , sender , x , y ) : <EOL> self . dragging = True <EOL> GlassWidget . show ( self . caption ) <EOL> self . dragStartX = x <EOL> self . dragStartY = y <EOL> def onMouseEnter ( self , sender ) : <EOL> pass <EOL> def onMouseLeave ( self , sender ) : <EOL> pass <EOL> def onMouseMove ( self , sender , x , y ) : <EOL> if not self . dragging : <EOL> return <EOL> absX = x + self . getAbsoluteLeft ( ) <EOL> absY = y + self . getAbsoluteTop ( ) <EOL> self . setPopupPosition ( absX - self . dragStartX , <EOL> absY - self . dragStartY ) <EOL> def onMouseUp ( self , sender , x , y ) : <EOL> self . endDragging ( ) <EOL> def onMouseGlassEnter ( self , sender ) : <EOL> pass <EOL> def onMouseGlassLeave ( self , sender ) : <EOL> self . endDragging ( ) <EOL> def endDragging ( self ) : <EOL> if not self . dragging : <EOL> return <EOL> self . dragging = False <EOL> GlassWidget . hide ( ) <EOL> def remove ( self , widget ) : <EOL> if self . child != widget : <EOL> return False <EOL> self . panel . remove ( widget ) <EOL> self . child = None <EOL> return True <EOL> def doAttachChildren ( self ) : <EOL> PopupPanel . doAttachChildren ( self ) <EOL> self . caption . onAttach ( ) <EOL> def doDetachChildren ( self ) : <EOL> PopupPanel . doDetachChildren ( self ) <EOL> self . caption . onDetach ( ) <EOL> def setWidget ( self , widget ) : <EOL> if self . child is not None : <EOL> self . panel . remove ( self . child ) <EOL> if widget is not None : <EOL> self . panel . setWidget ( <NUM_LIT:1> , <NUM_LIT:0> , widget ) <EOL> self . child = widget <EOL> def onWindowResized ( self , width , height ) : <EOL> super ( DialogBox , self ) . onWindowResized ( width , height ) <EOL> def show ( self ) : <EOL> super ( DialogBox , self ) . show ( ) <EOL> Factory . registerClass ( '<STR_LIT>' , '<STR_LIT>' , DialogBox ) </s>
