PageRenderTime 78ms CodeModel.GetById 66ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/search/BufferListSet.java

#
Java | 141 lines | 82 code | 19 blank | 40 comment | 32 complexity | 26c1ad80122677d5eb27b88b78aabf7f MD5 | raw file
  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
 23package org.gjt.sp.jedit.search;
 24
 25//{{{ Imports
 26import java.awt.Component;
 27import org.gjt.sp.jedit.*;
 28import org.gjt.sp.jedit.io.*;
 29//}}}
 30
 31/**
 32 * A file set for searching a user-specified list of buffers.
 33 * @author Slava Pestov
 34 * @version $Id: BufferListSet.java 4972 2004-02-22 20:00:54Z spestov $
 35 */
 36public abstract class BufferListSet implements SearchFileSet
 37{
 38	//{{{ getFirstFile() method
 39	public synchronized String getFirstFile(View view)
 40	{
 41		if(files == null)
 42			files = _getFiles(view);
 43
 44		if(files == null || files.length == 0)
 45			return null;
 46		else
 47			return files[0];
 48	} //}}}
 49
 50	//{{{ getNextFile() method
 51	public synchronized String getNextFile(View view, String file)
 52	{
 53		if(files == null)
 54			files = _getFiles(view);
 55
 56		if(files == null || files.length == 0)
 57			return null;
 58
 59		if(file == null)
 60		{
 61			file = view.getBuffer().getSymlinkPath();
 62			VFS vfs = VFSManager.getVFSForPath(file);
 63			boolean ignoreCase = ((vfs.getCapabilities()
 64				& VFS.CASE_INSENSITIVE_CAP) != 0);
 65
 66			for(int i = 0; i < files.length; i++)
 67			{
 68				if(MiscUtilities.compareStrings(
 69					files[i],file,ignoreCase) == 0)
 70				{
 71					return file;
 72				}
 73			}
 74
 75			return getFirstFile(view);
 76		}
 77		else
 78		{
 79			// -1 so that the last isn't checked
 80			VFS vfs = VFSManager.getVFSForPath(file);
 81			boolean ignoreCase = ((vfs.getCapabilities()
 82				& VFS.CASE_INSENSITIVE_CAP) != 0);
 83
 84			for(int i = 0; i < files.length - 1; i++)
 85			{
 86				if(MiscUtilities.compareStrings(
 87					files[i],file,ignoreCase) == 0)
 88				{
 89					return files[i+1];
 90				}
 91			}
 92
 93			return null;
 94		}
 95	} //}}}
 96
 97	//{{{ getFiles() method
 98	public synchronized String[] getFiles(View view)
 99	{
100		if(files == null)
101			files = _getFiles(view);
102
103		if(files == null || files.length == 0)
104			return null;
105		else
106			return files;
107	} //}}}
108
109	//{{{ getFileCount() method
110	public synchronized int getFileCount(View view)
111	{
112		if(files == null)
113			files = _getFiles(view);
114
115		if(files == null)
116			return 0;
117		else
118			return files.length;
119	} //}}}
120
121	//{{{ getCode() method
122	public String getCode()
123	{
124		// not supported for arbitriary filesets
125		return null;
126	} //}}}
127
128	//{{{ invalidateCachedList() method
129	public synchronized void invalidateCachedList()
130	{
131		files = null;
132	} //}}}
133
134	/**
135	 * Note that the paths in the returned list must be
136	 * fully canonicalized.
137	 */
138	protected abstract String[] _getFiles(Component comp);
139
140	private String[] files;
141}