|
1 |
| package net.sourceforge.pmd.util.viewer.gui; |
|
2 |
| |
|
3 |
| import net.sourceforge.pmd.ast.SimpleNode; |
|
4 |
| import net.sourceforge.pmd.util.viewer.model.ViewerModel; |
|
5 |
| import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent; |
|
6 |
| import net.sourceforge.pmd.util.viewer.model.ViewerModelListener; |
|
7 |
| |
|
8 |
| import javax.swing.*; |
|
9 |
| import javax.swing.event.ListSelectionEvent; |
|
10 |
| import javax.swing.event.ListSelectionListener; |
|
11 |
| import java.awt.BorderLayout; |
|
12 |
| import java.util.Vector; |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| public class EvaluationResultsPanel extends JPanel implements ViewerModelListener { |
|
21 |
| private ViewerModel model; |
|
22 |
| private JList list; |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
0
| public EvaluationResultsPanel(ViewerModel model) {
|
|
30 |
0
| super(new BorderLayout());
|
|
31 |
| |
|
32 |
0
| this.model = model;
|
|
33 |
| |
|
34 |
0
| init();
|
|
35 |
| } |
|
36 |
| |
|
37 |
0
| private void init() {
|
|
38 |
0
| model.addViewerModelListener(this);
|
|
39 |
| |
|
40 |
0
| list = new JList();
|
|
41 |
0
| list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
42 |
| |
|
43 |
0
| list.addListSelectionListener(new ListSelectionListener() {
|
|
44 |
0
| public void valueChanged(ListSelectionEvent e) {
|
|
45 |
0
| if (list.getSelectedValue() != null) {
|
|
46 |
0
| model.selectNode((SimpleNode) list.getSelectedValue(), EvaluationResultsPanel.this);
|
|
47 |
| } |
|
48 |
| } |
|
49 |
| }); |
|
50 |
| |
|
51 |
0
| add(new JScrollPane(list), BorderLayout.CENTER);
|
|
52 |
| } |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
0
| public void viewerModelChanged(ViewerModelEvent e) {
|
|
58 |
0
| switch (e.getReason()) {
|
|
59 |
0
| case ViewerModelEvent.PATH_EXPRESSION_EVALUATED:
|
|
60 |
| |
|
61 |
0
| if (e.getSource() != this) {
|
|
62 |
0
| list.setListData(new Vector(model.getLastEvaluationResults()));
|
|
63 |
| } |
|
64 |
| |
|
65 |
0
| break;
|
|
66 |
| |
|
67 |
0
| case ViewerModelEvent.CODE_RECOMPILED:
|
|
68 |
0
| list.setListData(new Vector(0));
|
|
69 |
| |
|
70 |
0
| break;
|
|
71 |
| } |
|
72 |
| } |
|
73 |
| } |