Class TextEditorPane
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Printable
,Serializable
,EventListener
,Accessible
,DocumentListener
,Scrollable
,SyntaxConstants
RSyntaxTextArea
that adds information about the file being edited, such as:
- Its name and location.
- Is it dirty?
- Is it read-only?
- The last time it was loaded or saved to disk (local files only).
- The file's encoding on disk.
- Easy access to the line separator.
When saving UTF-8 files, whether a BOM is written is controlled by
the UnicodeWriter
class.
Use UnicodeWriter.setWriteUtf8BOM(boolean)
to toggle writing BOMs
for UTF-8 files.
Both local and remote files (e.g. ftp) are supported. See the
FileLocation
class for more information.
- Version:
- 1.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.fife.ui.rtextarea.RTextArea
RTextArea.RTextAreaMutableCaretEvent
Nested classes/interfaces inherited from class org.fife.ui.rtextarea.RTextAreaBase
RTextAreaBase.RTAMouseListener
Nested classes/interfaces inherited from class javax.swing.JTextArea
JTextArea.AccessibleJTextArea
Nested classes/interfaces inherited from class javax.swing.text.JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBinding
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The charset to use when reading or writing this file.private static final String
The default name given to files if none is specified in a constructor.private boolean
Whether the file is dirty.static final String
Property change event fired when the text area's dirty flag changes.static final String
Property change event fired when the text area's encoding changes.static final String
Property change event fired when the file path this text area references is updated.static final long
The value returned bygetLastSaveOrLoadTime()
for remote files.private long
The last time this file was modified on disk, for local files.private FileLocation
The location of the file being edited.static final String
Property change event fired when the text area should be treated as read-only, and previously it should not, or vice-versa.private boolean
Whether the file should be treated as read-only.private static final long
Fields inherited from class org.fife.ui.rsyntaxtextarea.RSyntaxTextArea
ANIMATE_BRACKET_MATCHING_PROPERTY, ANTIALIAS_PROPERTY, AUTO_INDENT_PROPERTY, BRACKET_MATCHING_PROPERTY, CLEAR_WHITESPACE_LINES_PROPERTY, CLOSE_CURLY_BRACES_PROPERTY, CLOSE_MARKUP_TAGS_PROPERTY, CODE_FOLDING_PROPERTY, EOL_VISIBLE_PROPERTY, FOCUSABLE_TIPS_PROPERTY, FRACTIONAL_FONTMETRICS_PROPERTY, HIGHLIGHT_SECONDARY_LANGUAGES_PROPERTY, HYPERLINKS_ENABLED_PROPERTY, INSERT_PAIRED_CHARS_PROPERTY, MARK_OCCURRENCES_PROPERTY, MARKED_OCCURRENCES_CHANGED_PROPERTY, PAINT_MATCHED_BRACKET_PAIR_PROPERTY, PARSER_NOTICES_PROPERTY, SYNTAX_SCHEME_PROPERTY, SYNTAX_STYLE_PROPERTY, TAB_LINE_COLOR_PROPERTY, TAB_LINES_PROPERTY, USE_SELECTED_TEXT_COLOR_PROPERTY, VISIBLE_WHITESPACE_PROPERTY
Fields inherited from class org.fife.ui.rtextarea.RTextArea
COPY_ACTION, copyAction, CUT_ACTION, cutAction, DELETE_ACTION, INSERT_MODE, MARK_ALL_COLOR_PROPERTY, MARK_ALL_OCCURRENCES_CHANGED_PROPERTY, MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY, OVERWRITE_MODE, PASTE_ACTION, REDO_ACTION, SELECT_ALL_ACTION, UNDO_ACTION
Fields inherited from class org.fife.ui.rtextarea.RTextAreaBase
BACKGROUND_IMAGE_PROPERTY, CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY, CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY, HIGHLIGHT_CURRENT_LINE_PROPERTY, ROUNDED_SELECTION_PROPERTY
Fields inherited from class javax.swing.text.JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEY
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
Fields inherited from interface org.fife.ui.rsyntaxtextarea.SyntaxConstants
SYNTAX_STYLE_ACTIONSCRIPT, SYNTAX_STYLE_ASSEMBLER_6502, SYNTAX_STYLE_ASSEMBLER_X86, SYNTAX_STYLE_BBCODE, SYNTAX_STYLE_C, SYNTAX_STYLE_CLOJURE, SYNTAX_STYLE_CPLUSPLUS, SYNTAX_STYLE_CSHARP, SYNTAX_STYLE_CSS, SYNTAX_STYLE_CSV, SYNTAX_STYLE_D, SYNTAX_STYLE_DART, SYNTAX_STYLE_DELPHI, SYNTAX_STYLE_DOCKERFILE, SYNTAX_STYLE_DTD, SYNTAX_STYLE_FORTRAN, SYNTAX_STYLE_GO, SYNTAX_STYLE_GROOVY, SYNTAX_STYLE_HANDLEBARS, SYNTAX_STYLE_HOSTS, SYNTAX_STYLE_HTACCESS, SYNTAX_STYLE_HTML, SYNTAX_STYLE_INI, SYNTAX_STYLE_JAVA, SYNTAX_STYLE_JAVASCRIPT, SYNTAX_STYLE_JSON, SYNTAX_STYLE_JSON_WITH_COMMENTS, SYNTAX_STYLE_JSP, SYNTAX_STYLE_KOTLIN, SYNTAX_STYLE_LATEX, SYNTAX_STYLE_LESS, SYNTAX_STYLE_LISP, SYNTAX_STYLE_LUA, SYNTAX_STYLE_MAKEFILE, SYNTAX_STYLE_MARKDOWN, SYNTAX_STYLE_MXML, SYNTAX_STYLE_NONE, SYNTAX_STYLE_NSIS, SYNTAX_STYLE_PERL, SYNTAX_STYLE_PHP, SYNTAX_STYLE_PROPERTIES_FILE, SYNTAX_STYLE_PROTO, SYNTAX_STYLE_PYTHON, SYNTAX_STYLE_RUBY, SYNTAX_STYLE_RUST, SYNTAX_STYLE_SAS, SYNTAX_STYLE_SCALA, SYNTAX_STYLE_SQL, SYNTAX_STYLE_TCL, SYNTAX_STYLE_TYPESCRIPT, SYNTAX_STYLE_UNIX_SHELL, SYNTAX_STYLE_VISUAL_BASIC, SYNTAX_STYLE_WINDOWS_BATCH, SYNTAX_STYLE_XML, SYNTAX_STYLE_YAML
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.TextEditorPane
(int textMode) Constructor.TextEditorPane
(int textMode, boolean wordWrapEnabled) Creates a newTextEditorPane
.TextEditorPane
(int textMode, boolean wordWrapEnabled, FileLocation loc) Creates a newTextEditorPane
.TextEditorPane
(int textMode, boolean wordWrapEnabled, FileLocation loc, String defaultEnc) Creates a newTextEditorPane
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Callback for when styles in the current document change.private static String
Returns the default encoding for this operating system.Returns the encoding to use when reading or writing this file.Returns the full path to this document.Returns the file name of this document.long
Returns the timestamp for when this file was last loaded or saved by this editor pane.Returns the line separator used when writing this file (e.g.private void
init
(FileLocation loc, String defaultEnc) Initializes this editor with the specified file location.void
Callback for when text is inserted into the document.boolean
isDirty()
Returns whether the text in this editor has unsaved changes.boolean
isLocal()
Returns whether this file is a local file.boolean
Returns whether this is a local file that already exists.boolean
Returns whether the text file has been modified outside this editor since the last load or save operation.boolean
Returns whether the text area should be treated as read-only.void
load
(FileLocation loc) Loads the specified file in this editor.void
load
(FileLocation loc, String defaultEnc) Loads the specified file in this editor.void
load
(FileLocation loc, Charset defaultEnc) Loads the specified file in this editor.void
reload()
Reloads this file from disk.void
Called whenever text is removed from this editor.void
save()
Saves the file in its current encoding.void
saveAs
(FileLocation loc) Saves this file in a new local location.private void
saveImpl
(FileLocation loc) Saves the text in this editor to the specified location.void
setDirty
(boolean dirty) Sets whether this text in this editor has unsaved changes.void
setDocument
(Document doc) Sets the document for this editor.void
setEncoding
(String encoding) Sets the encoding to use when reading or writing this file.void
setLineSeparator
(String separator) Sets the line separator sequence to use when this file is saved (e.g.void
setLineSeparator
(String separator, boolean setDirty) Sets the line separator sequence to use when this file is saved (e.g.void
setReadOnly
(boolean readOnly) Sets whether this text area should be treated as read-only.void
Syncs this text area's "last saved or loaded" time to that of the file being edited, if that file is local and exists.Methods inherited from class org.fife.ui.rsyntaxtextarea.RSyntaxTextArea
addActiveLineRangeListener, addHyperlinkListener, addNotify, addParser, appendFoldingMenu, clearParsers, configurePopupMenu, copyAsStyledText, copyAsStyledText, createDefaultModel, createMouseListener, createPopupMenu, createRTextAreaUI, doBracketMatching, fireCaretUpdate, fireHyperlinkUpdate, fireMarkedOccurrencesChanged, fireParserNoticesChange, foldToggled, forceReparsing, forceReparsing, getAnimateBracketMatching, getAntiAliasingEnabled, getBackgroundForToken, getCloseCurlyBraces, getCloseMarkupTags, getCodeTemplateManager, getDefaultBracketMatchBGColor, getDefaultBracketMatchBorderColor, getDefaultSelectionColor, getDefaultSyntaxScheme, getDotRectangle, getEOLMarkersVisible, getFoldManager, getFontForTokenType, getFontMetricsForTokenType, getForegroundForToken, getForegroundForTokenType, getFractionalFontMetricsEnabled, getHighlightSecondaryLanguages, getHyperlinkForeground, getHyperlinksEnabled, getInsertPairedCharacters, getLastVisibleOffset, getLineHeight, getLinkGenerator, getMarkAllHighlightRanges, getMarkedOccurrences, getMarkOccurrences, getMarkOccurrencesColor, getMarkOccurrencesDelay, getMarkOccurrencesOfTokenType, getMatchedBracketBGColor, getMatchedBracketBorderColor, getMatchRectangle, getMaxAscent, getPaintMarkOccurrencesBorder, getPaintMatchedBracketPair, getPaintTabLines, getPaintTokenBackgrounds, getParser, getParserCount, getParserDelay, getParserNotices, getRightHandSideCorrection, getSecondaryLanguageBackground, getSecondaryLanguageCount, getShouldIndentNextLine, getShowMatchedBracketPopup, getSyntaxEditingStyle, getSyntaxScheme, getTabLineColor, getTemplatesEnabled, getTokenListFor, getTokenListForLine, getTokenPainter, getToolTipText, getToolTipTextImpl, getUnderlineForToken, getUseFocusableTips, getUseSelectedTextColor, init, isAutoIndentEnabled, isBracketMatchingEnabled, isClearWhitespaceLinesEnabled, isCodeFoldingEnabled, isWhitespaceVisible, modelToToken, paintComponent, redoLastAction, removeActiveLineRangeListener, removeHyperlinkListener, removeNotify, removeParser, restoreDefaultSyntaxScheme, saveTemplates, setActiveLineRange, setAnimateBracketMatching, setAntiAliasingEnabled, setAutoIndentEnabled, setBracketMatchingEnabled, setClearWhitespaceLinesEnabled, setCloseCurlyBraces, setCloseMarkupTags, setCodeFoldingEnabled, setEOLMarkersVisible, setFont, setFractionalFontMetricsEnabled, setHighlighter, setHighlightSecondaryLanguages, setHyperlinkForeground, setHyperlinksEnabled, setInsertPairedCharacters, setLinkGenerator, setLinkScanningMask, setMarkOccurrences, setMarkOccurrencesColor, setMarkOccurrencesDelay, setMatchedBracketBGColor, setMatchedBracketBorderColor, setPaintMarkOccurrencesBorder, setPaintMatchedBracketPair, setPaintTabLines, setParserDelay, setRightHandSideCorrection, setSecondaryLanguageBackground, setShowMatchedBracketPopup, setSyntaxEditingStyle, setSyntaxScheme, setTabLineColor, setTemplateDirectory, setTemplatesEnabled, setUseFocusableTips, setUseSelectedTextColor, setWhitespaceVisible, undoLastAction, viewToToken
Methods inherited from class org.fife.ui.rtextarea.RTextArea
addLineHighlight, beginAtomicEdit, beginRecordingMacro, canRedo, canUndo, clearMarkAllHighlights, createPopupMenuItem, createUndoManager, discardAllEdits, endAtomicEdit, endRecordingMacro, getAction, getCurrentMacro, getDefaultMarkAllHighlightColor, getDefaultModifier, getIconGroup, getMarkAllHighlightColor, getMarkAllOnOccurrenceSearches, getPopupMenu, getSelectedOccurrenceText, getTextMode, getToolTipSupplier, handleReplaceSelection, isRecordingMacro, loadMacro, markAll, paste, playbackLastMacro, print, processMouseEvent, read, removeAllLineHighlights, removeLineHighlight, replaceRange, replaceSelection, setActionProperties, setActionProperties, setCaret, setCaretStyle, setIconGroup, setMarkAllHighlightColor, setMarkAllOnOccurrenceSearches, setPopupMenu, setRoundedSelectionEdges, setSelectedOccurrenceText, setTextMode, setToolTipSupplier, setUI
Methods inherited from class org.fife.ui.rtextarea.RTextAreaBase
convertSpacesToTabs, convertTabsToSpaces, forceCurrentLineHighlightRepaint, getBackground, getBackgroundImage, getBackgroundObject, getCaretLineNumber, getCaretOffsetFromLineStart, getCurrentCaretY, getCurrentLineHighlightColor, getDefaultCaretColor, getDefaultCurrentLineHighlightColor, getDefaultFont, getDefaultForeground, getDefaultMarginLineColor, getDefaultMarginLinePosition, getDefaultTabSize, getFadeCurrentLineHighlight, getHighlightCurrentLine, getLineEndOffsetOfCurrentLine, getLineStartOffsetOfCurrentLine, getMarginLineColor, getMarginLinePixelLocation, getMarginLinePosition, getRoundedSelectionEdges, getTabsEmulated, isMarginLineEnabled, isOSX, possiblyUpdateCurrentLineHighlightLocation, processComponentEvent, setBackground, setBackgroundImage, setBackgroundObject, setCurrentLineHighlightColor, setFadeCurrentLineHighlight, setHighlightCurrentLine, setLineWrap, setMargin, setMarginLineColor, setMarginLineEnabled, setMarginLinePosition, setRTextAreaUI, setTabsEmulated, setTabSize, updateMarginLineX, yForLine, yForLineContaining
Methods inherited from class javax.swing.JTextArea
append, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, setColumns, setRows, setWrapStyleWord
Methods inherited from class javax.swing.text.JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, print, print, print, processInputMethodEvent, removeCaretListener, removeKeymap, restoreComposedText, saveComposedText, select, selectAll, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setKeymap, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, updateUI, viewToModel, viewToModel2D, write
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
FULL_PATH_PROPERTY
Property change event fired when the file path this text area references is updated.- See Also:
-
DIRTY_PROPERTY
Property change event fired when the text area's dirty flag changes.- See Also:
-
READ_ONLY_PROPERTY
Property change event fired when the text area should be treated as read-only, and previously it should not, or vice-versa.- See Also:
-
ENCODING_PROPERTY
Property change event fired when the text area's encoding changes.- See Also:
-
loc
The location of the file being edited. -
charSet
The charset to use when reading or writing this file. -
readOnly
private boolean readOnlyWhether the file should be treated as read-only. -
dirty
private boolean dirtyWhether the file is dirty. -
lastSaveOrLoadTime
private long lastSaveOrLoadTimeThe last time this file was modified on disk, for local files. For remote files, this value should always beLAST_MODIFIED_UNKNOWN
. -
LAST_MODIFIED_UNKNOWN
public static final long LAST_MODIFIED_UNKNOWNThe value returned bygetLastSaveOrLoadTime()
for remote files.- See Also:
-
DEFAULT_FILE_NAME
The default name given to files if none is specified in a constructor.- See Also:
-
-
Constructor Details
-
TextEditorPane
public TextEditorPane()Constructor. The file will be given a default name. -
TextEditorPane
public TextEditorPane(int textMode) Constructor. The file will be given a default name.- Parameters:
textMode
- EitherINSERT_MODE
orOVERWRITE_MODE
.
-
TextEditorPane
public TextEditorPane(int textMode, boolean wordWrapEnabled) Creates a newTextEditorPane
. The file will be given a default name.- Parameters:
textMode
- EitherINSERT_MODE
orOVERWRITE_MODE
.wordWrapEnabled
- Whether to use word wrap in this pane.
-
TextEditorPane
Creates a newTextEditorPane
.- Parameters:
textMode
- EitherINSERT_MODE
orOVERWRITE_MODE
.wordWrapEnabled
- Whether to use word wrap in this pane.loc
- The location of the text file being edited. If this value isnull
, a file named "Untitled.txt" in the current directory is used.- Throws:
IOException
- If an IO error occurs reading the file atloc
. This of course won't happen ifloc
isnull
.
-
TextEditorPane
public TextEditorPane(int textMode, boolean wordWrapEnabled, FileLocation loc, String defaultEnc) throws IOException Creates a newTextEditorPane
.- Parameters:
textMode
- EitherINSERT_MODE
orOVERWRITE_MODE
.wordWrapEnabled
- Whether to use word wrap in this pane.loc
- The location of the text file being edited. If this value isnull
, a file named "Untitled.txt" in the current directory is used. This file is displayed as empty even if it actually exists.defaultEnc
- The default encoding to use when opening the file, if the file is not Unicode. If this value isnull
, a system default value is used.- Throws:
IOException
- If an IO error occurs reading the file atloc
. This of course won't happen ifloc
isnull
.
-
-
Method Details
-
changedUpdate
Callback for when styles in the current document change. This method is never called.- Specified by:
changedUpdate
in interfaceDocumentListener
- Parameters:
e
- The document event.
-
getDefaultEncoding
Returns the default encoding for this operating system.- Returns:
- The default encoding.
-
getEncoding
Returns the encoding to use when reading or writing this file.- Returns:
- The encoding.
- See Also:
-
getFileFullPath
Returns the full path to this document.- Returns:
- The full path to the document.
-
getFileName
Returns the file name of this document.- Returns:
- The file name.
-
getLastSaveOrLoadTime
public long getLastSaveOrLoadTime()Returns the timestamp for when this file was last loaded or saved by this editor pane. If the file has been modified on disk by another process after it was loaded into this editor pane, this method will not return the actual file's last modified time.For remote files, this method will always return
LAST_MODIFIED_UNKNOWN
.- Returns:
- The timestamp when this file was last loaded or saved by this
editor pane, if it is a local file, or
LAST_MODIFIED_UNKNOWN
if it is a remote file. - See Also:
-
getLineSeparator
Returns the line separator used when writing this file (e.g. "\n
", "\r\n
", or "\r
").Note that this value is an
Object
and not aString
as that is the way theDocument
interface defines its property values. If you always usesetLineSeparator(String)
to modify this value, then the value returned from this method will always be aString
.- Returns:
- The line separator. If this value is
null
, then the system default line separator is used (usually the value ofSystem.getProperty("line.separator")
). - See Also:
-
init
Initializes this editor with the specified file location.- Parameters:
loc
- The file location. If this isnull
, a default location is used and an empty file is displayed.defaultEnc
- The default encoding to use when opening the file, if the file is not Unicode. If this value isnull
, a system default value is used.- Throws:
IOException
- If an IO error occurs reading fromloc
. Ifloc
isnull
, this cannot happen.
-
insertUpdate
Callback for when text is inserted into the document.- Specified by:
insertUpdate
in interfaceDocumentListener
- Parameters:
e
- Information on the insertion.
-
isDirty
public boolean isDirty()Returns whether the text in this editor has unsaved changes.- Returns:
- Whether the text has unsaved changes.
- See Also:
-
isLocal
public boolean isLocal()Returns whether this file is a local file.- Returns:
- Whether this is a local file.
-
isLocalAndExists
public boolean isLocalAndExists()Returns whether this is a local file that already exists.- Returns:
- Whether this is a local file that already exists.
-
isModifiedOutsideEditor
public boolean isModifiedOutsideEditor()Returns whether the text file has been modified outside this editor since the last load or save operation. Note that if this is a remote file, this method will always returnfalse
.This method may be used by applications to implement a reloading feature, where the user is prompted to reload a file if it has been modified since their last open or save.
- Returns:
- Whether the text file has been modified outside this editor.
- See Also:
-
isReadOnly
public boolean isReadOnly()Returns whether the text area should be treated as read-only.- Returns:
- Whether the text area should be treated as read-only.
- See Also:
-
load
Loads the specified file in this editor. This method fires a property change event of typeFULL_PATH_PROPERTY
.The file will be checked for a BOM; if one is found, the proper Unicode flavor is used to load the file. If not, the system default encoding is assumed.
- Parameters:
loc
- The location of the file to load. This cannot benull
.- Throws:
IOException
- If an IO error occurs.- See Also:
-
load
Loads the specified file in this editor. This method fires a property change event of typeFULL_PATH_PROPERTY
.- Parameters:
loc
- The location of the file to load. This cannot benull
.defaultEnc
- The encoding to use when loading/saving the file. This encoding will only be used if the file is not Unicode. If this value isnull
, the system default encoding is used.- Throws:
IOException
- If an IO error occurs.- See Also:
-
load
Loads the specified file in this editor. This method fires a property change event of typeFULL_PATH_PROPERTY
.- Parameters:
loc
- The location of the file to load. This cannot benull
.defaultEnc
- The encoding to use when loading/saving the file. This encoding will only be used if the file is not Unicode. If this value isnull
, the system default encoding is used.- Throws:
IOException
- If an IO error occurs.- See Also:
-
reload
Reloads this file from disk. The file must exist for this operation to not throw an exception.The file's "dirty" state will be set to
false
after this operation. If this is a local file, its "last modified" time is updated to reflect that of the actual file.Note that if the file has been modified on disk, and is now a Unicode encoding when before it wasn't (or if it is a different Unicode now), this will cause this
TextEditorPane
's encoding to change. Otherwise, the file's encoding will stay the same.- Throws:
IOException
- If the file does not exist, or if an IO error occurs reading the file.- See Also:
-
removeUpdate
Called whenever text is removed from this editor.- Specified by:
removeUpdate
in interfaceDocumentListener
- Parameters:
e
- The document event.
-
save
Saves the file in its current encoding.The text area's "dirty" state is set to
false
, and if this is a local file, its "last modified" time is updated.- Throws:
IOException
- If an IO error occurs.- See Also:
-
saveAs
Saves this file in a new local location. This method fires a property change event of typeFULL_PATH_PROPERTY
.- Parameters:
loc
- The location to save to.- Throws:
IOException
- If an IO error occurs.- See Also:
-
saveImpl
Saves the text in this editor to the specified location.- Parameters:
loc
- The location to save to.- Throws:
IOException
- If an IO error occurs.
-
setDirty
public void setDirty(boolean dirty) Sets whether this text in this editor has unsaved changes. This fires a property change event of typeDIRTY_PROPERTY
.Applications will usually have no need to call this method directly; the only time you might have a need to call this method directly is if you have to initialize an instance of TextEditorPane with content that does not come from a file.
TextEditorPane
automatically sets its own dirty flag when its content is edited, when its encoding is changed, or when its line ending property is changed. It is cleared wheneverload()
,reload()
,save()
, orsaveAs()
are called.- Parameters:
dirty
- Whether the text has been modified.- See Also:
-
setDocument
Sets the document for this editor.- Overrides:
setDocument
in classRSyntaxTextArea
- Parameters:
doc
- The new document.
-
setEncoding
Sets the encoding to use when reading or writing this file. This method sets the editor's dirty flag when the encoding is changed, and fires a property change event of typeENCODING_PROPERTY
.- Parameters:
encoding
- The new encoding.- Throws:
UnsupportedCharsetException
- If the encoding is not supported.NullPointerException
- Ifencoding
isnull
.- See Also:
-
setLineSeparator
Sets the line separator sequence to use when this file is saved (e.g. "\n
", "\r\n
" or "\r
"). Besides parameter checking, this method is preferred overgetDocument().putProperty()
because it sets the editor's dirty flag when the line separator is changed.- Parameters:
separator
- The new line separator.- Throws:
NullPointerException
- Ifseparator
isnull
.IllegalArgumentException
- Ifseparator
is not one of "\n
", "\r\n
" or "\r
".- See Also:
-
setLineSeparator
Sets the line separator sequence to use when this file is saved (e.g. "\n
", "\r\n
" or "\r
"). Besides parameter checking, this method is preferred overgetDocument().putProperty()
because can set the editor's dirty flag when the line separator is changed.- Parameters:
separator
- The new line separator.setDirty
- Whether the dirty flag should be set if the line separator is changed.- Throws:
NullPointerException
- Ifseparator
isnull
.IllegalArgumentException
- Ifseparator
is not one of "\n
", "\r\n
" or "\r
".- See Also:
-
setReadOnly
public void setReadOnly(boolean readOnly) Sets whether this text area should be treated as read-only. This fires a property change event of typeREAD_ONLY_PROPERTY
.- Parameters:
readOnly
- Whether the document is read-only.- See Also:
-
syncLastSaveOrLoadTimeToActualFile
public void syncLastSaveOrLoadTimeToActualFile()Syncs this text area's "last saved or loaded" time to that of the file being edited, if that file is local and exists. If the file is remote or is local but does not yet exist, nothing happens.You normally do not have to call this method, as the "last saved or loaded" time for
TextEditorPane
s is kept up-to-date internally during such operations assave()
,reload()
, etc.- See Also:
-