![]()
Searching
You can add search functionality to your application using the provided classes. These classes allow users of your application to:
- Find the next or previous matching phrase
- Highlight all matching phrases
- Perform case sensitive and case insensitive searching
- Perform whole-word based searching
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:
- Create a new Search object as follows:
Search search = thePilot.getSearch();- 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.
- 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.
- 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:
- Create a new instance of SearchPanel:
searchBar = new SearchPanel(a_top_level_viewport);- 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"); } } } });- Add searchBar to its container.
- Implement an action listener to show searchBar:
SearchBar.setVisible(true);- Dispose searchBar when its containing window is dismissed:
searchBar.dispose();
|
Copyright 2005. ICEsoft Technologies, Inc. http://www.icesoft.com |