Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 83 |  | Methods: | 5
| NCLOC: | 56 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
SourceCodePanel.java | 0% | 0% | 0% | 0% |

1 |  | package net.sourceforge.pmd.util.viewer.gui;
2 |  |
3 |  |
4 |  | import net.sourceforge.pmd.ast.SimpleNode;
5 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModel;
6 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModelEvent;
7 |  | import net.sourceforge.pmd.util.viewer.model.ViewerModelListener;
8 |  | import net.sourceforge.pmd.util.viewer.util.NLS;
9 |  |
10 |  | import javax.swing.*;
11 |  | import javax.swing.text.BadLocationException;
12 |  | import javax.swing.text.DefaultHighlighter;
13 |  | import java.awt.BorderLayout;
14 |  | import java.awt.Color;
15 |  |
16 |  |
17 |  | /**
18 |  | * source code panel
19 |  | *
20 |  | * @author Boris Gruschko ( boris at gruschko.org )
21 |  | * @version $Id: SourceCodePanel.java,v 1.12 2006/10/20 02:40:49 hooperbloob Exp $
22 |  | */
23 |  |
24 |  | public class SourceCodePanel extends JPanel implements ViewerModelListener {
25 |  |
26 |  | private ViewerModel model;
27 |  | private JTextArea sourceCodeArea;
28 |  |
29 |  | private static final Color highlightColor = new Color(79, 237, 111);
30 |  |
31 | 0 | public SourceCodePanel(ViewerModel model) {
32 | 0 | this.model = model;
33 | 0 | init();
34 |  | }
35 |  |
36 | 0 | private void init() {
37 | 0 | model.addViewerModelListener(this);
38 | 0 | setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("SOURCE.PANEL.TITLE")));
39 | 0 | setLayout(new BorderLayout());
40 | 0 | sourceCodeArea = new JTextArea();
41 | 0 | add(new JScrollPane(sourceCodeArea), BorderLayout.CENTER);
42 |  | }
43 |  |
44 |  | /**
45 |  | * retrieves the string representation of the source code
46 |  | *
47 |  | * @return source code's string representation
48 |  | */
49 | 0 | public String getSourceCode() {
50 | 0 | return sourceCodeArea.getText();
51 |  | }
52 |  |
53 |  | /**
54 |  | * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
55 |  | */
56 | 0 | public void viewerModelChanged(ViewerModelEvent e) {
57 | 0 | if (e.getReason() == ViewerModelEvent.NODE_SELECTED) {
58 | 0 | final SimpleNode node = (SimpleNode) e.getParameter();
59 | 0 | SwingUtilities.invokeLater(new Runnable() {
60 | 0 | public void run() {
61 | 0 | try {
62 | 0 | sourceCodeArea.getHighlighter().removeAllHighlights();
63 | 0 | if (node == null) {
64 | 0 | return;
65 |  | }
66 | 0 | int startOffset =
67 |  | (sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1) +
68 |  | node.getBeginColumn()) - 1;
69 | 0 | int end =
70 |  | (sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) +
71 |  | node.getEndColumn());
72 | 0 | sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
73 |  | new DefaultHighlighter.DefaultHighlightPainter(highlightColor));
74 | 0 | sourceCodeArea.moveCaretPosition(startOffset);
75 |  | } catch (BadLocationException exc) {
76 | 0 | throw new IllegalStateException(exc.getMessage());
77 |  | }
78 |  | }
79 |  | });
80 |  | }
81 |  | }
82 |  | }
83 |  |