📄 textareapainter.java
字号:
/* * TextAreaPainter.java - Paints the text area * Copyright (C) 1999, 2000, 2001 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;import javax.swing.text.*;import javax.swing.JComponent;import java.awt.event.MouseEvent;import java.awt.*;import org.gjt.sp.jedit.syntax.*;import org.gjt.sp.jedit.Buffer;import org.gjt.sp.jedit.TextUtilities;import org.gjt.sp.util.Log;/** * The text area repaint manager. It performs double buffering and paints * lines of text. * @author Slava Pestov * @version $Id: TextAreaPainter.java,v 1.1.1.1 2001/09/02 05:38:12 spestov Exp $ */public class TextAreaPainter extends JComponent implements TabExpander{ /** * Creates a new painter. Do not create instances of this class * directly. */ public TextAreaPainter(JEditTextArea textArea) { enableEvents(AWTEvent.FOCUS_EVENT_MASK | AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); this.textArea = textArea; setAutoscrolls(true); setDoubleBuffered(true); setOpaque(true); setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); } /** * Returns if this component can be traversed by pressing the * Tab key. This returns false. */ public boolean isManagingFocus() { return false; } /** * Makes the tab key work in Java 1.4. * @since jEdit 3.2pre4 */ public boolean getFocusTraversalKeysEnabled() { return false; } /** * 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; } /** * 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) { this.styles = styles; repaint(); } /** * Returns the caret color. */ public final Color getCaretColor() { return caretColor; } /** * 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()); } /** * Returns the selection color. */ public final Color getSelectionColor() { return selectionColor; } /** * Sets the selection color. * @param selectionColor The selection color */ public final void setSelectionColor(Color selectionColor) { this.selectionColor = selectionColor; if(textArea.getBuffer() != null) textArea.invalidateSelectedLines(); } /** * Returns the line highlight color. */ public final Color getLineHighlightColor() { return lineHighlightColor; } /** * 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()); } /** * Returns true if line highlight is enabled, false otherwise. */ public final boolean isLineHighlightEnabled() { return lineHighlight; } /** * 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(); } /** * Returns the bracket highlight color. */ public final Color getBracketHighlightColor() { return bracketHighlightColor; } /** * Sets the bracket highlight color. * @param bracketHighlightColor The bracket highlight color */ public final void setBracketHighlightColor(Color bracketHighlightColor) { this.bracketHighlightColor = bracketHighlightColor; if(textArea.getBuffer() != null) textArea.invalidateLine(textArea.getBracketLine()); } /** * Returns true if bracket highlighting is enabled, false otherwise. * When bracket highlighting is enabled, the bracket matching the * one before the caret (if any) is highlighted. */ public final boolean isBracketHighlightEnabled() { return bracketHighlight; } /** * Enables or disables bracket highlighting. * When bracket highlighting is enabled, the bracket matching the * one before the caret (if any) is highlighted. * @param bracketHighlight True if bracket highlighting should be * enabled, false otherwise */ public final void setBracketHighlightEnabled(boolean bracketHighlight) { this.bracketHighlight = bracketHighlight; if(textArea.getBuffer() != null) textArea.invalidateLine(textArea.getBracketLine()); } /** * Returns true if the caret should be drawn as a block, false otherwise. */ public final boolean isBlockCaretEnabled() { return blockCaret; } /** * 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; if(textArea.getBuffer() != null) textArea.invalidateLine(textArea.getCaretLine()); } /** * Returns the EOL marker color. */ public final Color getEOLMarkerColor() { return eolMarkerColor; } /** * Sets the EOL marker color. * @param eolMarkerColor The EOL marker color */ public final void setEOLMarkerColor(Color eolMarkerColor) { this.eolMarkerColor = eolMarkerColor; repaint(); } /** * Returns true if EOL markers are drawn, false otherwise. */ public final boolean getEOLMarkersPainted() { return eolMarkers; } /** * 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(); } /** * Returns the wrap guide color. */ public final Color getWrapGuideColor() { return wrapGuideColor; } /** * Sets the wrap guide color. * @param wrapGuideColor The wrap guide color */ public final void setWrapGuideColor(Color wrapGuideColor) { this.wrapGuideColor = wrapGuideColor; repaint(); } /** * Returns true if the wrap guide is drawn, false otherwise. */ public final boolean getWrapGuidePainted() { return wrapGuide; } /** * 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(); } /** * 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; textArea.getTextRenderer().configure(antiAlias,fracFontMetrics); } /** * Returns if anti-aliasing is enabled. * @since jEdit 3.2pre6 */ public boolean isAntiAliasEnabled() { return antiAlias; } /** * 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; textArea.getTextRenderer().configure(antiAlias,fracFontMetrics); } /** * Returns if fractional font metrics are enabled. * @since jEdit 3.2pre6 */ public boolean isFractionalFontMetricsEnabled() { return fracFontMetrics; } /** * Adds a custom highlight painter. * @param highlight The highlight */ public void addCustomHighlight(TextAreaHighlight highlight) { highlight.init(textArea,highlights); highlights = highlight; } /** * Returns the tool tip to display at the specified location. * @param evt The mouse event */ public String getToolTipText(MouseEvent evt) { if(maxLineLen != 0) { int wrapGuidePos = maxLineLen + textArea.getHorizontalOffset(); if(Math.abs(evt.getX() - wrapGuidePos) < 5) { return String.valueOf(textArea.getBuffer() .getProperty("maxLineLen")); } } if(highlights != null) return highlights.getToolTipText(evt); else return null; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -