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.8 2005/09/02 19:36:22 tomcopeland Exp $
18 */
19
20 public class ParseExceptionHandler
21
22 extends JDialog
23
24 implements ActionListener {
25
26 private Exception exc;
27
28 private JTextArea errorArea;
29
30 private JButton okBtn;
31
32
33 /***
34 * creates the dialog
35 *
36 * @param parent dialog's parent
37 * @param exc exception to be handled
38 */
39
40 public ParseExceptionHandler(JFrame parent, Exception exc) {
41
42 super(parent, NLS.nls("COMPILE_ERROR.DIALOG.TITLE"), true);
43
44
45 this.exc = exc;
46
47
48 init();
49
50 }
51
52
53 private void init() {
54
55 errorArea = new JTextArea();
56
57 errorArea.setEditable(false);
58
59 errorArea.setText(exc.getMessage() + "\n");
60
61
62 getContentPane().setLayout(new BorderLayout());
63
64
65 JPanel messagePanel = new JPanel(new BorderLayout());
66
67
68 messagePanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createRaisedBevelBorder(),
69
70 BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
71
72 NLS.nls("COMPILE_ERROR.PANEL.TITLE"))));
73
74
75 messagePanel.add(new JScrollPane(errorArea), BorderLayout.CENTER);
76
77
78 getContentPane().add(messagePanel, BorderLayout.CENTER);
79
80
81 JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
82
83
84 okBtn = new JButton(NLS.nls("COMPILE_ERROR.OK_BUTTON.CAPTION"));
85
86
87 okBtn.addActionListener(this);
88
89
90 btnPane.add(okBtn);
91
92
93 getRootPane().setDefaultButton(okBtn);
94
95
96 getContentPane().add(btnPane, BorderLayout.SOUTH);
97
98
99 pack();
100
101
102 setLocationRelativeTo(getParent());
103
104
105 setVisible(true);
106
107 }
108
109
110 /***
111 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
112 */
113
114 public void actionPerformed(ActionEvent e) {
115
116 if (e.getSource() == okBtn) {
117
118 dispose();
119
120 }
121
122 }
123
124 }