Class RSyntaxTextArea
- All Implemented Interfaces:
ImageObserver, MenuContainer, Printable, Serializable, Accessible, Scrollable, SyntaxConstants
- Direct Known Subclasses:
TextEditorPane
RTextArea that adds syntax highlighting
of certain programming languages to its list of features. Languages
currently supported include:
|
|
- 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 regular
JScrollPane as this class allows you to add line numbers and
bookmarks easily to your text area.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classA timer that animates the "bracket matching" animation.private final classRenders the text on the line containing the "matched bracket" after a delay.private classHandles hyperlinks.Nested classes/interfaces inherited from class RTextArea
RTextArea.RTextAreaMutableCaretEventNested classes/interfaces inherited from class RTextAreaBase
RTextAreaBase.RTAMouseListenerNested classes/interfaces inherited from class JTextArea
JTextArea.AccessibleJTextAreaNested classes/interfaces inherited from class JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map<?, ?> Cached desktop anti-aliasing hints, if anti-aliasing is enabled.static final Stringprivate booleanWhether bracket matching is animated.static final Stringstatic final Stringprivate booleanWhether auto-indent is on.static final Stringprivate PointUsed to store the location of the bracket at the caret position (either just before or just after it) and the location of its match.private booleanWhether bracket matching is enabled.private Stringprivate PointUsed to work around an issue with Apple JVMs.static final Stringprivate booleanWhether lines with nothing but whitespace are "made empty".static final Stringstatic final Stringprivate booleanWhether curly braces should be closed on Enter key presses, (if the current language supports it).private booleanWhether closing markup tags should be automatically completed when "</" is typed (if the current language is a markup language).static final Stringprivate static CodeTemplateManagerHandles code templates.private static RecordableTextActionprivate static RecordableTextActionprivate static final Colorprivate static final Colorprivate static final Colorprivate FontMetricsMetrics of the text area's font.private RectangleThe rectangle surrounding the current offset if both bracket matching and "match both brackets" are enabled.static final Stringprivate booleanWhether EOL markers should be visible at the end of each line.private static RecordableTextActionstatic final Stringprivate FocusableTipThe last focusable tip displayed.private JMenuprivate FoldManagerstatic final Stringprivate booleanstatic final Stringprivate booleanWhether secondary languages have their backgrounds colored.private intprivate ColorThe color to use when painting hyperlinks.static final Stringprivate booleanWhether hyperlinks are enabled (must be supported by the syntax scheme being used).static final Stringprivate booleanprivate booleanWhether the editor is currently scanning for hyperlinks on mouse movement.private intThe location of the last matched bracket.private intprivate LinkGeneratorprivate LinkGeneratorResultprivate intMask used to determine if the correct key is being held down to scan for hyperlinks (ctrl, meta, etc.).static final Stringstatic final Stringprivate ColorThe color used to render "marked occurrences".private intThe delay before occurrences are marked in the editor.private MarkOccurrencesSupportHandles "mark occurrences" support.private RectangleThe rectangle surrounding the "matched bracket" if bracket matching is enabled.private ColorColors used for the "matched bracket" if bracket matching is enabled.private Colorprivate intprivate booleanprivate static final Stringstatic final Stringprivate booleanWhether a border should be painted around marked occurrences.private booleanWhether both brackets are highlighted when bracket matching.private booleanWhether tab lines are enabled.static final Stringprivate ParserManagerManages running the parser.private intprivate Color[]private booleanWhether a popup showing matched bracket lines when they're off-screen.static final Stringstatic final Stringprivate SyntaxSchemeThe colors used for syntax highlighting.private StringThe key for the syntax style to be highlighting.static final Stringstatic final Stringprivate ColorThe color to use when painting tab lines.private static booleanWhether templates are enabled.private static RecordableTextActionprivate TokenPainterRenders tokens.static final Stringprivate booleanWhether "focusable" tool tips are used instead of standard ones.private booleanWhether the "selected text" color should be used with selected text.static final Stringprivate booleanWhether we are displaying visible whitespace (spaces and tabs).Fields inherited from class 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_ACTIONFields inherited from class RTextAreaBase
BACKGROUND_IMAGE_PROPERTY, CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY, CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY, HIGHLIGHT_CURRENT_LINE_PROPERTY, ROUNDED_SELECTION_PROPERTYFields inherited from class JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface Printable
NO_SUCH_PAGE, PAGE_EXISTSFields inherited from interface 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.RSyntaxTextArea(int textMode) Creates a newRSyntaxTextArea.RSyntaxTextArea(int rows, int cols) Constructor.RSyntaxTextArea(String text) Constructor.RSyntaxTextArea(String text, int rows, int cols) Constructor.Constructor.RSyntaxTextArea(RSyntaxDocument doc, String text, int rows, int cols) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an "active line range" listener to this text area.voidAdds a hyperlink listener to this text area.voidUpdates the font metrics the first time we're displayed.voidAdds the parser to "validate" the source code in this text area.protected voidappendFoldingMenu(JPopupMenu popup) Appends a submenu with code folding options to this text component's popup menu.private voidRecalculates the height of a line in this text area and the maximum ascent of all fonts displayed.voidRemoves all parsers from this text area.private TokenImplClones a token list.protected voidconfigurePopupMenu(JPopupMenu popupMenu) Overridden to toggle the enabled state of various RSyntaxTextArea-specific menu items.private static voidvoidCopies the currently selected text to the system clipboard, with any necessary style information (font, foreground color and background color).voidcopyAsStyledText(Theme theme) Copies the currently selected text to the system clipboard, with style information from the specified theme.protected DocumentReturns the document to use for anRSyntaxTextArea.private HyperlinkEventprotected RTextAreaBase.RTAMouseListenerReturns the caret event/mouse listener forRTextAreas.protected JPopupMenuOverridden to add menu items related to cold folding.private static voidSee createPopupMenuActions() in RTextArea.protected RTextAreaUIReturns a real UI to install on this text area.protected final voidIf the caret is on a bracket, this method finds the matching bracket, and if it exists, highlights it.private voidfireActiveLineRangeEvent(int min, int max) Notifies all listeners that the active line range has changed.protected voidNotifies all listeners that a caret change has occurred.protected voidNotifies all listeners that have registered interest in notification on this event type.(package private) voidNotifies listeners that the marked occurrences for this text area have changed.(package private) voidFires a notification that the parser notices for this text area have changed.voidfoldToggled(Fold fold) Called whenever a fold is collapsed or expanded.voidforceReparsing(int parser) Forces the givenParserto reparse the content of this text area.booleanforceReparsing(Parser parser) Forces reparsing with a specific parser.booleanReturns whether bracket matching should be animated.booleanReturns whether anti-aliasing is enabled in this editor.getBackgroundForToken(Token token) Returns the background color for a token.booleanReturns whether curly braces should be automatically closed when a newline is entered after an opening curly brace.booleanReturns whether closing markup tags should be automatically completed when "</" is typed.static CodeTemplateManagerReturns the code template manager for all instances ofRSyntaxTextArea.static ColorReturns the default bracket-match background color.static ColorReturns the default bracket-match border color.static ColorReturns the default selection color for this text area.Returns the "default" syntax highlighting color scheme.(package private) RectangleReturns the caret's offset's rectangle, ornullif there is currently no matched bracket, bracket matching is disabled, or "paint both matched brackets" is disabled.booleanReturns whether an EOL marker should be drawn at the end of each line.Returns the fold manager for this text area.getFontForTokenType(int type) Returns the font for tokens of the specified type.getFontMetricsForTokenType(int type) Returns the font metrics for tokens of the specified type.Returns the foreground color to use when painting a token.getForegroundForTokenType(int type) Returns the foreground color to use when painting a token.booleanReturns whether fractional font metrics are enabled for this text area.private Graphics2DReturns aGraphics2Dversion of the specified graphics that has been initialized with the proper rendering hints.booleanReturns whether "secondary" languages should have their backgrounds colored differently to visually differentiate them.Returns the color to use when painting hyperlinks.booleanReturns whether hyperlinks are enabled for this text area.booleanReturns whether paired characters should be inserted when there is a selection.intReturns the last visible offset in this text area.intReturns the height to use for a line of text in this text area.Returns a list of "mark all" highlights in the text area.Returns a list of "marked occurrences" in the text area.booleanReturns whether "Mark Occurrences" is enabled.Returns the color used for "mark occurrences" highlights.intReturns the delay between when the caret is moved and when "marked occurrences" are highlighted.(package private) booleangetMarkOccurrencesOfTokenType(int type) Returns whether tokens of the specified type should have "mark occurrences" enabled for the current programming language.Gets the color used as the background for a matched bracket.Gets the color used as the border for a matched bracket.(package private) RectangleReturns the matched bracket's rectangle, ornullif there is currently no matched bracket.intOverridden to return the max ascent for any font used in the editor.booleanReturns whether a border is painted around marked occurrences.booleanReturns whether the bracket at the caret position is painted as a "match" when a matched bracket is found.booleanReturns whether tab lines are painted.(package private) booleangetPaintTokenBackgrounds(int line, float y) Returns whether to paint the backgrounds of tokens on the specified line (assuming they are not obstructed by e.g.getParser(int index) Returns the specified parser.intReturns the number of parsers operating on this text area.intReturns the currently set parser delay.Returns a list of the current parser notices for this text area.intWorkaround for JTextComponents allowing the caret to be rendered entirely off-screen if the entire "previous" character fit entirely.getSecondaryLanguageBackground(int index) Returns the background color for the specified secondary language.intReturns the number of secondary language backgrounds.booleangetShouldIndentNextLine(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).booleanReturns whether a small popup window should display the text on the line containing a matched bracket whenever a matched bracket is off- screen.Returns what type of syntax highlighting this editor is doing.Returns all the colors currently being used in syntax highlighting by this text component.Returns the color used to paint tab lines.static booleanReturns whether templates are enabled for all instances ofRSyntaxTextArea.private byte[]getTextAsRtf(int start, int end) getTokenListFor(int startOffs, int endOffs) Returns a token list for the given range in the document.getTokenListForLine(int line) Returns a list of tokens representing the given line.(package private) TokenPainterReturns the painter to use for rendering tokens.Returns the tool tip to display for a mouse event at the given location.protected StringDoes the dirty work of getting the tool tip text.booleanReturns whether the specified token should be underlined.booleanReturns whether "focusable" tool tips are used instead of standard ones.booleanReturns whether selected text should use the "selected text color" property set viaJTextComponent.setSelectedTextColor(Color).protected voidinit()Called by constructors to initialize common properties of the text editor.booleanReturns whether auto-indent is enabled.final booleanReturns whether bracket matching is enabled.booleanReturns whether lines containing nothing but whitespace are made into blank lines when Enter is pressed in them.booleanReturns whether code folding is enabled.booleanReturns whether whitespace (spaces and tabs) is visible.modelToToken(int offs) Returns the token at the specified position in the model.protected voidThepaintComponentmethod is overridden so we apply any necessary rendering hints to the Graphics object.voidAttempt to redo the last action.private voidvoidRemoves an "active line range" listener from this text area.voidRemoves a hyperlink listener from this text area.voidOverridden so we stop this text area's parsers, if any.booleanremoveParser(Parser parser) Removes a parser from this text area.voidSets the colors used for syntax highlighting to their defaults.static booleanAttempts to save all currently-known templates to the current template directory, as set bysetTemplateDirectory.voidsetActiveLineRange(int min, int max) Sets the "active line range." Note that thisRSyntaxTextAreaitself 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.voidsetAnimateBracketMatching(boolean animate) Sets whether bracket matching should be animated.voidsetAntiAliasingEnabled(boolean enabled) Sets whether anti-aliasing is enabled in this editor.voidsetAutoIndentEnabled(boolean enabled) Sets whether auto-indent is enabled.voidsetBracketMatchingEnabled(boolean enabled) Sets whether bracket matching is enabled.voidsetClearWhitespaceLinesEnabled(boolean enabled) Sets whether lines containing nothing but whitespace are made into blank lines when Enter is pressed in them.voidsetCloseCurlyBraces(boolean close) Toggles whether curly braces should be automatically closed when a newline is entered after an opening curly brace.voidsetCloseMarkupTags(boolean close) Sets whether closing markup tags should be automatically completed when "</" is typed.voidsetCodeFoldingEnabled(boolean enabled) Sets whether code folding is enabled.private voidSets anti-aliasing to whatever the user's desktop value is.voidsetDocument(Document document) Sets the document used by this text area.voidsetEOLMarkersVisible(boolean visible) Sets whether EOL markers are visible at the end of each line.voidSets the font used by this text area.voidsetFractionalFontMetricsEnabled(boolean enabled) Sets whether fractional font metrics are enabled.voidSets the highlighter used by this text area.voidsetHighlightSecondaryLanguages(boolean highlight) Sets whether "secondary" languages should have their backgrounds colored differently to visually differentiate them.voidSets the color to use when painting hyperlinks.voidsetHyperlinksEnabled(boolean enabled) Sets whether hyperlinks are enabled for this text area.voidsetInsertPairedCharacters(boolean insertPairedCharacters) Toggles whether paired characters should be inserted when there is a selection.voidsetLinkGenerator(LinkGenerator generator) voidsetLinkScanningMask(int mask) Sets the mask for the key used to toggle whether we are scanning for hyperlinks with mouse hovering.voidsetMarkOccurrences(boolean markOccurrences) Toggles whether "mark occurrences" is enabled.voidsetMarkOccurrencesColor(Color color) Sets the "mark occurrences" color.voidsetMarkOccurrencesDelay(int delay) Sets the delay between when the caret is moved and when "marked occurrences" are highlighted.voidsetMatchedBracketBGColor(Color color) Sets the color used as the background for a matched bracket.voidSets the color used as the border for a matched bracket.voidsetPaintMarkOccurrencesBorder(boolean paintBorder) Toggles whether a border should be painted around marked occurrences.voidsetPaintMatchedBracketPair(boolean paintPair) Sets whether the bracket at the caret position is painted as a "match" when a matched bracket is found.voidsetPaintTabLines(boolean paint) Toggles whether tab lines are painted.voidsetParserDelay(int millis) Sets the parser delay.voidsetRightHandSideCorrection(int rhsCorrection) Applications typically have no need to modify this value.voidsetSecondaryLanguageBackground(int index, Color color) Sets the background color to use for a secondary language.voidsetShowMatchedBracketPopup(boolean show) Sets whether a small popup window should display the text on the line containing a matched bracket whenever a matched bracket is off- screen.voidsetSyntaxEditingStyle(String styleKey) Sets what type of syntax highlighting this editor is doing.voidsetSyntaxScheme(SyntaxScheme scheme) Sets all the colors used in syntax highlighting to the colors specified.voidSets the color use to paint tab lines.static booleanIf 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 voidsetTemplatesEnabled(boolean enabled) Enables or disables templates.voidsetUseFocusableTips(boolean use) Sets whether "focusable" tool tips are used instead of standard ones.voidsetUseSelectedTextColor(boolean use) Sets whether selected text should use the "selected text color" property (set viaJTextComponent.setSelectedTextColor(Color)).voidsetWhitespaceVisible(boolean visible) Sets whether whitespace is visible.private voidResets the editor state after the user clicks on a hyperlink or releases the hyperlink modifier.voidAttempt to undo an "action" done in this text area.viewToToken(Point p) Returns the token at the specified position in the view.Methods inherited from class 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, setUIMethods inherited from class 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, yForLineContainingMethods inherited from class JTextArea
append, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, setColumns, setRows, setWrapStyleWordMethods inherited from class 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, writeMethods inherited from class 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, updateMethods inherited from class 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, validateTreeMethods inherited from class 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
-
ANIMATE_BRACKET_MATCHING_PROPERTY
- See Also:
-
ANTIALIAS_PROPERTY
- See Also:
-
AUTO_INDENT_PROPERTY
- See Also:
-
BRACKET_MATCHING_PROPERTY
- See Also:
-
CLEAR_WHITESPACE_LINES_PROPERTY
- See Also:
-
CLOSE_CURLY_BRACES_PROPERTY
- See Also:
-
CLOSE_MARKUP_TAGS_PROPERTY
- See Also:
-
CODE_FOLDING_PROPERTY
- See Also:
-
EOL_VISIBLE_PROPERTY
- See Also:
-
FOCUSABLE_TIPS_PROPERTY
- See Also:
-
FRACTIONAL_FONTMETRICS_PROPERTY
- See Also:
-
HIGHLIGHT_SECONDARY_LANGUAGES_PROPERTY
- See Also:
-
HYPERLINKS_ENABLED_PROPERTY
- See Also:
-
INSERT_PAIRED_CHARS_PROPERTY
- See Also:
-
MARK_OCCURRENCES_PROPERTY
- See Also:
-
MARKED_OCCURRENCES_CHANGED_PROPERTY
- See Also:
-
PAINT_MATCHED_BRACKET_PAIR_PROPERTY
- See Also:
-
PARSER_NOTICES_PROPERTY
- See Also:
-
SYNTAX_SCHEME_PROPERTY
- See Also:
-
SYNTAX_STYLE_PROPERTY
- See Also:
-
TAB_LINE_COLOR_PROPERTY
- See Also:
-
TAB_LINES_PROPERTY
- See Also:
-
USE_SELECTED_TEXT_COLOR_PROPERTY
- See Also:
-
VISIBLE_WHITESPACE_PROPERTY
- See Also:
-
DEFAULT_BRACKET_MATCH_BG_COLOR
-
DEFAULT_BRACKET_MATCH_BORDER_COLOR
-
DEFAULT_SELECTION_COLOR
-
MSG
- See Also:
-
foldingMenu
-
toggleCurrentFoldAction
-
collapseAllCommentFoldsAction
-
collapseAllFoldsAction
-
expandAllFoldsAction
-
syntaxStyleKey
The key for the syntax style to be highlighting. -
syntaxScheme
The colors used for syntax highlighting. -
codeTemplateManager
Handles code templates. -
templatesEnabled
private static boolean templatesEnabledWhether templates are enabled. -
match
The rectangle surrounding the "matched bracket" if bracket matching is enabled. -
dotRect
The rectangle surrounding the current offset if both bracket matching and "match both brackets" are enabled. -
bracketInfo
Used to store the location of the bracket at the caret position (either just before or just after it) and the location of its match. -
matchedBracketBGColor
Colors used for the "matched bracket" if bracket matching is enabled. -
matchedBracketBorderColor
-
lastBracketMatchPos
private int lastBracketMatchPosThe location of the last matched bracket. -
bracketMatchingEnabled
private boolean bracketMatchingEnabledWhether bracket matching is enabled. -
animateBracketMatching
private boolean animateBracketMatchingWhether bracket matching is animated. -
paintMatchedBracketPair
private boolean paintMatchedBracketPairWhether both brackets are highlighted when bracket matching. -
bracketRepaintTimer
-
matchedBracketPopupTimer
-
metricsNeverRefreshed
private boolean metricsNeverRefreshed -
autoIndentEnabled
private boolean autoIndentEnabledWhether auto-indent is on. -
closeCurlyBraces
private boolean closeCurlyBracesWhether curly braces should be closed on Enter key presses, (if the current language supports it). -
closeMarkupTags
private boolean closeMarkupTagsWhether closing markup tags should be automatically completed when "</" is typed (if the current language is a markup language). -
clearWhitespaceLines
private boolean clearWhitespaceLinesWhether lines with nothing but whitespace are "made empty". -
whitespaceVisible
private boolean whitespaceVisibleWhether we are displaying visible whitespace (spaces and tabs). -
eolMarkersVisible
private boolean eolMarkersVisibleWhether EOL markers should be visible at the end of each line. -
paintTabLines
private boolean paintTabLinesWhether tab lines are enabled. -
tabLineColor
The color to use when painting tab lines. -
hyperlinksEnabled
private boolean hyperlinksEnabledWhether hyperlinks are enabled (must be supported by the syntax scheme being used). -
hyperlinkFG
The color to use when painting hyperlinks. -
linkScanningMask
private int linkScanningMaskMask used to determine if the correct key is being held down to scan for hyperlinks (ctrl, meta, etc.). -
highlightSecondaryLanguages
private boolean highlightSecondaryLanguagesWhether secondary languages have their backgrounds colored. -
useSelectedTextColor
private boolean useSelectedTextColorWhether the "selected text" color should be used with selected text. -
markOccurrencesSupport
Handles "mark occurrences" support. -
markOccurrencesColor
The color used to render "marked occurrences". -
markOccurrencesDelay
private int markOccurrencesDelayThe delay before occurrences are marked in the editor. -
paintMarkOccurrencesBorder
private boolean paintMarkOccurrencesBorderWhether a border should be painted around marked occurrences. -
defaultFontMetrics
Metrics of the text area's font. -
parserManager
Manages running the parser. -
cachedTip
-
cachedTipLoc
Used to work around an issue with Apple JVMs. -
isScanningForLinks
private boolean isScanningForLinksWhether the editor is currently scanning for hyperlinks on mouse movement. -
hoveredOverLinkOffset
private int hoveredOverLinkOffset -
linkGenerator
-
linkGeneratorResult
-
rhsCorrection
private int rhsCorrection -
foldManager
-
useFocusableTips
private boolean useFocusableTipsWhether "focusable" tool tips are used instead of standard ones. -
focusableTip
The last focusable tip displayed. -
aaHints
Cached desktop anti-aliasing hints, if anti-aliasing is enabled. -
tokenPainter
Renders tokens. -
showMatchedBracketPopup
private boolean showMatchedBracketPopupWhether a popup showing matched bracket lines when they're off-screen. -
lineHeight
private int lineHeight -
maxAscent
private int maxAscent -
fractionalFontMetricsEnabled
private boolean fractionalFontMetricsEnabled -
secondaryLanguageBackgrounds
-
insertPairedCharacters
private boolean insertPairedCharacters
-
-
Constructor Details
-
RSyntaxTextArea
public RSyntaxTextArea()Constructor. -
RSyntaxTextArea
Constructor.- Parameters:
doc- The document for the editor.
-
RSyntaxTextArea
-
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 eitherrowsorcolsis negative.
-
RSyntaxTextArea
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 eitherrowsorcolsis negative.
-
RSyntaxTextArea
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 eitherrowsorcolsis negative.
-
RSyntaxTextArea
public RSyntaxTextArea(int textMode) Creates a newRSyntaxTextArea.- Parameters:
textMode- EitherINSERT_MODEorOVERWRITE_MODE.
-
-
Method Details
-
addActiveLineRangeListener
Adds an "active line range" listener to this text area.- Parameters:
l- The listener to add.- See Also:
-
addHyperlinkListener
Adds a hyperlink listener to this text area. Assuming hyperlinks are enabled, this listener will receive events when the mouse enters, leaves, and clicks on hyperlinks when the scanning mask modifier button (e.g. the control key) is pressed.- Parameters:
l- The listener to add.- See Also:
-
addNotify
public void addNotify()Updates the font metrics the first time we're displayed.- Overrides:
addNotifyin classRTextAreaBase
-
addParser
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 ofnullwill do nothing.- See Also:
-
appendFoldingMenu
Appends a submenu with code folding options to this text component's popup menu.- Parameters:
popup- The popup menu to append to.- See Also:
-
calculateLineHeight
private void calculateLineHeight()Recalculates the height of a line in this text area and the maximum ascent of all fonts displayed. -
clearParsers
public void clearParsers()Removes all parsers from this text area.- See Also:
-
cloneTokenList
Clones a token list. This is necessary as tokens are reused inRSyntaxDocument, so we can't simply use the ones we are handed from it.- Parameters:
t- The token list to clone.- Returns:
- The clone of the token list.
-
configurePopupMenu
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:
configurePopupMenuin classRTextArea- Parameters:
popupMenu- The popup menu. This will never benull.- See Also:
-
copyAsStyledText
Copies the currently selected text to the system clipboard, with style information from the specified theme. Does nothing fornullor empty selections.- Parameters:
theme- The theme to use for the color and font information. This may benull, in which case this text area's current styles are used.- See Also:
-
copyAsStyledText
public void copyAsStyledText()Copies the currently selected text to the system clipboard, with any necessary style information (font, foreground color and background color). Does nothing fornullor empty selections.- See Also:
-
createDefaultModel
Returns the document to use for anRSyntaxTextArea.- Overrides:
createDefaultModelin classRTextArea- Returns:
- The document.
-
createHyperlinkEvent
-
createMouseListener
Returns the caret event/mouse listener forRTextAreas.- Overrides:
createMouseListenerin classRTextArea- Returns:
- The caret event/mouse listener.
-
createPopupMenu
Overridden to add menu items related to cold folding.- Overrides:
createPopupMenuin classRTextArea- Returns:
- The popup menu.
- See Also:
-
createRstaPopupMenuActions
private static void createRstaPopupMenuActions()See createPopupMenuActions() in RTextArea. TODO: Remove these horrible hacks and move localizing of actions into the editor kits, where it should be! The context menu should contain actions from the editor kits. -
copyActionAttributes
-
createRTextAreaUI
Returns a real UI to install on this text area.- Overrides:
createRTextAreaUIin 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
Notifies all listeners that a caret change has occurred.- Overrides:
fireCaretUpdatein classRTextArea- Parameters:
e- The caret event.
-
fireActiveLineRangeEvent
private void fireActiveLineRangeEvent(int min, int max) Notifies all listeners that the active line range has changed.- Parameters:
min- The minimum "active" line, or-1.max- The maximum "active" line, or-1.
-
fireHyperlinkUpdate
Notifies all listeners that have registered interest in notification on this event type. The listener list is processed last to first.- Parameters:
type- The type of event to fire.
-
fireMarkedOccurrencesChanged
void fireMarkedOccurrencesChanged()Notifies listeners that the marked occurrences for this text area have changed. -
fireParserNoticesChange
void fireParserNoticesChange()Fires a notification that the parser notices for this text area have changed. -
foldToggled
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 givenParserto reparse the content of this text area. This should only be called on the EDT.This method can be useful when a
Parsercan 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 reparsed.- Parameters:
parser- The index of theParserto re-run.- See Also:
-
forceReparsing
Forces reparsing with a specific parser. Note that if this parser is not installed on this text area, nothing will happen. This method should only be called on the EDT.- Parameters:
parser- The parser that should reparse 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:
-
getAnimateBracketMatching
public boolean getAnimateBracketMatching()Returns whether bracket matching should be animated.- Returns:
- Whether bracket matching should be animated.
- See Also:
-
getAntiAliasingEnabled
public boolean getAntiAliasingEnabled()Returns whether anti-aliasing is enabled in this editor.- Returns:
- Whether anti-aliasing is enabled in this editor.
- See Also:
-
getBackgroundForToken
-
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:
-
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:
-
getCodeTemplateManager
Returns the code template manager for all instances ofRSyntaxTextArea. The manager is lazily created.- Returns:
- The code template manager.
- See Also:
-
getDefaultBracketMatchBGColor
Returns the default bracket-match background color.- Returns:
- The color.
- See Also:
-
getDefaultBracketMatchBorderColor
Returns the default bracket-match border color.- Returns:
- The color.
- See Also:
-
getDefaultSelectionColor
Returns the default selection color for this text area. This color was chosen because it's light andRSyntaxTextAreadoes not change text color between selected/unselected text for contrast like regularJTextAreas do.- Returns:
- The default selection color.
-
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:
-
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:
-
getFoldManager
Returns the fold manager for this text area.- Returns:
- The fold manager.
-
getFontForTokenType
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
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:
-
getForegroundForToken
-
getForegroundForTokenType
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:
-
getFractionalFontMetricsEnabled
public boolean getFractionalFontMetricsEnabled()Returns whether fractional font metrics are enabled for this text area.- Returns:
- Whether fractional font metrics are enabled.
- See Also:
-
getGraphics2D
Returns aGraphics2Dversion of the specified graphics that has been initialized with the proper rendering hints.- Parameters:
g- The graphics context for which to get aGraphics2D.- Returns:
- The
Graphics2D.
-
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:
-
getHyperlinkForeground
Returns the color to use when painting hyperlinks.- Returns:
- The color to use when painting hyperlinks.
- See Also:
-
getHyperlinksEnabled
public boolean getHyperlinksEnabled()Returns whether hyperlinks are enabled for this text area.- Returns:
- Whether hyperlinks are enabled for this text area.
- See Also:
-
getInsertPairedCharacters
public boolean getInsertPairedCharacters()Returns whether paired characters should be inserted when there is a selection. For example, If the following text is selected:
And the double quote character,something", is typed, the selection will be replaced with:
If enabled, this occurs for the following characters:"something""'[({
- Returns:
- Whether to insert paired characters if a relevant key is typed while there is a selection.
- See Also:
-
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:
getLineHeightin classRTextAreaBase- Returns:
- The height of a line of text in this text area.
-
getLinkGenerator
-
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
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:
-
getMarkOccurrencesColor
Returns the color used for "mark occurrences" highlights.- Returns:
- The mark occurrences color.
- See Also:
-
getMarkOccurrencesDelay
public int getMarkOccurrencesDelay()Returns the delay between when the caret is moved and when "marked occurrences" are highlighted.- Returns:
- The "mark occurrences" delay, in milliseconds.
- See Also:
-
getMarkOccurrencesOfTokenType
boolean getMarkOccurrencesOfTokenType(int type) Returns whether tokens of the specified type should have "mark occurrences" enabled for the current programming language.- Parameters:
type- The token type.- Returns:
- Whether tokens of this type should have "mark occurrences" enabled.
-
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:
-
getMatchedBracketBorderColor
Gets the color used as the border for a matched bracket.- Returns:
- The color used.
- See Also:
-
getDotRectangle
Rectangle getDotRectangle()Returns the caret's offset's rectangle, ornullif there is currently no matched bracket, bracket matching is disabled, or "paint both matched brackets" is disabled. This should never be called by the programmer directly.- Returns:
- The rectangle surrounding the matched bracket.
- See Also:
-
getMatchRectangle
Rectangle getMatchRectangle()Returns the matched bracket's rectangle, ornullif there is currently no matched bracket. This should never be called by the programmer directly.- Returns:
- The rectangle surrounding the matched bracket.
- See Also:
-
getMaxAscent
public int getMaxAscent()Overridden to return the max ascent for any font used in the editor.- Overrides:
getMaxAscentin 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:
-
getPaintTabLines
public boolean getPaintTabLines()Returns whether tab lines are painted.- Returns:
- Whether tab lines are painted.
- See Also:
-
getPaintTokenBackgrounds
boolean getPaintTokenBackgrounds(int line, float y) Returns whether to paint the backgrounds of tokens on the specified line (assuming they are not obstructed by e.g. selection).- Parameters:
line- The line number.y- The y-offset of the line. This is used when line wrap is enabled, since each logical line can be rendered as several physical lines.- Returns:
- Whether to paint the token backgrounds on this line.
-
getParser
-
getParserCount
public int getParserCount()Returns the number of parsers operating on this text area.- Returns:
- The parser count.
- See Also:
-
getParserDelay
public int getParserDelay()Returns the currently set parser delay. This is the delay that must occur between edits for any registeredParsers to run.- Returns:
- The currently set parser delay, in milliseconds.
- See Also:
-
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:
-
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:
-
getShowMatchedBracketPopup
public boolean getShowMatchedBracketPopup()Returns whether a small popup window should display the text on the line containing a matched bracket whenever a matched bracket is off- screen.- Returns:
- Whether to show the popup.
- See Also:
-
getSyntaxEditingStyle
Returns what type of syntax highlighting this editor is doing.- Returns:
- The style being used, such as
SyntaxConstants.SYNTAX_STYLE_JAVA. - See Also:
-
getSyntaxScheme
Returns all the colors currently being used in syntax highlighting by this text component.- Returns:
- An instance of
SyntaxSchemethat represents the colors currently being used for syntax highlighting. - See Also:
-
getTabLineColor
Returns the color used to paint tab lines.- Returns:
- The color used to paint tab lines.
- See Also:
-
getPaintMarkOccurrencesBorder
public boolean getPaintMarkOccurrencesBorder()Returns whether a border is painted around marked occurrences.- Returns:
- Whether a border is painted.
- See Also:
-
getSecondaryLanguageBackground
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
nullif none. - See Also:
-
getSecondaryLanguageCount
public int getSecondaryLanguageCount()Returns the number of secondary language backgrounds.- Returns:
- The number of secondary language backgrounds.
- See Also:
-
getTemplatesEnabled
public static boolean getTemplatesEnabled()Returns whether 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:
-
getTextAsRtf
private byte[] getTextAsRtf(int start, int end) -
getTokenListFor
Returns a token list for the given range in the document.- Parameters:
startOffs- The starting offset in the document.endOffs- The end offset in the document.- Returns:
- The first token in the token list.
-
getTokenListForLine
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.
-
getTokenPainter
TokenPainter getTokenPainter()Returns the painter to use for rendering tokens.- Returns:
- The painter to use for rendering tokens.
-
getToolTipText
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:
getToolTipTextin classRTextArea- Parameters:
e- The mouse event.- Returns:
- The tool tip text, or
nullif none. - See Also:
-
getToolTipTextImpl
Does the dirty work of getting the tool tip text.- Parameters:
e- The mouse event.- Returns:
- The tool tip text.
-
getUnderlineForToken
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:
-
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:
-
init
-
isAutoIndentEnabled
public boolean isAutoIndentEnabled()Returns whether auto-indent is enabled.- Returns:
- Whether auto-indent is enabled.
- See Also:
-
isBracketMatchingEnabled
public final boolean isBracketMatchingEnabled()Returns whether bracket matching is enabled.- Returns:
trueiff bracket matching is enabled.- See Also:
-
isClearWhitespaceLinesEnabled
public boolean isClearWhitespaceLinesEnabled()Returns whether lines containing nothing but whitespace are made into blank lines when Enter is pressed in them.- Returns:
- Whether whitespace-only lines are cleared when the user presses Enter on them.
- See Also:
-
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:
-
isWhitespaceVisible
public boolean isWhitespaceVisible()Returns whether whitespace (spaces and tabs) is visible.- Returns:
- Whether whitespace is visible.
- See Also:
-
modelToToken
Returns the token at the specified position in the model.- Parameters:
offs- The position in the model.- Returns:
- The token, or
nullif no token is at that position. - See Also:
-
paintComponent
ThepaintComponentmethod is overridden so we apply any necessary rendering hints to the Graphics object.- Overrides:
paintComponentin classRTextAreaBase- Parameters:
g- The graphics context with which to paint.
-
refreshFontMetrics
-
redoLastAction
public void redoLastAction()Description copied from class:RTextAreaAttempt to redo the last action.- Overrides:
redoLastActionin classRTextArea- See Also:
-
removeActiveLineRangeListener
Removes an "active line range" listener from this text area.- Parameters:
l- The listener to remove.- See Also:
-
removeHyperlinkListener
Removes a hyperlink listener from this text area.- Parameters:
l- The listener to remove.- See Also:
-
removeNotify
public void removeNotify()Overridden so we stop this text area's parsers, if any.- Overrides:
removeNotifyin classJTextComponent
-
removeParser
-
restoreDefaultSyntaxScheme
public void restoreDefaultSyntaxScheme()Sets the colors used for syntax highlighting to their defaults.- See Also:
-
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 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:
-
setActiveLineRange
public void setActiveLineRange(int min, int max) Sets the "active line range." Note that thisRSyntaxTextAreaitself 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
RSyntaxTextAreawill not call this method directly; rather, it is usually called by instances ofLanguageSupportin theRSTALanguageSupportlibrary. See https://github.com/bobbylight/RSTALanguageSupport for more information about this library.- Parameters:
min- The "minimum" line in the active line range, or-1if the range is being cleared.max- The "maximum" line in the active line range, or-1if the range is being cleared.- See Also:
-
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:
-
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:
-
setAutoIndentEnabled
public void setAutoIndentEnabled(boolean enabled) Sets whether auto-indent is enabled. This fires a property change event of typeAUTO_INDENT_PROPERTY.- Parameters:
enabled- Whether auto-indent is enabled.- See Also:
-
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 bracket matching should be enabled.- See Also:
-
setClearWhitespaceLinesEnabled
public void setClearWhitespaceLinesEnabled(boolean enabled) Sets whether 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 whitespace-only lines are cleared when the user presses Enter on them.- See Also:
-
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:
-
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:
-
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:
-
setDefaultAntiAliasingState
private void setDefaultAntiAliasingState()Sets anti-aliasing to whatever the user's desktop value is.- See Also:
-
setDocument
Sets the document used by this text area. This is overridden so that only instances ofRSyntaxDocumentare accepted; for all others, an exception will be thrown.- Overrides:
setDocumentin 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:
-
setFont
Sets the font used by this text area.Note that if some token styles are using a different font family (not style, e.g. bold and italics don't count), they will not be changed by calling this method. In particular, if you are using multiple different fonts in your text area for different token types, and are looking for an easy way to increase or decrease all font sizes, use
RSyntaxTextAreaEditorKit.IncreaseFontSizeActionandRSyntaxTextAreaEditorKit.DecreaseFontSizeActionrather than this method.- Overrides:
setFontin classRTextAreaBase- Parameters:
font- The font.- See Also:
-
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:
-
setHighlighter
Sets the highlighter used by this text area.- Overrides:
setHighlighterin classJTextComponent- Parameters:
h- The highlighter.- Throws:
IllegalArgumentException- Ifhis 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.- Parameters:
highlight- Whether to highlight secondary languages.- See Also:
-
setHyperlinkForeground
Sets the color to use when painting hyperlinks.- Parameters:
fg- The color to use when painting hyperlinks.- Throws:
NullPointerException- Iffgisnull.- See Also:
-
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:
-
setInsertPairedCharacters
public void setInsertPairedCharacters(boolean insertPairedCharacters) Toggles whether paired characters should be inserted when there is a selection. For example, If the following text is selected:
And the double quote character,something", is typed, the selection can be replaced with:
If enabled, this occurs for the following characters:"something""'[({
- Parameters:
insertPairedCharacters- Whether to insert paired characters if a relevant key is typed while there is a selection.- See Also:
-
setLinkGenerator
-
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.Note that this value will be ignored if
setHyperlinksEnabled(boolean)is called and set tofalse. If you wish to disable hyperlinks, use that method rather than changing this mask value.- Parameters:
mask- The mask to use. This should be some bitwise combination ofInputEvent.CTRL_DOWN_MASK,InputEvent.ALT_DOWN_MASK,InputEvent.SHIFT_DOWN_MASKorInputEvent.META_DOWN_MASK. For invalid values, behavior is undefined.- See Also:
-
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:
-
setMarkOccurrencesColor
Sets the "mark occurrences" color.- Parameters:
color- The new color. This cannot benull.- See Also:
-
setMarkOccurrencesDelay
public void setMarkOccurrencesDelay(int delay) Sets the delay between when the caret is moved and when "marked occurrences" are highlighted. It is recommended to set this to a value greater than0to debounce the "mark occurrences" operation, since it can be an expensive operation.- Parameters:
delay- The new delay, in milliseconds. This must be greater than or equal to0.- See Also:
-
setMatchedBracketBGColor
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:
-
setMatchedBracketBorderColor
Sets the color used as the border for a matched bracket.- Parameters:
color- The color to use.- See Also:
-
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:
-
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:
-
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:
-
setParserDelay
public void setParserDelay(int millis) Sets the parser delay. This is the delay that must occur between edits for any registeredParsers to run.- Parameters:
millis- The new parser delay, in milliseconds. This must be greater than zero.- See Also:
-
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:
-
setSecondaryLanguageBackground
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, ornullfor none.- See Also:
-
setShowMatchedBracketPopup
public void setShowMatchedBracketPopup(boolean show) Sets whether a small popup window should display the text on the line containing a matched bracket whenever a matched bracket is off- screen.- Parameters:
show- Whether to show the popup.- See Also:
-
setSyntaxEditingStyle
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_NONEorSyntaxConstants.SYNTAX_STYLE_JAVA.- See Also:
-
setSyntaxScheme
Sets all 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 ofSyntaxSchemeto use.- See Also:
-
setTemplateDirectory
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.xmlthat contain templates to load.- Returns:
trueif the load was successful;falseif either templates aren't currently enabled or the load failed somehow (most likely, the directory doesn't exist).- See Also:
-
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 templates should be enabled.- See Also:
-
setTabLineColor
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:
-
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:
-
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:
-
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:
-
stopScanningForLinks
private void stopScanningForLinks()Resets the editor state after the user clicks on a hyperlink or releases the hyperlink modifier. -
undoLastAction
public void undoLastAction()Description copied from class:RTextAreaAttempt to undo an "action" done in this text area.- Overrides:
undoLastActionin classRTextArea- See Also:
-
viewToToken
-