📄 textareapainter.java
字号:
/* * TextAreaPainter.java - Paints the text area * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 1999, 2003 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */package org.gjt.sp.jedit.textarea;//{{{ Importsimport javax.swing.text.*;import javax.swing.JComponent;import java.awt.event.MouseEvent;import java.awt.font.*;import java.awt.*;import java.util.HashMap;import org.gjt.sp.jedit.buffer.IndentFoldHandler;import org.gjt.sp.jedit.syntax.*;import org.gjt.sp.jedit.Buffer;import org.gjt.sp.jedit.Debug;import org.gjt.sp.util.Log;//}}}/** * The text area painter is the component responsible for displaying the * text of the current buffer. The only methods in this class that should * be called by plugins are those for adding and removing * text area extensions. * * @see #addExtension(TextAreaExtension) * @see #addExtension(int,TextAreaExtension) * @see #removeExtension(TextAreaExtension) * @see TextAreaExtension * @see JEditTextArea * * @author Slava Pestov * @version $Id: TextAreaPainter.java,v 1.93 2003/12/30 04:47:03 spestov Exp $ */public class TextAreaPainter extends JComponent implements TabExpander{ //{{{ Layers /** * The lowest possible layer. * @see #addExtension(int,TextAreaExtension) * @since jEdit 4.0pre4 */ public static final int LOWEST_LAYER = Integer.MIN_VALUE; /** * Below selection layer. The JDiff plugin will use this. * @see #addExtension(int,TextAreaExtension) * @since jEdit 4.0pre4 */ public static final int BACKGROUND_LAYER = -60; /** * The line highlight and collapsed fold highlight layer. * @see #addExtension(int,TextAreaExtension) * @since jEdit 4.0pre7 */ public static final int LINE_BACKGROUND_LAYER = -50; /** * Below selection layer. * @see #addExtension(int,TextAreaExtension) * @since jEdit 4.0pre4 */ public static final int BELOW_SELECTION_LAYER = -40; /** * Selection layer. Most extensions will be above this layer, but some * (eg, JDiff) will want to be below the selection. * @see #addExtension(int,TextAreaExtension) * @since jEdit 4.0pre4 */ public static final int SELECTION_LAYER = -30; /** * Wrap guide layer. Most extensions will be above this layer. * @since jEdit 4.0pre4 */ public static final int WRAP_GUIDE_LAYER = -20; /** * Below most extensions layer. * @see #addExtension(int,TextAreaExtension) * @since jEdit 4.0pre4 */ public static final int BELOW_MOST_EXTENSIONS_LAYER = -10; /** * Default extension layer. This is above the wrap guide but below the * structure highlight. * @since jEdit 4.0pre4 */ public static final int DEFAULT_LAYER = 0; /** * Block caret layer. Most extensions will be below this layer. * @since jEdit 4.2pre1 */ public static final int BLOCK_CARET_LAYER = 50; /** * Bracket highlight layer. Most extensions will be below this layer. * @since jEdit 4.0pre4 */ public static final int BRACKET_HIGHLIGHT_LAYER = 100; /** * Text layer. Most extensions will be below this layer. * @since jEdit 4.2pre1 */ public static final int TEXT_LAYER = 200; /** * Caret layer. Most extensions will be below this layer. * @since jEdit 4.2pre1 */ public static final int CARET_LAYER = 300; /** * Highest possible layer. * @since jEdit 4.0pre4 */ public static final int HIGHEST_LAYER = Integer.MAX_VALUE; //}}} //{{{ setBounds() method /** * It is a bad idea to override this, but we need to get the component * event before the first repaint. */ public void setBounds(int x, int y, int width, int height) { if(x == getX() && y == getY() && width == getWidth() && height == getHeight()) { return; } super.setBounds(x,y,width,height); textArea.recalculateVisibleLines(); if(textArea.getBuffer().isLoaded()) textArea.recalculateLastPhysicalLine(); textArea.propertiesChanged(); textArea.scrollBarsInitialized = true; } //}}} //{{{ isManagingFocus() method /** * Returns if this component can be traversed by pressing the * Tab key. This returns false. */ public boolean isManagingFocus() { return false; } //}}} //{{{ getFocusTraversalKeysEnabled() method /** * Makes the tab key work in Java 1.4. * @since jEdit 3.2pre4 */ public boolean getFocusTraversalKeysEnabled() { return false; } //}}} //{{{ Getters and setters //{{{ getStyles() method /** * Returns the syntax styles used to paint colorized text. Entry <i>n</i> * will be used to paint tokens with id = <i>n</i>. * @see org.gjt.sp.jedit.syntax.Token */ public final SyntaxStyle[] getStyles() { return styles; } //}}} //{{{ setStyles() method /** * Sets the syntax styles used to paint colorized text. Entry <i>n</i> * will be used to paint tokens with id = <i>n</i>. * @param styles The syntax styles * @see org.gjt.sp.jedit.syntax.Token */ public final void setStyles(SyntaxStyle[] styles) { // assumed this is called after a font render context is set up. // changing font render context settings without a setStyles() // call will not reset cached monospaced font info. fonts.clear(); this.styles = styles; styles[Token.NULL] = new SyntaxStyle(getForeground(),null,getFont()); for(int i = 0; i < styles.length; i++) { styles[i].setCharWidth(getCharWidth(styles[i].getFont())); } repaint(); } //}}} //{{{ getCaretColor() method /** * Returns the caret color. */ public final Color getCaretColor() { return caretColor; } //}}} //{{{ setCaretColor() method /** * Sets the caret color. * @param caretColor The caret color */ public final void setCaretColor(Color caretColor) { this.caretColor = caretColor; if(textArea.getBuffer() != null) textArea.invalidateLine(textArea.getCaretLine()); } //}}} //{{{ getSelectionColor() method /** * Returns the selection color. */ public final Color getSelectionColor() { return selectionColor; } //}}} //{{{ setSelectionColor() method /** * Sets the selection color. * @param selectionColor The selection color */ public final void setSelectionColor(Color selectionColor) { this.selectionColor = selectionColor; if(textArea.getBuffer() != null) textArea.invalidateSelectedLines(); } //}}} //{{{ getMultipleSelectionColor() method /** * Returns the multiple selection color. * @since jEdit 4.2pre1 */ public final Color getMultipleSelectionColor() { return multipleSelectionColor; } //}}} //{{{ setMultipleSelectionColor() method /** * Sets the multiple selection color. * @param multipleSelectionColor The multiple selection color * @since jEdit 4.2pre1 */ public final void setMultipleSelectionColor(Color multipleSelectionColor) { this.multipleSelectionColor = multipleSelectionColor; if(textArea.getBuffer() != null) textArea.invalidateSelectedLines(); } //}}} //{{{ getLineHighlightColor() method /** * Returns the line highlight color. */ public final Color getLineHighlightColor() { return lineHighlightColor; } //}}} //{{{ setLineHighlightColor() method /** * Sets the line highlight color. * @param lineHighlightColor The line highlight color */ public final void setLineHighlightColor(Color lineHighlightColor) { this.lineHighlightColor = lineHighlightColor; if(textArea.getBuffer() != null) textArea.invalidateLine(textArea.getCaretLine()); } //}}} //{{{ isLineHighlightEnabled() method /** * Returns true if line highlight is enabled, false otherwise. */ public final boolean isLineHighlightEnabled() { return lineHighlight; } //}}} //{{{ setLineHighlightEnabled() method /** * Enables or disables current line highlighting. * @param lineHighlight True if current line highlight should be enabled, * false otherwise */ public final void setLineHighlightEnabled(boolean lineHighlight) { this.lineHighlight = lineHighlight; if(textArea.getBuffer() != null) textArea.invalidateSelectedLines(); } //}}} //{{{ getStructureHighlightColor() method /** * Returns the structure highlight color. * @since jEdit 4.2pre3 */ public final Color getStructureHighlightColor() { return structureHighlightColor; } //}}} //{{{ setStructureHighlightColor() method /** * Sets the structure highlight color. * @param structureHighlightColor The bracket highlight color * @since jEdit 4.2pre3 */ public final void setStructureHighlightColor( Color structureHighlightColor) { this.structureHighlightColor = structureHighlightColor; StructureMatcher.Match match = textArea.getStructureMatch(); if(match != null) { textArea.invalidateLineRange( match.startLine,match.endLine ); } } //}}} //{{{ isStructureHighlightEnabled() method /** * Returns true if structure highlighting is enabled, false otherwise. * @since jEdit 4.2pre3 */ public final boolean isStructureHighlightEnabled() { return structureHighlight; } //}}} //{{{ setStructureHighlightEnabled() method /** * Enables or disables structure highlighting. * @param structureHighlight True if structure highlighting should be * enabled, false otherwise * @since jEdit 4.2pre3 */ public final void setStructureHighlightEnabled(boolean structureHighlight) { this.structureHighlight = structureHighlight; StructureMatcher.Match match = textArea.getStructureMatch(); if(match != null) { textArea.invalidateLineRange( match.startLine, match.endLine ); } } //}}} //{{{ isBlockCaretEnabled() method /** * Returns true if the caret should be drawn as a block, false otherwise. */ public final boolean isBlockCaretEnabled() { return blockCaret; } //}}} //{{{ setBlockCaretEnabled() method /** * Sets if the caret should be drawn as a block, false otherwise. * @param blockCaret True if the caret should be drawn as a block, * false otherwise. */ public final void setBlockCaretEnabled(boolean blockCaret) { this.blockCaret = blockCaret; extensionMgr.removeExtension(caretExtension); if(blockCaret) addExtension(BLOCK_CARET_LAYER,caretExtension); else addExtension(CARET_LAYER,caretExtension); if(textArea.getBuffer() != null) textArea.invalidateLine(textArea.getCaretLine()); } //}}} //{{{ getEOLMarkerColor() method /** * Returns the EOL marker color. */ public final Color getEOLMarkerColor() { return eolMarkerColor; } //}}} //{{{ setEOLMarkerColor() method /** * Sets the EOL marker color. * @param eolMarkerColor The EOL marker color */ public final void setEOLMarkerColor(Color eolMarkerColor) { this.eolMarkerColor = eolMarkerColor; repaint(); } //}}} //{{{ getEOLMarkersPainted() method /** * Returns true if EOL markers are drawn, false otherwise. */ public final boolean getEOLMarkersPainted() { return eolMarkers; } //}}} //{{{ setEOLMarkersPainted() method /** * Sets if EOL markers are to be drawn. * @param eolMarkers True if EOL markers should be drawn, false otherwise */ public final void setEOLMarkersPainted(boolean eolMarkers) { this.eolMarkers = eolMarkers; repaint(); } //}}} //{{{ getWrapGuideColor() method /** * Returns the wrap guide color. */ public final Color getWrapGuideColor() { return wrapGuideColor; } //}}} //{{{ setWrapGuideColor() method /** * Sets the wrap guide color. * @param wrapGuideColor The wrap guide color */ public final void setWrapGuideColor(Color wrapGuideColor) { this.wrapGuideColor = wrapGuideColor; repaint(); } //}}} //{{{ isWrapGuidePainted() method /** * Returns true if the wrap guide is drawn, false otherwise. * @since jEdit 4.0pre4 */ public final boolean isWrapGuidePainted() { return wrapGuide; } //}}} //{{{ setWrapGuidePainted() method /** * Sets if the wrap guide is to be drawn. * @param wrapGuide True if the wrap guide should be drawn, false otherwise */ public final void setWrapGuidePainted(boolean wrapGuide) { this.wrapGuide = wrapGuide; repaint(); } //}}} //{{{ getFoldLineStyle() method /** * Returns the fold line style. The first element is the style for * lines with a fold level greater than 3. The remaining elements * are for fold levels 1 to 3. */ public final SyntaxStyle[] getFoldLineStyle() { return foldLineStyle; } //}}} //{{{ setFoldLineStyle() method /** * Sets the fold line style. The first element is the style for * lines with a fold level greater than 3. The remaining elements * are for fold levels 1 to 3. * @param foldLineStyle The fold line style */ public final void setFoldLineStyle(SyntaxStyle[] foldLineStyle) { this.foldLineStyle = foldLineStyle; repaint(); } //}}} //{{{ setAntiAliasEnabled() method /** * Sets if anti-aliasing should be enabled. Has no effect when * running on Java 1.1. * @since jEdit 3.2pre6 */ public void setAntiAliasEnabled(boolean antiAlias) { this.antiAlias = antiAlias; updateRenderingHints(); } //}}} //{{{ isAntiAliasEnabled() method /** * Returns if anti-aliasing is enabled. * @since jEdit 3.2pre6 */ public boolean isAntiAliasEnabled() { return antiAlias; } //}}} //{{{ setFractionalFontMetricsEnabled() method /** * Sets if fractional font metrics should be enabled. Has no effect when * running on Java 1.1. * @since jEdit 3.2pre6 */ public void setFractionalFontMetricsEnabled(boolean fracFontMetrics) { this.fracFontMetrics = fracFontMetrics; updateRenderingHints(); } //}}} //{{{ isFractionalFontMetricsEnabled() method /** * Returns if fractional font metrics are enabled. * @since jEdit 3.2pre6 */ public boolean isFractionalFontMetricsEnabled() { return fracFontMetrics; } //}}} //{{{ getFontRenderContext() method /** * Returns the font render context. * @since jEdit 4.0pre4 */ public FontRenderContext getFontRenderContext() { return fontRenderContext; } //}}} //}}} //{{{ addExtension() method /** * Adds a text area extension, which can perform custom painting and * tool tip handling. * @param extension The extension * @since jEdit 4.0pre4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -