PageRenderTime 69ms CodeModel.GetById 62ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/search/BufferListSet.java

#
Java | 120 lines | 68 code | 17 blank | 35 comment | 28 complexity | 9dddd16d5bfd30a359130367a31d3811 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, 2001 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 javax.swing.SwingUtilities;
 27import java.util.Vector;
 28import org.gjt.sp.jedit.io.VFSManager;
 29import org.gjt.sp.jedit.*;
 30import org.gjt.sp.util.Log;
 31//}}}
 32
 33/**
 34 * A file set for searching a user-specified list of buffers.
 35 * @author Slava Pestov
 36 * @version $Id: BufferListSet.java 3931 2001-12-02 11:40:51Z spestov $
 37 */
 38public abstract class BufferListSet implements SearchFileSet
 39{
 40	//{{{ getFirstFile() method
 41	public String getFirstFile(View view)
 42	{
 43		if(files == null)
 44			files = _getFiles();
 45
 46		if(files == null || files.length == 0)
 47			return null;
 48		else
 49			return files[0];
 50	} //}}}
 51
 52	//{{{ getNextFile() method
 53	public String getNextFile(View view, String file)
 54	{
 55		if(files == null)
 56			files = _getFiles();
 57
 58		if(files == null || files.length == 0)
 59			return null;
 60
 61		if(file == null)
 62		{
 63			file = view.getBuffer().getPath();
 64
 65			for(int i = 0; i < files.length; i++)
 66			{
 67				if(files[i].equals(file))
 68					return file;
 69			}
 70
 71			return getFirstFile(view);
 72		}
 73		else
 74		{
 75			// -1 so that the last isn't checked
 76			for(int i = 0; i < files.length - 1; i++)
 77			{
 78				if(files[i].equals(file))
 79					return files[i+1];
 80			}
 81
 82			return null;
 83		}
 84	} //}}}
 85
 86	//{{{ getFiles() method
 87	public String[] getFiles(View view)
 88	{
 89		if(files == null)
 90			files = _getFiles();
 91
 92		if(files == null || files.length == 0)
 93			return null;
 94		else
 95			return files;
 96	} //}}}
 97
 98	//{{{ getFileCount() method
 99	public int getFileCount()
100	{
101		if(files == null)
102			files = _getFiles();
103
104		if(files == null)
105			return 0;
106		else
107			return files.length;
108	} //}}}
109
110	//{{{ getCode() method
111	public String getCode()
112	{
113		// not supported for arbitriary filesets
114		return null;
115	} //}}}
116
117	protected abstract String[] _getFiles();
118
119	private String[] files;
120}