<s> import time <EOL> from java . awt import GridLayout <EOL> from java . awt . event import WindowAdapter <EOL> from javax . swing import JLabel , JOptionPane , JPanel , JPasswordField , JTextField <EOL> from javax . swing . JOptionPane import PLAIN_MESSAGE , UNINITIALIZED_VALUE , YES_NO_OPTION , OK_CANCEL_OPTION , OK_OPTION , DEFAULT_OPTION <EOL> class _SwingDialog ( object ) : <EOL> def __init__ ( self , pane ) : <EOL> self . _pane = pane <EOL> def show ( self ) : <EOL> self . _show_dialog ( self . _pane ) <EOL> return self . _get_value ( self . _pane ) <EOL> def _show_dialog ( self , pane ) : <EOL> dialog = pane . createDialog ( None , '<STR_LIT>' ) <EOL> dialog . setModal ( False ) <EOL> dialog . setAlwaysOnTop ( True ) <EOL> dialog . addWindowFocusListener ( pane . focus_listener ) <EOL> dialog . show ( ) <EOL> while dialog . isShowing ( ) : <EOL> time . sleep ( <NUM_LIT> ) <EOL> dialog . dispose ( ) <EOL> def _get_value ( self , pane ) : <EOL> value = pane . getInputValue ( ) <EOL> return value if value != UNINITIALIZED_VALUE else None <EOL> class MessageDialog ( _SwingDialog ) : <EOL> def __init__ ( self , message ) : <EOL> pane = WrappedOptionPane ( message , PLAIN_MESSAGE , DEFAULT_OPTION ) <EOL> _SwingDialog . __init__ ( self , pane ) <EOL> class InputDialog ( _SwingDialog ) : <EOL> def __init__ ( self , message , default , hidden = False ) : <EOL> self . _input_field = JPasswordField ( ) if hidden else JTextField ( ) <EOL> self . _input_field . setText ( default ) <EOL> self . _input_field . selectAll ( ) <EOL> panel = JPanel ( layout = GridLayout ( <NUM_LIT:2> , <NUM_LIT:1> ) ) <EOL> panel . add ( JLabel ( message ) ) <EOL> panel . add ( self . _input_field ) <EOL> pane = WrappedOptionPane ( panel , PLAIN_MESSAGE , OK_CANCEL_OPTION ) <EOL> pane . set_focus_listener ( self . _input_field ) <EOL> _SwingDialog . __init__ ( self , pane ) <EOL> def _get_value ( self , pane ) : <EOL> if pane . getValue ( ) != OK_OPTION : <EOL> return None <EOL> return self . _input_field . getText ( ) <EOL> class SelectionDialog ( _SwingDialog ) : <EOL> def __init__ ( self , message , options ) : <EOL> pane = WrappedOptionPane ( message , PLAIN_MESSAGE , OK_CANCEL_OPTION ) <EOL> pane . setWantsInput ( True ) <EOL> pane . setSelectionValues ( options ) <EOL> _SwingDialog . __init__ ( self , pane ) <EOL> class PassFailDialog ( _SwingDialog ) : <EOL> def __init__ ( self , message ) : <EOL> pane = WrappedOptionPane ( message , PLAIN_MESSAGE , YES_NO_OPTION , <EOL> None , [ '<STR_LIT>' , '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> _SwingDialog . __init__ ( self , pane ) <EOL> def _get_value ( self , pane ) : <EOL> return pane . getValue ( ) == '<STR_LIT>' <EOL> class WrappedOptionPane ( JOptionPane ) : <EOL> focus_listener = None <EOL> def getMaxCharactersPerLineCount ( self ) : <EOL> return <NUM_LIT> <EOL> def set_focus_listener ( self , component ) : <EOL> self . focus_listener = WindowFocusListener ( component ) <EOL> class WindowFocusListener ( WindowAdapter ) : <EOL> def __init__ ( self , component ) : <EOL> self . component = component <EOL> def windowGainedFocus ( self , event ) : <EOL> self . component . requestFocusInWindow ( ) </s>
