001 /* 002 * $Id: Searchable.java,v 1.4 2005/11/14 15:23:55 kizune Exp $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021 022 package org.jdesktop.swingx; 023 024 import java.util.regex.Pattern; 025 026 /** 027 * Interface that used to implement search logic in all the search capable 028 * components. 029 * 030 * @author Ramesh Gupta 031 */ 032 public interface Searchable { 033 034 /** 035 * Search <code>searchString</code> from the beginning of a document. 036 * 037 * @param searchString <code>String</code> we should find in a document. 038 * 039 * @return index of matched <code>String</code> or -1 if a match cannot be found. 040 */ 041 public int search(String searchString); 042 043 /** 044 * Search <code>searchString</code> from the given position in a document. 045 * 046 * @param searchString <code>String</code> we should find in a document. 047 * @param startIndex Start position in a document or -1 if we want to search from the beginning. 048 * 049 * @return index of matched <code>String</code> or -1 if a match cannot be found. 050 */ 051 public int search(String searchString, int startIndex); 052 053 /** 054 * Search <code>searchString</code> in the given direction from the some position in a document. 055 * 056 * @param searchString <code>String</code> we should find in a document. 057 * @param startIndex Start position in a document or -1 if we want to search from the beginning. 058 * @param backward Indicates search direction, will search from the given position towards the 059 * beginning of a document if this parameter is <code>true</code>. 060 * 061 * @return index of matched <code>String</code> or -1 if a match cannot be found. 062 */ 063 public int search(String searchString, int startIndex, boolean backward); 064 065 /** 066 * Search for the pattern from the beginning of the document. 067 * 068 * @param pattern Pattern for search 069 * 070 * @return index of matched <code>Pattern</code> or -1 if a match cannot be found. 071 */ 072 public int search(Pattern pattern); 073 074 /** 075 * Search for the pattern from the start index. 076 * @param pattern Pattern for search 077 * @param startIndex starting index of search. If -1 then start from the beginning 078 * @return index of matched pattern or -1 if a match cannot be found. 079 */ 080 public int search(Pattern pattern, int startIndex); 081 082 /** 083 * Search for the pattern from the start index. 084 * @param pattern Pattern for search 085 * @param startIndex starting index of search. If -1 then start from the beginning 086 * @param backward indicates the direction if true then search is backwards 087 * @return index of matched pattern or -1 if a match cannot be found. 088 */ 089 public int search(Pattern pattern, int startIndex, boolean backward); 090 }