<s> from Sink import Sink , SinkInfo <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . PasswordTextBox import PasswordTextBox <EOL> from pyjamas . ui . TextArea import TextArea <EOL> from pyjamas . ui . TextBox import TextBox <EOL> from pyjamas . ui . TextBoxBase import TextBoxBase <EOL> from pyjamas . ui . VerticalPanel import VerticalPanel <EOL> from pyjamas . ui . Widget import Widget <EOL> class Text ( Sink ) : <EOL> def __init__ ( self ) : <EOL> Sink . __init__ ( self ) <EOL> self . fPasswordText = PasswordTextBox ( ) <EOL> self . fTextArea = TextArea ( ) <EOL> self . fTextBox = TextBox ( ) <EOL> panel = VerticalPanel ( ) <EOL> panel . setSpacing ( <NUM_LIT:8> ) <EOL> panel . add ( HTML ( "<STR_LIT>" ) ) <EOL> panel . add ( self . createTextThing ( self . fTextBox ) ) <EOL> panel . add ( HTML ( "<STR_LIT>" ) ) <EOL> panel . add ( self . createTextThing ( self . fPasswordText ) ) <EOL> panel . add ( HTML ( "<STR_LIT>" ) ) <EOL> panel . add ( self . createTextThing ( self . fTextArea ) ) <EOL> panel . add ( HTML ( """<STR_LIT>""" ) ) <EOL> vp = VerticalPanel ( ) <EOL> self . echo = HTML ( ) <EOL> textArea = TextArea ( ) <EOL> vp . add ( textArea ) <EOL> vp . add ( self . echo ) <EOL> textArea . addInputListener ( self ) <EOL> panel . add ( vp ) <EOL> self . initWidget ( panel ) <EOL> def onShow ( self ) : <EOL> pass <EOL> def onInput ( self , sender ) : <EOL> self . echo . setText ( sender . getText ( ) ) <EOL> def createTextThing ( self , textBox ) : <EOL> p = HorizontalPanel ( ) <EOL> p . setSpacing ( <NUM_LIT:4> ) <EOL> p . add ( textBox ) <EOL> echo = HTML ( ) <EOL> select_all = Button ( "<STR_LIT>" ) <EOL> p . add ( select_all ) <EOL> p . add ( echo ) <EOL> listener = TextBoxListener ( self , textBox , echo , select_all ) <EOL> select_all . addClickListener ( listener ) <EOL> textBox . addKeyboardListener ( listener ) <EOL> textBox . addClickListener ( listener ) <EOL> return p <EOL> def updateText ( self , text , echo ) : <EOL> echo . setHTML ( "<STR_LIT>" + text . getText ( ) + "<STR_LIT>" + "<STR_LIT>" % text . getCursorPos ( ) + "<STR_LIT>" % text . getSelectionLength ( ) ) <EOL> class TextBoxListener : <EOL> def __init__ ( self , parent , textBox , echo , select_all ) : <EOL> self . textBox = textBox <EOL> self . echo = echo <EOL> self . parent = parent <EOL> self . select_all = select_all <EOL> def onClick ( self , sender ) : <EOL> if sender == self . select_all : <EOL> self . textBox . selectAll ( ) <EOL> self . textBox . setFocus ( True ) <EOL> self . parent . updateText ( self . textBox , self . echo ) <EOL> def onKeyUp ( self , sender , keyCode , modifiers ) : <EOL> self . parent . updateText ( self . textBox , self . echo ) <EOL> def onKeyDown ( self , sender , keyCode , modifiers ) : <EOL> pass <EOL> def onKeyPress ( self , sender , keyCode , modifiers ) : <EOL> pass <EOL> def init ( ) : <EOL> text = "<STR_LIT>" <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" <EOL> text += "<STR_LIT>" <EOL> return SinkInfo ( "<STR_LIT>" , text , Text ) </s>
