Class StyledTextEditorPanel

    • Field Detail

      • m_Modified

        protected boolean m_Modified
        whether the content was modified.
      • m_IgnoreChanges

        protected boolean m_IgnoreChanges
        whether to ignore changes.
      • m_FileChooser

        protected transient TextFileChooser m_FileChooser
        for saving the content.
      • m_Undo

        protected UndoManager m_Undo
        for managing undo/redo.
      • m_LastFind

        protected String m_LastFind
        the last search string used.
      • m_ChangeListeners

        protected HashSet<ChangeListener> m_ChangeListeners
        the listeners for modification events.
      • m_CurrentFile

        protected File m_CurrentFile
        the current file.
    • Constructor Detail

      • StyledTextEditorPanel

        public StyledTextEditorPanel()
    • Method Detail

      • initialize

        protected void initialize()
        For initializing members.
        Overrides:
        initialize in class BasePanel
      • initGUI

        protected void initGUI()
        For initializing the GUI.
        Overrides:
        initGUI in class BasePanel
      • getFileChooser

        protected TextFileChooser getFileChooser()
        Returns the file chooser and creates it if necessary.
      • newBaseTextPane

        protected BaseTextPaneWithWordWrap newBaseTextPane()
        Returns a new text pane.
        Returns:
        the text pane
      • setModified

        public void setModified​(boolean value)
        Sets the modified state. If false, all edits are discarded and the last search string reset as well.
        Parameters:
        value - if true then the content is flagged as modified
      • isModified

        public boolean isModified()
        Returns whether the content has been modified.
        Returns:
        true if the content was modified
      • setContent

        public void setContent​(String value)
        Sets the content to display. Resets the modified state.
        Parameters:
        value - the text
      • getContent

        public String getContent()
        Returns the content to display.
        Returns:
        the text
      • setEditable

        public void setEditable​(boolean value)
        Sets whether the text area is editable or not.
        Parameters:
        value - if true then the text will be editable
      • isEditable

        public boolean isEditable()
        Returns whether the text area is editable or not.
        Returns:
        true if the text is editable
      • setTextFont

        public void setTextFont​(Font value)
        Sets the font of the text area.
        Parameters:
        value - the font to use
      • getTextFont

        public Font getTextFont()
        Returns the font currently in use by the text area.
        Returns:
        the font in use
      • getLastFind

        public String getLastFind()
        Returns the last search string.
        Returns:
        the last search string, can be null if no search performed yet
      • getTextPane

        public BaseTextPane getTextPane()
        Returns the underlying BaseTextArea element.
        Returns:
        the component
      • getDocument

        public Document getDocument()
        Returns the underlying document of the text area.
        Returns:
        the document
      • setCaretPosition

        public void setCaretPosition​(int value)
        Sets the position of the cursor.
        Parameters:
        value - the position
      • getCaretPosition

        public int getCaretPosition()
        Returns the current position of the cursor.
        Returns:
        the cursor position
      • setCaretPositionLast

        public void setCaretPositionLast()
        Sets the position of the cursor at the end.
      • setWordWrap

        public void setWordWrap​(boolean value)
        Sets the wordwrap state.
        Parameters:
        value - whether to wrap or not
      • getWordWrap

        public boolean getWordWrap()
        Returns the wordwrap status.
        Returns:
        true if wordwrap is on
      • checkForModified

        public boolean checkForModified()
        Returns whether we can proceed with the operation or not, depending on whether the user saved the content or discarded the changes.
        Returns:
        true if safe to proceed
      • open

        public void open()
        Pops up dialog to open a file.
      • open

        public void open​(File file)
        Opens the specified file and loads/displays the content, using UTF-8.
        Parameters:
        file - the file to load
      • open

        public void open​(File file,
                         String encoding)
        Opens the specified file and loads/displays the content.
        Parameters:
        file - the file to load
        encoding - the encoding to use, use null or empty string for default UTF-8
      • save

        public void save()
        Pops up dialog to save the content in a file.
      • saveAs

        public void saveAs()
        Pops up dialog to save the content in a file.
      • save

        protected void save​(File file)
        Saves the content under the specified file.
        Parameters:
        file - the file to save the content int
      • clear

        public void clear()
        Removes all content. Does not reset the undos.
      • canUndo

        public boolean canUndo()
        Checks whether an undo action is available.
        Returns:
        true if an undo action is available
      • undo

        public void undo()
        Performs an undo, if possible.
      • canRedo

        public boolean canRedo()
        Checks whether a redo action is available.
        Returns:
        true if a redo action is available
      • redo

        public void redo()
        Performs a redo, if possible.
      • canCut

        public boolean canCut()
        Checks whether text can be cut at the moment.
        Returns:
        true if text is available for cutting
      • cut

        public void cut()
        Cuts the currently selected text and places it on the clipboard.
      • canCopy

        public boolean canCopy()
        Checks whether text can be copied at the moment.
        Returns:
        true if text is available for copying
      • copy

        public void copy()
        Copies the currently selected text to the clipboard.
      • canPaste

        public boolean canPaste()
        Checks whether text can be pasted at the moment.
        Returns:
        true if text is available for pasting
      • paste

        public void paste()
        Pastes the text from the clipboard into the document.
      • selectAll

        public void selectAll()
        Selects all the text.
      • find

        public void find()
        Initiates a search.
      • findNext

        public void findNext()
        Finds the next occurrence.
      • printText

        public void printText()
        Pops up a print dialog.
      • selectFont

        public void selectFont()
        Pops up a dialog for selecting the font.
      • addChangeListener

        public void addChangeListener​(ChangeListener l)
        Adds the given change listener to its internal list.
        Parameters:
        l - the listener to add
      • removeChangeListener

        public void removeChangeListener​(ChangeListener l)
        Removes the given change listener from its internal list.
        Parameters:
        l - the listener to remove
      • notifyChangeListeners

        protected void notifyChangeListeners()
        Sends an event to all change listeners.
      • append

        public void append​(String text)
        Appends the text at the end.
        Parameters:
        text - the text to append
      • append

        public void append​(String text,
                           AttributeSet a)
        Appends the text at the end.
        Parameters:
        text - the text to append
        a - the attribute set, null if to use current
      • setText

        public void setText​(String value)
        Sets the current text.
        Parameters:
        value - the text
      • getText

        public String getText()
        Returns the current text.
        Returns:
        the tex