01: package net.xoetrope.builder.editor.dialog;
02:
03: import java.awt.event.ActionEvent;
04: import java.awt.event.ActionListener;
05: import javax.swing.JButton;
06: import javax.swing.JDialog;
07: import javax.swing.JLabel;
08: import javax.swing.JTextField;
09: import java.awt.Font;
10: import javax.swing.JPasswordField;
11: import net.xoetrope.builder.editor.XuiDefaults;
12:
13: /**
14: * <p>A dialog for setup of a new page/screen</p>
15: * <p>Copyright (c) Xoetrope Ltd., 1998-2003</p>
16: * $Revision: 1.2 $
17: */
18: public class InputDialog extends JDialog implements ActionListener {
19: protected JTextField inputField;
20: protected JButton btnOK, btnCancel;
21: protected String inputString;
22:
23: public InputDialog(String title, String prompt) {
24: setTitle(title);
25: getContentPane().setLayout(null);
26: setModal(true);
27:
28: setFont(XuiDefaults.defaultFont);
29:
30: JLabel lbl = new JLabel(prompt);
31: lbl.setBounds(10, 10, 200, 20);
32: lbl.setFont(XuiDefaults.defaultFont);
33: getContentPane().add(lbl);
34:
35: inputField = new JTextField();
36: inputField.setBounds(10, 30, 210, 20);
37: inputField.setFont(XuiDefaults.defaultFont);
38: getContentPane().add(inputField);
39:
40: btnCancel = new JButton("Cancel");
41: btnCancel.setBounds(10, 60, 100, 20);
42: btnCancel.setFont(XuiDefaults.defaultFont);
43: btnCancel.addActionListener(this );
44: getContentPane().add(btnCancel);
45:
46: btnOK = new JButton("OK");
47: btnOK.setBounds(120, 60, 100, 20);
48: btnOK.setFont(XuiDefaults.defaultFont);
49: btnOK.addActionListener(this );
50: getContentPane().add(btnOK);
51:
52: setLocation(100, 100);
53: setSize(240, 125);
54: }
55:
56: /**
57: * Gets the user input value
58: * @return the text of the input field
59: */
60: public String getInputValue() {
61: show();
62: return inputString;
63: }
64:
65: public void actionPerformed(ActionEvent evt) {
66: if (evt.getSource().equals(btnOK))
67: inputString = inputField.getText();
68: else
69: inputString = null;
70:
71: hide();
72: }
73:
74: /**
75: * Changes the input field to a password field
76: * @param b true to make the input field a password field
77: */
78: public void setPassword(boolean b) {
79: if (b)
80: inputField = new JPasswordField(inputField.getText());
81: else
82: inputField = new JTextField(inputField.getText());
83: }
84: }
|