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

file stats: | LOC: | 82 |  | Methods: | 5
| NCLOC: | 57 |  | 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.11 2006/02/10 14:15:31 tomcopeland Exp $
22 |  | */
23 |  |
24 |  | public class SourceCodePanel
25 |  | extends JPanel
26 |  | implements ViewerModelListener {
27 |  | private ViewerModel model;
28 |  | private JTextArea sourceCodeArea;
29 |  |
30 | 0 | public SourceCodePanel(ViewerModel model) {
31 | 0 | this.model = model;
32 | 0 | init();
33 |  | }
34 |  |
35 | 0 | private void init() {
36 | 0 | model.addViewerModelListener(this);
37 | 0 | setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), NLS.nls("SOURCE.PANEL.TITLE")));
38 | 0 | setLayout(new BorderLayout());
39 | 0 | sourceCodeArea = new JTextArea();
40 | 0 | add(new JScrollPane(sourceCodeArea), BorderLayout.CENTER);
41 |  | }
42 |  |
43 |  | /**
44 |  | * retrieves the string representation of the source code
45 |  | *
46 |  | * @return source code's string representation
47 |  | */
48 | 0 | public String getSourceCode() {
49 | 0 | return sourceCodeArea.getText();
50 |  | }
51 |  |
52 |  | /**
53 |  | * @see ViewerModelListener#viewerModelChanged(ViewerModelEvent)
54 |  | */
55 | 0 | public void viewerModelChanged(ViewerModelEvent e) {
56 | 0 | if (e.getReason() == ViewerModelEvent.NODE_SELECTED) {
57 | 0 | final SimpleNode node = (SimpleNode) e.getParameter();
58 | 0 | SwingUtilities.invokeLater(new Runnable() {
59 | 0 | public void run() {
60 | 0 | try {
61 | 0 | sourceCodeArea.getHighlighter().removeAllHighlights();
62 | 0 | if (node == null) {
63 | 0 | return;
64 |  | }
65 | 0 | int startOffset =
66 |  | (sourceCodeArea.getLineStartOffset(node.getBeginLine() - 1) +
67 |  | node.getBeginColumn()) - 1;
68 | 0 | int end =
69 |  | (sourceCodeArea.getLineStartOffset(node.getEndLine() - 1) +
70 |  | node.getEndColumn());
71 | 0 | sourceCodeArea.getHighlighter().addHighlight(startOffset, end,
72 |  | new DefaultHighlighter.DefaultHighlightPainter(new Color(79, 237, 111)));
73 | 0 | sourceCodeArea.moveCaretPosition(startOffset);
74 |  | } catch (BadLocationException exc) {
75 | 0 | throw new IllegalStateException(exc.getMessage());
76 |  | }
77 |  | }
78 |  | });
79 |  | }
80 |  | }
81 |  | }
82 |  |