<s> """<STR_LIT>""" <EOL> from java import awt <EOL> from java . applet import Applet <EOL> from java . awt . event import ActionListener , ItemListener , AdjustmentListener <EOL> from pawt import GridBag <EOL> basicUnits = [ [ '<STR_LIT>' , [ ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1.0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) ] ] , <EOL> [ '<STR_LIT>' , [ ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) ] ] <EOL> ] <EOL> class SimpleBorder : <EOL> def paint ( self , g ) : <EOL> g . drawRect ( <NUM_LIT:0> , <NUM_LIT:0> , self . size . width - <NUM_LIT:1> , self . size . height - <NUM_LIT:1> ) <EOL> def getInsets ( self ) : <EOL> return awt . Insets ( <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> ) <EOL> class Converter ( Applet , SimpleBorder ) : <EOL> def init ( self , unitSets = basicUnits ) : <EOL> self . setLayout ( awt . GridLayout ( <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:5> ) ) <EOL> self . panels = [ ] <EOL> for name , units in unitSets : <EOL> panel = ConversionPanel ( name , units , self ) <EOL> self . panels . append ( panel ) <EOL> self . add ( panel ) <EOL> def convert ( self , master ) : <EOL> value = master . getValue ( ) <EOL> multiplier = master . getMultiplier ( ) <EOL> for panel in self . panels : <EOL> if panel is not master : <EOL> panel . setValue ( multiplier / panel . getMultiplier ( ) * value ) <EOL> class ConversionPanel ( awt . Panel , SimpleBorder , <EOL> ActionListener , AdjustmentListener , ItemListener ) : <EOL> max , block = <NUM_LIT> , <NUM_LIT:100> <EOL> def __init__ ( self , title , units , controller ) : <EOL> self . units = units <EOL> self . controller = controller <EOL> bag = GridBag ( self , fill = '<STR_LIT>' ) <EOL> label = awt . Label ( title , awt . Label . CENTER ) <EOL> bag . addRow ( label ) <EOL> self . text = awt . TextField ( '<STR_LIT:0>' , <NUM_LIT:10> , actionListener = self ) <EOL> bag . add ( self . text , weightx = <NUM_LIT:1.0> ) <EOL> self . chooser = awt . Choice ( itemListener = self ) <EOL> for name , multiplier in units : <EOL> self . chooser . add ( name ) <EOL> bag . addRow ( self . chooser ) <EOL> self . slider = awt . Scrollbar ( awt . Scrollbar . HORIZONTAL , <EOL> maximum = self . max + <NUM_LIT:10> , <EOL> blockIncrement = self . block , <EOL> adjustmentListener = self ) <EOL> bag . add ( self . slider ) <EOL> def getMultiplier ( self ) : <EOL> return self . units [ self . chooser . selectedIndex ] [ <NUM_LIT:1> ] <EOL> def getValue ( self ) : <EOL> try : <EOL> return float ( self . text . getText ( ) ) <EOL> except : <EOL> return <NUM_LIT:0.0> <EOL> def actionPerformed ( self , e ) : <EOL> self . setSlider ( self . getValue ( ) ) <EOL> self . controller . convert ( self ) <EOL> def itemStateChanged ( self , e ) : <EOL> self . controller . convert ( self ) <EOL> def adjustmentValueChanged ( self , e ) : <EOL> self . text . setText ( str ( e . getValue ( ) ) ) <EOL> self . controller . convert ( self ) <EOL> def setValue ( self , v ) : <EOL> self . text . setText ( str ( v ) ) <EOL> self . setSlider ( v ) <EOL> def setSlider ( self , f ) : <EOL> if f > self . max : <EOL> f = self . max <EOL> if f < <NUM_LIT:0> : <EOL> f = <NUM_LIT:0> <EOL> self . slider . value = int ( f ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import pawt <EOL> pawt . test ( Converter ( ) ) </s>
