KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > lib2 > highlighting > Factory


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
20 package org.netbeans.modules.editor.lib2.highlighting;
21
22 import java.util.ArrayList JavaDoc;
23 import org.netbeans.api.lexer.TokenHierarchy;
24 import org.netbeans.spi.editor.highlighting.HighlightsLayer;
25 import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
26 import org.netbeans.spi.editor.highlighting.ZOrder;
27
28 /**
29  * The factory for editor default highlighting layers.
30  *
31  * @author Vita Stejskal
32  */

33 public class Factory implements HighlightsLayerFactory {
34
35     /** A unique identifier of the block search layer type. */
36     public static final String JavaDoc BLOCK_SEARCH_LAYER = "org.netbeans.modules.editor.lib2.highlighting.BlockHighlighting/BLOCK_SEARCH"; //NOI18N
37

38     /** A unique identifier of the incremental search layer type. */
39     public static final String JavaDoc INC_SEARCH_LAYER = "org.netbeans.modules.editor.lib2.highlighting.BlockHighlighting/INC_SEARCH"; //NOI18N
40

41     /** Creates a new instance of Factory */
42     public Factory() {
43     }
44
45     public HighlightsLayer[] createLayers(HighlightsLayerFactory.Context context) {
46         ArrayList JavaDoc<HighlightsLayer> layers = new ArrayList JavaDoc<HighlightsLayer>();
47         
48         layers.add(HighlightsLayer.create(
49             CaretBasedBlockHighlighting.CaretRowHighlighting.LAYER_TYPE_ID,
50             ZOrder.CARET_RACK,
51             true,
52             new CaretBasedBlockHighlighting.CaretRowHighlighting(context.getComponent()))
53         );
54
55         layers.add(HighlightsLayer.create(
56             CaretBasedBlockHighlighting.TextSelectionHighlighting.LAYER_TYPE_ID,
57             ZOrder.SHOW_OFF_RACK.aboveLayers(CaretBasedBlockHighlighting.CaretRowHighlighting.LAYER_TYPE_ID),
58             true,
59             new CaretBasedBlockHighlighting.TextSelectionHighlighting(context.getComponent()))
60         );
61
62         layers.add(HighlightsLayer.create(
63             BLOCK_SEARCH_LAYER,
64             ZOrder.SHOW_OFF_RACK.aboveLayers(CaretBasedBlockHighlighting.CaretRowHighlighting.LAYER_TYPE_ID),
65             true,
66             new BlockHighlighting(BLOCK_SEARCH_LAYER, context.getComponent()))
67         );
68
69         layers.add(HighlightsLayer.create(
70             TextSearchHighlighting.LAYER_TYPE_ID,
71             ZOrder.SHOW_OFF_RACK.aboveLayers(BLOCK_SEARCH_LAYER),
72             true,
73             new TextSearchHighlighting(context.getComponent()))
74         );
75
76         layers.add(HighlightsLayer.create(
77             INC_SEARCH_LAYER,
78             ZOrder.SHOW_OFF_RACK.aboveLayers(TextSearchHighlighting.LAYER_TYPE_ID).belowLayers(CaretBasedBlockHighlighting.TextSelectionHighlighting.LAYER_TYPE_ID),
79             true,
80             new BlockHighlighting(INC_SEARCH_LAYER, context.getComponent()))
81         );
82
83         // If there is a lexer for the document create lexer-based syntax highlighting
84
if (TokenHierarchy.get(context.getDocument()) != null) {
85             layers.add(HighlightsLayer.create(
86                 SyntaxHighlighting.LAYER_TYPE_ID,
87                 ZOrder.SYNTAX_RACK,
88                 true,
89                 new SyntaxHighlighting(context.getDocument()))
90             );
91         }
92         
93         return layers.toArray(new HighlightsLayer [layers.size()]);
94     }
95     
96 }
97
Popular Tags