Packages
 In this topic

*Constructors

*Methods

*Fields

 

Packages   PreviousThis PackageNext
Package com.ms.ui   Previous This
Package
Next

 


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

Constructors

UIFindReplaceDialog

public UIFindReplaceDialog(UIFrame frame, String title, boolean modal);

Creates an empty UIFindReplace dialog box.

ParameterDescription
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.

Methods

action

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.

ParameterDescription
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.

createFindDialog

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

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

display

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).

ParameterDescription
style The style of the dialog box. To display a Find dialog box, pass FIND. To display a Replace dialog box, pass REPLACE.

doFindNext

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.

doReplace

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.

doReplaceAll

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.

findEditControl

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.

ParameterDescription
id This may be either ID_REPLACETEXT or ID_FINDTEXT.

getFindText

public String getFindText();

Retrieves the current search string.

Return Value:

Returns a String object that contains the search string.

See Also: setFindText

getForwardSearch

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

getFromTop

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

getMatchCase

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

getReplaceText

public String getReplaceText();

Retrieves the current replace string.

Return Value:

Returns a String object that contains the replace string.

See Also: setReplaceText

handleEvent

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.

ParameterDescription
evt The event.

Overrides:

handleEvent(Event) in UIDialog.

isCaseSensitive

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

isForward

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

isWholeWord

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

setCaseSensitive

public void setCaseSensitive(boolean b);

Sets whether the string comparison should be case sensitive.

Return Value:

No return value.

ParameterDescription
b Set to true to make a search case sensitive.

See Also: isCaseSensitive

setFindText

public void setFindText(String text);

Sets the current search string to the specified text.

Return Value:

No return value.

ParameterDescription
text A buffer that contains the current search string.

See Also: getFindText

setForward

public void setForward(boolean b);

Sets a search in the forward direction when the appropriate radio button is selected.

Return Value:

No return value.

ParameterDescription
b Set to true to specify forward searches.

See Also: isForward

setForwardSearch

public void setForwardSearch(boolean b);

Sets the direction of the search through a file or selection.

Return Value:

No return value.

ParameterDescription
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

setFromTop

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.

ParameterDescription
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

setMatchCase

public void setMatchCase(boolean b);

Sets whether the string comparison should be match case.

Return Value:

No return value.

ParameterDescription
b Set to true if the comparison should match case.

See Also: getMatchCase

setReplaceText

public void setReplaceText(String text);

Sets the current replace string to the specified text.

Return Value:

No return value.

ParameterDescription
text A buffer that contains the current replace string.

See Also: getReplaceText

setWholeWord

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.

ParameterDescription
b Set this value to true if the search should match only tokenized instances with the search string.

See Also: isWholeWord

Fields

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.

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.