org.ceryle.ui.search
Class FindReplaceDialog

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Dialog
                  extended by javax.swing.JDialog
                      extended by org.ceryle.ui.search.FindReplaceDialog
All Implemented Interfaces:
ActionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants, MessageWriter

public class FindReplaceDialog
extends JDialog
implements ActionListener, MessageWriter

A class that creates a dialog box used for searching and replacing within the editor text area. The dialog is used for either Find or Replace operations, depending on how it is called. This uses the gnu.regexp regular expression (RE) package, which allows for sixteen different (!) RE syntax variations, which should pretty much satisfy anyone's preferences.

Since:
JDK1.3
Version:
$Id: FindReplaceDialog.java,v 1.20 2007-06-20 04:41:24 altheim Exp $
Author:
Murray Altheim
See Also:
Serialized Form

Nested Class Summary
 class FindReplaceDialog.KeyHandler
           
 
Nested classes/interfaces inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes/interfaces inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  String ACTION_graph
           
protected  String ACTION_keyword
           
protected  String ACTION_regexp
           
protected  String ACTION_string
           
protected  String ACTION_xpath
           
static int BIT_asyoutype
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_caseSens
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_gettopic
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_graph
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_keyword
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_modal
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_multiline
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_regexp
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_replace
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_searchId
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_string
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_synonyms
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_vizOnly
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int BIT_xpath
          Indices for BitSet settings used for searching and replacing (see code for docs).
static int bitcount
          This number should match the number of BitSet settings (the maximum count + 1).
static int defaultLength
          Default length (in characters) for the Find and Replace fields.
static String graphNid
          The node ID within the 'help' Collection for the graph search Help topic.
static String graphResultsHeight
          The identifier of the property containing the height of the find dialog box when the graph results are visible.
protected  FindReplaceDialog.KeyHandler key_handler
           
static String keywordNid
          The node ID within the 'help' Collection for the keyword search Help topic.
static String keywordResultsHeight
          The identifier of the property containing the height of the find dialog box when the keyword results are visible.
static int maxHistory
          Default number of Find and Replace history items to store (must be greater than zero).
static String regexpNid
          The node ID within the 'help' Collection for the regular expression search Help topic.
static RESyntax[] resyntax
          An array of RESyntax types (0-15).
static String[] resyntaxDesc
          An array containing the names of the available types of regular expression syntaxes.
static String searchNid
          The node ID within the 'help' Collection for the introduction to searching Help topic.
static String stringNid
          The node ID within the 'help' Collection for the string match search Help topic.
static String xpathNid
          The node ID within the 'help' Collection for the XPath search Help topic.
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FindReplaceDialog(Desktop desktop, GraphView graphview, String title)
          Constructor for a FindReplace dialog in 'return Topic' mode.
FindReplaceDialog(Desktop desktop, String defaultString, BitSet settings)
          Constructor for a FindReplace dialog, including find and replace histories as Vectors, an optional default search String defaultString (which can be null), and a BitSet settings to provide various search and replacement settings.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Responds to the radio buttons.
 void clearResults()
          Clears the results list.
 void closeDialog()
          Closes the FindReplace dialog (disposing of it).
 void configure(BitSet bits)
          Shows or hides the replace field and enables or disables buttons according to the provided bitwise settings.
 void doFind(boolean next)
          Performs the Find function, Find Next if next is true.
protected  void doReplace(boolean all)
          Performs the replace function, on the entire document if the boolean all is true.
protected  boolean find(JTextArea textarea, String searchString, boolean next)
          Performs the find function using the search string searchString, starting at the beginning of the text if next is false, or at the end of the last search if true.
 void findNext()
          Performs the find function using the existing search string, from the end of the last search location in the text.
protected  DocumentView getDocumentView()
          Returns the current DocumentView.
protected  GraphView getGraphView()
          Returns the current GraphView.
 KeywordPanel getKeywordPanel()
          Lazily instantiates the keyword search panel.
 Lexicon getLexicon()
          Returns a lazily-instantiated lexicon utility.
 boolean getReplaceMode()
          Returns true if the dialog is currently in replace mode.
protected  RESyntax getRESyntax(int index)
          Returns an RESyntax object when provided an index index synchronous with the RE syntax JComboBox.
 TNode getSelectedTNode()
          Returns the TNode selected in 'return Topic' mode, or null if there was no selected Topic.
 Topic getSelectedTopic()
          Returns the Topic selected in 'return Topic' mode, or null if there was no selected Topic.
 BitSet getSettings()
          Returns the current dialog settings as a BitSet.
 boolean harmonizeWithView()
          Configure the dialog's search type to be compatible with the current view.
protected  void hideDialog()
          Hides the FindReplace dialog.
 void keyInSource()
          Called when any key is typed into the search entry.
 boolean lexiconAvailable()
          Returns true if lexicon/synonym support is available.
 void setCLUT(ColorLookupTable clut)
          Sets the ColorLookupTable (CLUT) to clut.
 void setReplaceMode(boolean replace)
          Depending on the parameter, sets the dialog mode to either find (false) or replace (true) mode.
static void setSearchMode(BitSet bs, int mode)
          Sets the search mode of the provided BitSet to one of the available modes.
 void setSearchMode(int mode)
          Sets the search mode to one of the available modes, then calls configure(BitSet) to update the UI.
 void setSearchString(String s)
          Sets the search string to s.
 void setVisible(boolean visible)
          Overrides the dialog's method to put the insertion caret into the search field.
 void updateSelectionInfo(int[] stats)
          Updates the display of search domain selection information.
 String writeMessage(int status, String message)
          Writes the message to the existing MessageHandler service, prepending a status indicator for errors and warnings.
 void writeMessage(String message)
          Writes the message to the existing MessageHandler service.
 void writeStatus(String message)
          Sets the content of the status line to the String message.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

searchNid

public static String searchNid
The node ID within the 'help' Collection for the introduction to searching Help topic. Default is "search".


stringNid

public static String stringNid
The node ID within the 'help' Collection for the string match search Help topic. Default is "search_string".


regexpNid

public static String regexpNid
The node ID within the 'help' Collection for the regular expression search Help topic. Default is "search_regexp".


keywordNid

public static String keywordNid
The node ID within the 'help' Collection for the keyword search Help topic. Default is "search_keywords".


xpathNid

public static String xpathNid
The node ID within the 'help' Collection for the XPath search Help topic. Default is "search_xpath".


graphNid

public static String graphNid
The node ID within the 'help' Collection for the graph search Help topic. Default is "search_graph".


keywordResultsHeight

public static final String keywordResultsHeight
The identifier of the property containing the height of the find dialog box when the keyword results are visible.

See Also:
Constant Field Values

graphResultsHeight

public static final String graphResultsHeight
The identifier of the property containing the height of the find dialog box when the graph results are visible.

See Also:
Constant Field Values

defaultLength

public static int defaultLength
Default length (in characters) for the Find and Replace fields.


maxHistory

public static int maxHistory
Default number of Find and Replace history items to store (must be greater than zero).


bitcount

public static final int bitcount
This number should match the number of BitSet settings (the maximum count + 1).

See Also:
Constant Field Values

BIT_replace

public static final int BIT_replace
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_string

public static final int BIT_string
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_regexp

public static final int BIT_regexp
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_keyword

public static final int BIT_keyword
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_xpath

public static final int BIT_xpath
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_graph

public static final int BIT_graph
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_caseSens

public static final int BIT_caseSens
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_multiline

public static final int BIT_multiline
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_vizOnly

public static final int BIT_vizOnly
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_searchId

public static final int BIT_searchId
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_modal

public static final int BIT_modal
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_asyoutype

public static final int BIT_asyoutype
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_synonyms

public static final int BIT_synonyms
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

BIT_gettopic

public static final int BIT_gettopic
Indices for BitSet settings used for searching and replacing (see code for docs).

See Also:
Constant Field Values

resyntax

public static final RESyntax[] resyntax
An array of RESyntax types (0-15). The default used can be set from the Ceryle property http://purl.org/ceryle/prop/#reSyntaxDefault (in the ".ceryle.prop" file). Enumerated values include: awk utility (0), ed utility (1), egrep utility (2), grep utility (3), sed utility (4), GNU Emacs editor (5), perl4 (6), perl4 single line mode (7), perl5 (8), perl5 single line mode (9), POSIX awk specification (10), POSIX basic regexp (11), POSIX egrep specification (12 ), POSIX extended regexp (13), POSIX basic minimal regexp (14), and POSIX extended minimal regexp (15).

See Also:
RESyntax

resyntaxDesc

public static final String[] resyntaxDesc
An array containing the names of the available types of regular expression syntaxes. This list is aligned with the values of resyntax.


key_handler

protected FindReplaceDialog.KeyHandler key_handler

ACTION_string

protected final String ACTION_string
See Also:
Constant Field Values

ACTION_regexp

protected final String ACTION_regexp
See Also:
Constant Field Values

ACTION_keyword

protected final String ACTION_keyword
See Also:
Constant Field Values

ACTION_graph

protected final String ACTION_graph
See Also:
Constant Field Values

ACTION_xpath

protected final String ACTION_xpath
See Also:
Constant Field Values
Constructor Detail

FindReplaceDialog

public FindReplaceDialog(Desktop desktop,
                         GraphView graphview,
                         String title)
Constructor for a FindReplace dialog in 'return Topic' mode. This is a graph search mode designed to minimize available features, returning a single selected Topic.


FindReplaceDialog

public FindReplaceDialog(Desktop desktop,
                         String defaultString,
                         BitSet settings)
Constructor for a FindReplace dialog, including find and replace histories as Vectors, an optional default search String defaultString (which can be null), and a BitSet settings to provide various search and replacement settings. If both keyword search and replace mode are set, they are mutually exclusive and the latter takes precedence.

Method Detail

setVisible

public void setVisible(boolean visible)
Overrides the dialog's method to put the insertion caret into the search field.

Overrides:
setVisible in class Component

harmonizeWithView

public boolean harmonizeWithView()
Configure the dialog's search type to be compatible with the current view.

Returns:
true if any configuration changes were made.

setSearchString

public void setSearchString(String s)
Sets the search string to s.


setCLUT

public void setCLUT(ColorLookupTable clut)
Sets the ColorLookupTable (CLUT) to clut. This is used by both the keyword and graph search panels.


setSearchMode

public void setSearchMode(int mode)
Sets the search mode to one of the available modes, then calls configure(BitSet) to update the UI. The modes include:


setSearchMode

public static void setSearchMode(BitSet bs,
                                 int mode)
Sets the search mode of the provided BitSet to one of the available modes.


configure

public void configure(BitSet bits)
Shows or hides the replace field and enables or disables buttons according to the provided bitwise settings. If a null is provided, the dialog is configured according to its current bitwise settings. If this method notices a discrepancy between the dialog and the "Replace" mode setting, it will reconfigure the dialog type accordingly.


getReplaceMode

public boolean getReplaceMode()
Returns true if the dialog is currently in replace mode.


setReplaceMode

public void setReplaceMode(boolean replace)
Depending on the parameter, sets the dialog mode to either find (false) or replace (true) mode.


getSettings

public BitSet getSettings()
Returns the current dialog settings as a BitSet.


getKeywordPanel

public KeywordPanel getKeywordPanel()
Lazily instantiates the keyword search panel. After that, a call to this method returns the existing panel.


updateSelectionInfo

public void updateSelectionInfo(int[] stats)
Updates the display of search domain selection information. This is called each time the ActionListener for the search list indicates a user input.

See Also:
SearchTree.getSelectionInfo()

getGraphView

protected GraphView getGraphView()
Returns the current GraphView. Returns null if not available.


getDocumentView

protected DocumentView getDocumentView()
Returns the current DocumentView. If one does not exist, displays an error message, returning null. Not all methods require a DocumentView (e.g., keyword search). This is used internally to the class to obtain the document to be searched.


findNext

public void findNext()
Performs the find function using the existing search string, from the end of the last search location in the text.


doFind

public void doFind(boolean next)
Performs the Find function, Find Next if next is true. If the search string is null (i.e., a search has not yet occurred), a Find is performed. This generally is not called directly because it uses but does not interact with the find field, which needs to be set prior to this method being called.


keyInSource

public void keyInSource()
Called when any key is typed into the search entry. This is public only so that it can be called by the LocationBar in harmonizing its 'as you type' feature.


clearResults

public void clearResults()
Clears the results list.


find

protected boolean find(JTextArea textarea,
                       String searchString,
                       boolean next)
Performs the find function using the search string searchString, starting at the beginning of the text if next is false, or at the end of the last search if true. Returns true if the search was successful.


getSelectedTNode

public TNode getSelectedTNode()
Returns the TNode selected in 'return Topic' mode, or null if there was no selected Topic.


getSelectedTopic

public Topic getSelectedTopic()
Returns the Topic selected in 'return Topic' mode, or null if there was no selected Topic.


doReplace

protected void doReplace(boolean all)
Performs the replace function, on the entire document if the boolean all is true. Mode and settings affect the process used.


getRESyntax

protected RESyntax getRESyntax(int index)
Returns an RESyntax object when provided an index index synchronous with the RE syntax JComboBox.


writeStatus

public void writeStatus(String message)
Sets the content of the status line to the String message. Implementation method for the MessageWriter API.

Specified by:
writeStatus in interface MessageWriter