KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > syntax > jedit > IReportKeywordLookup


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * IReportKeywordLookup.java
28  *
29  */

30
31 package org.syntax.jedit;
32
33 import java.util.*;
34
35 import org.syntax.jedit.tokenmarker.*;
36 import javax.swing.text.Segment JavaDoc;
37
38 public class IReportKeywordLookup implements KeywordLookupIF
39 {
40         private ArrayList keys = new ArrayList();
41
42         public IReportKeywordLookup()
43         {
44         }
45
46         public void addKeyword(String JavaDoc keyword)
47         {
48           addKeyword(keyword, Token.PARAMETER_OK);
49         }
50
51         public void addKeyword(String JavaDoc keyword, byte token)
52         {
53           //System.out.println("add : " + keyword);
54
keys.add(new Key(keyword, token));
55         }
56
57         public void removeKeyword(String JavaDoc keyword)
58         {
59           Key key;
60
61           for(int i=0; i<keys.size(); i++)
62           {
63             key = (Key) keys.get(i);
64             if(key.keyword.equals(keyword))
65             {
66               keys.remove(key);
67             }
68           }
69         }
70
71     /**
72      * Looks up a key.
73      * @param text The text segment
74      * @param offset The offset of the substring within the text segment
75      * @param length The length of the substring
76      */

77     public byte lookup(Segment JavaDoc text, int offset, int length)
78         {
79           Key key;
80           String JavaDoc keyword;
81           boolean found;
82
83           for(int i=0; i<keys.size(); i++)
84           {
85             key = (Key) keys.get(i);
86             keyword = key.keyword;
87
88             if(keyword.length() != length)
89             {
90               continue;
91             }
92
93             found = true;
94             for(int j=0; j<keyword.length(); j++)
95             {
96               if(keyword.charAt(j) != text.array[offset + j])
97               {
98                 found = false;
99                 break;
100               }
101             }
102
103             if(found)
104             {
105               return key.token;
106             }
107           }
108
109           return Token.NULL;
110         }
111
112         private class Key
113         {
114           String JavaDoc keyword;
115           byte token;
116
117           Key(String JavaDoc keyword, byte token)
118           {
119             this.keyword = keyword;
120             this.token = token;
121           }
122         }
123
124 }
125
Popular Tags