Package mars.venus

Class EditPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Observer, Accessible

public class EditPane extends JPanel implements Observer
Represents one file opened for editing. Maintains required internal structures. Before Mars 4.0, there was only one editor pane, a tab, and only one file could be open at a time. With 4.0 came the multifile (pane, tab) editor, and existing duties were split between EditPane and the new EditTabbedPane class.
Author:
Sanderson and Bumgarner
See Also:
Serialized Form
  • Constructor Details

    • EditPane

      public EditPane(VenusUI appFrame)
      Constructor for the EditPane class.
  • Method Details

    • setSourceCode

      public void setSourceCode(String s, boolean editable)
      For initializing the source code when opening an ASM file
      Parameters:
      s - String containing text
      editable - set true if code is editable else false
    • 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.
    • getLineNumbersList

      public String getLineNumbersList(Document doc)
    • getTextArea

      public MARSTextEditingArea getTextArea()
      Get the MARSTextEditingArea of the EditPane
    • getSourceLineCount

      public int getSourceLineCount()
      Calculate and return number of lines in source code text. Do this by counting newline characters then adding one if last line does not end with newline character.
    • getSource

      public String getSource()
      Get source code text
      Returns:
      String containing source code
    • setFileStatus

      public void setFileStatus(int fileStatus)
      Set the editing status for this EditPane's associated document. For the argument, use one of the constants from class FileStatus.
      Parameters:
      fileStatus - the status constant from class FileStatus
    • getFileStatus

      public int getFileStatus()
      Get the editing status for this EditPane's associated document. This will be one of the constants from class FileStatus.
    • getFilename

      public String getFilename()
      Delegates to corresponding FileStatus method
    • getPathname

      public String getPathname()
      Delegates to corresponding FileStatus method
    • setPathname

      public void setPathname(String pathname)
      Delegates to corresponding FileStatus method
    • hasUnsavedEdits

      public boolean hasUnsavedEdits()
      Delegates to corresponding FileStatus method
    • isNew

      public boolean isNew()
      Delegates to corresponding FileStatus method
    • tellEditingComponentToRequestFocusInWindow

      public void tellEditingComponentToRequestFocusInWindow()
      Delegates to text area's requestFocusInWindow method.
    • updateStaticFileStatus

      public void updateStaticFileStatus()
      Delegates to corresponding FileStatus method
    • getUndoManager

      public UndoManager getUndoManager()
      get the manager in charge of Undo and Redo operations
      Returns:
      the UnDo manager
    • copyText

      public void copyText()
      copy currently-selected text into clipboard
    • cutText

      public void cutText()
      cut currently-selected text into clipboard
    • pasteText

      public void pasteText()
      paste clipboard contents at cursor position
    • selectAllText

      public void selectAllText()
      select all text
    • undo

      public void undo()
      Undo previous edit
    • redo

      public void redo()
      Redo previous edit
    • updateUndoState

      public void updateUndoState()
      Update state of Edit menu's Undo menu item.
    • updateRedoState

      public void updateRedoState()
      Update state of Edit menu's Redo menu item.
    • showingLineNumbers

      public boolean showingLineNumbers()
      get editor's line number display status
      Returns:
      true if editor is current displaying line numbers, false otherwise.
    • setShowLineNumbersEnabled

      public void setShowLineNumbersEnabled(boolean enabled)
      enable or disable checkbox that controls display of line numbers
      Parameters:
      enabled - True to enable box, false to disable.
    • displayCaretPosition

      public void displayCaretPosition(int pos)
      Update the caret position label on the editor's border to display the current line and column. The position is given as text stream offset and will be converted into line and column.
      Parameters:
      pos - Offset into the text stream of caret.
    • displayCaretPosition

      public void displayCaretPosition(Point p)
      Display cursor coordinates
      Parameters:
      p - Point object with x-y (column, line number) coordinates of cursor
    • convertStreamPositionToLineColumn

      public Point convertStreamPositionToLineColumn(int position)
    • convertLineColumnToStreamPosition

      public int convertLineColumnToStreamPosition(int line, int column)
      Given line and column (position in the line) numbers, calculate its byte stream position in text being edited.
      Parameters:
      line - Line number in file (starts with 1)
      column - Position within that line (starts with 1)
      Returns:
      corresponding stream position. Returns -1 if there is no corresponding position.
    • selectLine

      public void selectLine(int line)
      Select the specified editor text line. Lines are numbered starting with 1, consistent with line numbers displayed by the editor.
      Parameters:
      line - The desired line number of this TextPane's text. Numbering starts at 1, and nothing will happen if the parameter value is less than 1
    • selectLine

      public void selectLine(int line, int column)
      Select the specified editor text line. Lines are numbered starting with 1, consistent with line numbers displayed by the editor.
      Parameters:
      line - The desired line number of this TextPane's text. Numbering starts at 1, and nothing will happen if the parameter value is less than 1
      column - Desired column at which to place the cursor.
    • doFindText

      public int doFindText(String find, 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.
      Parameters:
      find - 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.
    • doReplace

      public int doReplace(String find, 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.
      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:
      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 reaplacement 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.
      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.
    • update

      public void update(Observable fontChanger, Object arg)
      Update, if source code is visible, when Font setting changes. This method is specified by the Observer interface.
      Specified by:
      update in interface Observer