1 package net.sourceforge.pmd.util.viewer.gui;
2
3
4 import net.sourceforge.pmd.util.viewer.util.NLS;
5
6 import javax.swing.*;
7 import java.awt.BorderLayout;
8 import java.awt.FlowLayout;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11
12
13 /***
14 * handles parsing exceptions
15 *
16 * @author Boris Gruschko ( boris at gruschko.org )
17 * @version $Id: ParseExceptionHandler.java,v 1.10 2006/02/10 14:15:31 tomcopeland Exp $
18 */
19
20 public class ParseExceptionHandler extends JDialog implements ActionListener {
21 private Exception exc;
22 private JTextArea errorArea;
23 private JButton okBtn;
24
25 /***
26 * creates the dialog
27 *
28 * @param parent dialog's parent
29 * @param exc exception to be handled
30 */
31 public ParseExceptionHandler(JFrame parent, Exception exc) {
32 super(parent, NLS.nls("COMPILE_ERROR.DIALOG.TITLE"), true);
33 this.exc = exc;
34 init();
35 }
36
37 private void init() {
38 errorArea = new JTextArea();
39 errorArea.setEditable(false);
40 errorArea.setText(exc.getMessage() + "\n");
41 getContentPane().setLayout(new BorderLayout());
42 JPanel messagePanel = new JPanel(new BorderLayout());
43 messagePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),
44 BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
45 NLS.nls("COMPILE_ERROR.PANEL.TITLE"))));
46 messagePanel.add(new JScrollPane(errorArea), BorderLayout.CENTER);
47 getContentPane().add(messagePanel, BorderLayout.CENTER);
48 JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
49 okBtn = new JButton(NLS.nls("COMPILE_ERROR.OK_BUTTON.CAPTION"));
50 okBtn.addActionListener(this);
51 btnPane.add(okBtn);
52 getRootPane().setDefaultButton(okBtn);
53 getContentPane().add(btnPane, BorderLayout.SOUTH);
54 pack();
55 setLocationRelativeTo(getParent());
56 setVisible(true);
57 }
58
59 /***
60 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
61 */
62 public void actionPerformed(ActionEvent e) {
63 if (e.getSource() == okBtn) {
64 dispose();
65 }
66 }
67 }