Clover coverage report - PMD - 3.9
Coverage timestamp: Tue Dec 19 2006 09:38:44 EST
file stats: LOC: 75   Methods: 4
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CodeEditorTextPane.java 0% 0% 0% 0%
coverage
 1    package net.sourceforge.pmd.util.designer;
 2   
 3    import net.sourceforge.pmd.util.LineGetter;
 4   
 5    import javax.swing.*;
 6    import java.awt.Dimension;
 7    import java.awt.event.ActionEvent;
 8    import java.awt.event.ActionListener;
 9    import java.io.BufferedReader;
 10    import java.io.File;
 11    import java.io.FileReader;
 12    import java.io.FileWriter;
 13    import java.io.IOException;
 14    import java.util.StringTokenizer;
 15   
 16    public class CodeEditorTextPane extends JTextPane implements LineGetter, ActionListener {
 17   
 18    private static final String SETTINGS_FILE_NAME = System.getProperty("user.home") + System.getProperty("file.separator") + ".pmd_designer";
 19    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
 20   
 21  0 public CodeEditorTextPane() {
 22  0 setPreferredSize(new Dimension(400, 200));
 23  0 setText(loadCode());
 24    }
 25   
 26  0 public String getLine(int number) {
 27  0 int count = 1;
 28  0 for (StringTokenizer st = new StringTokenizer(getText(), "\n"); st.hasMoreTokens();) {
 29  0 String tok = st.nextToken();
 30  0 if (count == number) {
 31  0 return tok;
 32    }
 33  0 count++;
 34    }
 35  0 throw new RuntimeException("Line number " + number + " not found");
 36    }
 37   
 38  0 public void actionPerformed(ActionEvent ae) {
 39  0 FileWriter fw = null;
 40  0 try {
 41  0 fw = new FileWriter(new File(SETTINGS_FILE_NAME));
 42  0 fw.write(getText());
 43    } catch (IOException ioe) {
 44    } finally {
 45  0 try {
 46  0 if (fw != null)
 47  0 fw.close();
 48    } catch (IOException ioe) {
 49  0 ioe.printStackTrace();
 50    }
 51    }
 52    }
 53   
 54  0 private String loadCode() {
 55  0 BufferedReader br = null;
 56  0 try {
 57  0 br = new BufferedReader(new FileReader(new File(SETTINGS_FILE_NAME)));
 58  0 StringBuffer text = new StringBuffer();
 59  0 String hold;
 60  0 while ((hold = br.readLine()) != null) {
 61  0 text.append(hold).append(LINE_SEPARATOR);
 62    }
 63  0 return text.toString();
 64    } catch (IOException e) {
 65  0 e.printStackTrace();
 66  0 return "";
 67    } finally {
 68  0 try {
 69  0 if (br != null) br.close();
 70    } catch (IOException e) {
 71  0 e.printStackTrace();
 72    }
 73    }
 74    }
 75    }