KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > sourceViewer > MyTest


1 /*
2  * FindBugs - Find Bugs in Java programs
3  * Copyright (C) 2006, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307, USA
18  */

19
20 package edu.umd.cs.findbugs.sourceViewer;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.Font JavaDoc;
26 import java.awt.FontMetrics JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.io.FileReader JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.io.Reader JavaDoc;
32
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JEditorPane JavaDoc;
35 import javax.swing.JFrame JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.JScrollPane JavaDoc;
38 import javax.swing.text.BadLocationException JavaDoc;
39 import javax.swing.text.DefaultStyledDocument JavaDoc;
40 import javax.swing.text.Element JavaDoc;
41 import javax.swing.text.SimpleAttributeSet JavaDoc;
42 import javax.swing.text.Style JavaDoc;
43 import javax.swing.text.StyleConstants JavaDoc;
44 import javax.swing.text.StyleContext JavaDoc;
45 import javax.swing.text.TabSet JavaDoc;
46 import javax.swing.text.TabStop JavaDoc;
47
48 public class MyTest extends JPanel JavaDoc {
49
50     JEditorPane JavaDoc textArea;
51
52     JScrollPane JavaDoc scrollPane;
53
54     
55     MyTest(String JavaDoc fileName) throws IOException JavaDoc, BadLocationException JavaDoc {
56         setLayout(new BorderLayout JavaDoc());
57         textArea = new JEditorPane JavaDoc();
58         textArea.setPreferredSize(new Dimension JavaDoc(500, 500));
59         
60         scrollPane = new JScrollPane JavaDoc(textArea);
61
62         add(scrollPane);
63     
64         JavaSourceDocument source = new JavaSourceDocument(fileName, new FileReader JavaDoc(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 JavaDoc {
77         //Create and set up the window.
78
JFrame JavaDoc frame = new JFrame JavaDoc("MyTest");
79         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
80
81         //Create and set up the content pane.
82
JComponent JavaDoc newContentPane = new MyTest("MyTest.java");
83         newContentPane.setOpaque(true); //content panes must be opaque
84
frame.setContentPane(newContentPane);
85
86         //Display the window.
87
frame.pack();
88         frame.setVisible(true);
89     }
90
91     public static void main(String JavaDoc[] args) {
92         //Schedule a job for the event-dispatching thread:
93
//creating and showing this application's GUI.
94
javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
95             public void run() {
96                 try {
97                     createAndShowGUI();
98                 } catch (Exception JavaDoc e) {
99                     // TODO Auto-generated catch block
100
e.printStackTrace();
101                 }
102             }
103         });
104     }
105
106 }
107
Popular Tags