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 20 public class EvaluationResultsPanel extends JPanel implements ViewerModelListener { 21 private ViewerModel model; 22 private JList list; 23 24 29 public EvaluationResultsPanel(ViewerModel model) { 30 super(new BorderLayout ()); 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 () { 44 public void valueChanged(ListSelectionEvent 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 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 (model.getLastEvaluationResults())); 63 } 64 65 break; 66 67 case ViewerModelEvent.CODE_RECOMPILED: 68 list.setListData(new Vector (0)); 69 70 break; 71 } 72 } 73 } 74 | Popular Tags |