/* UserInputFrame.java User Input Frame - allows users to provide data Note: need to reset text_complete when text is changed */ package ciips.animation; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; import java.net.*; import java.lang.reflect.*; /** * User input frame which pops up when user input is allowed * @see AlgAnimFrame */ public class UIFrame extends Frame implements ActionListener { private AlgAnimFrame parent; private static final boolean DEBUG = true; private static boolean user_input_allowed = false; private static int DEF_ROWS = 10, DEF_COLUMNS = 30; private Panel text_input; private TextArea ta = null; private Button text_ok = null; private boolean text_complete = false; private Panel file_input; public static void allowUI( boolean UI_allowed ) { user_input_allowed = UI_allowed; } public static boolean isUIAllowed() { return user_input_allowed; } public UIFrame( AlgAnimFrame parent_frame, String algname ) { if ( !user_input_allowed ) return; // Don't create a user input frame setTitle("User Input for " + algname); if( DEBUG ) System.out.println("UIFrame - User input allowed "); setLayout( new BorderLayout() ); // setFont(helv14); // Make the text input panel text_input = new Panel(); text_input.setLayout( new FlowLayout() ); TextField prompt = new TextField( "Type desired input, click OK" ); prompt.setEditable( false ); text_input.add( prompt ); ta = new TextArea( DEF_ROWS, DEF_COLUMNS ); text_input.add( ta ); text_ok = new Button( "OK" ); text_ok.addActionListener( this ); add("North", text_input); file_input = new Panel(); Label f_input = new Label( "File Input" ); file_input.add( f_input ); Label not_imp = new Label( "Not implemented yet" ); file_input.add( not_imp ); add( BorderLayout.SOUTH, file_input ); setVisible( false ); } public void setVisible( boolean visible ) { if ( !user_input_allowed ) return; if ( visible ) { if( DEBUG ) System.out.println("User Input Window Visible"); validate(); } super.setVisible( visible ); } public String getTextInput() { if( text_complete ) { text_complete = false; // Grey out text? return ta.getText(); } else return null; } public void actionPerformed( ActionEvent e ) { if( DEBUG ) System.out.println("UIFrame:actionPerformed - from " + e.getSource() ); if ( e.getSource() == text_ok ) { text_complete = true; } } } // class UIFrame