KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > editor > semantic > ShowGoldenFiles


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java.editor.semantic;
20
21 import java.awt.Dialog JavaDoc;
22 import java.awt.event.WindowAdapter JavaDoc;
23 import java.awt.event.WindowEvent JavaDoc;
24 import java.awt.event.WindowListener JavaDoc;
25 import java.io.BufferedReader JavaDoc;
26 import java.io.File JavaDoc;
27 import java.io.FileInputStream JavaDoc;
28 import java.io.FileReader JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.InputStreamReader JavaDoc;
31 import java.io.Reader JavaDoc;
32 import java.text.ParseException JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Collections JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.concurrent.CountDownLatch JavaDoc;
37 import javax.swing.JDialog JavaDoc;
38 import javax.swing.JFrame JavaDoc;
39 import javax.swing.SwingUtilities JavaDoc;
40 import javax.swing.text.BadLocationException JavaDoc;
41 import javax.swing.text.StyledDocument JavaDoc;
42 import javax.swing.text.html.HTMLDocument JavaDoc;
43 import org.netbeans.junit.NbTestCase;
44
45 /**
46  *
47  * @author Jan Lahoda
48  */

49 public class ShowGoldenFiles extends NbTestCase {
50     
51     /** Creates a new instance of ShowGoldenFiles */
52     public ShowGoldenFiles(String JavaDoc name) {
53         super(name);
54     }
55     
56     public void testX() throws Exception JavaDoc {
57         main(null);
58     }
59
60     private static List JavaDoc<HighlightImpl> parse(StyledDocument JavaDoc doc, File JavaDoc highlights) throws IOException JavaDoc, ParseException JavaDoc, BadLocationException JavaDoc {
61         if (!highlights.exists())
62             return Collections.emptyList();
63         
64         BufferedReader JavaDoc bis = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(new FileInputStream JavaDoc(highlights)));
65         List JavaDoc<HighlightImpl> result = new ArrayList JavaDoc<HighlightImpl>();
66         String JavaDoc line = null;
67         
68         while ((line = bis.readLine()) != null) {
69             result.add(HighlightImpl.parse(doc, line));
70         }
71         
72         return result;
73     }
74     
75     private static StyledDocument JavaDoc loadDocument(File JavaDoc file) throws IOException JavaDoc, BadLocationException JavaDoc {
76         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
77         Reader JavaDoc r = new FileReader JavaDoc(file);
78         int c;
79         
80         while ((c = r.read()) != (-1)) {
81             sb.append((char) c);
82         }
83         
84         StyledDocument JavaDoc result = new HTMLDocument JavaDoc();//new DefaultStyledDocument();
85

86         result.insertString(0, sb.toString(), null);
87         
88         return result;
89     }
90     
91     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
92         String JavaDoc className = "DetectorTest";
93         String JavaDoc testName = "testReadWriteUseArgumentOfAbstractMethod";
94     }
95     
96     public static void run(String JavaDoc className, String JavaDoc testName, String JavaDoc fileName) throws Exception JavaDoc {
97         final File JavaDoc golden = new File JavaDoc("/space/nm/java/editor/test/unit/data/goldenfiles/org/netbeans/modules/java/editor/semantic/" + className + "/" + testName + ".pass");
98         final File JavaDoc test = new File JavaDoc("/tmp/tests/org.netbeans.modules.java.editor.semantic." + className + "/" + testName + "/" + testName + ".out");
99         final File JavaDoc source = new File JavaDoc("/tmp/tests/org.netbeans.modules.java.editor.semantic." + className + "/" + testName + "/test/" + fileName + ".java");
100         
101         final StyledDocument JavaDoc doc = loadDocument(source);
102         final List JavaDoc<HighlightImpl> goldenHighlights = parse(doc, golden);
103         final List JavaDoc<HighlightImpl> testHighlights = parse(doc, test);
104
105         Runnable JavaDoc show = new Runnable JavaDoc() {
106             public void run() {
107                 JDialog JavaDoc d = new JDialog JavaDoc();
108                 
109                 d.setModal(true);
110                 
111                 ShowGoldenFilesPanel panel = new ShowGoldenFilesPanel(d);
112                 
113                 panel.setDocument(doc, goldenHighlights, testHighlights, golden, test);
114                 
115                 d.getContentPane().add(panel);
116                 
117                 d.show();
118             }
119         };
120
121         if (SwingUtilities.isEventDispatchThread()) {
122             show.run();
123         } else {
124             SwingUtilities.invokeAndWait(show);
125         }
126     }
127     
128 }
129
Popular Tags