01: /*
02: * Copyright (C) 2004 Giuseppe MANNA
03: *
04: * This file is part of FreeReportBuilder
05: *
06: * FreeReportBuilder is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package it.frb;
23:
24: import java.awt.*;
25: import java.awt.event.*;
26: import javax.swing.*;
27:
28: public class WindowText {
29: static final int CANCEL = 0;
30: static final int OK = 1;
31:
32: private static JButton ok = null;
33: private static JButton cancel = null;
34: private static JDialog dialog = null;
35: private static int action = 0;
36:
37: public static Object showInputDialog(String title,
38: String initialValue, Container parent) {
39: JTextArea ta = new JTextArea(new String(initialValue));
40: ta.setWrapStyleWord(true);
41: ta.setLineWrap(true);
42: ta.setSize(200, 300);
43: dialog = new JDialog((JFrame) SwingUtilities.getRoot(parent),
44: title);
45: dialog.setSize(350, 300);
46: DataEngine.centerWindow(dialog, parent);
47: JPanel jpButtons = new JPanel(new GridLayout(1, 2));
48: MyAction acl = new MyAction();
49: ok = new JButton("Ok");
50: ok.addActionListener(acl);
51: cancel = new JButton("Cancel");
52: cancel.addActionListener(acl);
53: jpButtons.add(ok);
54: jpButtons.add(cancel);
55: dialog.setModal(true);
56: dialog.getContentPane().add(ta);
57: dialog.getContentPane().add(jpButtons, BorderLayout.SOUTH);
58: dialog.setResizable(true);
59: dialog.show();
60:
61: if (action == OK) {
62: return ta;
63: } else {
64: return null;
65: }
66: }
67:
68: private static class MyAction implements ActionListener {
69: public void actionPerformed(ActionEvent e) {
70: if (e.getSource() == ok) {
71: WindowText.action = OK;
72: } else {
73: WindowText.action = CANCEL;
74: }
75: dialog.dispose();
76: }
77: }
78: }
|