1 19 package org.netbeans.modules.retouche.editor.semantic; 20 21 import java.awt.Color ; 22 import java.util.Collection ; 23 import javax.swing.text.BadLocationException ; 24 import javax.swing.text.Document ; 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 39 public class Utilities { 40 private static Highlight createHighlightImpl(Document doc, int startOffset, int endOffset, Collection <ColoringAttributes> c, Color 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 e) { 48 e.printStackTrace(); 49 return null; 50 } 51 } 52 53 public static Highlight createHighlight(final Document doc, final int startOffset, final int endOffset, final Collection <ColoringAttributes> c, final Color es) { 54 final Highlight[] result = new Highlight[1]; 55 56 doc.render(new Runnable () { 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 doc, int startOffset, int endOffset, Collection <ColoringAttributes> c, Color 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 e) { 73 e.printStackTrace(); 74 return null; 75 } 76 } 77 78 public static Highlight createHighlight(final ParserResult pr, final PositionManager positions, final Document doc, final int startOffset, final int endOffset, final Collection <ColoringAttributes> c, final Color es) { 79 final Highlight[] result = new Highlight[1]; 80 81 doc.render(new Runnable () { 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 |