Class RSyntaxTextArea
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.text.JTextComponent
-
- javax.swing.JTextArea
-
- org.fife.ui.rtextarea.RTextAreaBase
-
- org.fife.ui.rtextarea.RTextArea
-
- org.fife.ui.rsyntaxtextarea.RSyntaxTextArea
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Printable
,Serializable
,Accessible
,Scrollable
,SyntaxConstants
- Direct Known Subclasses:
TextEditorPane
public class RSyntaxTextArea extends RTextArea implements SyntaxConstants
An extension ofRTextArea
that adds syntax highlighting of certain programming languages to its list of features. Languages currently supported include:- ActionScript
- Assembler (X86)
- BBCode
- C
- C++
- CSS
- C#
- Clojure
- Dart
- Delphi
- DTD
- Fortran
- Groovy
- HTML
- htaccess
- Java
- JavaScript
- .jshintrc
- JSP
- LaTeX
- Lisp
- Lua
- Make
- MXML
- NSIS
- Perl
- PHP
- Properties files
- Python
- Ruby
- SAS
- Scala
- SQL
- Tcl
- UNIX shell scripts
- Visual Basic
- Windows batch
- XML files
- Code folding
- Bracket matching
- Auto-indentation
- Copy as RTF
- Clickable hyperlinks (if the language scanner being used supports it)
- A pluggable "parser" system that can be used to implement syntax validation, spell checking, etc.
RTextScrollPane
instead of a regularJScrollPane
as this class allows you to add line numbers and bookmarks easily to your text area.- See Also:
TextEditorPane
, Serialized Form
-
-
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
Fields Modifier and Type Field Description static String
ANIMATE_BRACKET_MATCHING_PROPERTY
static String
ANTIALIAS_PROPERTY
static String
AUTO_INDENT_PROPERTY
static String
BRACKET_MATCHING_PROPERTY
static String
CLEAR_WHITESPACE_LINES_PROPERTY
static String
CLOSE_CURLY_BRACES_PROPERTY
static String
CLOSE_MARKUP_TAGS_PROPERTY
static String
CODE_FOLDING_PROPERTY
static String
EOL_VISIBLE_PROPERTY
static String
FOCUSABLE_TIPS_PROPERTY
static String
FRACTIONAL_FONTMETRICS_PROPERTY
static String
HIGHLIGHT_SECONDARY_LANGUAGES_PROPERTY
static String
HYPERLINKS_ENABLED_PROPERTY
static String
MARK_OCCURRENCES_PROPERTY
static String
MARKED_OCCURRENCES_CHANGED_PROPERTY
static String
PAINT_MATCHED_BRACKET_PAIR_PROPERTY
static String
PARSER_NOTICES_PROPERTY
static String
SYNTAX_SCHEME_PROPERTY
static String
SYNTAX_STYLE_PROPERTY
static String
TAB_LINE_COLOR_PROPERTY
static String
TAB_LINES_PROPERTY
static String
USE_SELECTED_TEXT_COLOR_PROPERTY
static String
VISIBLE_WHITESPACE_PROPERTY
-
Fields inherited from class org.fife.ui.rtextarea.RTextArea
COPY_ACTION, CUT_ACTION, DELETE_ACTION, INSERT_MODE, MARK_ALL_COLOR_PROPERTY, MARK_ALL_OCCURRENCES_CHANGED_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_X86, SYNTAX_STYLE_BBCODE, SYNTAX_STYLE_C, SYNTAX_STYLE_CLOJURE, SYNTAX_STYLE_CPLUSPLUS, SYNTAX_STYLE_CSHARP, SYNTAX_STYLE_CSS, SYNTAX_STYLE_D, SYNTAX_STYLE_DART, SYNTAX_STYLE_DELPHI, SYNTAX_STYLE_DTD, SYNTAX_STYLE_FORTRAN, SYNTAX_STYLE_GROOVY, SYNTAX_STYLE_HTACCESS, SYNTAX_STYLE_HTML, SYNTAX_STYLE_JAVA, SYNTAX_STYLE_JAVASCRIPT, SYNTAX_STYLE_JSHINTRC, SYNTAX_STYLE_JSON, SYNTAX_STYLE_JSP, SYNTAX_STYLE_LATEX, SYNTAX_STYLE_LESS, SYNTAX_STYLE_LISP, SYNTAX_STYLE_LUA, SYNTAX_STYLE_MAKEFILE, SYNTAX_STYLE_MXML, SYNTAX_STYLE_NONE, SYNTAX_STYLE_NSIS, SYNTAX_STYLE_PERL, SYNTAX_STYLE_PHP, SYNTAX_STYLE_PROPERTIES_FILE, SYNTAX_STYLE_PYTHON, SYNTAX_STYLE_RUBY, SYNTAX_STYLE_SAS, SYNTAX_STYLE_SCALA, SYNTAX_STYLE_SQL, SYNTAX_STYLE_TCL, SYNTAX_STYLE_UNIX_SHELL, SYNTAX_STYLE_VISUAL_BASIC, SYNTAX_STYLE_WINDOWS_BATCH, SYNTAX_STYLE_XML
-
-
Constructor Summary
Constructors Constructor Description RSyntaxTextArea()
Constructor.RSyntaxTextArea(int textMode)
Creates a newRSyntaxTextArea
.RSyntaxTextArea(int rows, int cols)
Constructor.RSyntaxTextArea(String text)
Constructor.RSyntaxTextArea(String text, int rows, int cols)
Constructor.RSyntaxTextArea(RSyntaxDocument doc)
Constructor.RSyntaxTextArea(RSyntaxDocument doc, String text, int rows, int cols)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActiveLineRangeListener(ActiveLineRangeListener l)
Adds an "active line range" listener to this text area.void
addHyperlinkListener(HyperlinkListener l)
Adds a hyperlink listener to this text area.void
addNotify()
Updates the font metrics the first time we're displayed.void
addParser(Parser parser)
Adds the parser to "validate" the source code in this text area.protected void
appendFoldingMenu(JPopupMenu popup)
Appends a submenu with code folding options to this text component's popup menu.void
clearParsers()
Removes all parsers from this text area.protected void
configurePopupMenu(JPopupMenu popupMenu)
Overridden to toggle the enabled state of various RSyntaxTextArea-specific menu items.void
copyAsRtf()
Copies the currently selected text to the system clipboard, with any necessary style information (font, foreground color and background color).protected Document
createDefaultModel()
Returns the document to use for anRSyntaxTextArea
protected RTextAreaBase.RTAMouseListener
createMouseListener()
Returns the caret event/mouse listener forRTextArea
s.protected JPopupMenu
createPopupMenu()
Overridden to add menu items related to cold folding.protected RTextAreaUI
createRTextAreaUI()
Returns the a real UI to install on this text area.protected void
doBracketMatching()
If the caret is on a bracket, this method finds the matching bracket, and if it exists, highlights it.protected void
fireCaretUpdate(CaretEvent e)
Notifies all listeners that a caret change has occurred.void
foldToggled(Fold fold)
Called whenever a fold is collapsed or expanded.void
forceReparsing(int parser)
Forces the givenParser
to re-parse the content of this text area.boolean
forceReparsing(Parser parser)
Forces re-parsing with a specific parser.boolean
getAnimateBracketMatching()
Returns whether bracket matching should be animated.boolean
getAntiAliasingEnabled()
Returns whether anti-aliasing is enabled in this editor.Color
getBackgroundForToken(Token token)
Returns the background color for a token.boolean
getCloseCurlyBraces()
Returns whether curly braces should be automatically closed when a newline is entered after an opening curly brace.boolean
getCloseMarkupTags()
Returns whether closing markup tags should be automatically completed when "</
" is typed.static CodeTemplateManager
getCodeTemplateManager()
Returns the code template manager for all instances ofRSyntaxTextArea
.static Color
getDefaultBracketMatchBGColor()
Returns the default bracket-match background color.static Color
getDefaultBracketMatchBorderColor()
Returns the default bracket-match border color.static Color
getDefaultSelectionColor()
Returns the default selection color for this text area.SyntaxScheme
getDefaultSyntaxScheme()
Returns the "default" syntax highlighting color scheme.boolean
getEOLMarkersVisible()
Returns whether an EOL marker should be drawn at the end of each line.FoldManager
getFoldManager()
Returns the fold manager for this text area.Font
getFontForTokenType(int type)
Returns the font for tokens of the specified type.FontMetrics
getFontMetricsForTokenType(int type)
Returns the font metrics for tokens of the specified type.Color
getForegroundForToken(Token t)
Returns the foreground color to use when painting a token.Color
getForegroundForTokenType(int type)
Returns the foreground color to use when painting a token.boolean
getFractionalFontMetricsEnabled()
Returns whether fractional font metrics are enabled for this text area.boolean
getHighlightSecondaryLanguages()
Returns whether "secondary" languages should have their backgrounds colored differently to visually differentiate them.Color
getHyperlinkForeground()
Returns the color to use when painting hyperlinks.boolean
getHyperlinksEnabled()
Returns whether hyperlinks are enabled for this text area.int
getLastVisibleOffset()
Returns the last visible offset in this text area.int
getLineHeight()
Returns the height to use for a line of text in this text area.LinkGenerator
getLinkGenerator()
List<DocumentRange>
getMarkAllHighlightRanges()
Returns a list of "mark all" highlights in the text area.List<DocumentRange>
getMarkedOccurrences()
Returns a list of "marked occurrences" in the text area.boolean
getMarkOccurrences()
Returns whether "Mark Occurrences" is enabled.Color
getMarkOccurrencesColor()
Returns the color used to "mark occurrences."Color
getMatchedBracketBGColor()
Gets the color used as the background for a matched bracket.Color
getMatchedBracketBorderColor()
Gets the color used as the border for a matched bracket.int
getMaxAscent()
Overridden to return the max ascent for any font used in the editor.boolean
getPaintMarkOccurrencesBorder()
Returns whether a border is painted around marked occurrences.boolean
getPaintMatchedBracketPair()
Returns whether the bracket at the caret position is painted as a "match" when a matched bracket is found.boolean
getPaintTabLines()
Returns whether tab lines are painted.Parser
getParser(int index)
Returns the specified parser.int
getParserCount()
Returns the number of parsers operating on this text area.int
getParserDelay()
Returns the currently set parser delay.List<ParserNotice>
getParserNotices()
Returns a list of the current parser notices for this text area.int
getRightHandSideCorrection()
Workaround for JTextComponents allowing the caret to be rendered entirely off-screen if the entire "previous" character fit entirely.Color
getSecondaryLanguageBackground(int index)
Returns the background color for the specified secondary language.int
getSecondaryLanguageCount()
Returns the number of secondary language backgrounds.boolean
getShouldIndentNextLine(int line)
If auto-indent is enabled, this method returns whether a new line after this one should be indented (based on the standard indentation rules for the current programming language).String
getSyntaxEditingStyle()
Returns what type of syntax highlighting this editor is doing.SyntaxScheme
getSyntaxScheme()
Returns all of the colors currently being used in syntax highlighting by this text component.Color
getTabLineColor()
Returns the color used to paint tab lines.static boolean
getTemplatesEnabled()
Returns whether or not templates are enabled for all instances ofRSyntaxTextArea
.Token
getTokenListForLine(int line)
Returns a list of tokens representing the given line.String
getToolTipText(MouseEvent e)
Returns the tool tip to display for a mouse event at the given location.protected String
getToolTipTextImpl(MouseEvent e)
Does the dirty work of getting the tool tip text.boolean
getUnderlineForToken(Token t)
Returns whether the specified token should be underlined.boolean
getUseFocusableTips()
Returns whether "focusable" tool tips are used instead of standard ones.boolean
getUseSelectedTextColor()
Returns whether selected text should use the "selected text color" property set viaJTextComponent.setSelectedTextColor(Color)
.protected void
init()
Called by constructors to initialize common properties of the text editor.boolean
isAutoIndentEnabled()
Returns whether or not auto-indent is enabled.boolean
isBracketMatchingEnabled()
Returns whether or not bracket matching is enabled.boolean
isClearWhitespaceLinesEnabled()
Returns whether or not lines containing nothing but whitespace are made into blank lines when Enter is pressed in them.boolean
isCodeFoldingEnabled()
Returns whether code folding is enabled.boolean
isWhitespaceVisible()
Returns whether whitespace (spaces and tabs) is visible.Token
modelToToken(int offs)
Returns the token at the specified position in the model.protected void
paintComponent(Graphics g)
ThepaintComponent
method is overridden so we apply any necessary rendering hints to the Graphics object.void
redoLastAction()
Attempt to redo the last action.void
removeActiveLineRangeListener(ActiveLineRangeListener l)
Removes an "active line range" listener from this text area.void
removeHyperlinkListener(HyperlinkListener l)
Removes a hyperlink listener from this text area.void
removeNotify()
Overridden so we stop this text area's parsers, if any.boolean
removeParser(Parser parser)
Removes a parser from this text area.void
restoreDefaultSyntaxScheme()
Sets the colors used for syntax highlighting to their defaults.static boolean
saveTemplates()
Attempts to save all currently-known templates to the current template directory, as set bysetTemplateDirectory
.void
setActiveLineRange(int min, int max)
Sets the "active line range." Note that thisRSyntaxTextArea
itself does nothing with this information, but if it is contained inside anRTextScrollPane
, the active line range may be displayed in the icon area of theGutter
.void
setAnimateBracketMatching(boolean animate)
Sets whether bracket matching should be animated.void
setAntiAliasingEnabled(boolean enabled)
Sets whether anti-aliasing is enabled in this editor.void
setAutoIndentEnabled(boolean enabled)
Sets whether or not auto-indent is enabled.void
setBracketMatchingEnabled(boolean enabled)
Sets whether bracket matching is enabled.void
setClearWhitespaceLinesEnabled(boolean enabled)
Sets whether or not lines containing nothing but whitespace are made into blank lines when Enter is pressed in them.void
setCloseCurlyBraces(boolean close)
Toggles whether curly braces should be automatically closed when a newline is entered after an opening curly brace.void
setCloseMarkupTags(boolean close)
Sets whether closing markup tags should be automatically completed when "</
" is typed.void
setCodeFoldingEnabled(boolean enabled)
Sets whether code folding is enabled.void
setDocument(Document document)
Sets the document used by this text area.void
setEOLMarkersVisible(boolean visible)
Sets whether EOL markers are visible at the end of each line.void
setFont(Font font)
Sets the font used by this text area.void
setFractionalFontMetricsEnabled(boolean enabled)
Sets whether fractional font metrics are enabled.void
setHighlighter(Highlighter h)
Sets the highlighter used by this text area.void
setHighlightSecondaryLanguages(boolean highlight)
Sets whether "secondary" languages should have their backgrounds colored differently to visually differentiate them.void
setHyperlinkForeground(Color fg)
Sets the color to use when painting hyperlinks.void
setHyperlinksEnabled(boolean enabled)
Sets whether hyperlinks are enabled for this text area.void
setLinkGenerator(LinkGenerator generator)
void
setLinkScanningMask(int mask)
Sets the mask for the key used to toggle whether we are scanning for hyperlinks with mouse hovering.void
setMarkOccurrences(boolean markOccurrences)
Toggles whether "mark occurrences" is enabled.void
setMarkOccurrencesColor(Color color)
Sets the "mark occurrences" color.void
setMatchedBracketBGColor(Color color)
Sets the color used as the background for a matched bracket.void
setMatchedBracketBorderColor(Color color)
Sets the color used as the border for a matched bracket.void
setPaintMarkOccurrencesBorder(boolean paintBorder)
Toggles whether a border should be painted around marked occurrences.void
setPaintMatchedBracketPair(boolean paintPair)
Sets whether the bracket at the caret position is painted as a "match" when a matched bracket is found.void
setPaintTabLines(boolean paint)
Toggles whether tab lines are painted.void
setParserDelay(int millis)
Sets the parser delay.void
setRightHandSideCorrection(int rhsCorrection)
Applications typically have no need to modify this value.void
setSecondaryLanguageBackground(int index, Color color)
Sets the background color to use for a secondary language.void
setSyntaxEditingStyle(String styleKey)
Sets what type of syntax highlighting this editor is doing.void
setSyntaxScheme(SyntaxScheme scheme)
Sets all of the colors used in syntax highlighting to the colors specified.void
setTabLineColor(Color c)
Sets the color use to paint tab lines.static boolean
setTemplateDirectory(String dir)
If templates are enabled, all currently-known templates are forgotten and all templates are loaded from all files in the specified directory ending in "*.xml".static void
setTemplatesEnabled(boolean enabled)
Enables or disables templates.void
setUseFocusableTips(boolean use)
Sets whether "focusable" tool tips are used instead of standard ones.void
setUseSelectedTextColor(boolean use)
Sets whether selected text should use the "selected text color" property (set viaJTextComponent.setSelectedTextColor(Color)
).void
setWhitespaceVisible(boolean visible)
Sets whether whitespace is visible.void
undoLastAction()
Attempt to undo an "action" done in this text area.Token
viewToToken(Point p)
Returns the token at the specified position in the view.-
Methods inherited from class org.fife.ui.rtextarea.RTextArea
addLineHighlight, beginAtomicEdit, beginRecordingMacro, canRedo, canUndo, createPopupMenuItem, createUndoManager, discardAllEdits, endAtomicEdit, endRecordingMacro, getAction, getCurrentMacro, getDefaultMarkAllHighlightColor, getIconGroup, getMarkAllHighlightColor, getPopupMenu, getSelectedOccurrenceText, getTextMode, getToolTipSupplier, handleReplaceSelection, isRecordingMacro, loadMacro, paste, playbackLastMacro, print, read, removeAllLineHighlights, removeLineHighlight, replaceRange, replaceSelection, setActionProperties, setActionProperties, setCaret, setCaretStyle, setIconGroup, setMarkAllHighlightColor, 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, processMouseEvent, 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 Detail
-
ANIMATE_BRACKET_MATCHING_PROPERTY
public static final String ANIMATE_BRACKET_MATCHING_PROPERTY
- See Also:
- Constant Field Values
-
ANTIALIAS_PROPERTY
public static final String ANTIALIAS_PROPERTY
- See Also:
- Constant Field Values
-
AUTO_INDENT_PROPERTY
public static final String AUTO_INDENT_PROPERTY
- See Also:
- Constant Field Values
-
BRACKET_MATCHING_PROPERTY
public static final String BRACKET_MATCHING_PROPERTY
- See Also:
- Constant Field Values
-
CLEAR_WHITESPACE_LINES_PROPERTY
public static final String CLEAR_WHITESPACE_LINES_PROPERTY
- See Also:
- Constant Field Values
-
CLOSE_CURLY_BRACES_PROPERTY
public static final String CLOSE_CURLY_BRACES_PROPERTY
- See Also:
- Constant Field Values
-
CLOSE_MARKUP_TAGS_PROPERTY
public static final String CLOSE_MARKUP_TAGS_PROPERTY
- See Also:
- Constant Field Values
-
CODE_FOLDING_PROPERTY
public static final String CODE_FOLDING_PROPERTY
- See Also:
- Constant Field Values
-
EOL_VISIBLE_PROPERTY
public static final String EOL_VISIBLE_PROPERTY
- See Also:
- Constant Field Values
-
FOCUSABLE_TIPS_PROPERTY
public static final String FOCUSABLE_TIPS_PROPERTY
- See Also:
- Constant Field Values
-
FRACTIONAL_FONTMETRICS_PROPERTY
public static final String FRACTIONAL_FONTMETRICS_PROPERTY
- See Also:
- Constant Field Values
-
HIGHLIGHT_SECONDARY_LANGUAGES_PROPERTY
public static final String HIGHLIGHT_SECONDARY_LANGUAGES_PROPERTY
- See Also:
- Constant Field Values
-
HYPERLINKS_ENABLED_PROPERTY
public static final String HYPERLINKS_ENABLED_PROPERTY
- See Also:
- Constant Field Values
-
MARK_OCCURRENCES_PROPERTY
public static final String MARK_OCCURRENCES_PROPERTY
- See Also:
- Constant Field Values
-
MARKED_OCCURRENCES_CHANGED_PROPERTY
public static final String MARKED_OCCURRENCES_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
PAINT_MATCHED_BRACKET_PAIR_PROPERTY
public static final String PAINT_MATCHED_BRACKET_PAIR_PROPERTY
- See Also:
- Constant Field Values
-
PARSER_NOTICES_PROPERTY
public static final String PARSER_NOTICES_PROPERTY
- See Also:
- Constant Field Values
-
SYNTAX_SCHEME_PROPERTY
public static final String SYNTAX_SCHEME_PROPERTY
- See Also:
- Constant Field Values
-
SYNTAX_STYLE_PROPERTY
public static final String SYNTAX_STYLE_PROPERTY
- See Also:
- Constant Field Values
-
TAB_LINE_COLOR_PROPERTY
public static final String TAB_LINE_COLOR_PROPERTY
- See Also:
- Constant Field Values
-
TAB_LINES_PROPERTY
public static final String TAB_LINES_PROPERTY
- See Also:
- Constant Field Values
-
USE_SELECTED_TEXT_COLOR_PROPERTY
public static final String USE_SELECTED_TEXT_COLOR_PROPERTY
- See Also:
- Constant Field Values
-
VISIBLE_WHITESPACE_PROPERTY
public static final String VISIBLE_WHITESPACE_PROPERTY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RSyntaxTextArea
public RSyntaxTextArea()
Constructor.
-
RSyntaxTextArea
public RSyntaxTextArea(RSyntaxDocument doc)
Constructor.- Parameters:
doc
- The document for the editor.
-
RSyntaxTextArea
public RSyntaxTextArea(String text)
Constructor.- Parameters:
text
- The initial text to display.
-
RSyntaxTextArea
public RSyntaxTextArea(int rows, int cols)
Constructor.- Parameters:
rows
- The number of rows to display.cols
- The number of columns to display.- Throws:
IllegalArgumentException
- If eitherrows
orcols
is negative.
-
RSyntaxTextArea
public RSyntaxTextArea(String text, int rows, int cols)
Constructor.- Parameters:
text
- The initial text to display.rows
- The number of rows to display.cols
- The number of columns to display.- Throws:
IllegalArgumentException
- If eitherrows
orcols
is negative.
-
RSyntaxTextArea
public RSyntaxTextArea(RSyntaxDocument doc, String text, int rows, int cols)
Constructor.- Parameters:
doc
- The document for the editor.text
- The initial text to display.rows
- The number of rows to display.cols
- The number of columns to display.- Throws:
IllegalArgumentException
- If eitherrows
orcols
is negative.
-
RSyntaxTextArea
public RSyntaxTextArea(int textMode)
Creates a newRSyntaxTextArea
.- Parameters:
textMode
- EitherINSERT_MODE
orOVERWRITE_MODE
.
-
-
Method Detail
-
addActiveLineRangeListener
public void addActiveLineRangeListener(ActiveLineRangeListener l)
Adds an "active line range" listener to this text area.- Parameters:
l
- The listener to add.- See Also:
removeActiveLineRangeListener(ActiveLineRangeListener)
-
addHyperlinkListener
public void addHyperlinkListener(HyperlinkListener l)
Adds a hyperlink listener to this text area.- Parameters:
l
- The listener to add.- See Also:
removeHyperlinkListener(HyperlinkListener)
-
addNotify
public void addNotify()
Updates the font metrics the first time we're displayed.- Overrides:
addNotify
in classRTextAreaBase
-
addParser
public void addParser(Parser parser)
Adds the parser to "validate" the source code in this text area. This can be anything from a spell checker to a "compiler" that verifies source code.- Parameters:
parser
- The new parser. A value ofnull
will do nothing.- See Also:
getParser(int)
,getParserCount()
,removeParser(Parser)
-
appendFoldingMenu
protected void appendFoldingMenu(JPopupMenu popup)
Appends a submenu with code folding options to this text component's popup menu.- Parameters:
popup
- The popup menu to append to.- See Also:
createPopupMenu()
-
clearParsers
public void clearParsers()
Removes all parsers from this text area.- See Also:
removeParser(Parser)
-
configurePopupMenu
protected void configurePopupMenu(JPopupMenu popupMenu)
Overridden to toggle the enabled state of various RSyntaxTextArea-specific menu items. If you set the popup menu viaRTextArea.setPopupMenu(JPopupMenu)
, you will want to override this method, especially if you removed any of the menu items in the default popup menu.- Overrides:
configurePopupMenu
in classRTextArea
- Parameters:
popupMenu
- The popup menu. This will never benull
.- See Also:
createPopupMenu()
,RTextArea.setPopupMenu(JPopupMenu)
-
copyAsRtf
public void copyAsRtf()
Copies the currently selected text to the system clipboard, with any necessary style information (font, foreground color and background color). Does nothing fornull
selections.
-
createDefaultModel
protected Document createDefaultModel()
Returns the document to use for anRSyntaxTextArea
- Overrides:
createDefaultModel
in classRTextArea
- Returns:
- The document.
-
createMouseListener
protected RTextAreaBase.RTAMouseListener createMouseListener()
Returns the caret event/mouse listener forRTextArea
s.- Overrides:
createMouseListener
in classRTextArea
- Returns:
- The caret event/mouse listener.
-
createPopupMenu
protected JPopupMenu createPopupMenu()
Overridden to add menu items related to cold folding.- Overrides:
createPopupMenu
in classRTextArea
- Returns:
- The popup menu.
- See Also:
appendFoldingMenu(JPopupMenu)
-
createRTextAreaUI
protected RTextAreaUI createRTextAreaUI()
Returns the a real UI to install on this text area.- Overrides:
createRTextAreaUI
in classRTextArea
- Returns:
- The UI.
-
doBracketMatching
protected final void doBracketMatching()
If the caret is on a bracket, this method finds the matching bracket, and if it exists, highlights it.
-
fireCaretUpdate
protected void fireCaretUpdate(CaretEvent e)
Notifies all listeners that a caret change has occurred.- Overrides:
fireCaretUpdate
in classRTextArea
- Parameters:
e
- The caret event.
-
foldToggled
public void foldToggled(Fold fold)
Called whenever a fold is collapsed or expanded. This causes the text editor to revalidate. This method is here because of poor design and should be removed.- Parameters:
fold
- The fold that was collapsed or expanded.
-
forceReparsing
public void forceReparsing(int parser)
Forces the givenParser
to re-parse the content of this text area.This method can be useful when a
Parser
can be configured as to what notices it returns. For example, if a Java language parser can be configured to set whether no serialVersionUID is a warning, error, or ignored, this method can be called after changing the expected notice type to have the document re-parsed.- Parameters:
parser
- The index of theParser
to re-run.- See Also:
getParser(int)
-
forceReparsing
public boolean forceReparsing(Parser parser)
Forces re-parsing with a specific parser. Note that if this parser is not installed on this text area, nothing will happen.- Parameters:
parser
- The parser that should re-parse this text area's contents. This should be installed on this text area.- Returns:
- Whether the parser was installed on this text area.
- See Also:
forceReparsing(int)
-
getAnimateBracketMatching
public boolean getAnimateBracketMatching()
Returns whether bracket matching should be animated.- Returns:
- Whether bracket matching should be animated.
- See Also:
setAnimateBracketMatching(boolean)
-
getAntiAliasingEnabled
public boolean getAntiAliasingEnabled()
Returns whether anti-aliasing is enabled in this editor.- Returns:
- Whether anti-aliasing is enabled in this editor.
- See Also:
setAntiAliasingEnabled(boolean)
,getFractionalFontMetricsEnabled()
-
getBackgroundForToken
public Color getBackgroundForToken(Token token)
Returns the background color for a token.- Parameters:
token
- The token.- Returns:
- The background color to use for that token. If this value is
is
null
then this token has no special background color. - See Also:
getForegroundForToken(Token)
-
getCloseCurlyBraces
public boolean getCloseCurlyBraces()
Returns whether curly braces should be automatically closed when a newline is entered after an opening curly brace. Note that this property is only honored for languages that use curly braces to denote code blocks.- Returns:
- Whether curly braces should be automatically closed.
- See Also:
setCloseCurlyBraces(boolean)
-
getCloseMarkupTags
public boolean getCloseMarkupTags()
Returns whether closing markup tags should be automatically completed when "</
" is typed. Note that this property is only honored for markup languages, such as HTML, XML and PHP.- Returns:
- Whether closing markup tags should be automatically completed.
- See Also:
setCloseMarkupTags(boolean)
-
getCodeTemplateManager
public static CodeTemplateManager getCodeTemplateManager()
Returns the code template manager for all instances ofRSyntaxTextArea
. The manager is lazily created.- Returns:
- The code template manager.
- See Also:
setTemplatesEnabled(boolean)
-
getDefaultBracketMatchBGColor
public static final Color getDefaultBracketMatchBGColor()
Returns the default bracket-match background color.- Returns:
- The color.
- See Also:
getDefaultBracketMatchBorderColor()
-
getDefaultBracketMatchBorderColor
public static final Color getDefaultBracketMatchBorderColor()
Returns the default bracket-match border color.- Returns:
- The color.
- See Also:
getDefaultBracketMatchBGColor()
-
getDefaultSelectionColor
public static Color getDefaultSelectionColor()
Returns the default selection color for this text area. This color was chosen because it's light andRSyntaxTextArea
does not change text color between selected/unselected text for contrast like regularJTextArea
s do.- Returns:
- The default selection color.
-
getDefaultSyntaxScheme
public SyntaxScheme getDefaultSyntaxScheme()
Returns the "default" syntax highlighting color scheme. The colors used are somewhat standard among syntax highlighting text editors.- Returns:
- The default syntax highlighting color scheme.
- See Also:
restoreDefaultSyntaxScheme()
,getSyntaxScheme()
,setSyntaxScheme(SyntaxScheme)
-
getEOLMarkersVisible
public boolean getEOLMarkersVisible()
Returns whether an EOL marker should be drawn at the end of each line.- Returns:
- Whether EOL markers should be visible.
- See Also:
setEOLMarkersVisible(boolean)
,isWhitespaceVisible()
-
getFoldManager
public FoldManager getFoldManager()
Returns the fold manager for this text area.- Returns:
- The fold manager.
-
getFontForTokenType
public Font getFontForTokenType(int type)
Returns the font for tokens of the specified type.- Parameters:
type
- The type of token.- Returns:
- The font to use for that token type.
- See Also:
getFontMetricsForTokenType(int)
-
getFontMetricsForTokenType
public FontMetrics getFontMetricsForTokenType(int type)
Returns the font metrics for tokens of the specified type.- Parameters:
type
- The type of token.- Returns:
- The font metrics to use for that token type.
- See Also:
getFontForTokenType(int)
-
getForegroundForToken
public Color getForegroundForToken(Token t)
Returns the foreground color to use when painting a token.- Parameters:
t
- The token.- Returns:
- The foreground color to use for that token. This
value is never
null
. - See Also:
getBackgroundForToken(Token)
-
getForegroundForTokenType
public Color getForegroundForTokenType(int type)
Returns the foreground color to use when painting a token. This does not take into account whether the token is a hyperlink.- Parameters:
type
- The token type.- Returns:
- The foreground color to use for that token. This
value is never
null
. - See Also:
getForegroundForToken(Token)
-
getFractionalFontMetricsEnabled
public boolean getFractionalFontMetricsEnabled()
Returns whether fractional font metrics are enabled for this text area.- Returns:
- Whether fractional font metrics are enabled.
- See Also:
setFractionalFontMetricsEnabled(boolean)
,getAntiAliasingEnabled()
-
getHighlightSecondaryLanguages
public boolean getHighlightSecondaryLanguages()
Returns whether "secondary" languages should have their backgrounds colored differently to visually differentiate them. This feature imposes a fair performance penalty.- Returns:
- Whether secondary languages have their backgrounds colored differently.
- See Also:
setHighlightSecondaryLanguages(boolean)
,getSecondaryLanguageBackground(int)
,getSecondaryLanguageCount()
,setSecondaryLanguageBackground(int, Color)
-
getHyperlinkForeground
public Color getHyperlinkForeground()
Returns the color to use when painting hyperlinks.- Returns:
- The color to use when painting hyperlinks.
- See Also:
setHyperlinkForeground(Color)
,getHyperlinksEnabled()
-
getHyperlinksEnabled
public boolean getHyperlinksEnabled()
Returns whether hyperlinks are enabled for this text area.- Returns:
- Whether hyperlinks are enabled for this text area.
- See Also:
setHyperlinksEnabled(boolean)
-
getLastVisibleOffset
public int getLastVisibleOffset()
Returns the last visible offset in this text area. This may not be the length of the document if code folding is enabled.- Returns:
- The last visible offset in this text area.
-
getLineHeight
public int getLineHeight()
Returns the height to use for a line of text in this text area.- Overrides:
getLineHeight
in classRTextAreaBase
- Returns:
- The height of a line of text in this text area.
-
getLinkGenerator
public LinkGenerator getLinkGenerator()
-
getMarkAllHighlightRanges
public List<DocumentRange> getMarkAllHighlightRanges()
Returns a list of "mark all" highlights in the text area. If there are no such highlights, this will be an empty list.- Returns:
- The list of "mark all" highlight ranges.
-
getMarkedOccurrences
public List<DocumentRange> getMarkedOccurrences()
Returns a list of "marked occurrences" in the text area. If there are no marked occurrences, this will be an empty list.- Returns:
- The list of marked occurrences.
-
getMarkOccurrences
public boolean getMarkOccurrences()
Returns whether "Mark Occurrences" is enabled.- Returns:
- Whether "Mark Occurrences" is enabled.
- See Also:
setMarkOccurrences(boolean)
-
getMarkOccurrencesColor
public Color getMarkOccurrencesColor()
Returns the color used to "mark occurrences."- Returns:
- The mark occurrences color.
- See Also:
setMarkOccurrencesColor(Color)
-
getMatchedBracketBGColor
public Color getMatchedBracketBGColor()
Gets the color used as the background for a matched bracket.- Returns:
- The color used. If this is
null
, no special background is painted behind a matched bracket. - See Also:
setMatchedBracketBGColor(java.awt.Color)
,getMatchedBracketBorderColor()
-
getMatchedBracketBorderColor
public Color getMatchedBracketBorderColor()
Gets the color used as the border for a matched bracket.- Returns:
- The color used.
- See Also:
setMatchedBracketBorderColor(java.awt.Color)
,getMatchedBracketBGColor()
-
getMaxAscent
public int getMaxAscent()
Overridden to return the max ascent for any font used in the editor.- Overrides:
getMaxAscent
in classRTextArea
- Returns:
- The max ascent value.
-
getPaintMatchedBracketPair
public boolean getPaintMatchedBracketPair()
Returns whether the bracket at the caret position is painted as a "match" when a matched bracket is found. Note that this property does nothing ifisBracketMatchingEnabled()
returnsfalse
.- Returns:
- Whether both brackets in a bracket pair are highlighted when bracket matching is enabled.
- See Also:
setPaintMatchedBracketPair(boolean)
,isBracketMatchingEnabled()
,setBracketMatchingEnabled(boolean)
-
getPaintTabLines
public boolean getPaintTabLines()
Returns whether tab lines are painted.- Returns:
- Whether tab lines are painted.
- See Also:
setPaintTabLines(boolean)
,getTabLineColor()
-
getParser
public Parser getParser(int index)
Returns the specified parser.- Parameters:
index
- TheParser
to retrieve.- Returns:
- The
Parser
. - See Also:
getParserCount()
,addParser(Parser)
-
getParserCount
public int getParserCount()
Returns the number of parsers operating on this text area.- Returns:
- The parser count.
- See Also:
addParser(Parser)
-
getParserDelay
public int getParserDelay()
Returns the currently set parser delay. This is the delay that must occur between edits for any registeredParser
s to run.- Returns:
- The currently set parser delay, in milliseconds.
- See Also:
setParserDelay(int)
-
getParserNotices
public List<ParserNotice> getParserNotices()
Returns a list of the current parser notices for this text area. This method (like most Swing methods) should only be called on the EDT.- Returns:
- The list of notices. This will be an empty list if there are none.
-
getRightHandSideCorrection
public int getRightHandSideCorrection()
Workaround for JTextComponents allowing the caret to be rendered entirely off-screen if the entire "previous" character fit entirely.- Returns:
- The amount of space to add to the x-axis preferred span.
- See Also:
setRightHandSideCorrection(int)
-
getShouldIndentNextLine
public boolean getShouldIndentNextLine(int line)
If auto-indent is enabled, this method returns whether a new line after this one should be indented (based on the standard indentation rules for the current programming language). For example, in Java, for a line containing:for (int i=0; i<10; i++) {
the following line should be indented.- Parameters:
line
- The line to check.- Returns:
- Whether a line inserted after this one should be auto-indented.
If auto-indentation is disabled, this will always return
false
. - See Also:
isAutoIndentEnabled()
-
getSyntaxEditingStyle
public String getSyntaxEditingStyle()
Returns what type of syntax highlighting this editor is doing.- Returns:
- The style being used, such as
SyntaxConstants.SYNTAX_STYLE_JAVA
. - See Also:
setSyntaxEditingStyle(String)
,SyntaxConstants
-
getSyntaxScheme
public SyntaxScheme getSyntaxScheme()
Returns all of the colors currently being used in syntax highlighting by this text component.- Returns:
- An instance of
SyntaxScheme
that represents the colors currently being used for syntax highlighting. - See Also:
setSyntaxScheme(SyntaxScheme)
-
getTabLineColor
public Color getTabLineColor()
Returns the color used to paint tab lines.- Returns:
- The color used to paint tab lines.
- See Also:
setTabLineColor(Color)
,getPaintTabLines()
,setPaintTabLines(boolean)
-
getPaintMarkOccurrencesBorder
public boolean getPaintMarkOccurrencesBorder()
Returns whether a border is painted around marked occurrences.- Returns:
- Whether a border is painted.
- See Also:
setPaintMarkOccurrencesBorder(boolean)
,getMarkOccurrencesColor()
,getMarkOccurrences()
-
getSecondaryLanguageBackground
public Color getSecondaryLanguageBackground(int index)
Returns the background color for the specified secondary language.- Parameters:
index
- The language index. Note that these are 1-based, not 0-based, and should be in the range1-getSecondaryLanguageCount()
, inclusive.- Returns:
- The color, or
null
if none. - See Also:
getSecondaryLanguageCount()
,setSecondaryLanguageBackground(int, Color)
,getHighlightSecondaryLanguages()
-
getSecondaryLanguageCount
public int getSecondaryLanguageCount()
Returns the number of secondary language backgrounds.- Returns:
- The number of secondary language backgrounds.
- See Also:
getSecondaryLanguageBackground(int)
,setSecondaryLanguageBackground(int, Color)
,getHighlightSecondaryLanguages()
-
getTemplatesEnabled
public static boolean getTemplatesEnabled()
Returns whether or not templates are enabled for all instances ofRSyntaxTextArea
.For more flexible boilerplate code insertion, consider using the TemplateCompletion class in the AutoComplete add-on library.
- Returns:
- Whether templates are enabled.
- See Also:
saveTemplates()
,setTemplateDirectory(String)
,setTemplatesEnabled(boolean)
-
getTokenListForLine
public Token getTokenListForLine(int line)
Returns a list of tokens representing the given line.- Parameters:
line
- The line number to get tokens for.- Returns:
- A linked list of tokens representing the line's text.
-
getToolTipText
public String getToolTipText(MouseEvent e)
Returns the tool tip to display for a mouse event at the given location. This method is overridden to give a registered parser a chance to display a tool tip (such as an error description when the mouse is over an error highlight).- Overrides:
getToolTipText
in classRTextArea
- Parameters:
e
- The mouse event.- Returns:
- The tool tip text, or
null
if none. - See Also:
RTextArea.getToolTipSupplier()
,RTextArea.setToolTipSupplier(ToolTipSupplier)
-
getToolTipTextImpl
protected String getToolTipTextImpl(MouseEvent e)
Does the dirty work of getting the tool tip text.- Parameters:
e
- The mouse event.- Returns:
- The tool tip text.
-
getUnderlineForToken
public boolean getUnderlineForToken(Token t)
Returns whether the specified token should be underlined. A token is underlined if its syntax style includes underlining, or if it is a hyperlink and hyperlinks are enabled.- Parameters:
t
- The token.- Returns:
- Whether the specified token should be underlined.
-
getUseFocusableTips
public boolean getUseFocusableTips()
Returns whether "focusable" tool tips are used instead of standard ones. Focusable tool tips are tool tips that the user can click on, resize, copy from, and click links in.- Returns:
- Whether to use focusable tool tips.
- See Also:
setUseFocusableTips(boolean)
,FocusableTip
-
getUseSelectedTextColor
public boolean getUseSelectedTextColor()
Returns whether selected text should use the "selected text color" property set viaJTextComponent.setSelectedTextColor(Color)
. This is the typical behavior of text components. By default, RSyntaxTextArea does not do this, so that token styles are visible even in selected regions of text.- Returns:
- Whether the "selected text" color is used when painting text in selected regions.
- See Also:
setUseSelectedTextColor(boolean)
-
init
protected void init()
Called by constructors to initialize common properties of the text editor.
-
isAutoIndentEnabled
public boolean isAutoIndentEnabled()
Returns whether or not auto-indent is enabled.- Returns:
- Whether or not auto-indent is enabled.
- See Also:
setAutoIndentEnabled(boolean)
-
isBracketMatchingEnabled
public final boolean isBracketMatchingEnabled()
Returns whether or not bracket matching is enabled.- Returns:
true
iff bracket matching is enabled.- See Also:
setBracketMatchingEnabled(boolean)
-
isClearWhitespaceLinesEnabled
public boolean isClearWhitespaceLinesEnabled()
Returns whether or not lines containing nothing but whitespace are made into blank lines when Enter is pressed in them.- Returns:
- Whether or not whitespace-only lines are cleared when the user presses Enter on them.
- See Also:
setClearWhitespaceLinesEnabled(boolean)
-
isCodeFoldingEnabled
public boolean isCodeFoldingEnabled()
Returns whether code folding is enabled. Note that only certain languages support code folding; those that do not will ignore this property.- Returns:
- Whether code folding is enabled.
- See Also:
setCodeFoldingEnabled(boolean)
-
isWhitespaceVisible
public boolean isWhitespaceVisible()
Returns whether whitespace (spaces and tabs) is visible.- Returns:
- Whether whitespace is visible.
- See Also:
setWhitespaceVisible(boolean)
,getEOLMarkersVisible()
-
modelToToken
public Token modelToToken(int offs)
Returns the token at the specified position in the model.- Parameters:
offs
- The position in the model.- Returns:
- The token, or
null
if no token is at that position. - See Also:
viewToToken(Point)
-
paintComponent
protected void paintComponent(Graphics g)
ThepaintComponent
method is overridden so we apply any necessary rendering hints to the Graphics object.- Overrides:
paintComponent
in classRTextAreaBase
- Parameters:
g
- The graphics context with which to paint.
-
redoLastAction
public void redoLastAction()
Attempt to redo the last action.- Overrides:
redoLastAction
in classRTextArea
- See Also:
RTextArea.undoLastAction()
-
removeActiveLineRangeListener
public void removeActiveLineRangeListener(ActiveLineRangeListener l)
Removes an "active line range" listener from this text area.- Parameters:
l
- The listener to remove.- See Also:
removeActiveLineRangeListener(ActiveLineRangeListener)
-
removeHyperlinkListener
public void removeHyperlinkListener(HyperlinkListener l)
Removes a hyperlink listener from this text area.- Parameters:
l
- The listener to remove.- See Also:
addHyperlinkListener(HyperlinkListener)
-
removeNotify
public void removeNotify()
Overridden so we stop this text area's parsers, if any.- Overrides:
removeNotify
in classJTextComponent
-
removeParser
public boolean removeParser(Parser parser)
Removes a parser from this text area.- Parameters:
parser
- TheParser
to remove.- Returns:
- Whether the parser was found and removed.
- See Also:
clearParsers()
,addParser(Parser)
,getParser(int)
-
restoreDefaultSyntaxScheme
public void restoreDefaultSyntaxScheme()
Sets the colors used for syntax highlighting to their defaults.
-
saveTemplates
public static boolean saveTemplates()
Attempts to save all currently-known templates to the current template directory, as set bysetTemplateDirectory
. Templates will be saved as XML files with names equal to their abbreviations; for example, a template that expands on the word "forb" will be saved asforb.xml
.- Returns:
- Whether or not the save was successful. The save will
be unsuccessful if the template directory does not exist or
if it has not been set (i.e., you have not yet called
setTemplateDirectory
). - See Also:
getTemplatesEnabled()
,setTemplateDirectory(java.lang.String)
,setTemplatesEnabled(boolean)
-
setActiveLineRange
public void setActiveLineRange(int min, int max)
Sets the "active line range." Note that thisRSyntaxTextArea
itself does nothing with this information, but if it is contained inside anRTextScrollPane
, the active line range may be displayed in the icon area of theGutter
.Note that basic users of
RSyntaxTextArea
will not call this method directly; rather, it is usually called by instances ofLanguageSupport
in theRSTALangaugeSupport
library. See http://fifesoft.com for more information about this library.- Parameters:
min
- The "minimum" line in the active line range, or-1
if the range is being cleared.max
- The "maximum" line in the active line range, or-1
if the range is being cleared.- See Also:
addActiveLineRangeListener(ActiveLineRangeListener)
-
setAnimateBracketMatching
public void setAnimateBracketMatching(boolean animate)
Sets whether bracket matching should be animated. This fires a property change event of typeANIMATE_BRACKET_MATCHING_PROPERTY
.- Parameters:
animate
- Whether to animate bracket matching.- See Also:
getAnimateBracketMatching()
-
setAntiAliasingEnabled
public void setAntiAliasingEnabled(boolean enabled)
Sets whether anti-aliasing is enabled in this editor. This method fires a property change event of typeANTIALIAS_PROPERTY
.- Parameters:
enabled
- Whether anti-aliasing is enabled.- See Also:
getAntiAliasingEnabled()
-
setAutoIndentEnabled
public void setAutoIndentEnabled(boolean enabled)
Sets whether or not auto-indent is enabled. This fires a property change event of typeAUTO_INDENT_PROPERTY
.- Parameters:
enabled
- Whether or not auto-indent is enabled.- See Also:
isAutoIndentEnabled()
-
setBracketMatchingEnabled
public void setBracketMatchingEnabled(boolean enabled)
Sets whether bracket matching is enabled. This fires a property change event of typeBRACKET_MATCHING_PROPERTY
.- Parameters:
enabled
- Whether or not bracket matching should be enabled.- See Also:
isBracketMatchingEnabled()
-
setClearWhitespaceLinesEnabled
public void setClearWhitespaceLinesEnabled(boolean enabled)
Sets whether or not lines containing nothing but whitespace are made into blank lines when Enter is pressed in them. This method fires a property change event of typeCLEAR_WHITESPACE_LINES_PROPERTY
.- Parameters:
enabled
- Whether or not whitespace-only lines are cleared when the user presses Enter on them.- See Also:
isClearWhitespaceLinesEnabled()
-
setCloseCurlyBraces
public void setCloseCurlyBraces(boolean close)
Toggles whether curly braces should be automatically closed when a newline is entered after an opening curly brace. Note that this property is only honored for languages that use curly braces to denote code blocks.This method fires a property change event of type
CLOSE_CURLY_BRACES_PROPERTY
.- Parameters:
close
- Whether curly braces should be automatically closed.- See Also:
getCloseCurlyBraces()
-
setCloseMarkupTags
public void setCloseMarkupTags(boolean close)
Sets whether closing markup tags should be automatically completed when "</
" is typed. Note that this property is only honored for markup languages, such as HTML, XML and PHP.This method fires a property change event of type
CLOSE_MARKUP_TAGS_PROPERTY
.- Parameters:
close
- Whether closing markup tags should be automatically completed.- See Also:
getCloseMarkupTags()
-
setCodeFoldingEnabled
public void setCodeFoldingEnabled(boolean enabled)
Sets whether code folding is enabled. Note that only certain languages will support code folding out of the box. Those languages which do not support folding will ignore this property.This method fires a property change event of type
CODE_FOLDING_PROPERTY
.- Parameters:
enabled
- Whether code folding should be enabled.- See Also:
isCodeFoldingEnabled()
-
setDocument
public void setDocument(Document document)
Sets the document used by this text area. This is overridden so that only instances ofRSyntaxDocument
are accepted; for all others, an exception will be thrown.- Overrides:
setDocument
in classRTextArea
- Parameters:
document
- The new document for this text area.- Throws:
IllegalArgumentException
- If the document is not anRSyntaxDocument
.
-
setEOLMarkersVisible
public void setEOLMarkersVisible(boolean visible)
Sets whether EOL markers are visible at the end of each line. This method fires a property change of typeEOL_VISIBLE_PROPERTY
.- Parameters:
visible
- Whether EOL markers are visible.- See Also:
getEOLMarkersVisible()
,setWhitespaceVisible(boolean)
-
setFont
public void setFont(Font font)
Sets the font used by this text area. Note that if some token styles are using a different font, they will not be changed by calling this method. To set different fonts on individual token types, use the text area'sSyntaxScheme
.- Overrides:
setFont
in classRTextAreaBase
- Parameters:
font
- The font.- See Also:
SyntaxScheme.getStyle(int)
-
setFractionalFontMetricsEnabled
public void setFractionalFontMetricsEnabled(boolean enabled)
Sets whether fractional font metrics are enabled. This method fires a property change event of typeFRACTIONAL_FONTMETRICS_PROPERTY
.- Parameters:
enabled
- Whether fractional font metrics are enabled.- See Also:
getFractionalFontMetricsEnabled()
-
setHighlighter
public void setHighlighter(Highlighter h)
Sets the highlighter used by this text area.- Overrides:
setHighlighter
in classJTextComponent
- Parameters:
h
- The highlighter.- Throws:
IllegalArgumentException
- Ifh
is not an instance ofRSyntaxTextAreaHighlighter
.
-
setHighlightSecondaryLanguages
public void setHighlightSecondaryLanguages(boolean highlight)
Sets whether "secondary" languages should have their backgrounds colored differently to visually differentiate them. This feature imposes a fair performance penalty. This method fires a property change event of typeHIGHLIGHT_SECONDARY_LANGUAGES_PROPERTY
.
-
setHyperlinkForeground
public void setHyperlinkForeground(Color fg)
Sets the color to use when painting hyperlinks.- Parameters:
fg
- The color to use when painting hyperlinks.- Throws:
NullPointerException
- Iffg
isnull
.- See Also:
getHyperlinkForeground()
,setHyperlinksEnabled(boolean)
-
setHyperlinksEnabled
public void setHyperlinksEnabled(boolean enabled)
Sets whether hyperlinks are enabled for this text area. This method fires a property change event of typeHYPERLINKS_ENABLED_PROPERTY
.- Parameters:
enabled
- Whether hyperlinks are enabled.- See Also:
getHyperlinksEnabled()
-
setLinkGenerator
public void setLinkGenerator(LinkGenerator generator)
-
setLinkScanningMask
public void setLinkScanningMask(int mask)
Sets the mask for the key used to toggle whether we are scanning for hyperlinks with mouse hovering. The default value isCTRL_DOWN_MASK
.- Parameters:
mask
- The mask to use. This should be some bitwise combination ofInputEvent.CTRL_DOWN_MASK
,InputEvent.ALT_DOWN_MASK
,InputEvent.SHIFT_DOWN_MASK
orInputEvent.META_DOWN_MASK
. For invalid values, behavior is undefined.- See Also:
InputEvent
-
setMarkOccurrences
public void setMarkOccurrences(boolean markOccurrences)
Toggles whether "mark occurrences" is enabled. This method fires a property change event of typeMARK_OCCURRENCES_PROPERTY
.- Parameters:
markOccurrences
- Whether "Mark Occurrences" should be enabled.- See Also:
getMarkOccurrences()
,setMarkOccurrencesColor(Color)
-
setMarkOccurrencesColor
public void setMarkOccurrencesColor(Color color)
Sets the "mark occurrences" color.- Parameters:
color
- The new color. This cannot benull
.- See Also:
getMarkOccurrencesColor()
,setMarkOccurrences(boolean)
-
setMatchedBracketBGColor
public void setMatchedBracketBGColor(Color color)
Sets the color used as the background for a matched bracket.- Parameters:
color
- The color to use. If this isnull
, then no special background is painted behind a matched bracket.- See Also:
getMatchedBracketBGColor()
,setMatchedBracketBorderColor(java.awt.Color)
,setPaintMarkOccurrencesBorder(boolean)
-
setMatchedBracketBorderColor
public void setMatchedBracketBorderColor(Color color)
Sets the color used as the border for a matched bracket.- Parameters:
color
- The color to use.- See Also:
getMatchedBracketBorderColor()
,setMatchedBracketBGColor(java.awt.Color)
-
setPaintMarkOccurrencesBorder
public void setPaintMarkOccurrencesBorder(boolean paintBorder)
Toggles whether a border should be painted around marked occurrences.- Parameters:
paintBorder
- Whether to paint a border.- See Also:
getPaintMarkOccurrencesBorder()
,setMarkOccurrencesColor(Color)
,setMarkOccurrences(boolean)
-
setPaintMatchedBracketPair
public void setPaintMatchedBracketPair(boolean paintPair)
Sets whether the bracket at the caret position is painted as a "match" when a matched bracket is found. Note that this property does nothing ifisBracketMatchingEnabled()
returnsfalse
.This method fires a property change event of type
PAINT_MATCHED_BRACKET_PAIR_PROPERTY
.- Parameters:
paintPair
- Whether both brackets in a bracket pair should be highlighted when bracket matching is enabled.- See Also:
getPaintMatchedBracketPair()
,isBracketMatchingEnabled()
,setBracketMatchingEnabled(boolean)
-
setPaintTabLines
public void setPaintTabLines(boolean paint)
Toggles whether tab lines are painted. This method fires a property change event of typeTAB_LINES_PROPERTY
.- Parameters:
paint
- Whether tab lines are painted.- See Also:
getPaintTabLines()
,setTabLineColor(Color)
-
setParserDelay
public void setParserDelay(int millis)
Sets the parser delay. This is the delay that must occur between edits for any registeredParser
s to run.- Parameters:
millis
- The new parser delay, in milliseconds. This must be greater than zero.- See Also:
getParserDelay()
-
setRightHandSideCorrection
public void setRightHandSideCorrection(int rhsCorrection)
Applications typically have no need to modify this value.Workaround for JTextComponents allowing the caret to be rendered entirely off-screen if the entire "previous" character fit entirely.
- Parameters:
rhsCorrection
- The amount of space to add to the x-axis preferred span. This should be non-negative.- See Also:
getRightHandSideCorrection()
-
setSecondaryLanguageBackground
public void setSecondaryLanguageBackground(int index, Color color)
Sets the background color to use for a secondary language.- Parameters:
index
- The language index. Note that these are 1-based, not 0-based, and should be in the range1-getSecondaryLanguageCount()
, inclusive.color
- The new color, ornull
for none.- See Also:
getSecondaryLanguageBackground(int)
,getSecondaryLanguageCount()
-
setSyntaxEditingStyle
public void setSyntaxEditingStyle(String styleKey)
Sets what type of syntax highlighting this editor is doing. This method fires a property change of typeSYNTAX_STYLE_PROPERTY
.- Parameters:
styleKey
- The syntax editing style to use, for example,SyntaxConstants.SYNTAX_STYLE_NONE
orSyntaxConstants.SYNTAX_STYLE_JAVA
.- See Also:
getSyntaxEditingStyle()
,SyntaxConstants
-
setSyntaxScheme
public void setSyntaxScheme(SyntaxScheme scheme)
Sets all of the colors used in syntax highlighting to the colors specified. This uses a shallow copy of the color scheme so that multiple text areas can share the same color scheme and have their properties changed simultaneously.This method fires a property change event of type
SYNTAX_SCHEME_PROPERTY
.- Parameters:
scheme
- The instance ofSyntaxScheme
to use.- See Also:
getSyntaxScheme()
-
setTemplateDirectory
public static boolean setTemplateDirectory(String dir)
If templates are enabled, all currently-known templates are forgotten and all templates are loaded from all files in the specified directory ending in "*.xml". If templates aren't enabled, nothing happens.- Parameters:
dir
- The directory containing files ending in extension.xml
that contain templates to load.- Returns:
true
if the load was successful;false
if either templates aren't currently enabled or the load failed somehow (most likely, the directory doesn't exist).- See Also:
getTemplatesEnabled()
,setTemplatesEnabled(boolean)
,saveTemplates()
-
setTemplatesEnabled
public static void setTemplatesEnabled(boolean enabled)
Enables or disables templates.Templates are a set of "shorthand identifiers" that you can configure so that you only have to type a short identifier (such as "forb") to insert a larger amount of code into the document (such as:
for (<caret>) { }
Templates are a shared resource among all instances ofRSyntaxTextArea
; that is, templates can only be enabled/disabled for all text areas globally, not individually, and all text areas have access of the same templates. This should not be an issue; rather, it should be beneficial as it promotes uniformity among all text areas in an application.For more flexible boilerplate code insertion, consider using the TemplateCompletion class in the AutoComplete add-on library.
- Parameters:
enabled
- Whether or not templates should be enabled.- See Also:
getTemplatesEnabled()
-
setTabLineColor
public void setTabLineColor(Color c)
Sets the color use to paint tab lines. This method fires a property change event of typeTAB_LINE_COLOR_PROPERTY
.- Parameters:
c
- The color. If this value isnull
, the default (gray) is used.- See Also:
getTabLineColor()
,setPaintTabLines(boolean)
,getPaintTabLines()
-
setUseFocusableTips
public void setUseFocusableTips(boolean use)
Sets whether "focusable" tool tips are used instead of standard ones. Focusable tool tips are tool tips that the user can click on, resize, copy from, and clink links in. This method fires a property change event of typeFOCUSABLE_TIPS_PROPERTY
.- Parameters:
use
- Whether to use focusable tool tips.- See Also:
getUseFocusableTips()
,FocusableTip
-
setUseSelectedTextColor
public void setUseSelectedTextColor(boolean use)
Sets whether selected text should use the "selected text color" property (set viaJTextComponent.setSelectedTextColor(Color)
). This is the typical behavior of text components. By default, RSyntaxTextArea does not do this, so that token styles are visible even in selected regions of text. This method fires a property change event of typeUSE_SELECTED_TEXT_COLOR_PROPERTY
.- Parameters:
use
- Whether to use the "selected text" color when painting text in selected regions.- See Also:
getUseSelectedTextColor()
-
setWhitespaceVisible
public void setWhitespaceVisible(boolean visible)
Sets whether whitespace is visible. This method fires a property change of typeVISIBLE_WHITESPACE_PROPERTY
.- Parameters:
visible
- Whether whitespace should be visible.- See Also:
isWhitespaceVisible()
-
undoLastAction
public void undoLastAction()
Attempt to undo an "action" done in this text area.- Overrides:
undoLastAction
in classRTextArea
- See Also:
RTextArea.redoLastAction()
-
viewToToken
public Token viewToToken(Point p)
Returns the token at the specified position in the view.- Parameters:
p
- The position in the view.- Returns:
- The token, or
null
if no token is at that position. - See Also:
modelToToken(int)
-
-