org.gjt.sp.jedit.textarea
Class TextAreaPainter

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byorg.gjt.sp.jedit.textarea.TextAreaPainter
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.text.TabExpander

public class TextAreaPainter
extends javax.swing.JComponent
implements javax.swing.text.TabExpander

The text area repaint manager. It performs double buffering and paints lines of text.

Version:
$Id: TextAreaPainter.java,v 1.7 2003/03/03 19:09:25 gfx Exp $
Author:
Slava Pestov
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.awt.RenderingHints ANTI_ALIASED_RENDERING
           
protected  boolean blockCaret
           
protected  boolean bracketHighlight
           
protected  java.awt.Color bracketHighlightColor
           
protected  java.awt.Color caretColor
           
protected  int cols
           
static java.awt.RenderingHints DEFAULT_RENDERING
           
protected  java.awt.Color eolMarkerColor
           
protected  boolean eolMarkers
           
protected  TextAreaHighlight firstPriorityHighlights
           
protected  java.awt.FontMetrics fm
           
protected  java.awt.Color highlightColor
           
protected  TextAreaHighlight highlights
           
protected  boolean lineHighlight
           
protected  java.awt.Color lineHighlightColor
           
protected  boolean paintInvalid
           
protected  int rows
           
protected  java.awt.Color selectionColor
           
protected  SyntaxStyle[] styles
           
protected  int tabSize
           
protected  JEditTextArea textArea
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TextAreaPainter(JEditTextArea textArea, TextAreaDefaults defaults)
          Creates a new repaint manager.
 
Method Summary
 void addCustomFirstPriorityHighlight(TextAreaHighlight highlight)
          Adds a custom first priority highlight painter.
 void addCustomHighlight(TextAreaHighlight highlight)
          Adds a custom highlight painter.
 java.awt.Color getBracketHighlightColor()
          Returns the bracket highlight color.
 java.awt.Color getCaretColor()
          Returns the caret color.
 java.awt.Color getEOLMarkerColor()
          Returns the EOL marker color.
 boolean getEOLMarkersPainted()
          Returns true if EOL markers are drawn, false otherwise.
 java.awt.FontMetrics getFontMetrics()
          Returns the font metrics used by this component.
 java.awt.Color getHighlightColor()
          Returns the highlight color.
 boolean getInvalidLinesPainted()
          Returns true if invalid lines are painted as red tildes (~), false otherwise.
 java.awt.Color getLineHighlightColor()
          Returns the line highlight color.
 java.awt.Dimension getMinimumSize()
          Returns the painter's minimum size.
 java.awt.Dimension getPreferredSize()
          Returns the painter's preferred size.
 java.awt.Color getSelectionColor()
          Returns the selection color.
 SyntaxStyle[] getStyles()
          Returns the syntax styles used to paint colorized text.
 java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
          Returns the tool tip to display at the specified location.
 void invalidateLine(int line)
          Marks a line as needing a repaint.
 void invalidateLineRange(int firstLine, int lastLine)
          Marks a range of lines as needing a repaint.
 void invalidateSelectedLines()
          Repaints the lines containing the selection.
 boolean isAntiAliasingEnabled()
           
 boolean isBlockCaretEnabled()
          Returns true if the caret should be drawn as a block, false otherwise.
 boolean isBracketHighlightEnabled()
          Returns true if bracket highlighting is enabled, false otherwise.
 boolean isLineHighlightEnabled()
          Returns true if line highlight is enabled, false otherwise.
 boolean isManagingFocus()
          Returns if this component can be traversed by pressing the Tab key.
 float nextTabStop(float x, int tabOffset)
          Implementation of TabExpander interface.
 void paint(java.awt.Graphics gfx)
          Repaints the text.
protected  void paintBracketHighlight(java.awt.Graphics gfx, int line, int y)
           
protected  void paintCaret(java.awt.Graphics gfx, int line, int y)
           
protected  void paintHighlight(java.awt.Graphics gfx, int line, int y)
           
protected  int paintLine(java.awt.Graphics gfx, TokenMarker tokenMarker, boolean valid, int line, int x)
           
protected  void paintLineHighlight(java.awt.Graphics gfx, int line, int y)
           
protected  void paintLinesInterval(java.awt.Graphics gfx, int line, int y)
           
protected  void paintShadowCaret(java.awt.Graphics gfx, int line, int y)
           
protected  int paintSyntaxLine(java.awt.Graphics gfx, TokenMarker tokenMarker, int line, java.awt.Font defaultFont, java.awt.Color defaultColor, int x, int y)
           
protected  void paintWrapGuide(java.awt.Graphics gfx, int line, int y)
           
 void setAntiAliasingEnabled(boolean on)
           
 void setBlockCaretEnabled(boolean blockCaret)
          Sets if the caret should be drawn as a block, false otherwise.
 void setBracketHighlightColor(java.awt.Color bracketHighlightColor)
          Sets the bracket highlight color.
 void setBracketHighlightEnabled(boolean bracketHighlight)
          Enables or disables bracket highlighting.
 void setCaretColor(java.awt.Color caretColor)
          Sets the caret color.
 void setEOLMarkerColor(java.awt.Color eolMarkerColor)
          Sets the EOL marker color.
 void setEOLMarkersPainted(boolean eolMarkers)
          Sets if EOL markers are to be drawn.
 void setFont(java.awt.Font font)
          Sets the font for this component.
 void setHighlightColor(java.awt.Color highlightColor)
          Sets the highlight color.
 void setInvalidLinesPainted(boolean paintInvalid)
          Sets if invalid lines are to be painted as red tildes.
 void setLineHighlightColor(java.awt.Color lineHighlightColor)
          Sets the line highlight color.
 void setLineHighlightEnabled(boolean lineHighlight)
          Enables or disables current line highlighting.
 void setLinesInterval(int offset)
           
 void setLinesIntervalHighlightColor(java.awt.Color color)
           
 void setLinesIntervalHighlightEnabled(boolean enabled)
           
 void setSelectionColor(java.awt.Color selectionColor)
          Sets the selection color.
 void setStyles(SyntaxStyle[] styles)
          Sets the syntax styles used to paint colorized text.
 void setWrapGuideColor(java.awt.Color color)
           
 void setWrapGuideEnabled(boolean enabled)
           
 void setWrapGuideOffset(int offset)
           
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANTI_ALIASED_RENDERING

public static java.awt.RenderingHints ANTI_ALIASED_RENDERING

DEFAULT_RENDERING

public static java.awt.RenderingHints DEFAULT_RENDERING

textArea

protected JEditTextArea textArea

styles

protected SyntaxStyle[] styles

caretColor

protected java.awt.Color caretColor

selectionColor

protected java.awt.Color selectionColor

lineHighlightColor

protected java.awt.Color lineHighlightColor

highlightColor

protected java.awt.Color highlightColor

bracketHighlightColor

protected java.awt.Color bracketHighlightColor

eolMarkerColor

protected java.awt.Color eolMarkerColor

blockCaret

protected boolean blockCaret

lineHighlight

protected boolean lineHighlight

bracketHighlight

protected boolean bracketHighlight

paintInvalid

protected boolean paintInvalid

eolMarkers

protected boolean eolMarkers

cols

protected int cols

rows

protected int rows

tabSize

protected int tabSize

fm

protected java.awt.FontMetrics fm

highlights

protected TextAreaHighlight highlights

firstPriorityHighlights

protected TextAreaHighlight firstPriorityHighlights
Constructor Detail

TextAreaPainter

public TextAreaPainter(JEditTextArea textArea,
                       TextAreaDefaults defaults)
Creates a new repaint manager. This should be not be called directly.

Method Detail

isAntiAliasingEnabled

public boolean isAntiAliasingEnabled()

setAntiAliasingEnabled

public void setAntiAliasingEnabled(boolean on)

setWrapGuideEnabled

public void setWrapGuideEnabled(boolean enabled)

setWrapGuideOffset

public void setWrapGuideOffset(int offset)

setWrapGuideColor

public void setWrapGuideColor(java.awt.Color color)

setLinesIntervalHighlightEnabled

public void setLinesIntervalHighlightEnabled(boolean enabled)

setLinesInterval

public void setLinesInterval(int offset)

setLinesIntervalHighlightColor

public void setLinesIntervalHighlightColor(java.awt.Color color)

isManagingFocus

public final boolean isManagingFocus()
Returns if this component can be traversed by pressing the Tab key. This returns false.


getStyles

public final SyntaxStyle[] getStyles()
Returns the syntax styles used to paint colorized text. Entry n will be used to paint tokens with id = n.

See Also:
Token

setStyles

public final void setStyles(SyntaxStyle[] styles)
Sets the syntax styles used to paint colorized text. Entry n will be used to paint tokens with id = n.

Parameters:
styles - The syntax styles
See Also:
Token

getCaretColor

public final java.awt.Color getCaretColor()
Returns the caret color.


setCaretColor

public final void setCaretColor(java.awt.Color caretColor)
Sets the caret color.

Parameters:
caretColor - The caret color

getSelectionColor

public final java.awt.Color getSelectionColor()
Returns the selection color.


setSelectionColor

public final void setSelectionColor(java.awt.Color selectionColor)
Sets the selection color.

Parameters:
selectionColor - The selection color

getHighlightColor

public final java.awt.Color getHighlightColor()
Returns the highlight color.


setHighlightColor

public final void setHighlightColor(java.awt.Color highlightColor)
Sets the highlight color.

Parameters:
highlightColor - The highlight color

getLineHighlightColor

public final java.awt.Color getLineHighlightColor()
Returns the line highlight color.


setLineHighlightColor

public final void setLineHighlightColor(java.awt.Color lineHighlightColor)
Sets the line highlight color.

Parameters:
lineHighlightColor - The line highlight color

isLineHighlightEnabled

public final boolean isLineHighlightEnabled()
Returns true if line highlight is enabled, false otherwise.


setLineHighlightEnabled

public final void setLineHighlightEnabled(boolean lineHighlight)
Enables or disables current line highlighting.

Parameters:
lineHighlight - True if current line highlight should be enabled, false otherwise

getBracketHighlightColor

public final java.awt.Color getBracketHighlightColor()
Returns the bracket highlight color.


setBracketHighlightColor

public final void setBracketHighlightColor(java.awt.Color bracketHighlightColor)
Sets the bracket highlight color.

Parameters:
bracketHighlightColor - The bracket highlight color

isBracketHighlightEnabled

public final boolean isBracketHighlightEnabled()
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.


setBracketHighlightEnabled

public final void setBracketHighlightEnabled(boolean bracketHighlight)
Enables or disables bracket highlighting. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.

Parameters:
bracketHighlight - True if bracket highlighting should be enabled, false otherwise

isBlockCaretEnabled

public final boolean isBlockCaretEnabled()
Returns true if the caret should be drawn as a block, false otherwise.


setBlockCaretEnabled

public final void setBlockCaretEnabled(boolean blockCaret)
Sets if the caret should be drawn as a block, false otherwise.

Parameters:
blockCaret - True if the caret should be drawn as a block, false otherwise.

getEOLMarkerColor

public final java.awt.Color getEOLMarkerColor()
Returns the EOL marker color.


setEOLMarkerColor

public final void setEOLMarkerColor(java.awt.Color eolMarkerColor)
Sets the EOL marker color.

Parameters:
eolMarkerColor - The EOL marker color

getEOLMarkersPainted

public final boolean getEOLMarkersPainted()
Returns true if EOL markers are drawn, false otherwise.


setEOLMarkersPainted

public final void setEOLMarkersPainted(boolean eolMarkers)
Sets if EOL markers are to be drawn.

Parameters:
eolMarkers - True if EOL markers should be drawn, false otherwise

getInvalidLinesPainted

public boolean getInvalidLinesPainted()
Returns true if invalid lines are painted as red tildes (~), false otherwise.


setInvalidLinesPainted

public void setInvalidLinesPainted(boolean paintInvalid)
Sets if invalid lines are to be painted as red tildes.

Parameters:
paintInvalid - True if invalid lines should be drawn, false otherwise

addCustomHighlight

public void addCustomHighlight(TextAreaHighlight highlight)
Adds a custom highlight painter.

Parameters:
highlight - The highlight

addCustomFirstPriorityHighlight

public void addCustomFirstPriorityHighlight(TextAreaHighlight highlight)
Adds a custom first priority highlight painter.

Parameters:
highlight - The highlight

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
Returns the tool tip to display at the specified location.

Parameters:
evt - The mouse event

getFontMetrics

public java.awt.FontMetrics getFontMetrics()
Returns the font metrics used by this component.


setFont

public void setFont(java.awt.Font font)
Sets the font for this component. This is overridden to update the cached font metrics and to recalculate which lines are visible.

Parameters:
font - The font

paint

public void paint(java.awt.Graphics gfx)
Repaints the text.


invalidateLine

public final void invalidateLine(int line)
Marks a line as needing a repaint.

Parameters:
line - The line to invalidate

invalidateLineRange

public final void invalidateLineRange(int firstLine,
                                      int lastLine)
Marks a range of lines as needing a repaint.

Parameters:
firstLine - The first line to invalidate
lastLine - The last line to invalidate

invalidateSelectedLines

public final void invalidateSelectedLines()
Repaints the lines containing the selection.


nextTabStop

public float nextTabStop(float x,
                         int tabOffset)
Implementation of TabExpander interface. Returns next tab stop after a specified point.

Specified by:
nextTabStop in interface javax.swing.text.TabExpander
Parameters:
x - The x co-ordinate
tabOffset - Ignored
Returns:
The next tab stop after x

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the painter's preferred size.


getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the painter's minimum size.


paintLine

protected int paintLine(java.awt.Graphics gfx,
                        TokenMarker tokenMarker,
                        boolean valid,
                        int line,
                        int x)

paintSyntaxLine

protected int paintSyntaxLine(java.awt.Graphics gfx,
                              TokenMarker tokenMarker,
                              int line,
                              java.awt.Font defaultFont,
                              java.awt.Color defaultColor,
                              int x,
                              int y)

paintHighlight

protected void paintHighlight(java.awt.Graphics gfx,
                              int line,
                              int y)

paintWrapGuide

protected void paintWrapGuide(java.awt.Graphics gfx,
                              int line,
                              int y)

paintLinesInterval

protected void paintLinesInterval(java.awt.Graphics gfx,
                                  int line,
                                  int y)

paintLineHighlight

protected void paintLineHighlight(java.awt.Graphics gfx,
                                  int line,
                                  int y)

paintBracketHighlight

protected void paintBracketHighlight(java.awt.Graphics gfx,
                                     int line,
                                     int y)

paintCaret

protected void paintCaret(java.awt.Graphics gfx,
                          int line,
                          int y)

paintShadowCaret

protected void paintShadowCaret(java.awt.Graphics gfx,
                                int line,
                                int y)


Copyright © 2002 Romain Guy.