KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > editor > semantic > Utilities


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.retouche.editor.semantic;
20
21 import java.awt.Color JavaDoc;
22 import java.util.Collection JavaDoc;
23 import javax.swing.text.BadLocationException JavaDoc;
24 import javax.swing.text.Document JavaDoc;
25 import org.netbeans.api.gsf.ColoringAttributes;
26 import org.netbeans.api.gsf.ParserResult;
27 import org.netbeans.api.gsf.PositionManager;
28 import org.netbeans.modules.editor.highlights.spi.Highlight;
29
30 /**
31  * This file is originally from Retouche, the Java Support
32  * infrastructure in NetBeans. I have modified the file as little
33  * as possible to make merging Retouche fixes back as simple as
34  * possible.
35  *
36  *
37  * @author Jan Lahoda
38  */

39 public class Utilities {
40     private static Highlight createHighlightImpl(Document JavaDoc doc, int startOffset, int endOffset, Collection JavaDoc<ColoringAttributes> c, Color JavaDoc es) {
41         try {
42             if (startOffset > doc.getLength() || endOffset > doc.getLength()) {
43                 return null;
44             }
45             
46             return new HighlightImpl(doc, startOffset, endOffset, c, es);
47         } catch (BadLocationException JavaDoc e) {
48             e.printStackTrace();
49             return null;
50         }
51     }
52
53     public static Highlight createHighlight(final Document JavaDoc doc, final int startOffset, final int endOffset, final Collection JavaDoc<ColoringAttributes> c, final Color JavaDoc es) {
54         final Highlight[] result = new Highlight[1];
55         
56         doc.render(new Runnable JavaDoc() {
57             public void run() {
58                 result[0] = createHighlightImpl(doc, startOffset, endOffset, c, es);
59             }
60         });
61         
62         return result[0];
63     }
64     
65     private static Highlight createHighlightImpl(ParserResult pr, PositionManager positions, Document JavaDoc doc, int startOffset, int endOffset, Collection JavaDoc<ColoringAttributes> c, Color JavaDoc es) {
66         try {
67             if (startOffset > doc.getLength() || endOffset > doc.getLength()) {
68                 return null;
69             }
70             
71             return new HighlightImpl(doc, startOffset, endOffset, c, es);
72         } catch (BadLocationException JavaDoc e) {
73             e.printStackTrace();
74             return null;
75         }
76     }
77     
78     public static Highlight createHighlight(final ParserResult pr, final PositionManager positions, final Document JavaDoc doc, final int startOffset, final int endOffset, final Collection JavaDoc<ColoringAttributes> c, final Color JavaDoc es) {
79         final Highlight[] result = new Highlight[1];
80         
81         doc.render(new Runnable JavaDoc() {
82             public void run() {
83                 result[0] = createHighlightImpl(pr, positions, doc, startOffset, endOffset, c, es);
84             }
85         });
86         
87         return result[0];
88     }
89 }
90
Popular Tags