KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > util > viewer > gui > EvaluationResultsPanel


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 JavaDoc;
10 import javax.swing.event.ListSelectionListener JavaDoc;
11 import java.awt.BorderLayout JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 /**
15  * A panel showing XPath expression evaluation results
16  *
17  * @author Boris Gruschko ( boris at gruschko.org )
18  * @version $Id: EvaluationResultsPanel.java,v 1.11 2006/02/10 14:15:31 tomcopeland Exp $
19  */

20 public class EvaluationResultsPanel extends JPanel implements ViewerModelListener {
21     private ViewerModel model;
22     private JList list;
23
24     /**
25      * constructs the panel
26      *
27      * @param model model to refer to
28      */

29     public EvaluationResultsPanel(ViewerModel model) {
30         super(new BorderLayout JavaDoc());
31
32         this.model = model;
33
34         init();
35     }
36
37     private void init() {
38         model.addViewerModelListener(this);
39
40         list = new JList();
41         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
42
43         list.addListSelectionListener(new ListSelectionListener JavaDoc() {
44             public void valueChanged(ListSelectionEvent JavaDoc e) {
45                 if (list.getSelectedValue() != null) {
46                     model.selectNode((SimpleNode) list.getSelectedValue(), EvaluationResultsPanel.this);
47                 }
48             }
49         });
50
51         add(new JScrollPane(list), BorderLayout.CENTER);
52     }
53
54     /**
55      * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
56      */

57     public void viewerModelChanged(ViewerModelEvent e) {
58         switch (e.getReason()) {
59             case ViewerModelEvent.PATH_EXPRESSION_EVALUATED:
60
61                 if (e.getSource() != this) {
62                     list.setListData(new Vector JavaDoc(model.getLastEvaluationResults()));
63                 }
64
65                 break;
66
67             case ViewerModelEvent.CODE_RECOMPILED:
68                 list.setListData(new Vector JavaDoc(0));
69
70                 break;
71         }
72     }
73 }
74
Popular Tags