KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
23 * Token-item presents a token as a piece information
24 * without dependence on a character buffer and it enables
25 * to chain the token-items in both directions.
26 *
27 * @author Miloslav Metelka
28 * @version 1.00
29 */

30
31 public interface TokenItem {
32
33     /** Get the token-id of this token-item */
34     public TokenID getTokenID();
35
36     /** Get the token-id of this token-item */
37     public TokenContextPath getTokenContextPath();
38
39     /** Get the position of the token in the document */
40     public int getOffset();
41
42     /** Get the image of this token. */
43     public String JavaDoc getImage();
44
45     /** Get next token-item in the text. It returns null
46     * if there's no more next tokens in the text. It can throw
47     * <tt>IllegalStateException</tt> in case the document
48     * was changed so the token-item chain becomes invalid.
49     */

50     public TokenItem getNext();
51
52     /** Get previous token-item in the text. It returns null
53     * if there's no more previous tokens in the text. It can throw
54     * <tt>IllegalStateException</tt> in case the document
55     * was changed so the token-item chain becomes invalid.
56     */

57     public TokenItem getPrevious();
58
59     /** Abstract implementation that doesn't contain chaining methods. */
60     public static abstract class AbstractItem implements TokenItem {
61
62         private TokenID tokenID;
63
64         private TokenContextPath tokenContextPath;
65
66         private String JavaDoc image;
67
68         private int offset;
69
70         public AbstractItem(TokenID tokenID, TokenContextPath tokenContextPath,
71         int offset, String JavaDoc image) {
72             this.tokenID = tokenID;
73             this.tokenContextPath = tokenContextPath;
74             this.offset = offset;
75             this.image = image;
76         }
77
78         public TokenID getTokenID() {
79             return tokenID;
80         }
81
82         public TokenContextPath getTokenContextPath() {
83             return tokenContextPath;
84         }
85
86         public int getOffset() {
87             return offset;
88         }
89
90         public String JavaDoc getImage() {
91             return image;
92         }
93
94         public String JavaDoc toString() {
95             return "'" + org.netbeans.editor.EditorDebug.debugString(getImage()) // NOI18N
96
+ "', tokenID=" + getTokenID() + ", tcp=" + getTokenContextPath() // NOI18N
97
+ ", offset=" + getOffset(); // NOI18N
98
}
99
100     }
101
102     /** Implementation useful for delegation. */
103     public static class FilterItem implements TokenItem {
104
105         protected TokenItem delegate;
106
107         public FilterItem(TokenItem delegate) {
108             this.delegate = delegate;
109         }
110
111         public TokenID getTokenID() {
112             return delegate.getTokenID();
113         }
114
115         public TokenContextPath getTokenContextPath() {
116             return delegate.getTokenContextPath();
117         }
118
119         public int getOffset() {
120             return delegate.getOffset();
121         }
122
123         public String JavaDoc getImage() {
124             return delegate.getImage();
125         }
126
127         public TokenItem getNext() {
128             return delegate.getNext();
129         }
130
131         public TokenItem getPrevious() {
132             return delegate.getPrevious();
133         }
134
135         public String JavaDoc toString() {
136             return delegate.toString();
137         }
138
139     }
140
141 }
142
Popular Tags