1 19 20 package edu.umd.cs.findbugs.sourceViewer; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Color ; 24 import java.awt.Dimension ; 25 import java.awt.Font ; 26 import java.awt.FontMetrics ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import java.io.FileReader ; 30 import java.io.IOException ; 31 import java.io.Reader ; 32 33 import javax.swing.JComponent ; 34 import javax.swing.JEditorPane ; 35 import javax.swing.JFrame ; 36 import javax.swing.JPanel ; 37 import javax.swing.JScrollPane ; 38 import javax.swing.text.BadLocationException ; 39 import javax.swing.text.DefaultStyledDocument ; 40 import javax.swing.text.Element ; 41 import javax.swing.text.SimpleAttributeSet ; 42 import javax.swing.text.Style ; 43 import javax.swing.text.StyleConstants ; 44 import javax.swing.text.StyleContext ; 45 import javax.swing.text.TabSet ; 46 import javax.swing.text.TabStop ; 47 48 public class MyTest extends JPanel { 49 50 JEditorPane textArea; 51 52 JScrollPane scrollPane; 53 54 55 MyTest(String fileName) throws IOException , BadLocationException { 56 setLayout(new BorderLayout ()); 57 textArea = new JEditorPane (); 58 textArea.setPreferredSize(new Dimension (500, 500)); 59 60 scrollPane = new JScrollPane (textArea); 61 62 add(scrollPane); 63 64 JavaSourceDocument source = new JavaSourceDocument(fileName, new FileReader (fileName), null); 65 66 textArea.setEditorKit(source.getEditorKit()); 67 textArea.setDocument(source.getDocument()); 68 for(int i = 1; i < 200; i++) 69 if (i%3 ==0 || i % 5 == 0) 70 source.getHighlightInformation().setHighlight(i, Color.LIGHT_GRAY); 71 72 } 73 74 private static final long serialVersionUID = 0L; 75 76 private static void createAndShowGUI() throws Exception { 77 JFrame frame = new JFrame ("MyTest"); 79 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 80 81 JComponent newContentPane = new MyTest("MyTest.java"); 83 newContentPane.setOpaque(true); frame.setContentPane(newContentPane); 85 86 frame.pack(); 88 frame.setVisible(true); 89 } 90 91 public static void main(String [] args) { 92 javax.swing.SwingUtilities.invokeLater(new Runnable () { 95 public void run() { 96 try { 97 createAndShowGUI(); 98 } catch (Exception e) { 99 e.printStackTrace(); 101 } 102 } 103 }); 104 } 105 106 } 107 | Popular Tags |