📄 acltextareapainter.java
字号:
/******************************************************************
* JADE - Java Agent DEvelopment Framework is a framework to develop
* multi-agent systems in compliance with the FIPA specifications.
* Copyright (C) 2002 TILAB S.p.A.
*
* This file is donated by Acklin B.V. to the JADE project.
*
*
* GNU Lesser General Public License
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation,
* version 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* ***************************************************************/
package jade.tools.gui;
import java.awt.*;
import javax.swing.JComponent;
import javax.swing.text.*;
/**
* The text area repaint manager. It performs double buffering and paints
* lines of text.The original file is written by Slava Pestov (www.gjt.org)
* and altered to fit ACL/SL.
*
* @author Chris van Aart - Acklin B.V., the Netherlands & Slava Pestov
* @created June 14, 2002
*/
public class ACLTextAreaPainter extends JComponent implements TabExpander {
/**
* Creates a new repaint manager. This should be not be called directly.
*
* @param textArea Description of Parameter
*/
public ACLTextAreaPainter(ACLTextArea textArea) {
this.textArea = textArea;
currentLine = new Segment();
currentLineIndex = -1;
firstInvalid = lastInvalid = -1;
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
setFont(new Font("Dialog", Font.PLAIN, 11));
setForeground(Color.black);
setBackground(Color.white);
styles = ACLSyntaxUtilities.getDefaultSyntaxStyles(this);
cols = 80;
rows = 5;
caretColor = Color.red;
selectionColor = new Color(0xccccff);
lineHighlightColor = new Color(0xe0e0e0);
;
lineHighlight = true;
bracketHighlightColor = Color.black;
bracketHighlight = true;
eolMarkerColor = new Color(0x009999);
eolMarkers = true;
copyAreaBroken = true;
}
/**
* Returns if this component can be traversed by pressing the Tab key. This
* returns false.
*
* @return The ManagingFocus value
*/
public final boolean isManagingFocus() {
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> .
*
* @return The Styles value
* @see org.gjt.sp.jedit.syntax.Token
*/
public final ACLSytntaxStyle[] getStyles() {
return styles;
}
/**
* Returns the caret color.
*
* @return The CaretColor value
*/
public final Color getCaretColor() {
return caretColor;
}
/**
* Returns the selection color.
*
* @return The SelectionColor value
*/
public final Color getSelectionColor() {
return selectionColor;
}
/**
* Returns the line highlight color.
*
* @return The LineHighlightColor value
*/
public final Color getLineHighlightColor() {
return lineHighlightColor;
}
/**
* Returns true if line highlight is enabled, false otherwise.
*
* @return The LineHighlightEnabled value
*/
public final boolean isLineHighlightEnabled() {
return lineHighlight;
}
/**
* Returns the bracket highlight color.
*
* @return The BracketHighlightColor value
*/
public final Color getBracketHighlightColor() {
return bracketHighlightColor;
}
/**
* 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.
*
* @return The BracketHighlightEnabled value
*/
public final boolean isBracketHighlightEnabled() {
return bracketHighlight;
}
/**
* Returns true if the caret should be drawn as a block, false otherwise.
*
* @return The BlockCaretEnabled value
*/
public final boolean isBlockCaretEnabled() {
return blockCaret;
}
/**
* Returns the EOL marker color.
*
* @return The EOLMarkerColor value
*/
public final Color getEOLMarkerColor() {
return eolMarkerColor;
}
/**
* Returns true if EOL markers are drawn, false otherwise.
*
* @return The EOLMarkerEnabled value
*/
public final boolean isEOLMarkerEnabled() {
return eolMarkers;
}
/**
* 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(ACLSytntaxStyle[] styles) {
this.styles = styles;
invalidateOffscreen();
repaint();
}
/**
* Sets the caret color.
*
* @param caretColor The caret color
*/
public final void setCaretColor(Color caretColor) {
this.caretColor = caretColor;
invalidateSelectedLines();
}
/**
* Sets the selection color.
*
* @param selectionColor The selection color
*/
public final void setSelectionColor(Color selectionColor) {
this.selectionColor = selectionColor;
invalidateSelectedLines();
}
/**
* Sets the line highlight color.
*
* @param lineHighlightColor The line highlight color
*/
public final void setLineHighlightColor(Color lineHighlightColor) {
this.lineHighlightColor = lineHighlightColor;
invalidateSelectedLines();
}
/**
* 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;
invalidateSelectedLines();
}
/**
* Sets the bracket highlight color.
*
* @param bracketHighlightColor The bracket highlight color
*/
public final void setBracketHighlightColor(Color bracketHighlightColor) {
this.bracketHighlightColor = bracketHighlightColor;
invalidateLine(textArea.getBracketLine());
}
/**
* 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;
invalidateLine(textArea.getBracketLine());
}
/**
* 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;
invalidateSelectedLines();
}
/**
* Sets the EOL marker color.
*
* @param eolMarkerColor The EOL marker color
*/
public final void setEOLMarkerColor(Color eolMarkerColor) {
this.eolMarkerColor = eolMarkerColor;
invalidateOffscreen();
repaint();
}
/**
* Sets if EOL markers are to be drawn.
*
* @param eolMarkers True if EOL markers should be dranw, false otherwise
*/
public final void setEOLMarkerEnabled(boolean eolMarkers) {
this.eolMarkers = eolMarkers;
invalidateOffscreen();
repaint();
}
/**
* Queues a repaint of the changed lines only.
*/
public final void fastRepaint() {
if (firstInvalid == -1 && lastInvalid == -1) {
repaint();
}
else {
repaint(0, textArea.lineToY(firstInvalid)
+ fm.getLeading() + fm.getMaxDescent(),
getWidth(), (lastInvalid - firstInvalid + 1)
* fm.getHeight());
}
}
/**
* Repaints the specified line. This is equivalent to calling <code>_invalidateLine()</code>
* and <code>repaint()</code>.
*
* @param line The line
* @see #_invalidateLine(int)
*/
public final void invalidateLine(int line) {
_invalidateLine(line);
fastRepaint();
}
/**
* Repaints the specified line range. This is equivalent to calling <code>_invalidateLineRange()</code>
* then <code>repaint()</code>.
*
* @param firstLine The first line to repaint
* @param lastLine The last line to repaint
*/
public final void invalidateLineRange(int firstLine, int lastLine) {
_invalidateLineRange(firstLine, lastLine);
fastRepaint();
}
/**
* Repaints the lines containing the selection.
*/
public final void invalidateSelectedLines() {
invalidateLineRange(textArea.getSelectionStartLine(),
textArea.getSelectionEndLine());
}
/**
* Invalidates the offscreen graphics context. This should not be called
* directly.
*/
public final void invalidateOffscreen() {
offImg = null;
offGfx = null;
}
/**
* Returns the font metrics used by this component.
*
* @return The FontMetrics value
*/
public FontMetrics getFontMetrics() {
return fm;
}
/**
* Returns if the copyArea() should not be used.
*
* @return The CopyAreaBroken value
*/
public boolean isCopyAreaBroken() {
return copyAreaBroken;
}
/**
* Returns the painter's preferred size.
*
* @return The PreferredSize value
*/
public Dimension getPreferredSize() {
return super.getPreferredSize();
/*
Dimension dim = new Dimension();
dim.width = fm.charWidth('w') * cols;
dim.height = fm.getHeight() * rows;
return dim;
*/
}
/**
* Returns the painter's minimum size.
*
* @return The MinimumSize value
*/
public Dimension getMinimumSize() {
return super.getMinimumSize();
}
/**
* Sets the font for this component. This is overridden to update the
* cached font metrics and to recalculate which lines are visible.
*
* @param font The font
*/
public void setFont(Font font) {
super.setFont(font);
fm = textArea.getFontMetrics(font);
textArea.recalculateVisibleLines();
}
/**
* Disables the use of the copyArea() function (which is broken in JDK
* 1.2).
*
* @param copyAreaBroken The new CopyAreaBroken value
*/
public void setCopyAreaBroken(boolean copyAreaBroken) {
this.copyAreaBroken = copyAreaBroken;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -