01: package net.sourceforge.pmd.util.viewer.gui;
02:
03: import net.sourceforge.pmd.ast.SimpleNode;
04: import net.sourceforge.pmd.util.viewer.model.ViewerModel;
05: import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
06: import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
07:
08: import javax.swing.*;
09: import javax.swing.event.ListSelectionEvent;
10: import javax.swing.event.ListSelectionListener;
11: import java.awt.BorderLayout;
12: import java.util.Vector;
13:
14: /**
15: * A panel showing XPath expression evaluation results
16: *
17: * @author Boris Gruschko ( boris at gruschko.org )
18: * @version $Id: EvaluationResultsPanel.java 4217 2006-02-10 14:15:31Z tomcopeland $
19: */
20: public class EvaluationResultsPanel extends JPanel implements
21: ViewerModelListener {
22: private ViewerModel model;
23: private JList list;
24:
25: /**
26: * constructs the panel
27: *
28: * @param model model to refer to
29: */
30: public EvaluationResultsPanel(ViewerModel model) {
31: super (new BorderLayout());
32:
33: this .model = model;
34:
35: init();
36: }
37:
38: private void init() {
39: model.addViewerModelListener(this );
40:
41: list = new JList();
42: list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
43:
44: list.addListSelectionListener(new ListSelectionListener() {
45: public void valueChanged(ListSelectionEvent e) {
46: if (list.getSelectedValue() != null) {
47: model.selectNode((SimpleNode) list
48: .getSelectedValue(),
49: EvaluationResultsPanel.this );
50: }
51: }
52: });
53:
54: add(new JScrollPane(list), BorderLayout.CENTER);
55: }
56:
57: /**
58: * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
59: */
60: public void viewerModelChanged(ViewerModelEvent e) {
61: switch (e.getReason()) {
62: case ViewerModelEvent.PATH_EXPRESSION_EVALUATED:
63:
64: if (e.getSource() != this ) {
65: list.setListData(new Vector(model
66: .getLastEvaluationResults()));
67: }
68:
69: break;
70:
71: case ViewerModelEvent.CODE_RECOMPILED:
72: list.setListData(new Vector(0));
73:
74: break;
75: }
76: }
77: }
|