KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > DrawLayer


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.editor;
21
22 /** Draw layer applies changes to draw context during painting process.
23 * Each extended UI has its own set of layers.
24 * It can currently include changes to font bold and italic attributes,
25 * and foreground and background color (and probably more in future).
26 * These changes are made by draw layer to draw context
27 * in <CODE>updateContext()</CODE> method.
28 * Draw layers form double-linked lists. Renderer goes through
29 * this list every time it draws the tokens of the text.
30 * A layer can work either by returning the next-activity-change-offset
31 * or by being activated through the draw-marks that it places
32 * at the appropriate positions or it can mix these two approaches.
33 *
34 * @deprecated Please use Highlighting SPI instead, for details see
35 * <a HREF="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
36 *
37 * @author Miloslav Metelka
38 * @version 1.00
39 */

40
41
42 public interface DrawLayer {
43
44     /**
45      * Start of the next region with the frame.
46      */

47     public static final String JavaDoc TEXT_FRAME_START_POSITION_COMPONENT_PROPERTY
48             = "text-frame-start-position"; // NOI18N
49

50     /**
51      * End of the next region with the frame.
52      */

53     public static final String JavaDoc TEXT_FRAME_END_POSITION_COMPONENT_PROPERTY
54             = "text-frame-end-position"; // NOI18N
55

56     /** Get the name of the layer. The layers that should work together
57     * over one component must have the different names.
58     */

59     public String JavaDoc getName();
60
61     /** Whether the layer wants to use the last context's background
62     * till the end of the window or not.
63     */

64     public boolean extendsEOL();
65
66     /** Whether the layer marks the empty line with the background by half
67     * of the character.
68     */

69     public boolean extendsEmptyLine();
70
71     /** Get the next position at which the activity of the layer will change.
72     * It can return <tt>Integer.MAX_VALUE</tt> to mark that the activity
73     * will never change or if it will change only by draw-marks.
74     * When this position will be reached the <tt>isActive</tt> will be called.
75     */

76     public int getNextActivityChangeOffset(DrawContext ctx);
77
78     /** Called each time the paint begins for all layers
79     * in the layer chain regardless whether they are currently active
80     * or not. It is intended to prepare the layer. It doesn't need
81     * to set the next-activity-change-offset because <tt>isActive()</tt>
82     * will be called at the begining of the drawing when this method
83     * finishes.
84     */

85     public void init(DrawContext ctx);
86
87     /** Return whether the layer is active or not. This method
88     * is called at the begining of the drawing,
89     * then each time when the draw-mark is found at the current
90     * fragment offset or when drawing reaches the next-activity-change-offset
91     * of this layer (mark parameter is null in this case).
92     * The layer must return whether it wants to be active for the next drawing
93     * or not.
94     * The layer should also consider
95     * changing the next-activity-change-offset because the draw-engine
96     * will ask for it after this method finishes.
97     * If the mark is found at the same position like next-activity-change-offset
98     * is, then this method is called only once with the valid <tt>mark</tt> parameter.
99     * @param ctx current context with the information about the drawing
100     * @param mark draw-mark at the fragment-offset or null if called
101     * because of the next-activity-change-offset.
102     */

103     public boolean isActive(DrawContext ctx, MarkFactory.DrawMark mark);
104
105     /** Update draw context by setting colors, fonts and possibly other draw
106     * properties.
107     * The method can use information from the context to find where the painting
108     * process is currently located. It is called only if the layer is active.
109     */

110     public void updateContext(DrawContext ctx);
111
112     /** Update draw context related to the drawing of line number for the given
113     * line by setting colors, fonts and possibly other draw
114     * properties. The method can also change the current line number by returning
115     * the modified line-number than the original one. At the begining the first
116     * layer gets the line-number <tt>lineOffset + 1</tt> but some layers can
117     * change it. If the layer doesn't want to change the line-number it should
118     * return the same value as it gets.
119     * The context can be affected to change the font and colors for the line-number.
120     * The context's <tt>getFragmentOffset()</tt> returns the begining of the line.
121     * The following methods in the context return undefined values:
122     * <tt>isEOL(), getBuffer(), getTokenID(), getTokenOffset(), getTokenLength()</tt>.
123     * The process of calling this method is independent of the status
124     * of the layers and is called for each layer even if it's not active.
125     * @param lineNumber the number that will be drawn before the line's text.
126     * The layer can change it by returning a different value.
127     * @param ctx the draw context
128     */

129     public int updateLineNumberContext(int lineNumber, DrawContext ctx);
130
131     /**
132      * Abstract implementation of the draw-layer.
133      *
134      * @deprecated Please use Highlighting SPI instead, for details see
135      * <a HREF="@org-netbeans-modules-editor-lib2@/overview-summary.html">Editor Library 2</a>.
136      */

137     public static abstract class AbstractLayer implements DrawLayer {
138
139         /** Name of this layer. The name of the layer must be unique among
140         * layers installed into EditorUI
141         */

142         private String JavaDoc name;
143
144         /** Next position where the layer should be notified
145         * to update its state.
146         */

147         int nextActivityChangeOffset = Integer.MAX_VALUE;
148
149         /** Construct new abstract layer with the known name and visibility. */
150         public AbstractLayer(String JavaDoc name) {
151             this.name = name;
152         }
153
154         public String JavaDoc getName() {
155             return name;
156         }
157
158         public boolean extendsEOL() {
159             return false;
160         }
161
162         public boolean extendsEmptyLine() {
163             return false;
164         }
165
166         public int getNextActivityChangeOffset(DrawContext ctx) {
167             return nextActivityChangeOffset;
168         }
169
170         public void setNextActivityChangeOffset(int nextActivityChangeOffset) {
171             this.nextActivityChangeOffset = nextActivityChangeOffset;
172         }
173
174         public void init(DrawContext ctx) {
175         }
176
177         public int updateLineNumberContext(int lineNumber, DrawContext ctx) {
178             return lineNumber;
179         }
180
181         public String JavaDoc toString() {
182             return "Layer " + getClass() + ", name='" + name; // NOI18N
183
}
184
185     }
186
187 }
188
Popular Tags