Class JEditBasedTextArea

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, MARSTextEditingArea

public class JEditBasedTextArea extends JEditTextArea implements MARSTextEditingArea
Adaptor subclass for JEditTextArea.

Provides those methods required by the MARSTextEditingArea interface that are not defined by JEditTextArea. This permits JEditTextArea to be used within MARS largely without modification.

Since:
MARS 4.0
Author:
Pete Sanderson 4-20-2010
See Also:
  • Constructor Details

  • Method Details

    • setFont

      public void setFont(Font font)
      Specified by:
      setFont in interface MARSTextEditingArea
      Overrides:
      setFont in class JComponent
    • getFont

      public Font getFont()
      Specified by:
      getFont in interface MARSTextEditingArea
      Specified by:
      getFont in interface MenuContainer
      Overrides:
      getFont in class Component
    • setLineHighlightEnabled

      public void setLineHighlightEnabled(boolean highlight)
      Set whether highlighting of the line currently being edited is enabled.
      Specified by:
      setLineHighlightEnabled in interface MARSTextEditingArea
      Parameters:
      highlight - true to enable line highlighting, false to disable.
    • setCaretBlinkRate

      public void setCaretBlinkRate(int rate)
      Set the caret blinking rate in milliseconds. If rate is 0 or less, blinking is disabled.
      Specified by:
      setCaretBlinkRate in interface MARSTextEditingArea
      Parameters:
      rate - Blinking rate in milliseconds.
    • setTabSize

      public void setTabSize(int chars)
      Set the number of characters a tab will expand to.
      Specified by:
      setTabSize in interface MARSTextEditingArea
      Parameters:
      chars - number of characters
    • updateSyntaxStyles

      public void updateSyntaxStyles()
      Update the syntax style table, which is obtained from SyntaxUtilities.
      Specified by:
      updateSyntaxStyles in interface MARSTextEditingArea
    • getOuterComponent

      public Component getOuterComponent()
      Specified by:
      getOuterComponent in interface MARSTextEditingArea
    • discardAllUndoableEdits

      public void discardAllUndoableEdits()
      Get rid of any accumulated undoable edits. It is useful to call this method after opening a file into the text area. The act of setting its text content upon reading the file will generate an undoable edit. Normally you don't want a freshly-opened file to appear with its Undo action enabled. But it will unless you call this after setting the text.
      Specified by:
      discardAllUndoableEdits in interface MARSTextEditingArea
    • replaceSelection

      public void replaceSelection(String replacementText)
      Same as JEditTextArea.setSelectedText(String) but named for compatibility with JTextComponent method replaceSelection. DPS, 14 Apr 2010
      Specified by:
      replaceSelection in interface MARSTextEditingArea
      Parameters:
      replacementText - The replacement text for the selection
    • setSelectionVisible

      public void setSelectionVisible(boolean visible)
      Specified by:
      setSelectionVisible in interface MARSTextEditingArea
    • setSourceCode

      public void setSourceCode(String text, boolean editable)
      Specified by:
      setSourceCode in interface MARSTextEditingArea
    • getUndoManager

      public UndoManager getUndoManager()
      Returns the undo manager for this editing area.
      Specified by:
      getUndoManager in interface MARSTextEditingArea
      Returns:
      The undo manager.
    • undo

      public void undo()
      Undo previous edit.
      Specified by:
      undo in interface MARSTextEditingArea
    • redo

      public void redo()
      Redo previous edit.
      Specified by:
      redo in interface MARSTextEditingArea
    • commentLines

      public void commentLines()
      Comment or uncomment highlighted lines or line at cursor.
      Specified by:
      commentLines in interface MARSTextEditingArea
    • replaceLine

      public void replaceLine(int lineNumber, String text)
      Replace a line in the document with text.
      Parameters:
      lineNumber - line number to replace
      text - text to replace the line with
    • doFindText

      public int doFindText(String text, boolean caseSensitive)
      Finds next occurrence of text in a forward search of a string. Search begins at the current cursor location, and wraps around when the end of the string is reached.
      Specified by:
      doFindText in interface MARSTextEditingArea
      Parameters:
      text - The text to locate in the string.
      caseSensitive - true if search is to be case-sensitive, false otherwise.
      Returns:
      TEXT_FOUND or TEXT_NOT_FOUND, depending on the result.
    • nextIndex

      public int nextIndex(String input, String find, int start, boolean caseSensitive)
      Returns next index of word in text - forward search. If end of string is reached during the search, will wrap around to the beginning one time.
      Parameters:
      input - the string to search
      find - the string to find
      start - the character index to start the search
      caseSensitive - true for case sensitive. false to ignore case
      Returns:
      next indexed position of found text or -1 if not found
    • doReplace

      public int doReplace(String text, String replace, boolean caseSensitive)
      Finds and replaces next occurrence of text in a string in a forward search. If cursor is initially at end of matching selection, will immediately replace then find and select the next occurrence if any. Otherwise it performs a find operation. The replace can be undone with one undo operation.
      Specified by:
      doReplace in interface MARSTextEditingArea
      Parameters:
      text - the text to locate in the string
      replace - the text to replace the find text with - if the find text exists
      caseSensitive - true for case sensitive. false to ignore case
      Returns:
      Returns TEXT_FOUND if not initially at end of selected match and matching occurrence is found. Returns TEXT_NOT_FOUND if the text is not matched. Returns TEXT_REPLACED_NOT_FOUND_NEXT if replacement is successful but there are no additional matches. Returns TEXT_REPLACED_FOUND_NEXT if replacement is successful and there is at least one additional match.
    • doReplaceAll

      public int doReplaceAll(String find, String replace, boolean caseSensitive)
      Finds and replaces ALL occurrences of text in a string in a forward search. All replacements are bundled into one CompoundEdit, so one Undo operation will undo all of them.
      Specified by:
      doReplaceAll in interface MARSTextEditingArea
      Parameters:
      find - the text to locate in the string
      replace - the text to replace the find text with - if the find text exists
      caseSensitive - true for case sensitive. false to ignore case
      Returns:
      the number of occurrences that were matched and replaced.