TOC PREV NEXT INDEX




Searching


You can add search functionality to your application using the provided classes. These classes allow users of your application to:

The two classes that support searching are a core class ice.pilots.html4.Search and a helper class ice.ri.common.search.SearchHelper.

The Search class provides all the search functionality based on a viewport (an HTML frame). The SearchHelper is a wrapper of the Search class and provides search support to HTML documents with multiple child frames (frameset). These classes work with Java 1.1.8 and higher and are independent of the AWT or Swing GUI toolkit.

Using the ice.pilots.html4.Search Class

The following steps show how you can implement the "Find in document" function:

  1. Create a new Search object as follows:
    Search search = thePilot.getSearch();
     
    
  2. Implement a GUI widget for setting search parameters and call the property setters on the search object, followed by search.searchDocument(boolean selectFirst) to apply the change made by the setters. searchDocument returns the number of matches found.
    Method
    Description
    setSearchText(String searchText)
    Set the search string for a new search.
    search.searchDocument(flag) needs to be called afterwards to apply the change. To select the first match, set the flag to true.
    setHightlightSearches(boolean flag )
    Highlight and dehighlight all matching search text. By default, highlight mode is set to false.
    search.searchDocument(false) needs to be called afterwards.
    setMatchCase(boolean flag)
    Set case sensitivity. By default, search is case insensitive. setMatchCase(true) enables case sensitive search. search.searchDocument(flag) needs to be called afterwards to apply the change. To select the first match, set the flag to true.
    setWholeWordSearch(boolean flag)
    Sets whole-word search mode. Whole-word searching limits the search results to text that matches the search String and is surrounded by whitespace characters. By default, whole-word searching is disabled. setWholeWordSearch(true) enables whole-word search. search.searchDocument(flag) needs to be called afterwards to apply the change. To select the first match, set the flag to true.
  3. Call findNext() and findPrevious() to select the next and previous matches in the document, respectively, in the "Find next" and "Find previous" component's actionListener.
  4. Call dispose() to dispose all related resources.
Note: An instance of the Search class is linked to a Viewport (an HTML frame) so that all search operations in a search object are performed in the associated viewport and are not automatically performed in child viewport or other viewport. The Search class is not frameset aware.
Using the ice.ri.common.search.swing.SearchPanel Class

The class ice.ri.common.search.SearchHelper is a wrapper of class Search and provides additional search support to HTML documents with multiple child frames (frameset). It can be used in a modal form (modal dialog) and a non-modal form (a non-modal dialog or a Panel/JPanel).

Two examples are provided to show you how to use SearchHelper.

The SearchPanel is also used in the Swing RI. Check the source code of the class ice.ri.swing.BrowserWindow and search for searchBar. SearchPanel is basically a Jpanel and can be added to wherever a Jpanel can be.

The basic steps to integrate SearchPanel into your application are as follows:

  1. Create a new instance of SearchPanel:
    searchBar = new SearchPanel(a_top_level_viewport);
     
    
  2. Implement your SearchStatusEventListener and add it to searchBar to display search status messages in the desired location:
    searchBar.addSearchStatusEventListener(new SearchStatusEventAdapter() {
    
       public void setSearchStatusMessage(int status, int nMatches) {
    
          if ( status == SearchHelper.MATCH_FOUND ) {
    
             if ( nMatches > 1 )
    
                statusBar.setStatusText(Integer.toString(nMatches)+ 
    
                   " matches found"));
    
             else  {
    
                     if ( nMatches == 1 )
    
                        statusBar.setStatusText("1 match found" );
    
                     else 
    
                        statusBar.setStatusText("Match found");
    
                   }
    
            } else {
    
                    if ( status == SearchHelper.NO_MATCH_FOUND ) {
    
                      statusBar.setStatusText("No matches found");
    
                    }
    
                    else 
    
                       if ( status == SearchHelper.END_OF_SEARCH ) {
    
                           statusBar.setStatusText("Reached end of page,
    
                             continued from top/bottom");
    
                       }
    
                  }
    
             }
    
    });
    
    
     
    
  3. Add searchBar to its container.
  4. Implement an action listener to show searchBar:
    SearchBar.setVisible(true);
     
    
  5. Dispose searchBar when its containing window is dismissed:
    searchBar.dispose();
     
    


Copyright 2005. ICEsoft Technologies, Inc.
http://www.icesoft.com

TOC PREV NEXT INDEX