Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 91 |  | Methods: | 5
| NCLOC: | 65 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

ASTPanel.java

0%

0%

0%

0%

1 |  | package net.sourceforge.pmd.util.viewer.gui;
2 |  |
3 |  | import net.sourceforge.pmd.ast.Node;
4 |  | import net.sourceforge.pmd.ast.SimpleNode;
5 |  | import net.sourceforge.pmd.util.viewer.gui.menu.ASTNodePopupMenu;
6 |  | import net.sourceforge.pmd.util.viewer.model.ASTModel;
7 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModel;
8 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
9 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
10 |  | import net.sourceforge.pmd.util.viewer.util.NLS;
11 |  |
12 |  | import javax.swing.*;
13 |  | import javax.swing.event.TreeSelectionEvent;
14 |  | import javax.swing.event.TreeSelectionListener;
15 |  | import javax.swing.tree.TreeNode;
16 |  | import javax.swing.tree.TreePath;
17 |  | import java.awt.BorderLayout;
18 |  | import java.awt.event.MouseAdapter;
19 |  | import java.awt.event.MouseEvent;
20 |  | import java.util.LinkedList;
21 |  |
22 |  | /**
23 |  | * tree panel GUI
24 |  | *
25 |  | * @author Boris Gruschko ( boris at gruschko.org )
26 |  | * @version $Id: ASTPanel.java,v 1.11 2006/02/10 14:15:29 tomcopeland Exp $
27 |  | */
28 |  |
29 |  | public class ASTPanel extends JPanel implements ViewerModelListener, TreeSelectionListener {
30 |  | private ViewerModel model;
31 |  | private JTree tree;
32 |  |
33 |  | /**
34 |  | * constructs the panel
35 |  | *
36 |  | * @param model model to attach the panel to
37 |  | */
38 | 0 | public ASTPanel(ViewerModel model) {
39 | 0 | this.model = model;
40 | 0 | init();
41 |  | }
42 |  |
43 | 0 | private void init() {
44 | 0 | model.addViewerModelListener(this);
45 | 0 | setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("AST.PANEL.TITLE")));
46 | 0 | setLayout(new BorderLayout());
47 | 0 | tree = new JTree((TreeNode) null);
48 | 0 | tree.addTreeSelectionListener(this);
49 | 0 | tree.addMouseListener(new MouseAdapter() {
50 | 0 | public void mouseReleased(MouseEvent e) {
51 | 0 | if (e.isPopupTrigger()) {
52 | 0 | TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
53 | 0 | tree.setSelectionPath(path);
54 | 0 | JPopupMenu menu = new ASTNodePopupMenu(model, (SimpleNode) path.getLastPathComponent());
55 | 0 | menu.show(tree, e.getX(), e.getY());
56 |  | }
57 |  | }
58 |  | });
59 |  |
60 | 0 | add(new JScrollPane(tree), BorderLayout.CENTER);
61 |  | }
62 |  |
63 |  | /**
64 |  | * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
65 |  | */
66 | 0 | public void viewerModelChanged(ViewerModelEvent e) {
67 | 0 | switch (e.getReason()) {
68 | 0 | case ViewerModelEvent.CODE_RECOMPILED:
69 | 0 | tree.setModel(new ASTModel(model.getRootNode()));
70 | 0 | break;
71 | 0 | case ViewerModelEvent.NODE_SELECTED:
72 | 0 | if (e.getSource() != this) {
73 | 0 | LinkedList list = new LinkedList();
74 | 0 | for (Node n = (Node) e.getParameter(); n != null; n = n.jjtGetParent()) {
75 | 0 | list.addFirst(n);
76 |  | }
77 | 0 | TreePath path = new TreePath(list.toArray());
78 | 0 | tree.setSelectionPath(path);
79 | 0 | tree.scrollPathToVisible(path);
80 |  | }
81 | 0 | break;
82 |  | }
83 |  | }
84 |  |
85 |  | /**
86 |  | * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
87 |  | */
88 | 0 | public void valueChanged(TreeSelectionEvent e) {
89 | 0 | model.selectNode((SimpleNode) e.getNewLeadSelectionPath().getLastPathComponent(), this);
90 |  | }
91 |  | }