Package mars.venus

Class Editor

java.lang.Object
mars.venus.Editor

public class Editor extends Object
Manage the file being edited. Currently only manages one file at a time, but can be expanded.
  • Field Details

  • Constructor Details

    • Editor

      public Editor(VenusUI ui)
      Create editor.
      Parameters:
      ui - the GUI that owns this editor
  • Method Details

    • setEditTabbedPane

      public void setEditTabbedPane(EditTabbedPane editTabbedPane)
      Set associated EditTabbedPane. This is container for any/all open files.
      Parameters:
      editTabbedPane - an existing editTabbedPane object
    • getCurrentOpenDirectory

      public String getCurrentOpenDirectory()
      Get name of current directory for Open operation.
      Returns:
      String containing directory pathname. Returns null if there is no EditTabbedPane. Returns default, directory MARS is launched from, if no Opens have been performed.
    • getCurrentSaveDirectory

      public String getCurrentSaveDirectory()
      Get name of current directory for Save or Save As operation.
      Returns:
      String containing directory pathname. Returns null if there is no EditTabbedPane. Returns directory MARS was launched from if no Save or Save As operations have been performed.
    • getNextDefaultFilename

      public String getNextDefaultFilename()
      Generates a default file name
      Returns:
      returns string mipsN.asm, where N is 1,2,3,...
    • setTitle

      public void setTitle(String path, String name, int status)
      Places name of file currently being edited into its edit tab and the application's title bar. The edit tab will contain only the filename, the title bar will contain full pathname. If file has been modified since created, opened or saved, as indicated by value of the status parameter, the name and path will be followed with an '*'. If newly-created file has not yet been saved, the title bar will show (temporary) file name but not path.
      Parameters:
      path - Full pathname for file
      name - Name of file (last component of path)
      status - Edit status of file. See FileStatus static constants.
    • newFile

      public void newFile()
      Perform "new" operation to create an empty tab.
    • close

      public boolean close()
      Perform "close" operation on current tab's file.
      Returns:
      true if succeeded, else false.
    • closeAll

      public boolean closeAll()
      Close all currently open files.
      Returns:
      true if succeeded, else false.
    • save

      public boolean save()
      Perform "save" operation on current tab's file.
      Returns:
      true if succeeded, else false.
    • saveAs

      public boolean saveAs()
      Perform "save as" operation on current tab's file.
      Returns:
      true if succeeded, else false.
    • saveAll

      public boolean saveAll()
      Perform save operation on all open files (tabs).
      Returns:
      true if succeeded, else false.
    • open

      public boolean open()
      Open file in a new tab.
      Returns:
      true if succeeded, else false.
    • editsSavedOrAbandoned

      public boolean editsSavedOrAbandoned()
      Called by several of the Action objects when there is potential loss of editing changes. Specifically: if there is a current file open for editing and its modify flag is true, then give user a dialog box with choice to save, discard edits, or cancel and carry out the decision. This applies to File->New, File->Open, File->Close, and File->Exit.
      Returns:
      Whether the caller can proceed (edits were saved or discarded) or the user selected Cancel