PageRenderTime 15ms CodeModel.GetById 9ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/search/AllBufferSet.java

#
Java | 102 lines | 45 code | 10 blank | 47 comment | 2 complexity | a83b0b701aa56f1c2b5de42c198136fc MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1/*
  2 * AllBufferSet.java - All buffer matcher
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1999, 2000, 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 gnu.regexp.*;
 27import java.awt.Component;
 28import java.util.ArrayList;
 29import org.gjt.sp.jedit.*;
 30import org.gjt.sp.util.Log;
 31//}}}
 32
 33/**
 34 * A file set for searching all open buffers.
 35 * @author Slava Pestov
 36 * @version $Id: AllBufferSet.java 4261 2002-06-18 02:44:52Z spestov $
 37 */
 38public class AllBufferSet extends BufferListSet
 39{
 40	//{{{ AllBufferSet constructor
 41	/**
 42	 * Creates a new all buffer set.
 43	 * @param glob The filename glob
 44	 * @since jEdit 2.7pre3
 45	 */
 46	public AllBufferSet(String glob)
 47	{
 48		this.glob = glob;
 49	} //}}}
 50
 51	//{{{ getFileFilter() method
 52	/**
 53	 * Returns the filename filter.
 54	 * @since jEdit 2.7pre3
 55	 */
 56	public String getFileFilter()
 57	{
 58		return glob;
 59	} //}}}
 60
 61	//{{{ getCode() method
 62	/**
 63	 * Returns the BeanShell code that will recreate this file set.
 64	 * @since jEdit 2.7pre3
 65	 */
 66	public String getCode()
 67	{
 68		return "new AllBufferSet(\"" + MiscUtilities.charsToEscapes(glob)
 69			+ "\")";
 70	} //}}}
 71
 72	//{{{ Instance variables
 73	private String glob;
 74	//}}}
 75
 76	//{{{ _getFiles() method
 77	protected String[] _getFiles(Component comp)
 78	{
 79		Buffer[] buffers = jEdit.getBuffers();
 80		ArrayList returnValue = new ArrayList(buffers.length);
 81
 82		RE filter;
 83		try
 84		{
 85			filter = new RE(MiscUtilities.globToRE(glob));
 86		}
 87		catch(Exception e)
 88		{
 89			Log.log(Log.ERROR,this,e);
 90			return null;
 91		}
 92
 93		for(int i = 0; i < buffers.length; i++)
 94		{
 95			Buffer buffer = buffers[i];
 96			if(filter.isMatch(buffer.getName()))
 97				returnValue.add(buffer.getPath());
 98		}
 99
100		return (String[])returnValue.toArray(new String[returnValue.size()]);
101	} //}}}
102}