<s> """<STR_LIT>""" <EOL> from __pyjamas__ import console <EOL> from pyjamas import DOM <EOL> from pyjamas import Window <EOL> from pyjamas . DeferredCommand import queue_Call <EOL> from pyjamas . EventController import EventGenerator <EOL> from pyjamas . ui import GlassWidget <EOL> from pyjamas . ui . SimplePanel import SimplePanel <EOL> from pyjamas . ui . AbsolutePanel import AbsolutePanel <EOL> from pyjamas . ui . ScrollPanel import ScrollPanel <EOL> from pyjamas . ui . MouseListener import MouseHandler , fireMouseEvent <EOL> from pyjamas . ui import Event <EOL> class SplitPanelSplitter ( SimplePanel , MouseHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , splitPanel , ** kwargs ) : <EOL> self . _splitpanel = splitPanel <EOL> SimplePanel . __init__ ( self , ** kwargs ) <EOL> MouseHandler . __init__ ( self ) <EOL> self . addMouseListener ( self ) <EOL> elem = self . getElement ( ) <EOL> DOM . setStyleAttribute ( elem , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def onMouseDown ( self , sender , x , y ) : <EOL> """<STR_LIT>""" <EOL> ev = DOM . eventGetCurrentEvent ( ) <EOL> if DOM . eventGetButton ( ev ) != Event . BUTTON_LEFT : <EOL> return <EOL> DOM . eventPreventDefault ( DOM . eventGetCurrentEvent ( ) ) <EOL> self . _splitpanel . startSplitterDrag ( x , y ) <EOL> class SplitPanel ( AbsolutePanel , MouseHandler , EventGenerator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , vertical = False , ** kwargs ) : <EOL> if not '<STR_LIT>' in kwargs : <EOL> if vertical : <EOL> kwargs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> else : <EOL> kwargs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> self . _drag_start = None <EOL> self . _pos = "<STR_LIT>" <EOL> self . _vertical = vertical <EOL> AbsolutePanel . __init__ ( self , ** kwargs ) <EOL> MouseHandler . __init__ ( self ) <EOL> self . addListenedEvent ( "<STR_LIT>" ) <EOL> self . _container1 = ScrollPanel ( ) <EOL> self . _container2 = ScrollPanel ( ) <EOL> self . _splitter = SplitPanelSplitter ( self ) <EOL> self . _splitter . addMouseListener ( self ) <EOL> self . addMouseListener ( self ) <EOL> AbsolutePanel . add ( self , self . _container1 , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> AbsolutePanel . add ( self , self . _splitter , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> AbsolutePanel . add ( self , self . _container2 , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> if vertical : <EOL> self . _splitter . setStyleName ( "<STR_LIT>" ) <EOL> self . _splitter . setWidth ( "<STR_LIT>" ) <EOL> self . _container1 . setWidth ( "<STR_LIT>" ) <EOL> self . _container2 . setWidth ( "<STR_LIT>" ) <EOL> DOM . setStyleAttribute ( self . _splitter . getElement ( ) , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> else : <EOL> self . _splitter . setStyleName ( "<STR_LIT>" ) <EOL> self . _splitter . setHeight ( "<STR_LIT>" ) <EOL> self . _container1 . setHeight ( "<STR_LIT>" ) <EOL> self . _container2 . setHeight ( "<STR_LIT>" ) <EOL> DOM . setStyleAttribute ( self . _splitter . getElement ( ) , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def onAttach ( self ) : <EOL> AbsolutePanel . onAttach ( self ) <EOL> self . setSplitPosition ( ) <EOL> def _finalizePositions ( self , pos = None ) : <EOL> finalized = False <EOL> if self . _vertical : <EOL> if pos is None : <EOL> pos = self . _container1 . getOffsetHeight ( ) <EOL> space = self . getOffsetHeight ( ) <EOL> sz = self . _splitter . getOffsetHeight ( ) <EOL> if space > <NUM_LIT:0> and sz > <NUM_LIT:0> and pos > <NUM_LIT:0> : <EOL> if pos > space - sz : <EOL> pos = space - sz <EOL> self . _container1 . setHeight ( pos ) <EOL> self . setWidgetPosition ( self . _splitter , <NUM_LIT:0> , pos ) <EOL> self . setWidgetPosition ( self . _container2 , <NUM_LIT:0> , pos + sz ) <EOL> self . _container2 . setHeight ( space - ( pos + sz ) ) <EOL> finalized = True <EOL> else : <EOL> if pos is None : <EOL> pos = self . _container1 . getOffsetWidth ( ) <EOL> space = self . getOffsetWidth ( ) <EOL> sz = self . _splitter . getOffsetWidth ( ) <EOL> if space > <NUM_LIT:0> and sz > <NUM_LIT:0> and pos > <NUM_LIT:0> : <EOL> if pos > space - sz : <EOL> pos = space - sz <EOL> self . _container1 . setWidth ( pos ) <EOL> self . setWidgetPosition ( self . _splitter , pos , <NUM_LIT:0> ) <EOL> self . setWidgetPosition ( self . _container2 , pos + sz , <NUM_LIT:0> ) <EOL> self . _container2 . setWidth ( space - ( pos + sz ) ) <EOL> finalized = True <EOL> if finalized : <EOL> self . dispatchResizeEvent ( self , pos ) <EOL> return finalized <EOL> def _stopDragging ( self ) : <EOL> if self . _drag_start is not None : <EOL> self . _drag_start = None <EOL> GlassWidget . hide ( ) <EOL> DOM . eventCancelBubble ( DOM . eventGetCurrentEvent ( ) , True ) <EOL> def _isDragging ( self ) : <EOL> return self . _drag_start is not None <EOL> def startSplitterDrag ( self , x , y ) : <EOL> if self . _drag_start is None : <EOL> if self . _vertical : <EOL> self . _drag_start = y <EOL> else : <EOL> self . _drag_start = x <EOL> GlassWidget . show ( self ) <EOL> def onMouseMove ( self , sender , x , y ) : <EOL> if not self . _isDragging ( ) : <EOL> return <EOL> if self . _vertical : <EOL> self . _pos = y - self . _drag_start <EOL> else : <EOL> self . _pos = x - self . _drag_start <EOL> if self . _pos < <NUM_LIT:1> : <EOL> self . _pos = <NUM_LIT:1> <EOL> self . setSplitPosition ( ) <EOL> def onMouseUp ( self , sender , x , y ) : <EOL> ev = DOM . eventGetCurrentEvent ( ) <EOL> if DOM . eventGetButton ( ev ) != Event . BUTTON_LEFT : <EOL> return <EOL> DOM . eventPreventDefault ( ev ) <EOL> if self . _isDragging ( ) : <EOL> self . _stopDragging ( ) <EOL> def onMouseGlassEnter ( self , sender ) : <EOL> pass <EOL> def onMouseGlassLeave ( self , sender ) : <EOL> self . _stopDragging ( ) <EOL> def setSplitPosition ( self , pos = None ) : <EOL> if pos is not None : <EOL> self . _pos = pos <EOL> else : <EOL> pos = self . _pos <EOL> if pos < <NUM_LIT:1> : <EOL> pos = <NUM_LIT:1> <EOL> self . _pos = pos <EOL> if self . _vertical : <EOL> self . _container1 . setHeight ( pos ) <EOL> else : <EOL> self . _container1 . setWidth ( pos ) <EOL> finalized = False <EOL> if isinstance ( pos , int ) : <EOL> finalized = self . _finalizePositions ( pos ) <EOL> if not finalized : <EOL> queue_Call ( self . _finalizePositions ) <EOL> def getWidget ( self , index ) : <EOL> if index == <NUM_LIT:0> : <EOL> return self . _container1 . getWidget ( ) <EOL> return self . _container2 . getWidget ( ) <EOL> def setWidget ( self , index , widget ) : <EOL> if index == <NUM_LIT:0> : <EOL> return self . _container1 . setWidget ( widget ) <EOL> return self . _container2 . setWidget ( widget ) <EOL> def add ( self , widget ) : <EOL> if self . getWidget ( <NUM_LIT:0> ) == None : <EOL> self . setWidget ( <NUM_LIT:0> , widget ) <EOL> elif self . getWidget ( <NUM_LIT:1> ) == None : <EOL> self . setWidget ( <NUM_LIT:1> , widget ) <EOL> else : <EOL> console . error ( "<STR_LIT>" ) <EOL> def remove ( self , widget ) : <EOL> if self . getWidget ( <NUM_LIT:0> ) == widget : <EOL> self . _container1 . remove ( widget ) <EOL> elif self . getWidget ( <NUM_LIT:1> ) == widget : <EOL> self . _container2 . remove ( widget ) <EOL> else : <EOL> AbsolutePanel . remove ( self , widget ) <EOL> def getElement ( self , index = None ) : <EOL> if index is None : <EOL> return AbsolutePanel . getElement ( self ) <EOL> return self . getWidget ( index ) . getElement ( ) <EOL> def getEndOfLineWidget ( self ) : <EOL> return self . getWidget ( <NUM_LIT:1> ) <EOL> def getSplitElement ( self ) : <EOL> return self . _splitter . getElement ( ) <EOL> def getStartOfLineWidget ( self ) : <EOL> return self . getWidget ( <NUM_LIT:0> ) <EOL> def isResizing ( self ) : <EOL> return False <EOL> def setEndOfLineWidget ( self , widget ) : <EOL> self . setWidget ( <NUM_LIT:1> , widget ) <EOL> def setStartOfLineWidget ( self , widget ) : <EOL> self . setWidget ( <NUM_LIT:0> , widget ) </s>
