01 package net.sourceforge.pmd.util.viewer.gui;
02
03
04 import net.sourceforge.pmd.util.viewer.util.NLS;
05
06 import javax.swing.*;
07 import java.awt.BorderLayout;
08 import java.awt.FlowLayout;
09 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 5557 2007-10-19 08:03:30Z wfzelle $
18 */
19
20 public class ParseExceptionHandler extends JDialog implements ActionListener {
21 private Exception exc;
22 private JButton okBtn;
23
24 /**
25 * creates the dialog
26 *
27 * @param parent dialog's parent
28 * @param exc exception to be handled
29 */
30 public ParseExceptionHandler(JFrame parent, Exception exc) {
31 super(parent, NLS.nls("COMPILE_ERROR.DIALOG.TITLE"), true);
32 this.exc = exc;
33 init();
34 }
35
36 private void init() {
37 JTextArea errorArea = new JTextArea();
38 errorArea.setEditable(false);
39 errorArea.setText(exc.getMessage() + "\n");
40 getContentPane().setLayout(new BorderLayout());
41 JPanel messagePanel = new JPanel(new BorderLayout());
42 messagePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),
43 BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
44 NLS.nls("COMPILE_ERROR.PANEL.TITLE"))));
45 messagePanel.add(new JScrollPane(errorArea), BorderLayout.CENTER);
46 getContentPane().add(messagePanel, BorderLayout.CENTER);
47 JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
48 okBtn = new JButton(NLS.nls("COMPILE_ERROR.OK_BUTTON.CAPTION"));
49 okBtn.addActionListener(this);
50 btnPane.add(okBtn);
51 getRootPane().setDefaultButton(okBtn);
52 getContentPane().add(btnPane, BorderLayout.SOUTH);
53 pack();
54 setLocationRelativeTo(getParent());
55 setVisible(true);
56 }
57
58 /**
59 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
60 */
61 public void actionPerformed(ActionEvent e) {
62 if (e.getSource() == okBtn) {
63 dispose();
64 }
65 }
66 }
|