001    package sale.stdforms;
002    
003    import sale.*;
004    
005    import util.swing.*;
006    
007    import javax.swing.*;
008    
009    /**
010     * A simple FormSheet that displays a label and an {@link JTextInput input line}.
011     *
012     * <p>The FormSheet uses a {@link sale.FormSheetContentCreator} to create its contents.</p>
013     *
014     * @author Steffen Zschaler
015     * @version 2.0 12/07/1999
016     * @since v2.0
017     */
018    public class TextInputForm extends FormSheet {
019    
020        /**
021         * The String array that will hold the text that was entered into the text field.
022         *
023         * @serial
024         */
025        private String[] m_asResult = new String[] {
026                ""};
027    
028        /**
029         * Create a new TextInputForm.
030         *
031         * @param sCaption the caption of the FormSheet.
032         * @param sLabel the label to be put at the top of the FormSheet.
033         * @param sInitialText the text that is to appear in the input line when the user has not entered anything
034         * yet.
035         * @param fWaitResponse, the initial value for the "{@link FormSheet#waitResponse}" property.
036         */
037        public TextInputForm(String sCaption, final String sLabel, String sInitialText, boolean fWaitResponse) {
038            super(sCaption, (JComponent)null, fWaitResponse);
039    
040            m_asResult[0] = sInitialText;
041    
042            addContentCreator(new FormSheetContentCreator() {
043                protected void createFormSheetContent(FormSheet fs) {
044    
045                    JPanel jpForm = new JPanel();
046                    Box b = Box.createVerticalBox();
047    
048                    b.add(Box.createVerticalGlue());
049                    b.add(new JLabel(sLabel));
050                    b.add(new JTextInput(m_asResult, m_asResult[0]));
051                    b.add(Box.createGlue());
052    
053                    jpForm.add(b);
054    
055                    fs.setComponent(jpForm);
056                }
057            });
058        }
059    
060        /**
061         * Create a new TextInputForm. The value for the "{@link FormSheet#waitResponse}" property will
062         * initially be set to true.
063         *
064         * @param sCaption the caption of the FormSheet.
065         * @param sLabel the label to be put at the top of the FormSheet.
066         * @param sInitialText the text that is to appear in the input line when the user has not entered anything
067         * yet.
068         */
069        public TextInputForm(String sCaption, String sLabel, String sInitialText) {
070            this(sCaption, sLabel, sInitialText, true);
071        }
072    
073        /**
074         * Get the current contents of the input field.
075         *
076         * @override Never
077         */
078        public String getText() {
079            return m_asResult[0];
080        }
081    }