Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.greenstone.gatherer.sarm
Class SearchAndReplace  view SearchAndReplace download SearchAndReplace.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Dialog
                  extended byjavax.swing.JDialog
                      extended byorg.greenstone.gatherer.gui.ModalDialog
                          extended byorg.greenstone.gatherer.sarm.SearchAndReplace
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable, javax.swing.WindowConstants

public class SearchAndReplace
extends org.greenstone.gatherer.gui.ModalDialog

Provides a convenient class which searches through all of the various data attached to a collection, globally searching and replacing values as necessary, and firing the relevant events to have the gui update properly.

Version:
2.3

Nested Class Summary
private  class SearchAndReplace.CloseActionListener
           
private  class SearchAndReplace.FindActionListener
           
private  class SearchAndReplace.FindNextActionListener
           
private  class SearchAndReplace.RedoActionListener
           
private  class SearchAndReplace.ReplaceActionListener
           
private  class SearchAndReplace.ReplaceAllActionListener
           
private  class SearchAndReplace.ReplaceKeyListener
           
private  class SearchAndReplace.ResetActionListener
           
private  class SearchAndReplace.SearchKeyListener
           
private  class SearchAndReplace.UndoActionListener
           
private  class SearchAndReplace.UndoItem
           
 
Nested classes inherited from class javax.swing.JDialog
javax.swing.JDialog.AccessibleJDialog
 
Nested classes inherited from class java.awt.Dialog
java.awt.Dialog.AccessibleAWTDialog
 
Nested classes inherited from class java.awt.Window
java.awt.Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  javax.swing.JCheckBox case_sensitive
          When checked this control indicates the search comparisons should be made taking into account case.
private  javax.swing.JButton close_button
          The button used to close the dialog.
private  org.greenstone.gatherer.msm.ElementWrapper current_element
          The metadata element that we are currently inspecting.
private  org.greenstone.gatherer.file.FileNode current_record
          The file record that we are currently inspecting.
private  org.greenstone.gatherer.msm.Metadata current_value
          This is the current metadata value that we are inspecting.
private  java.util.Vector elements
          A vector of the metadata elements attached to this collection, in the form of ElementWrappers for ease of data access.
private  boolean enable_replace
          true if this dialog should allow for the replace and replace all buttons to be validated, false otherwise.
private  javax.swing.JButton find_button
          The button used to begin a find() function call.
private  javax.swing.JButton find_next_button
          The button used to repeat the find() call in order to find the next matching object.
private  boolean found
          true if the last call to find() found something, false otherwise.
private static java.awt.Dimension LABEL_SIZE
          The default size for a label, used to produce purty column alignment.
private  java.util.regex.Matcher matcher
          Whenever a string is tested against the compiled regular Pattern, a Matcher is created.
private  java.util.regex.Pattern pattern
          This object is created by compiling a regular expression string retrieved from the search field, and in only non-null when regualr_expressions is checked.
private  org.greenstone.gatherer.util.EnumeratedVector records
          A vector containing the result of a depth first enumeration of the records in the collection record set tree.
private  java.util.Stack redo
          A stack of actions that have been undone, wait to be done again.
private  javax.swing.JButton redo_button
          Redoes the action the was last undoes.
private  javax.swing.JCheckBox regular_expression
          When checked the SARM treats both search and replace string as regular expression when matching and replacing.
private  javax.swing.JTextField replace
          This field is used to enter a string which is in turn used to replace any text value that matches the search string.
private  javax.swing.JButton replace_all_button
          Replace all occurances of the search string with the replace string.
private  javax.swing.JButton replace_button
          Replaces the currently selected object with the given replacement text.
private  javax.swing.JButton reset_button
          When pressed this button returns the 'searching pointer' back to the start of the collection.
private  java.awt.Dimension screen_size
          The size of the current screen real-estate.
private  javax.swing.JTextField search
          The value entered in the search field is used to determine what object should be selected and brought to your attention.
private  javax.swing.JCheckBox search_elements
          When checked the SARM will search the metadata element identifiers for values that match your search string.
private  javax.swing.JCheckBox search_records
          When checked the SARM will search the file records in the collection for values that match your search string.
private  javax.swing.JCheckBox search_values
          When checked the SARM will search the metadata values associated with each file record in the collection for values that match your search string.
private  SearchAndReplace self
          A reference to ourselves so that our inner classes can dispose of us for the insurance money.
private static java.awt.Dimension SIZE
          The default size for the dialog.
private  javax.swing.JLabel status
          The status label shows the result of the last action.
private  java.lang.Object target
          This is used to determine the target class of any object whose text component we are trying to replace.
private  java.util.Stack undo
          A stack of actions that have been done, waiting to undo.
private  javax.swing.JButton undo_button
          This button undoes any changes made by the previous action, such as restoring all objects affected by a replace all.
 
Fields inherited from class org.greenstone.gatherer.gui.ModalDialog
modal, waiting
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Dialog
 
Fields inherited from class java.awt.Window
 
Fields inherited from class java.awt.Container
 
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
SearchAndReplace(boolean enable_replace)
          Constructor.
 
Method Summary
private  void changeStatus(java.lang.String key, int optional_count)
          Updates the status bar to reflect the result of the latest action.
private  boolean find()
          The guts of this module, the find method, in conjunction with the matches method, searches through the several targetted domains looking for values which match the search string, returning true while leaving itself in a state that points to the matching object if one is found.
private  void fireSelect(org.greenstone.gatherer.msm.ElementWrapper element)
          When a metadata element that matches our search string is found, this method is called to provide a visual cue as to what element matched in which collection.
private  void fireSelect(org.greenstone.gatherer.file.FileNode record)
          When a file record that matches our search string is found, this method is called to provide a visual cue as to what file matched.
private  void fireSelect(org.greenstone.gatherer.file.FileNode record, org.greenstone.gatherer.msm.Metadata metadata)
          When a metadata value that matches our search string is found, this method is called to provide a visual cue as to what value from which file matched.
private  java.lang.String get(java.lang.String key)
          Retrieve a pharse string from the Dictionary matching the given key.
private  java.lang.String get(java.lang.String key, java.lang.String[] args)
          Retrieve a pharse string from the Dictionary matching the given key and based apon the given arguments.
private  boolean match(java.lang.String target_str)
          Used to determine is one string matches another tkaing into account the options of case sensitivity and regular expressions.
private  boolean replace()
          Called once by the replace button, or repeatedly by replace all, in order to replace the text of the target object, as referenced by the current_s, with the replace text string.
private  void reset()
          Used to restore the search space within the collection to its initial state for find().
private  void unhideSelection(java.awt.Rectangle bounds)
          Attempts to move the dialog so that it doesn't obscure the coordinates detailed.
private  void updateElement(org.greenstone.gatherer.msm.ElementWrapper element, java.lang.String value)
          Whenever replace(), the undo action listener or the redo action listener wants to actually change the value of an element it uses this method.
private  void updateMetadata(org.greenstone.gatherer.msm.Metadata metadata, org.greenstone.gatherer.file.FileNode record, java.lang.String value)
          Whenever replace(), the undo action listener or the redo action listener wants to actually change the value of a metadata value it uses this method.
private  void updateRecord(org.greenstone.gatherer.file.FileNode record, java.lang.String value)
          Whenever replace(), the undo action listener or the redo action listener wants to actually change the value of a file record it uses this method.
private  void validateReplaceButtons()
          Several actions methods call this to check if the current state of the dialog allows for the replace butons to become active.
 
Methods inherited from class org.greenstone.gatherer.gui.ModalDialog
setModal, setVisible
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, dialogInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getPreferredSize, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, isUndecorated, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusOwner, getGraphicsConfiguration, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, swapComponents, 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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, isOpaque, 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, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

enable_replace

private boolean enable_replace
true if this dialog should allow for the replace and replace all buttons to be validated, false otherwise.


found

private boolean found
true if the last call to find() found something, false otherwise.


screen_size

private java.awt.Dimension screen_size
The size of the current screen real-estate.


current_element

private org.greenstone.gatherer.msm.ElementWrapper current_element
The metadata element that we are currently inspecting. If we are anywhere but within the find() function, then this is the last element found that matched the search string.


records

private org.greenstone.gatherer.util.EnumeratedVector records
A vector containing the result of a depth first enumeration of the records in the collection record set tree.


current_record

private org.greenstone.gatherer.file.FileNode current_record
The file record that we are currently inspecting. If we are anywhere but within the find() function, and the target type is a FileNode, then this is the last record that matched our search string. Otherwise this is the record that the last metadata value that matched resides in.


close_button

private javax.swing.JButton close_button
The button used to close the dialog. Has the same action as the destroy button.


find_button

private javax.swing.JButton find_button
The button used to begin a find() function call. Something must be typed in the search field before this button becomes active.


find_next_button

private javax.swing.JButton find_next_button
The button used to repeat the find() call in order to find the next matching object. Note this only becomes active after a successful find button press.


redo_button

private javax.swing.JButton redo_button
Redoes the action the was last undoes. Doesn't become active until there are job that are undone to be redone. :P


replace_button

private javax.swing.JButton replace_button
Replaces the currently selected object with the given replacement text. The selection was determined by find() either as part of a previous action, or immediately before the replace() is called. This button only become active if there is something typed in the search and replace fields and if enable_replace is set.


replace_all_button

private javax.swing.JButton replace_all_button
Replace all occurances of the search string with the replace string. This returns to the start of the collection and replaced every single matching reference. It only becomes enabled if something is typed in the search and replace fields and enable_replace is set.


reset_button

private javax.swing.JButton reset_button
When pressed this button returns the 'searching pointer' back to the start of the collection. This is used when there are no further matches for your query, or at anytime you wish to start a new query. This button only becomes active after a success find().


undo_button

private javax.swing.JButton undo_button
This button undoes any changes made by the previous action, such as restoring all objects affected by a replace all. It only makes sense for this button to be active after a successful action.


case_sensitive

private javax.swing.JCheckBox case_sensitive
When checked this control indicates the search comparisons should be made taking into account case. Otherwise the case becomes irrelevant to matching.


regular_expression

private javax.swing.JCheckBox regular_expression
When checked the SARM treats both search and replace string as regular expression when matching and replacing.


search_elements

private javax.swing.JCheckBox search_elements
When checked the SARM will search the metadata element identifiers for values that match your search string. Note that at least one of the search domains is selected at all times.


search_records

private javax.swing.JCheckBox search_records
When checked the SARM will search the file records in the collection for values that match your search string. Note that at least one of the search domains is selected at all times.


search_values

private javax.swing.JCheckBox search_values
When checked the SARM will search the metadata values associated with each file record in the collection for values that match your search string. Note that at least one of the search domains is selected at all times.


status

private javax.swing.JLabel status
The status label shows the result of the last action.


replace

private javax.swing.JTextField replace
This field is used to enter a string which is in turn used to replace any text value that matches the search string. If enable_replace is not set, this field remains grayed out. If enabled, and you type within this field the replace buttons will become active.


search

private javax.swing.JTextField search
The value entered in the search field is used to determine what object should be selected and brought to your attention. Note that this field can contain plain text or a regular expression, and that any typing in this field automatically resets the find() functions state to the start of the collection.


matcher

private java.util.regex.Matcher matcher
Whenever a string is tested against the compiled regular Pattern, a Matcher is created. Not only does this matcher allow us to determine if the test string matches the pattern, but is can be subsequently used during a replace action to evaluate special 'capture group flags' within a regular expression based replace string.

For instance:Seach - '(.*)fug(.*)' will match 'Refugee'
and
Replace - '\1\1\1. \2' will replace the match with 'ReReRe. ee'.


current_value

private org.greenstone.gatherer.msm.Metadata current_value
This is the current metadata value that we are inspecting. If non-null anywhere other then in the find() method, then this is the last metadata value that matched on search string. However it makes no sense by itself, and current_record is needed to actually reference this piece of metadata.


target

private java.lang.Object target
This is used to determine the target class of any object whose text component we are trying to replace. It is actually set to the last object that matched the search string.


pattern

private java.util.regex.Pattern pattern
This object is created by compiling a regular expression string retrieved from the search field, and in only non-null when regualr_expressions is checked. By compiling it once at the very beginning of the find() method, we lower processing time. Note that pattern is set to null whenever the find() state is reset.


self

private SearchAndReplace self
A reference to ourselves so that our inner classes can dispose of us for the insurance money.


redo

private java.util.Stack redo
A stack of actions that have been undone, wait to be done again.


undo

private java.util.Stack undo
A stack of actions that have been done, waiting to undo.


elements

private java.util.Vector elements
A vector of the metadata elements attached to this collection, in the form of ElementWrappers for ease of data access.


LABEL_SIZE

private static final java.awt.Dimension LABEL_SIZE
The default size for a label, used to produce purty column alignment.


SIZE

private static final java.awt.Dimension SIZE
The default size for the dialog.

Constructor Detail

SearchAndReplace

public SearchAndReplace(boolean enable_replace)
Constructor.

Method Detail

changeStatus

private void changeStatus(java.lang.String key,
                          int optional_count)
Updates the status bar to reflect the result of the latest action. Includes the ability to reset the status label whenever the find() state resets.


find

private boolean find()
The guts of this module, the find method, in conjunction with the matches method, searches through the several targetted domains looking for values which match the search string, returning true while leaving itself in a state that points to the matching object if one is found. What exact part of each object is matched against is decided by the objects type, and in one case this is made even more complex as one type of object exists inside the other so we need to carefully iterate through the inner before increamenting the outer.


fireSelect

private void fireSelect(org.greenstone.gatherer.msm.ElementWrapper element)
When a metadata element that matches our search string is found, this method is called to provide a visual cue as to what element matched in which collection. This is done by changing the tab view of the main gui and selecting the correct line from the list of sets/elements on one screen of the CDM. This method subsequently calls unhideBound() passing in the bounds of the selected component (cell or row).


fireSelect

private void fireSelect(org.greenstone.gatherer.file.FileNode record)
When a file record that matches our search string is found, this method is called to provide a visual cue as to what file matched. This is done by changing the tab view of the main gui and expanding and selecting the correct line from the tree of file records. This method subsequently calls unhideBound() passing in the bounds of the selected component (cell or row).


fireSelect

private void fireSelect(org.greenstone.gatherer.file.FileNode record,
                        org.greenstone.gatherer.msm.Metadata metadata)
When a metadata value that matches our search string is found, this method is called to provide a visual cue as to what value from which file matched. This is done by changing the tab view of the main gui and expanding and selecting the correct line from the tree of file records, and then highlighting the appropriate line of the metadata table. This method subsequently calls unhideBound() passing in the bounds of the selected component (cell or row).


get

private java.lang.String get(java.lang.String key)
Retrieve a pharse string from the Dictionary matching the given key.


get

private java.lang.String get(java.lang.String key,
                             java.lang.String[] args)
Retrieve a pharse string from the Dictionary matching the given key and based apon the given arguments.


match

private boolean match(java.lang.String target_str)
Used to determine is one string matches another tkaing into account the options of case sensitivity and regular expressions.


replace

private boolean replace()
Called once by the replace button, or repeatedly by replace all, in order to replace the text of the target object, as referenced by the current_s, with the replace text string. This takes into account if regular expressions are expected, and modifies the replacement string with appropriate 'capture groups'.


reset

private void reset()
Used to restore the search space within the collection to its initial state for find().


unhideSelection

private void unhideSelection(java.awt.Rectangle bounds)
Attempts to move the dialog so that it doesn't obscure the coordinates detailed. Can't always do so.


updateElement

private void updateElement(org.greenstone.gatherer.msm.ElementWrapper element,
                           java.lang.String value)
Whenever replace(), the undo action listener or the redo action listener wants to actually change the value of an element it uses this method. Hows that for code reuse.


updateMetadata

private void updateMetadata(org.greenstone.gatherer.msm.Metadata metadata,
                            org.greenstone.gatherer.file.FileNode record,
                            java.lang.String value)
Whenever replace(), the undo action listener or the redo action listener wants to actually change the value of a metadata value it uses this method. Hows that for code reuse.


updateRecord

private void updateRecord(org.greenstone.gatherer.file.FileNode record,
                          java.lang.String value)
Whenever replace(), the undo action listener or the redo action listener wants to actually change the value of a file record it uses this method. Hows that for code reuse.


validateReplaceButtons

private void validateReplaceButtons()
Several actions methods call this to check if the current state of the dialog allows for the replace butons to become active.