de.calcom.cclib.text

Class FindReplaceDialog

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

Version: 1.5, April 27, 2003

Author: Ulrich Hilger CalCom http://www.calcom.de info@calcom.de

See Also: javax.swing.text.Document javax.swing.JEditorPane

Field Summary
static intMODE_DOCUMENT
static intMODE_PROJECT
static intOP_FIND
static intOP_NONE
static intOP_REPLACE
static intRO_ALL
static intRO_DONE
static intRO_NO
static intRO_YES
static booleanSTATE_LOCKED
static booleanSTATE_UNLOCKED
Constructor Summary
FindReplaceDialog()
Construct a FindReplaceDialog.
FindReplaceDialog(Frame owner, JEditorPane editor)
Construct a FindReplaceDialog.
FindReplaceDialog(Frame owner, JEditorPane editor, FindReplaceListener listener)
Construct a FindReplaceDialog.
Method Summary
voidaddFindReplaceListener(FindReplaceListener listener)
add an event listener to this dialog.
voidcenterDialog(Frame owner)
Center this dialog window relative to its owning Frame.
voidremoveFindReplaceListener(FindReplaceListener listener)
remove an event listener from this dialog.
voidresumeOperation()
Resume the current operation after a getFirstDocument or getNextDocument event was fired
voidsetEditor(JEditorPane editor)
Set the JEditorPane holding the document to be searched
voidsetMode(int mode)
Set the mode.
voidterminateOperation()
Terminate the current operation

Field Detail

MODE_DOCUMENT

public static final int MODE_DOCUMENT

MODE_PROJECT

public static final int MODE_PROJECT

OP_FIND

public static final int OP_FIND

OP_NONE

public static final int OP_NONE

OP_REPLACE

public static final int OP_REPLACE

RO_ALL

public static final int RO_ALL

RO_DONE

public static final int RO_DONE

RO_NO

public static final int RO_NO

RO_YES

public static final int RO_YES

STATE_LOCKED

public static final boolean STATE_LOCKED

STATE_UNLOCKED

public static final boolean STATE_UNLOCKED

Constructor Detail

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: javax.swing.JEditorPane javax.swing.text.Document java.awt.Frame

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: javax.swing.JEditorPane javax.swing.text.Document java.awt.Frame

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: javax.swing.JEditorPane javax.swing.text.Document java.awt.Frame

Method Detail

addFindReplaceListener

public void addFindReplaceListener(FindReplaceListener listener)
add an event listener to this dialog.

Parameters: listener the event listener to add

centerDialog

public void centerDialog(Frame owner)
Center this dialog window relative to its owning Frame.

Parameters: owner Frame owning this dialog

See Also: java.awt.Frame

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

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: javax.swing.JEditorPane

setMode

public void setMode(int mode)
Set the mode.

Switches between

Parameters: mode one of MODE_DOCUMENT and MODE_PROJECT

terminateOperation

public void terminateOperation()
Terminate the current operation