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 * ID for serialization.
022 */
023 private static final long serialVersionUID = 5399067647623902724L;
024 /**
025 * The String array that will hold the text that was entered into the text field.
026 *
027 * @serial
028 */
029 private String[] m_asResult = new String[] {
030 ""};
031
032 /**
033 * Create a new TextInputForm.
034 *
035 * @param sCaption the caption of the FormSheet.
036 * @param sLabel the label to be put at the top of the FormSheet.
037 * @param sInitialText the text that is to appear in the input line when the user has not entered anything
038 * yet.
039 * @param fWaitResponse the initial value for the "{@link FormSheet#waitResponse}" property.
040 */
041 public TextInputForm(String sCaption, final String sLabel, String sInitialText, boolean fWaitResponse) {
042 super(sCaption, (JComponent)null, fWaitResponse);
043
044 m_asResult[0] = sInitialText;
045
046 addContentCreator(new FormSheetContentCreator() {
047 /**
048 * ID for serialization.
049 */
050 private static final long serialVersionUID = -5621164389642660910L;
051
052 protected void createFormSheetContent(FormSheet fs) {
053
054 JPanel jpForm = new JPanel();
055 Box b = Box.createVerticalBox();
056
057 b.add(Box.createVerticalGlue());
058 b.add(new JLabel(sLabel));
059 b.add(new JTextInput(m_asResult, m_asResult[0]));
060 b.add(Box.createGlue());
061
062 jpForm.add(b);
063
064 fs.setComponent(jpForm);
065 }
066 });
067 }
068
069 /**
070 * Create a new TextInputForm. The value for the "{@link FormSheet#waitResponse}" property will
071 * initially be set to true.
072 *
073 * @param sCaption the caption of the FormSheet.
074 * @param sLabel the label to be put at the top of the FormSheet.
075 * @param sInitialText the text that is to appear in the input line when the user has not entered anything
076 * yet.
077 */
078 public TextInputForm(String sCaption, String sLabel, String sInitialText) {
079 this(sCaption, sLabel, sInitialText, true);
080 }
081
082 /**
083 * Get the current contents of the input field.
084 *
085 * @override Never
086 */
087 public String getText() {
088 return m_asResult[0];
089 }
090 }