001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013:
014: package org.netbeans.editor;
015:
016: /**
017: * Draw layer applies changes to draw context during painting process. Each
018: * extended UI has its own set of layers. It can currently include changes to
019: * font bold and italic attributes, and foreground and background color (and
020: * probably more in future). These changes are made by draw layer to draw
021: * context in <CODE>updateContext()</CODE> method. Draw layers form
022: * double-linked lists. Renderer goes through this list every time it draws the
023: * tokens of the text. A layer can work either by returning the
024: * next-activity-change-offset or by being activated through the draw-marks that
025: * it places at the appropriate positions or it can mix these two approaches.
026: *
027: * @author Miloslav Metelka
028: * @version 1.00
029: */
030:
031: public interface DrawLayer {
032:
033: /**
034: * Get the name of the layer. The layers that should work together over one
035: * component must have the different names.
036: */
037: public String getName();
038:
039: /**
040: * Whether the layer wants to use the last context's background till the end
041: * of the window or not.
042: */
043: public boolean extendsEOL();
044:
045: /**
046: * Whether the layer marks the empty line with the background by half of the
047: * character.
048: */
049: public boolean extendsEmptyLine();
050:
051: /**
052: * Get the next position at which the activity of the layer will change. It
053: * can return <tt>Integer.MAX_VALUE</tt> to mark that the activity will
054: * never change or if it will change only by draw-marks. When this position
055: * will be reached the <tt>isActive</tt> will be called.
056: */
057: public int getNextActivityChangeOffset(DrawContext ctx);
058:
059: /**
060: * Called each time the paint begins for all layers in the layer chain
061: * regardless whether they are currently active or not. It is intended to
062: * prepare the layer. It doesn't need to set the next-activity-change-offset
063: * because <tt>isActive()</tt> will be called at the begining of the
064: * drawing when this method finishes.
065: */
066: public void init(DrawContext ctx);
067:
068: /**
069: * Return whether the layer is active or not. This method is called at the
070: * begining of the drawing, then each time when the draw-mark is found at
071: * the current fragment offset or when drawing reaches the
072: * next-activity-change-offset of this layer (mark parameter is null in this
073: * case). The layer must return whether it wants to be active for the next
074: * drawing or not. The layer should also consider changing the
075: * next-activity-change-offset because the draw-engine will ask for it after
076: * this method finishes. If the mark is found at the same position like
077: * next-activity-change-offset is, then this method is called only once with
078: * the valid <tt>mark</tt> parameter.
079: *
080: * @param ctx
081: * current context with the information about the drawing
082: * @param mark
083: * draw-mark at the fragment-offset or null if called because of
084: * the next-activity-change-offset.
085: */
086: public boolean isActive(DrawContext ctx, MarkFactory.DrawMark mark);
087:
088: /**
089: * Update draw context by setting colors, fonts and possibly other draw
090: * properties. The method can use information from the context to find where
091: * the painting process is currently located. It is called only if the layer
092: * is active.
093: */
094: public void updateContext(DrawContext ctx);
095:
096: /**
097: * Update draw context related to the drawing of line number for the given
098: * line by setting colors, fonts and possibly other draw properties. The
099: * method can also change the current line number by returning the modified
100: * line-number than the original one. At the begining the first layer gets
101: * the line-number <tt>lineOffset + 1</tt> but some layers can change it.
102: * If the layer doesn't want to change the line-number it should return the
103: * same value as it gets. The context can be affected to change the font and
104: * colors for the line-number. The context's <tt>getFragmentOffset()</tt>
105: * returns the begining of the line. The following methods in the context
106: * return undefined values:
107: * <tt>isEOL(), getBuffer(), getTokenID(), getTokenOffset(), getTokenLength()</tt>.
108: * The process of calling this method is independent of the status of the
109: * layers and is called for each layer even if it's not active.
110: *
111: * @param lineNumber
112: * the number that will be drawn before the line's text. The
113: * layer can change it by returning a different value.
114: * @param ctx
115: * the draw context
116: */
117: public int updateLineNumberContext(int lineNumber, DrawContext ctx);
118:
119: /** Abstract implementation of the draw-layer. */
120: public static abstract class AbstractLayer implements DrawLayer {
121:
122: /**
123: * Name of this layer. The name of the layer must be unique among layers
124: * installed into EditorUI
125: */
126: private String name;
127:
128: /**
129: * Next position where the layer should be notified to update its state.
130: */
131: int nextActivityChangeOffset = Integer.MAX_VALUE;
132:
133: /** Construct new abstract layer with the known name and visibility. */
134: public AbstractLayer(String name) {
135: this .name = name;
136: }
137:
138: public String getName() {
139: return name;
140: }
141:
142: public boolean extendsEOL() {
143: return false;
144: }
145:
146: public boolean extendsEmptyLine() {
147: return false;
148: }
149:
150: public int getNextActivityChangeOffset(DrawContext ctx) {
151: return nextActivityChangeOffset;
152: }
153:
154: public void setNextActivityChangeOffset(
155: int nextActivityChangeOffset) {
156: this .nextActivityChangeOffset = nextActivityChangeOffset;
157: }
158:
159: public void init(DrawContext ctx) {
160: }
161:
162: public int updateLineNumberContext(int lineNumber,
163: DrawContext ctx) {
164: return lineNumber;
165: }
166:
167: public String toString() {
168: return "Layer " + getClass() + ", name='" + name; // NOI18N
169: }
170:
171: }
172:
173: }
|