01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.client.gui.text;
19:
20: import javax.swing.JDialog;
21: import javax.swing.JLabel;
22: import javax.swing.JOptionPane;
23: import javax.swing.JTextField;
24:
25: import de.finix.contelligent.client.ContelligentClient;
26: import de.finix.contelligent.client.util.RestrictedTextField;
27:
28: public class StringOptionPane extends JOptionPane {
29:
30: private JTextField textField;
31:
32: private JOptionPane optionPane;
33:
34: private String allowString = null;
35:
36: public String getText() {
37: return textField.getText();
38: }
39:
40: public void setAllowString(String allowString) {
41: this .allowString = allowString;
42: }
43:
44: public int showStringDialog(String title, String label, String text) {
45: return showStringDialog(title, label, text, false);
46: }
47:
48: public int showStringDialog(String title, String label,
49: String text, boolean preSelect) {
50: JLabel stringLabel = new JLabel(label);
51: if (allowString != null) {
52: textField = new RestrictedTextField(text);
53: ((RestrictedTextField) textField)
54: .setAllowString(allowString);
55: } else {
56: textField = new JTextField(text);
57: }
58:
59: if (preSelect) {
60: textField.selectAll();
61: }
62:
63: Object[] array = { stringLabel, textField };
64:
65: setMessage(array);
66: setMessageType(QUESTION_MESSAGE);
67: setOptionType(JOptionPane.OK_CANCEL_OPTION);
68:
69: JDialog dialog = createDialog(ContelligentClient
70: .getActiveFrame(), title);
71: dialog.setVisible(true);
72: if (getValue() instanceof Integer) {
73: return ((Integer) getValue()).intValue();
74: }
75: return CANCEL_OPTION;
76: }
77: }
|