Package xtwm.ui

Class InternalEditorWindow

  • All Implemented Interfaces:
    java.lang.Comparable<TWidget>, Scrollable

    public class InternalEditorWindow
    extends TScrollableWindow
    InternalEditorWindow is a basic text file editor.
    • Constructor Detail

      • InternalEditorWindow

        public InternalEditorWindow​(TApplication parent)
        Public constructor.
        Parameters:
        parent - the main application
      • InternalEditorWindow

        public InternalEditorWindow​(TApplication parent,
                                    java.lang.String title)
        Public constructor with a custom title.
        Parameters:
        parent - the main application
        title - the window title
      • InternalEditorWindow

        public InternalEditorWindow​(TApplication parent,
                                    java.io.File file)
                             throws java.io.IOException
        Public constructor opens a file.
        Parameters:
        parent - the main application
        file - the file to open
        Throws:
        java.io.IOException - if a java.io operation throws
      • InternalEditorWindow

        public InternalEditorWindow​(TApplication parent,
                                    java.io.File file,
                                    int x,
                                    int y,
                                    int width,
                                    int height)
                             throws java.io.IOException
        Public constructor opens a file.
        Parameters:
        parent - the main application
        file - the file to open, or null for a new file
        x - column relative to parent
        y - row relative to parent
        width - width of window
        height - height of window
        Throws:
        java.io.IOException - if a java.io operation throws
    • Method Detail

      • onFocus

        public void onFocus()
        Called by application.switchWindow() when this window gets the focus, and also by application.addWindow().
        Overrides:
        onFocus in class TWindow
      • onUnfocus

        public void onUnfocus()
        Called by application.switchWindow() when another window gets the focus.
        Overrides:
        onUnfocus in class TWindow
      • onPreClose

        public void onPreClose()
        Prompt the user to save if we are about to be closed and the editor is dirty.
        Overrides:
        onPreClose in class TWindow
      • onMouseDown

        public void onMouseDown​(TMouseEvent mouse)
        Handle mouse press events.
        Overrides:
        onMouseDown in class TWindow
        Parameters:
        mouse - mouse button press event
      • onMouseUp

        public void onMouseUp​(TMouseEvent mouse)
        Handle mouse release events.
        Overrides:
        onMouseUp in class TWindow
        Parameters:
        mouse - mouse button release event
      • onMouseMotion

        public void onMouseMotion​(TMouseEvent mouse)
        Method that subclasses can override to handle mouse movements.
        Overrides:
        onMouseMotion in class TWindow
        Parameters:
        mouse - mouse motion event
      • onKeypress

        public void onKeypress​(TKeypressEvent keypress)
        Handle keystrokes.
        Overrides:
        onKeypress in class TWindow
        Parameters:
        keypress - keystroke event
      • onCommand

        public void onCommand​(TCommandEvent command)
        Method that subclasses can override to handle posted command events.
        Overrides:
        onCommand in class TWindow
        Parameters:
        command - command event
      • onMenu

        public void onMenu​(TMenuEvent menu)
        Handle posted menu events.
        Overrides:
        onMenu in class TWindow
        Parameters:
        menu - menu event
      • draw

        public void draw()
        Draw the window.
        Overrides:
        draw in class TWindow
      • hasHiddenMouse

        public boolean hasHiddenMouse()
        Returns true if this window does not want the application-wide mouse cursor drawn over it.
        Overrides:
        hasHiddenMouse in class TWindow
        Returns:
        true if this window does not want the application-wide mouse cursor drawn over it
      • setupAfterEditor

        protected void setupAfterEditor()
        Setup other fields after the editor is created.
      • getFilename

        public java.lang.String getFilename()
        Get the filename being edited.
        Returns:
        the filename, or null if this is a new file that has never been saved
      • askToSave

        public void askToSave()
        Ask to save the file if it is dirty. If the user accepts, save the file.
      • saveIfDirty

        public void saveIfDirty()
        Save the file if it is dirty.
      • setEditingColumnNumber

        public void setEditingColumnNumber​(int column)
        Set the current editing column number. 1-based.
        Parameters:
        column - the new editing column number. Column 1 is the leftmost column.
      • getEditingRowNumber

        public int getEditingRowNumber()
        Get the current editing row number. 1-based.
        Returns:
        the editing row number. Row 1 is the first row.
      • setEditingRowNumber

        public void setEditingRowNumber​(int row)
        Set the current editing row number. 1-based.
        Parameters:
        row - the new editing row number. Row 1 is the first row.
      • getLineCount

        public int getLineCount()
        Get the number of lines in the underlying Document.
        Returns:
        the number of lines
      • getEditingRawLine

        public java.lang.String getEditingRawLine​(int row)
        Get the current editing row plain text. 1-based.
        Parameters:
        row - the new editing row number. Row 1 is the first row.
        Returns:
        the plain text of the row
      • setEditingPositionNumber

        public void setEditingPositionNumber​(int row,
                                             int column)
        Set the current editing row and column number. 1-based.
        Parameters:
        row - the new editing row number. Row 1 is the first row.
        column - the new editing column number. Column 1 is the leftmost column.
      • setSelection

        public void setSelection​(int startRow,
                                 int startColumn,
                                 int endRow,
                                 int endColumn)
        Set the selection.
        Parameters:
        startRow - the starting row number. 0-based: row 0 is the first row.
        startColumn - the starting column number. 0-based: column 0 is the first column.
        endRow - the ending row number. 0-based: row 0 is the first row.
        endColumn - the ending column number. 0-based: column 0 is the first column.
      • replaceSelection

        public void replaceSelection​(java.lang.String text)
        Replace whatever is being selected with new text. If not in selection, nothing is replaced.
        Parameters:
        text - the new replacement text
      • hasSelection

        public boolean hasSelection()
        Check if selection is available.
        Returns:
        true if a selection has been made
      • getSelection

        public java.lang.String getSelection()
        Copy text within the selection bounds to a string.
        Returns:
        the selection as a string, or null if there is no selection
      • getSelectionStartRow

        public int getSelectionStartRow()
        Get the selection starting row number.
        Returns:
        the starting row number, or -1 if there is no selection. 0-based: row 0 is the first row.
      • getSelectionStartColumn

        public int getSelectionStartColumn()
        Get the selection starting column number.
        Returns:
        the starting column number, or -1 if there is no selection. 0-based: column 0 is the first column.
      • getText

        public java.lang.String getText()
        Get the entire contents of the editor as one string.
        Returns:
        the editor contents