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