Class EditTab

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

public class EditTab extends DynamicTabbedPane
The "Edit" tab in the main tabbed pane, which is itself a tabbed pane. Each of its tabs represents an open file.
Author:
Pete Sanderson
See Also:
  • Constructor Details

    • EditTab

      public EditTab(VenusUI gui, Editor editor)
      Create and initialize the Edit tab with no open files.
      Parameters:
      gui - The parent GUI instance.
      editor - The editor instance, which will be used to manage the text editors.
  • Method Details

    • getCurrentEditorTab

      public FileEditorTab getCurrentEditorTab()
      Get the currently selected editor tab.
      Returns:
      The current editor tab, or null if no files are open.
    • setCurrentEditorTab

      public void setCurrentEditorTab(FileEditorTab tab)
      Select the specified file editor tab to be the current tab.
      Parameters:
      tab - The tab to become current.
    • getEditorTab

      public FileEditorTab getEditorTab(File file)
      Get the editor tab corresponding to the given file, if the file is open.
      Parameters:
      file - File object for the desired tab.
      Returns:
      The tab for the given file, or null if no such tab was found.
    • getCurrentEditorTab

      public FileEditorTab getCurrentEditorTab(File file)
      If the given file is open, make it the current tab. If not opened, open it in a new tab and make it the current tab. If file is unable to be opened, leave current tab as is.
      Parameters:
      file - File object for the desired tab.
      Returns:
      The tab for the given file, or null if file is unable to be opened.
    • getEditorTabs

      public List<FileEditorTab> getEditorTabs()
      Get the list of currently open editor tabs by iterating through the component list.
      Returns:
      The list of editor tabs.
    • newFile

      public void newFile()
      Carries out all necessary operations to implement the New operation from the File menu.
    • openFiles

      public List<File> openFiles()
      Launch a file chooser for the user to select one or more files, attempting to open them in new editor tabs afterward.
      Returns:
      The list of files which could not be opened due to an error. (Can be empty.)
    • openFile

      public boolean openFile(File file)
      Open the specified file in a new editor tab, switching focus to that tab.
      Returns:
      False if the file could not be opened due to an error, true otherwise.
    • openFiles

      public List<File> openFiles(List<File> files)
      Open the specified files in new editor tabs, switching focus to the first newly opened tab. If any files cannot be opened, an error dialog will be displayed to the user indicating which files failed to open.
      Returns:
      The list of files which could not be opened due to an error. (Can be empty.)
    • showOpenFileErrorDialog

      public void showOpenFileErrorDialog(List<File> unopenedFiles)
      Display an error dialog to the user indicating that one or more files could not be opened.
      Parameters:
      unopenedFiles - The list of files which could not be opened. (Should not be empty.) Usually obtained from a call to openFiles.
    • removeTabAt

      public void removeTabAt(int index)
      Attempts to remove the tab at index. If the tab has unsaved changes, the user will be prompted to save them. If they select cancel, the tab will not be removed. Otherwise, the tab is removed. After a successful removal, VenusUI.saveWorkspaceState() is invoked.
      Overrides:
      removeTabAt in class JTabbedPane
      Parameters:
      index - The index of the tab to be removed.
      Throws:
      IndexOutOfBoundsException - Thrown if the index is out of range (index < 0 or indexJTabbedPane.getTabCount()).
    • closeCurrentFile

      public boolean closeCurrentFile()
      Carries out all necessary operations to implement the Close operation from the File menu. May return false, for instance when file has unsaved changes and user selects Cancel from the warning dialog.
      Returns:
      true if file was closed, false otherwise.
    • closeFile

      public boolean closeFile(FileEditorTab tab)
      Carries out all necessary operations to implement the Close operation from the File menu. May return false, for instance when file has unsaved changes and user selects Cancel from the warning dialog.
      Parameters:
      tab - The tab for the file to close.
      Returns:
      true if file was closed, false otherwise.
    • closeAllFiles

      public boolean closeAllFiles()
      Carries out all necessary operations to implement the Close All operation from the File menu.
      Returns:
      true if files closed, false otherwise.
    • saveCurrentFile

      public boolean saveCurrentFile()
      Saves file under existing name. If no name, will invoke Save As.
      Returns:
      true if the file was actually saved.
    • saveAsCurrentFile

      public File saveAsCurrentFile()
      Pops up a dialog box to do the "Save As" operation. The user will be asked to confirm before any file is overwritten.
      Returns:
      The file object if the file was actually saved, null if canceled.
    • saveAllFiles

      public boolean saveAllFiles()
      Saves all files currently open in the editor.
      Returns:
      true if operation succeeded, false otherwise.
    • updateTitleAndMenuState

      public void updateTitleAndMenuState(FileEditorTab tab)
      Update the title on a given tab and possibly the title of the window, as well as the GUI's menu state (i.e. which actions are enabled) if applicable. Should be invoked any time the tab's state might change in any way.
      Parameters:
      tab - The tab to update, or null if there are no tabs remaining.
    • resolveUnsavedChanges

      public boolean resolveUnsavedChanges(FileEditorTab tab)
      Check whether file has unsaved edits and, if so, check with user about saving them.
      Returns:
      true if no unsaved edits or if user chooses to save them or not; false if there are unsaved edits and user cancels the operation.