KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > editor > highlighting > HighlightsLayerFactory


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.spi.editor.highlighting;
21
22 import javax.swing.text.Document JavaDoc;
23 import javax.swing.text.JTextComponent JavaDoc;
24
25 /**
26  * Factory for producing <code>HighlightsLayer</code>s. Modules can implement
27  * this interface and register their implementations among the mime-type specific
28  * services under the <code>Editors</code> folder on the system filesystem.
29  *
30  * <p>The infrastructure uses <code>HighlightsLayerFactory</code> instances
31  * registered in the mime-type specific registry to create <code>HighlightsLayer</code>s,
32  * which will participate in rendering a document. All factories that the infrastructure
33  * considers relelvant for rendering a document will be asked to create
34  * <code>HighlightsLayer</code>s for that document.
35  *
36  * @author Miloslav Metelka
37  * @author Vita Stejskal
38  * @version 1.00
39  */

40 public interface HighlightsLayerFactory {
41
42     /**
43      * The context passed to a factory when it is asked to create <code>HighlightLayer</code>s.
44      * This context provides essential information such as a <code>Document</code> and
45      * <code>JTextComponent</code> for which <code>HighlightLayer</code>s should be created.
46      */

47     public static final class Context {
48         private Document JavaDoc document;
49         private JTextComponent JavaDoc component;
50
51         /**
52          * TODO: we might need a MimePath here as well. Remember the layers can
53          * be created/discarded depending on the appearance of embedded mime types
54          * as the user changes the document. Such a layer (or the factory) might be interested in
55          * knowing its mime-path, because it might need to load some settings at
56          * the creation time when no other information (eg. lexer's language path)
57          * is available.
58          */

59         /* package */ Context(Document JavaDoc document, JTextComponent JavaDoc component) {
60             this.document = document;
61             this.component = component;
62         }
63
64         /**
65          * Gets the document for which the highlight layers are created.
66          */

67         public Document JavaDoc getDocument() {
68             return document;
69         }
70
71         /**
72          * Gets the text component for which the highlight layers are created.
73          */

74         public JTextComponent JavaDoc getComponent() {
75             return component;
76         }
77     } // End of Context class
78

79     /**
80      * Creates <code>HighlightLayer</code>s appropriate for the context passed in.
81      *
82      * @param context The context that should be used for creating the layer.
83      *
84      * @return The array of <code>HighlightLayer</code>s that should be used
85      * for rendering the document in the <code>Context</code>. This method can
86      * return <code>null</code> if there are no <code>HighlightLayer</code>s available.
87      */

88     HighlightsLayer[] createLayers(Context context);
89
90 }
91
Popular Tags