📄 rsyntaxtextarea.java~1~
字号:
/*****************************************************************************/
/**
* Returns the code template manager for all instances of
* <code>RSyntaxTextArea</code>. Note that if templates
* are not enabled, this will return <code>null</code>.
*
* @return The code template manager.
* @see #enableTemplates
*/
static CodeTemplateManager getCodeTemplateManager() {
return codeTemplateManager;
}
/*****************************************************************************/
/**
* Returns the default bracket-match background color.
*
* @return The color.
* @see #getDefaultBracketMatchBorderColor
*/
public static final Color getDefaultBracketMatchBGColor() {
return DEFAULT_BRACKET_MATCH_BG_COLOR;
}
/*****************************************************************************/
/**
* Returns the default bracket-match border color.
*
* @return The color.
* @see #getDefaultBracketMatchBGColor
*/
public static final Color getDefaultBracketMatchBorderColor() {
return DEFAULT_BRACKET_MATCH_BORDER_COLOR;
}
/*****************************************************************************/
/**
* Returns the "default" syntax highlighting color scheme. The colors
* used are somewhat standard among syntax highlighting text editors.
*
* @return The default syntax highlighting color scheem.
*/
public SyntaxHighlightingColorScheme getDefaultSyntaxHighlightingColorScheme() {
return new SyntaxHighlightingColorScheme(true);
}
/*****************************************************************************/
/**
* Returns whether fractional fontmetrics are enabled for this text area.
*
* @return Whether fractional fontmetrics are enabled.
* @see #setFractionalFontMetricsEnabled
* @see #getAntiAliasEnabled
*/
public boolean getFractionalFontMetricsEnabled() {
return fractionalFontMetricsEnabled;
}
/*****************************************************************************/
/**
* Returns a <code>Graphics2D</code> version of the specified graphics
* that has been initialized with the proper rendering hints.
*
* @param g The graphics context for which to get a
* <code>Graphics2D</code>.
* @return The <code>Graphics2D</code>.
*/
private final Graphics2D getGraphics2D(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
if (antiAliasEnabled) {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
if (fractionalFontMetricsEnabled) {
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
return g2d;
}
/*****************************************************************************/
/**
* Returns the height to use for a line of text in this text area.
*
* @return The height of a line of text in this text area.
*/
public int getLineHeight() {
//System.err.println("... getLineHeight() returning " + lineHeight);
return lineHeight;
}
/*****************************************************************************/
/**
* Gets the color used as the background for a matched bracket.
*
* @return The color used.
* @see #setMatchedBracketBGColor
* @see #getMatchedBracketBorderColor
*/
public final Color getMatchedBracketBGColor() {
return matchedBracketBGColor;
}
/*****************************************************************************/
/**
* Gets the color used as the border for a matched bracket.
*
* @return The color used.
* @see #setMatchedBracketBorderColor
* @see #getMatchedBracketBGColor
*/
public final Color getMatchedBracketBorderColor() {
return matchedBracketBorderColor;
}
/*****************************************************************************/
/**
* Returns the matched bracket's rectangle, or <code>null</code> if there
* is currently no matched bracket. Note that this shouldn't ever be
* called by the user.
*
* @return The rectangle surrounding the matched bracket.
*/
public final Rectangle getMatchRectangle() {
return match;
}
/*****************************************************************************/
/**
* Returns the syntax scheme to use for coloring the given token type using
* the current syntax highlighting scheme.
*
* @param tokenType The type of token to colorize.
* @return The syntax scheme used to syntax highlight a token of type
* <code>tokenType</code>. If <code>tokenType</code> is invalid,
* <code>null</code> is returned.
*/
public SyntaxScheme getSchemeForTokenType(int tokenType) {
return (SyntaxScheme)colorScheme.syntaxSchemes[tokenType];
}
/*****************************************************************************/
/**
* Returns what type of syntax highlighting this editor is doing.
*
* @return The style being used, such as
* <code>RSyntaxTextArea.JAVA_SYNTAX_STYLE</code>.
* @see #setSyntaxEditingStyle
*/
public int getSyntaxEditingStyle() {
return syntaxStyle;
}
/*****************************************************************************/
/**
* Returns all of the colors currently being used in syntax highlighting
* by this text component.
*
* @return An instance of <code>SyntaxHighlightingColorScheme</code> that
* represents the colors currently being used for syntax
* highlighting.
* @see #setSyntaxHighlightingColorScheme
*/
public SyntaxHighlightingColorScheme getSyntaxHighlightingColorScheme() {
return colorScheme;
}
/*****************************************************************************/
/**
* Returns whether or not templates are enabled for all instances
* of <code>RSyntaxTextArea</code>.
*
* @return Whether templates are enabled.
* @see #saveTemplates
* @see #setTemplateDirectory
* @see #setTemplatesEnabled
*/
public synchronized static boolean getTemplatesEnabled() {
return templatesEnabled;
}
/*****************************************************************************/
/**
* Returns a list of tokens representing the given line.
*
* @param line The line number to get tokens for.
* @return A linked list of tokens representing <code>text</code>.
*/
public Token getTokenListForLine(int line) {
return ((RSyntaxDocument)getDocument()).getTokenListForLine(line);
}
/*****************************************************************************/
/**
* Returns the tooltip to display for a mouse event at the given
* location. This method is overridden to give a registered parser a
* chance to display a tooltip (such as an error description when the
* mouse is over an error highlight).
*
* @param e The mouse event.
*/
public String getToolTipText(MouseEvent e) {
String toolTip = parserManager==null ? null :
parserManager.getToolTipText(e);
return toolTip!=null ? toolTip : super.getToolTipText(e);
}
/*****************************************************************************/
/**
* Returns whether or not auto-indent is enabled.
*
* @return Whether or not auto-indent is enabled.
* @see #setAutoIndentEnabled
*/
public boolean isAutoIndentEnabled() {
return autoIndentEnabled;
}
/*****************************************************************************/
/**
* Returns whether or not bracket matching is enabled.
*
* @return <code>true</code> iff bracket matching is enabled.
* @see #setBracketMatchingEnabled
*/
public final boolean isBracketMatchingEnabled() {
return bracketMatchingEnabled;
}
/*****************************************************************************/
/**
* Returns whether or not lines containing nothing but whitespace are made
* into blank lines when Enter is pressed in them.
*
* @return Whether or not whitespace-only lines are cleared when
* the user presses Enter on them.
* @see #setClearWhitespaceLinesEnabled
*/
public boolean isClearWhitespaceLinesEnabled() {
return clearWhitespaceLines;
}
/*****************************************************************************/
/**
* Returns whether whitespace (spaces and tabs) is visible.
*
* @return Whether whitespace is visible.
* @see #setWhitespaceVisible
*/
public boolean isWhitespaceVisible() {
return whitespaceVisible;
}
/*****************************************************************************/
/**
* The <code>paintComponent</code> method is overridden so we
* apply any necessary rendering hints to the Graphics object.
*/
public void paintComponent(Graphics g) {
super.paintComponent(getGraphics2D(g));
}
/*****************************************************************************/
/**
* Refreshes the highlights in the text area from the parser.
*
* @param parserNoticeIterator An iterator over new parser notices.
* @see #clearParserNoticeHighlights
*/
void refreshParserNoticeHighlights(Iterator parserNoticeIterator) {
clearParserNoticeHighlights();
if (parserNoticeHighlights==null)
parserNoticeHighlights = new ArrayList();
Highlighter h = getHighlighter();
while (parserNoticeIterator.hasNext()) {
ParserNotice notice = (ParserNotice)parserNoticeIterator.next();
int start = notice.getStart();
int length = notice.getLength();
try {
parserNoticeHighlights.add(h.addHighlight(start,start+length,
parserErrorHighlightPainter));
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
/*****************************************************************************/
/**
* Overridden so we stop this text area's parser, if any.
*/
public void removeNotify() {
if (parserManager!=null) {
parserManager.stopParsing();
}
super.removeNotify();
}
/*****************************************************************************/
/**
* Sets the colors used for syntax highlighting to their defaults.
*/
public void restoreDefaultSyntaxHighlightingColorScheme() {
setSyntaxHighlightingColorScheme(getDefaultSyntaxHighlightingColorScheme());
}
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -