edu.rice.cs.drjava.ui
Class FindReplacePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by edu.rice.cs.drjava.ui.TabbedPanel
                      extended by edu.rice.cs.drjava.ui.FindReplacePanel
All Implemented Interfaces:
ClipboardOwner, DropTargetListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

 class FindReplacePanel
extends TabbedPanel
implements ClipboardOwner

The tabbed panel that handles requests for finding and replacing text.

Version:
$Id: FindReplacePanel.java 5431 2011-04-16 07:58:48Z mgricken $

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  boolean _caretChanged
           
private  CaretListener _caretListener
          Listens for changes to the cursor position in order to reset the start position
private  DefinitionsPane _defPane
           
private  Action _doFindAction
           
private  Action _findAllAction
           
private  JButton _findAllButton
           
private  JTextPane _findField
           
private  JLabel _findLabelBot
           
(package private)  Action _findNextAction
          The action performed when searching forwards
private  JButton _findNextButton
           
(package private)  Action _findPreviousAction
           
private  JButton _findPreviousButton
           
private  JCheckBox _ignoreCommentsAndStrings
           
private  JCheckBox _ignoreTestCases
           
private  boolean _isFindReplaceActive
           
private  FindReplaceMachine _machine
           
private  JCheckBox _matchCase
           
private  JCheckBox _matchWholeWord
           
private  SingleDisplayModel _model
           
(package private)  Action _replaceAction
           
private  Action _replaceAllAction
          Replaces all occurences of the findfield text with that of the replacefield text both before and after the cursor without prompting for wrapping around the end of the document.
private  JButton _replaceAllButton
           
private  JButton _replaceButton
           
private  JTextPane _replaceField
           
(package private)  Action _replaceFindNextAction
           
private  JButton _replaceFindNextButton
           
(package private)  Action _replaceFindPreviousAction
           
private  JButton _replaceFindPreviousButton
           
private  JCheckBox _searchAllDocuments
           
private  JCheckBox _searchSelectionOnly
           
(package private)  Action _standardNewlineAction
           
(package private)  Action copyAction
          Default copy action.
(package private)  Action cutAction
          Default cut action.
static char LEFT
           
static char RIGHT
           
 
Fields inherited from class edu.rice.cs.drjava.ui.TabbedPanel
_closeButton, _closePanel, _displayed, _frame, _mainPanel, dropTarget
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FindReplacePanel(MainFrame frame, SingleDisplayModel model)
          Standard Constructor.
 
Method Summary
protected  void _close()
          Visibly closes the panel and removes it from the frame.
private  void _doFind()
          Abstracted out since this is called from findNext and findPrevious.
private  void _findAll()
          Performs "find all" command.
private  void _replace()
           
private  void _replaceAll()
          Performs the "replace all" command.
private  void _replaceFindNext()
           
private  void _replaceFindPrevious()
           
private  void _selectFoundOrReplacedItem(int length)
          This method is used to select the item that has been inserted in a replacement.
private  void _selectFoundOrReplacedItem(int from, int to)
          Will select the identified text (from, to).
private  void _updateMachine()
          Sets appropriate variables in the FindReplaceMachine if the caret has been changed.
(package private)  void beginListeningTo(DefinitionsPane defPane)
          Called from MainFrame in response to opening this or changes in the active document.
 void findAll(String searchStr, boolean searchAll, boolean searchSelectionOnly, boolean matchCase, boolean wholeWord, boolean noComments, boolean noTestCases, OpenDefinitionsDocument startDoc, RegionManager<MovingDocumentRegion> rm, MovingDocumentRegion region, FindResultsPanel panel)
          Performs "find all" with the specified options.
(package private)  void findNext()
          Performs the "find next" command.
(package private)  void findPrevious()
          Called when user the activates "find previous" command.
 DefinitionsPane getDefPane()
          METHODS FOR TESTING PURPOSES ONLY
(package private)  JTextPane getFindField()
          Getter method for the _findField component
 JButton getFindNextButton()
           
 boolean isFindReplaceActive()
           
 boolean isSearchBackwards()
           
 void lostOwnership(Clipboard clipboard, Transferable contents)
          We lost ownership of what we put in the clipboard.
 boolean requestFocusInWindow()
          Focuses the find/replace dialog in the window, placing the focus on the _findField, and selecting all the text.
 void setFieldFont(Font f)
          Sets the font of the find and replace fields to f.
 void setSearchBackwards(boolean b)
           
 void stopListening()
          Called from MainFrame upon closing this Dialog or changes in the active document.
 void updateFirstDocInSearch()
          Updates the first document where the current all-document search began (called in two places: either when the _findField is updated, or when the user changes documents.
 
Methods inherited from class edu.rice.cs.drjava.ui.TabbedPanel
addCloseListener, dragEnter, dragExit, dragOver, drop, dropActionChanged, getMainPanel, getName, isDisplayed, setDisplayed, setVisible
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT

public static final char LEFT
See Also:
Constant Field Values

RIGHT

public static final char RIGHT
See Also:
Constant Field Values

_findNextButton

private JButton _findNextButton

_findPreviousButton

private JButton _findPreviousButton

_findAllButton

private JButton _findAllButton

_replaceButton

private JButton _replaceButton

_replaceFindNextButton

private JButton _replaceFindNextButton

_replaceFindPreviousButton

private JButton _replaceFindPreviousButton

_replaceAllButton

private JButton _replaceAllButton

_findField

private JTextPane _findField

_replaceField

private JTextPane _replaceField

_findLabelBot

private JLabel _findLabelBot

_ignoreCommentsAndStrings

private JCheckBox _ignoreCommentsAndStrings

_matchCase

private JCheckBox _matchCase

_searchAllDocuments

private JCheckBox _searchAllDocuments

_matchWholeWord

private JCheckBox _matchWholeWord

_ignoreTestCases

private JCheckBox _ignoreTestCases

_searchSelectionOnly

private JCheckBox _searchSelectionOnly

_machine

private FindReplaceMachine _machine

_model

private SingleDisplayModel _model

_defPane

private DefinitionsPane _defPane

_caretChanged

private boolean _caretChanged

_isFindReplaceActive

private boolean _isFindReplaceActive

_caretListener

private CaretListener _caretListener
Listens for changes to the cursor position in order to reset the start position


_findNextAction

Action _findNextAction
The action performed when searching forwards


_findPreviousAction

Action _findPreviousAction

_findAllAction

private Action _findAllAction

_doFindAction

private Action _doFindAction

_replaceAction

Action _replaceAction

_replaceFindNextAction

Action _replaceFindNextAction

_replaceFindPreviousAction

Action _replaceFindPreviousAction

_replaceAllAction

private Action _replaceAllAction
Replaces all occurences of the findfield text with that of the replacefield text both before and after the cursor without prompting for wrapping around the end of the document.


_standardNewlineAction

Action _standardNewlineAction

cutAction

Action cutAction
Default cut action.


copyAction

Action copyAction
Default copy action.

Constructor Detail

FindReplacePanel

public FindReplacePanel(MainFrame frame,
                        SingleDisplayModel model)
Standard Constructor.

Parameters:
frame - the overall enclosing window
model - the model containing the documents to search
Method Detail

isFindReplaceActive

public boolean isFindReplaceActive()

requestFocusInWindow

public boolean requestFocusInWindow()
Focuses the find/replace dialog in the window, placing the focus on the _findField, and selecting all the text.

Overrides:
requestFocusInWindow in class TabbedPanel

getFindField

JTextPane getFindField()
Getter method for the _findField component


_findAll

private void _findAll()
Performs "find all" command.


findAll

public void findAll(String searchStr,
                    boolean searchAll,
                    boolean searchSelectionOnly,
                    boolean matchCase,
                    boolean wholeWord,
                    boolean noComments,
                    boolean noTestCases,
                    OpenDefinitionsDocument startDoc,
                    RegionManager<MovingDocumentRegion> rm,
                    MovingDocumentRegion region,
                    FindResultsPanel panel)
Performs "find all" with the specified options.


_replaceAll

private void _replaceAll()
Performs the "replace all" command.


_replaceFindNext

private void _replaceFindNext()

_replaceFindPrevious

private void _replaceFindPrevious()

findNext

void findNext()
Performs the "find next" command. Package visibility to accommodate calls from MainFrame.


findPrevious

void findPrevious()
Called when user the activates "find previous" command. Package visibility to accommodate calls from MainFrame.


_replace

private void _replace()

beginListeningTo

void beginListeningTo(DefinitionsPane defPane)
Called from MainFrame in response to opening this or changes in the active document.


stopListening

public void stopListening()
Called from MainFrame upon closing this Dialog or changes in the active document.


_doFind

private void _doFind()
Abstracted out since this is called from findNext and findPrevious.


_close

protected void _close()
Description copied from class: TabbedPanel
Visibly closes the panel and removes it from the frame.

Overrides:
_close in class TabbedPanel

setSearchBackwards

public void setSearchBackwards(boolean b)

isSearchBackwards

public boolean isSearchBackwards()

setFieldFont

public void setFieldFont(Font f)
Sets the font of the find and replace fields to f.


updateFirstDocInSearch

public void updateFirstDocInSearch()
Updates the first document where the current all-document search began (called in two places: either when the _findField is updated, or when the user changes documents.


_updateMachine

private void _updateMachine()
Sets appropriate variables in the FindReplaceMachine if the caret has been changed.


_selectFoundOrReplacedItem

private void _selectFoundOrReplacedItem(int length)
This method is used to select the item that has been inserted in a replacement. Assumes the current offset identifies the found or replaced item. In a forward search, this offset is the RIGHT edge of the found/replaced item; in a backwards search it is the LEFT edge.


_selectFoundOrReplacedItem

private void _selectFoundOrReplacedItem(int from,
                                        int to)
Will select the identified text (from, to). Note that positions are technically between characters, so there is no distinction between open and closed intervals. Originally highlighted the text, but we ran into problems with the document remove method changing the view to where the cursor was located, resulting in replace constantly jumping from the replaced text back to the cursor. There was a removePreviousHighlight method which was removed since selections are removed automatically upon a caret change.


lostOwnership

public void lostOwnership(Clipboard clipboard,
                          Transferable contents)
We lost ownership of what we put in the clipboard.

Specified by:
lostOwnership in interface ClipboardOwner

getDefPane

public DefinitionsPane getDefPane()
METHODS FOR TESTING PURPOSES ONLY


getFindNextButton

public JButton getFindNextButton()