1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: ErrorDialog.java,v $
19 Created on $Date: 2003/09/06 08:40:52 $
20 */
21 package net.sf.bloof.browser.dialogs;
22
23
24 import java.awt.BorderLayout;
25 import java.awt.Color;
26 import java.awt.Container;
27 import java.awt.FlowLayout;
28 import java.awt.Frame;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31
32 import javax.swing.JButton;
33 import javax.swing.JComponent;
34 import javax.swing.JDialog;
35 import javax.swing.JLabel;
36 import javax.swing.JPanel;
37 import javax.swing.JScrollPane;
38 import javax.swing.JTextArea;
39
40 import net.sf.bloof.browser.GuiConstants;
41 import net.sf.bloof.browser.GuiFactory;
42 import net.sf.bloof.browser.intl.Messages;
43 import net.sf.bloof.browser.intl.Text;
44
45 /**
46 *
47 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
48 * @version $Id: ErrorDialog.java,v 1.2 2003/09/06 08:40:52 pekacki Exp $
49 */
50 public class ErrorDialog extends JDialog {
51
52 public ErrorDialog(Frame aParent, String aErrorMessage) {
53 super(aParent, Messages.getString(Text.ERROR),true);
54 Container content = getContentPane();
55 setSize(GuiConstants.DIALOG_SIZE);
56 GuiFactory.centerOnScreen(this);
57 content.setLayout(new BorderLayout(10,5));
58 content.add(getErrorTitle(), BorderLayout.NORTH);
59 content.add(getMessageComponent(aErrorMessage), BorderLayout.CENTER);
60 content.add(getSouthButtons(), BorderLayout.SOUTH);
61 setVisible(true);
62 }
63
64 private JComponent getSouthButtons() {
65 JPanel p = new JPanel();
66 JButton ok = new JButton(Messages.getString(Text.OK));
67 ok.addActionListener(new ActionListener() {
68 public void actionPerformed(ActionEvent e) {
69 closeMe();
70 }
71 });
72 p.add(ok);
73 return p;
74 }
75
76 private void closeMe() {
77 this.dispose();
78 }
79
80 private JComponent getErrorTitle() {
81 JPanel p = new JPanel(new FlowLayout(FlowLayout.CENTER));
82 JLabel l = new JLabel(Messages.getString(Text.ERROR_OCCURED));
83 l.setForeground(Color.RED);
84 l.setFont(GuiConstants.FONT_TITLE);
85 p.add(l);
86 return p;
87 }
88
89 private JComponent getMessageComponent(String aMessage) {
90 JPanel outerP = new JPanel();
91 JTextArea area = new JTextArea(aMessage);
92 int rows = aMessage.length() / DEFAULT_COLS;
93 area.setRows(rows+2);
94 area.setColumns(DEFAULT_COLS);
95 area.setWrapStyleWord(true);
96 area.setLineWrap(true);
97 area.setEditable(false);
98 JScrollPane p = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
99 outerP.add(p);
100 return outerP;
101 }
102
103 private static final int DEFAULT_COLS = 50;
104
105 }