KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 package org.gjt.sp.jedit.search;
24
25 //{{{ Imports
26
import java.awt.Component JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.regex.Pattern JavaDoc;
29 import org.gjt.sp.jedit.*;
30 import org.gjt.sp.util.Log;
31 import org.gjt.sp.util.StandardUtilities;
32 //}}}
33

34 /**
35  * A file set for searching all open buffers.
36  * @author Slava Pestov
37  * @version $Id: AllBufferSet.java 6808 2006-08-26 23:22:57Z vanza $
38  */

39 public class AllBufferSet extends BufferListSet
40 {
41     //{{{ AllBufferSet constructor
42
/**
43      * Creates a new all buffer set.
44      * @param glob The filename glob
45      * @since jEdit 2.7pre3
46      */

47     public AllBufferSet(String JavaDoc glob)
48     {
49         this.glob = glob;
50     } //}}}
51

52     //{{{ getFileFilter() method
53
/**
54      * Returns the filename filter.
55      * @since jEdit 2.7pre3
56      */

57     public String JavaDoc getFileFilter()
58     {
59         return glob;
60     } //}}}
61

62     //{{{ getCode() method
63
/**
64      * Returns the BeanShell code that will recreate this file set.
65      * @since jEdit 2.7pre3
66      */

67     public String JavaDoc getCode()
68     {
69         return "new AllBufferSet(\"" + MiscUtilities.charsToEscapes(glob)
70             + "\")";
71     } //}}}
72

73     //{{{ Instance variables
74
private String JavaDoc glob;
75     //}}}
76

77     //{{{ _getFiles() method
78
protected String JavaDoc[] _getFiles(Component JavaDoc comp)
79     {
80         Buffer[] buffers = jEdit.getBuffers();
81         ArrayList JavaDoc returnValue = new ArrayList JavaDoc(buffers.length);
82
83         Pattern JavaDoc filter;
84         try
85         {
86             filter = Pattern.compile(StandardUtilities.globToRE(glob));
87         }
88         catch(Exception JavaDoc e)
89         {
90             Log.log(Log.ERROR,this,e);
91             return null;
92         }
93
94         for(int i = 0; i < buffers.length; i++)
95         {
96             Buffer buffer = buffers[i];
97             if(filter.matcher(buffer.getName()).matches())
98                 returnValue.add(buffer.getPath());
99         }
100
101         return (String JavaDoc[])returnValue.toArray(new String JavaDoc[returnValue.size()]);
102     } //}}}
103
}
104
Popular Tags