Class UIFindReplaceDialog
public class UIFindReplaceDialog extends UIDialog
{
// Fields
public static final int FIND;
public static final int ID_BACKWARDS;
public static final int ID_CANCEL;
public static final int ID_CASESENSITIVE;
public static final int ID_FINDNEXT;
public static final int ID_FINDTEXT;
public static final int ID_FORWARDS;
public static final int ID_REPLACE;
public static final int ID_REPLACEALL;
public static final int ID_REPLACETEXT;
public static final int ID_WHOLEWORD;
public static final int REPLACE;
// Constructors
public UIFindReplaceDialog(UIFrame frame, String title,
boolean modal);
// Methods
public boolean action(Event evt, Object what);
protected void createFindDialog();
protected void createReplaceDialog();
public int display(int style);
public boolean doFindNext();
public boolean doReplace();
public boolean doReplaceAll();
protected IUIComponent findEditControl(int id);
public String getFindText();
public boolean getForwardSearch();
public boolean getFromTop();
public boolean getMatchCase();
public String getReplaceText();
public boolean handleEvent(Event evt);
public boolean isCaseSensitive();
public boolean isForward();
public boolean isWholeWord();
public void setCaseSensitive(boolean b);
public void setFindText(String text);
public void setForward(boolean b);
public void setForwardSearch(boolean b);
public void setFromTop(boolean b);
public void setMatchCase(boolean b);
public void setReplaceText(String text);
public void setWholeWord(boolean b);
}
This class implements a find-and-replace dialog window. The controls for the dialog box are loaded from resource files, depending on the specified dialog box style.
UIComponent
|
+--UIContainer
|
+--UIStateContainer
|
+--UIPanel
|
+--UIRoot
|
+--UIWindow
|
+--UIDialog
|
+--UIFindReplaceDialog
public UIFindReplaceDialog(UIFrame frame, String title, boolean modal);
Creates an empty UIFindReplace dialog box.
Parameter | Description |
frame
| The parent frame of the dialog box.
|
title
| The title of the Find or Replace dialog box. To use default titles, pass null for this parameter.
|
modal
| Set this value to true if the displayed UIFindReplaceDialog dialog box is modal.
|
public boolean action(Event evt, Object what);
Performs operations depending on which button is pushed inside the message box.
Return Value:
Returns true if the action was successfully executed; otherwise, returns false.
Parameter | Description |
evt
| The event, such as key release or mouse up, generated within the message box.
|
what
| The button that was pushed.
|
Remarks:
The action method specifically handles the OK, Cancel, Replace, and Replace All buttons in an UIFindReplaceDialog dialog box, depending on the style of the box. (The FIND style contains no Replace or Replace All buttons.) OK and Cancel are handled by closing the dialog box. Pushing the Replace button generates a call to the doReplace method, and pushing the Replace All button calls the doReplaceAll method.
Note When cancelling the dialog box, the method calls UIDialog.dispose.
protected void createFindDialog();
Creates a Find dialog box. This method is called by the display method. Override this method to change the look of the dialog. By default it will use the resources to load the controls.
Return Value:
No return value.
Exceptions:
ResourceFormattingException
if the dialog was not populated correctly.
See Also: createReplaceDialog
protected void createReplaceDialog();
Creates a Replace dialog box. This method is called by display. Override this method to change the look of the dialog. By default it will use the resources to load the controls.
Return Value:
No return value.
Exceptions:
ResourceFormattingException
if the dialog was not populated correctly.
See Also: createFindDialog
public int display(int style);
Displays the UIFindReplaceDialog dialog box in the given style.
Return Value:
Returns an integer identifying the button that was clicked in the dialog box. Possible return values include ID_FINDNEXT, ID_REPLACE, ID_REPLACEALL, ID_CANCEL, or 0 (if a button was not clicked).
Parameter | Description |
style
| The style of the dialog box. To display a Find dialog box, pass FIND. To display a Replace dialog box, pass REPLACE.
|
public boolean doFindNext();
Override this method to retrieve the next match to the search string, given the current search parameters (case sensitive, for example). This method is called in the action method when the "Find" button of an UIFindReplaceDialog dialog box is pressed.
Note This method should only be overridden if the dialog is not modal.
Return Value:
Returns true if a match is successfully found. Returns true by default.
public boolean doReplace();
Override this method to replace the selected text in the document or selection with that contained in the current replace buffer. This method is called by the action method when the "Replace" button of a REPLACE style dialog box is pushed.
Note This is a blocking call.
Return Value:
Returns true if the replace operation is completed successfully. Returns true by default.
public boolean doReplaceAll();
Override this method to search a selection and replace all matches with the text in the replace buffer. This method is called by the action method, when the "Replace All" button of a REPLACE style dialog box is pushed.
Note This is a blocking call.
Return Value:
Returns true if the replace operation is completed successfully. Returns true by default.
protected IUIComponent findEditControl(int id);
Used in the setReplaceText, setFindText, getReplaceText, getFindText methods to access edit controls contained in scroll viewer controls.
Return Value:
Returns the edit control if found; otherwise, returns null.
Parameter | Description |
id
| This may be either ID_REPLACETEXT or ID_FINDTEXT.
|
public String getFindText();
Retrieves the current search string.
Return Value:
Returns a String object that contains the search string.
See Also: setFindText
public boolean getForwardSearch();
Determines the search direction through a file or selection.
Return Value:
Returns true if the search direction is forward; returns false if the search direction is backward.
See Also: setForwardSearch
public boolean getFromTop();
Determines whether a search starts from the beginning of a file or from the current location of the text caret.
Return Value:
Returns true if the search starts from the beginning of the file; returns false if the search starts from the current location of the caret.
See Also: setFromTop
public boolean getMatchCase();
Determines whether the comparison between the search string and any resulting string should be match the case of the search string.
Return Value:
Returns true if the comparison should match case; otherwise, returns false.
See Also: setMatchCase
public String getReplaceText();
Retrieves the current replace string.
Return Value:
Returns a String object that contains the replace string.
See Also: setReplaceText
public boolean handleEvent(Event evt);
Called to handle events that occur inside the dialog box. In the UIFindReplaceDialog class, this method checks specifically for the WINDOW_DESTROY event identifier, and closes the message box appropriately.
Return Value:
Returns true if the event is handled successfully; otherwise, returns false.
Parameter | Description |
evt
| The event.
|
Overrides:
handleEvent(Event) in UIDialog.
public boolean isCaseSensitive();
Determines whether the comparison between the search string and result should be case sensitive.
Return Value:
Returns true if searches are case sensitive.
See Also: setCaseSensitive
public boolean isForward();
Determines whether a search is in the forward direction. This method is associated with a radio button that the end user uses to specify search direction.
Return Value:
Returns true if a search is in the forward direction; otherwise, returns false.
See Also: setForward
public boolean isWholeWord();
Determines whether a search finds all instances of the search string or finds only tokenized instances (complete words).
Return Value:
Returns true if the search only matches tokenized instances of the search string; otherwise, returns false.
See Also: setWholeWord
public void setCaseSensitive(boolean b);
Sets whether the string comparison should be case sensitive.
Return Value:
No return value.
Parameter | Description |
b
| Set to true to make a search case sensitive.
|
See Also: isCaseSensitive
public void setFindText(String text);
Sets the current search string to the specified text.
Return Value:
No return value.
Parameter | Description |
text
| A buffer that contains the current search string.
|
See Also: getFindText
public void setForward(boolean b);
Sets a search in the forward direction when the appropriate radio button is selected.
Return Value:
No return value.
Parameter | Description |
b
| Set to true to specify forward searches.
|
See Also: isForward
public void setForwardSearch(boolean b);
Sets the direction of the search through a file or selection.
Return Value:
No return value.
Parameter | Description |
b
| Set to true if the search operation proceeds forward through the document or selection. If b is set to false, the search operation proceeds backward.
|
See Also: getForwardSearch
public void setFromTop(boolean b);
Sets whether the search starts from the beginning of the file or from the current location of the caret.
Return Value:
No return value.
Parameter | Description |
b
| Set to true if the search starts from the beginning of the file. Set b to false if the search starts from the current location of the cursor.
|
See Also: getFromTop
public void setMatchCase(boolean b);
Sets whether the string comparison should be match case.
Return Value:
No return value.
Parameter | Description |
b
| Set to true if the comparison should match case.
|
See Also: getMatchCase
public void setReplaceText(String text);
Sets the current replace string to the specified text.
Return Value:
No return value.
Parameter | Description |
text
| A buffer that contains the current replace string.
|
See Also: getReplaceText
public void setWholeWord(boolean b);
Sets whether a search should include all instances of a search string (including fragments of a complete token) or if the search includes only tokenized instances of the search string.
Return Value:
No return value.
Parameter | Description |
b
| Set this value to true if the search should match only tokenized instances with the search string.
|
See Also: isWholeWord
- FIND
- A dialog box style that is used for only searching operations. Typically, this dialog box contains only one edit field and enables the user to set the properties of a particular search, such as check boxes for matching whole words and matching case in the search string.
- ID_BACKWARDS
- The identifier of one of the two search direction buttons in the dialog box.
- ID_CANCEL
- The identifier of the Cancel button in the dialog box.
- ID_CASESENSITIVE
- The identifier of the case sensitive search option checkbox in the dialog box.
- ID_FINDNEXT
- The identifier of the Find Next button in the dialog box.
- ID_FINDTEXT
- The identifier for the search string.
- ID_FORWARDS
- The identifier of one of the two search direction buttons in the dialog box.
- ID_REPLACE
- The identifier of the Replace button in the dialog box.
- ID_REPLACEALL
- The identifier of the Replace All button in the dialog box.
- ID_REPLACETEXT
- The identifier for the replace string.
- ID_WHOLEWORD
- The identifier of the whole word search option checkbox in the dialog box.
- REPLACE
- A dialog box style that is used for both searching and replacing operations. Typically, this style of dialog box contains two edit fields, Replace and Replace All buttons, as well as the other features commonly associated with the FIND style.