Class FindReplaceDialog

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class FindReplaceDialog extends JDialog
Dialog to manage find and replace on a Document shown in a JEditorPane.

The component has a 'pluggable' interface about how to deal with the event that one document has been searched to the end. If it is constructed with a FindReplaceListener, it shows an additional checkbox 'Whole project' where the user can select, if a group of documents shall be searched instead of a single document.

If only one document is searched, the dialog searches only in the document currently shown in the editor.

By adding a FindReplaceListener listening for FindReplaceEvents, the FindReplaceDialog notifies other classes about the fact that a group of documents shall be searched instead of only the current one.

Initially FindReplaceDialog notifies the listener that the first document in the group shall be loaded into the editor.

After loading the first document and resuming the find or replace operation, the listener gets informed that the end of a document has been reached. A handling method for that event should cause the editor to load the next document in the group before it resumes the find or replace operation.

Example for an implementation of FindReplaceListener:

IMPORTANT: the methods of the FindReplaceListener need to call either resumeOperation() or terminateOperation() on the FindReplaceDialog, that fired the FindReplaceEvent. Otherwise the FindReplaceDialog could 'hang'.

   FindReplaceDialog frd = new FindReplaceDialog(aFrame,
                             myEditorPane, new MyFindReplaceListener());

   protected class MyFindReplaceListener implements FindReplaceListener {
     public void getNextDocument(FindReplaceEvent e) {
       if(documentsLeft()) { // documentsLeft() is a method coded somewhere else
         myEditorPane.setDocument(nextDocument()); // nextDocument() is a method coded somewhere else
         ((FindReplaceDialog) e.getSource()).resumeOperation();
       }
       else {
         ((FindReplaceDialog) e.getSource()).terminateOperation();
       }
     }

     public void getFirstDocument(FindReplaceEvent e) {
       myEditorPane.setDocument(firstDocument()); // firstDocument() is a method coded somewhere else
       ((FindReplaceDialog) e.getSource()).resumeOperation();
     }
   }
 

Added i18n support for application SimplyHTML in version 1.5

See Also:
  • Field Details

  • Constructor Details

    • FindReplaceDialog

      public FindReplaceDialog()
      Construct a FindReplaceDialog.

      Does not show the dialog window, as fields 'editor' and 'doc' have to be set separately before the dialog is operable.

      See Also:
    • FindReplaceDialog

      public FindReplaceDialog(Frame owner, JEditorPane editor)
      Construct a FindReplaceDialog.

      Shows the dialog window modal, packed and centered over the owning Frame after construction.

      Using this constructor implies the dialog shall be used in mode MODE_DOCUMENT

      Parameters:
      owner - the Frame that owns this dialog
      editor - JEditorPane displaying the Document to seach in
      See Also:
    • FindReplaceDialog

      public FindReplaceDialog(Frame owner, JEditorPane editor, FindReplaceListener listener)
      Construct a FindReplaceDialog.

      Shows the dialog window modal, packed and centered over the owning Frame after construction.

      Using this constructor implies the dialog shall be used in mode MODE_PROJECT

      Parameters:
      owner - the Frame that owns this dialog
      editor - JEditorPane displaying the Document to seach in
      listener - listener for handling FindReplaceEvents
      See Also:
  • Method Details

    • addFindReplaceListener

      public void addFindReplaceListener(FindReplaceListener listener)
      add an event listener to this dialog.
      Parameters:
      listener - the event listener to add
    • removeFindReplaceListener

      public void removeFindReplaceListener(FindReplaceListener listener)
      remove an event listener from this dialog.
      Parameters:
      listener - the event listener to remove
    • resumeOperation

      public void resumeOperation()
      Resume the current operation after a getFirstDocument or getNextDocument event was fired
    • terminateOperation

      public void terminateOperation()
      Terminate the current operation
    • setEditor

      public void setEditor(JEditorPane editor)
      Set the JEditorPane holding the document to be searched
      Parameters:
      editor - the JEditorPane holding the document to be searched
      See Also:
    • setMode

      public void setMode(int mode)
      Set the mode.

      Switches between

      • MODE_DOCUMENT: only the document currently viewed in the editor can be searched
      • MODE_PROJECT: An additional check box allows to choose, whether or not the user likes to search a whole group of documents.
      Parameters:
      mode - one of MODE_DOCUMENT and MODE_PROJECT
    • setSearchingBusyCursor

      public void setSearchingBusyCursor()
    • setSearchingDefaultCursor

      public void setSearchingDefaultCursor()
    • centerDialog

      public void centerDialog(Frame owner)
      Center this dialog window relative to its owning Frame.
      Parameters:
      owner - Frame owning this dialog
      See Also:
    • rememberSearchTerm

      public static void rememberSearchTerm(String searchTerm, JComboBox searchTermCombo)