1 19 20 package org.netbeans.modules.editor.impl.highlighting; 21 22 import java.util.ArrayList ; 23 import javax.swing.text.Document ; 24 import javax.swing.text.JTextComponent ; 25 import org.netbeans.api.lexer.TokenHierarchy; 26 import org.netbeans.modules.editor.lib2.highlighting.CaretBasedBlockHighlighting.CaretRowHighlighting; 27 import org.netbeans.spi.editor.highlighting.HighlightsLayer; 28 import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory; 29 import org.netbeans.spi.editor.highlighting.ZOrder; 30 31 35 public final class HLFactory implements HighlightsLayerFactory { 36 37 38 public HLFactory() { 39 } 40 41 public HighlightsLayer[] createLayers(HighlightsLayerFactory.Context context) { 42 ArrayList <HighlightsLayer> layers = new ArrayList <HighlightsLayer>(); 43 44 final Document d = context.getDocument(); 45 final JTextComponent c = context.getComponent(); 46 final String mimeType = getMimeType(c, d); 47 48 layers.add(HighlightsLayer.create( 49 GuardedBlocksHighlighting.LAYER_TYPE_ID, 50 ZOrder.BOTTOM_RACK.belowLayers(CaretRowHighlighting.LAYER_TYPE_ID), 51 true, new GuardedBlocksHighlighting(d, mimeType) 53 )); 54 55 if (TokenHierarchy.get(context.getDocument()) == null) { 56 layers.add(HighlightsLayer.create( 58 NonLexerSyntaxHighlighting.LAYER_TYPE_ID, 59 ZOrder.SYNTAX_RACK, 60 true, new NonLexerSyntaxHighlighting(d, mimeType) 62 )); 63 } 64 65 return layers.toArray(new HighlightsLayer[layers.size()]); 66 } 67 68 private static String getMimeType(JTextComponent c, Document d) { 69 String mimeType = (String ) d.getProperty("mimeType"); 71 if (mimeType == null) { 72 mimeType = c.getUI().getEditorKit(c).getContentType(); 73 } 74 75 return mimeType == null ? "" : mimeType; } 77 } 78 | Popular Tags |