KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > search > BufferListSet


1 /*
2  * BufferListSet.java - Buffer list matcher
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 1999, 2004 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.search;
24
25 //{{{ Imports
26
import java.awt.Component JavaDoc;
27 import org.gjt.sp.jedit.*;
28 import org.gjt.sp.jedit.io.*;
29 import org.gjt.sp.util.StandardUtilities;
30 //}}}
31

32 /**
33  * A file set for searching a user-specified list of buffers.
34  * @author Slava Pestov
35  * @version $Id: BufferListSet.java 5570 2006-07-11 09:27:07Z kpouer $
36  */

37 public abstract class BufferListSet implements SearchFileSet
38 {
39     //{{{ getFirstFile() method
40
public synchronized String JavaDoc getFirstFile(View view)
41     {
42         if(files == null)
43             files = _getFiles(view);
44
45         if(files == null || files.length == 0)
46             return null;
47         else
48             return files[0];
49     } //}}}
50

51     //{{{ getNextFile() method
52
public synchronized String JavaDoc getNextFile(View view, String JavaDoc path)
53     {
54         if(files == null)
55             files = _getFiles(view);
56
57         if(files == null || files.length == 0)
58             return null;
59
60         if(path == null)
61         {
62             path = view.getBuffer().getSymlinkPath();
63             VFS vfs = VFSManager.getVFSForPath(path);
64             boolean ignoreCase = ((vfs.getCapabilities()
65                 & VFS.CASE_INSENSITIVE_CAP) != 0);
66
67             for(int i = 0; i < files.length; i++)
68             {
69                 if(StandardUtilities.compareStrings(
70                     files[i],path,ignoreCase) == 0)
71                 {
72                     return path;
73                 }
74             }
75
76             return getFirstFile(view);
77         }
78         else
79         {
80             // -1 so that the last isn't checked
81
VFS vfs = VFSManager.getVFSForPath(path);
82             boolean ignoreCase = ((vfs.getCapabilities()
83                 & VFS.CASE_INSENSITIVE_CAP) != 0);
84
85             for(int i = 0; i < files.length - 1; i++)
86             {
87                 if(StandardUtilities.compareStrings(
88                     files[i],path,ignoreCase) == 0)
89                 {
90                     return files[i+1];
91                 }
92             }
93
94             return null;
95         }
96     } //}}}
97

98     //{{{ getFiles() method
99
public synchronized String JavaDoc[] getFiles(View view)
100     {
101         if(files == null)
102             files = _getFiles(view);
103
104         if(files == null || files.length == 0)
105             return null;
106         else
107             return files;
108     } //}}}
109

110     //{{{ getFileCount() method
111
public synchronized int getFileCount(View view)
112     {
113         if(files == null)
114             files = _getFiles(view);
115
116         if(files == null)
117             return 0;
118         else
119             return files.length;
120     } //}}}
121

122     //{{{ getCode() method
123
public String JavaDoc getCode()
124     {
125         // not supported for arbitriary filesets
126
return null;
127     } //}}}
128

129     //{{{ invalidateCachedList() method
130
public void invalidateCachedList()
131     {
132         files = null;
133     } //}}}
134

135     /**
136      * Note that the paths in the returned list must be
137      * fully canonicalized.
138      */

139     protected abstract String JavaDoc[] _getFiles(Component JavaDoc comp);
140
141     private String JavaDoc[] files;
142 }
143
Popular Tags