org.gjt.sp.jedit.textarea
Class TextAreaPainter

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--org.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 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.

Version:
$Id: TextAreaPainter.java,v 1.61 2003/02/15 01:09:21 spestov Exp $
Author:
Slava Pestov
See Also:
addExtension(TextAreaExtension), addExtension(int,TextAreaExtension), removeExtension(TextAreaExtension), TextAreaExtension, JEditTextArea, Serialized Form

Field Summary
static int BACKGROUND_LAYER
          Below selection layer.
static int BELOW_MOST_EXTENSIONS_LAYER
          Below most extensions layer.
static int BELOW_SELECTION_LAYER
          Below selection layer.
static int BRACKET_HIGHLIGHT_LAYER
          Bracket highlight layer.
static int DEFAULT_LAYER
          Default extension layer.
static int HIGHEST_LAYER
          Highest possible layer.
static int LINE_BACKGROUND_LAYER
          The line highlight and collapsed fold highlight layer.
static int LOWEST_LAYER
          The lowest possible layer.
static int SELECTION_LAYER
          Selection layer.
static int WRAP_GUIDE_LAYER
          Wrap guide layer.
 
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)
          Creates a new painter.
 
Method Summary
 void addExtension(int layer, TextAreaExtension extension)
          Adds a text area extension, which can perform custom painting and tool tip handling.
 void addExtension(TextAreaExtension extension)
          Adds a text area extension, which can perform custom painting and tool tip handling.
 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.
 TextAreaExtension[] getExtensions()
          Returns an array of registered text area extensions.
 boolean getFocusTraversalKeysEnabled()
          Makes the tab key work in Java 1.4.
 SyntaxStyle getFoldLineStyle()
          Returns the fold line style.
 java.awt.FontMetrics getFontMetrics()
          Returns the font metrics used by this component.
 java.awt.font.FontRenderContext getFontRenderContext()
          Returns the font render context.
 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.
 java.awt.Color getWrapGuideColor()
          Returns the wrap guide color.
 boolean isAntiAliasEnabled()
          Returns if anti-aliasing is enabled.
 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 isFractionalFontMetricsEnabled()
          Returns if fractional font metrics are enabled.
 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.
 boolean isWrapGuidePainted()
          Returns true if the wrap guide is drawn, false otherwise.
 float nextTabStop(float x, int tabOffset)
          Implementation of TabExpander interface.
 void paintComponent(java.awt.Graphics _gfx)
          Repaints the text.
 void removeExtension(TextAreaExtension extension)
          Removes a text area extension.
 void setAntiAliasEnabled(boolean antiAlias)
          Sets if anti-aliasing should be enabled.
 void setBlockCaretEnabled(boolean blockCaret)
          Sets if the caret should be drawn as a block, false otherwise.
 void setBounds(int x, int y, int width, int height)
          It is a bad idea to override this, but we need to get the component event before the first repaint.
 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 setFoldLineStyle(SyntaxStyle foldLineStyle)
          Sets the fold line style.
 void setFont(java.awt.Font font)
          Sets the font for this component.
 void setFractionalFontMetricsEnabled(boolean fracFontMetrics)
          Sets if fractional font metrics should be enabled.
 void setLineHighlightColor(java.awt.Color lineHighlightColor)
          Sets the line highlight color.
 void setLineHighlightEnabled(boolean lineHighlight)
          Enables or disables current line highlighting.
 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 wrapGuideColor)
          Sets the wrap guide color.
 void setWrapGuidePainted(boolean wrapGuide)
          Sets if the wrap guide is to be drawn.
 
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, paint, paintBorder, paintChildren, 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, 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, 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

LOWEST_LAYER

public static final int LOWEST_LAYER
The lowest possible layer.

Since:
jEdit 4.0pre4
See Also:
addExtension(int,TextAreaExtension), Constant Field Values

BACKGROUND_LAYER

public static final int BACKGROUND_LAYER
Below selection layer. The JDiff plugin will use this.

Since:
jEdit 4.0pre4
See Also:
addExtension(int,TextAreaExtension), Constant Field Values

LINE_BACKGROUND_LAYER

public static final int LINE_BACKGROUND_LAYER
The line highlight and collapsed fold highlight layer.

Since:
jEdit 4.0pre7
See Also:
addExtension(int,TextAreaExtension), Constant Field Values

BELOW_SELECTION_LAYER

public static final int BELOW_SELECTION_LAYER
Below selection layer.

Since:
jEdit 4.0pre4
See Also:
addExtension(int,TextAreaExtension), Constant Field Values

SELECTION_LAYER

public static final int SELECTION_LAYER
Selection layer. Most extensions will be above this layer, but some (eg, JDiff) will want to be below the selection.

Since:
jEdit 4.0pre4
See Also:
addExtension(int,TextAreaExtension), Constant Field Values

WRAP_GUIDE_LAYER

public static final int WRAP_GUIDE_LAYER
Wrap guide layer. Most extensions will be above this layer.

Since:
jEdit 4.0pre4
See Also:
Constant Field Values

BELOW_MOST_EXTENSIONS_LAYER

public static final int BELOW_MOST_EXTENSIONS_LAYER
Below most extensions layer.

Since:
jEdit 4.0pre4
See Also:
addExtension(int,TextAreaExtension), Constant Field Values

DEFAULT_LAYER

public static final int DEFAULT_LAYER
Default extension layer. This is above the wrap guide but below the bracket highlight.

Since:
jEdit 4.0pre4
See Also:
Constant Field Values

BRACKET_HIGHLIGHT_LAYER

public static final int BRACKET_HIGHLIGHT_LAYER
Bracket highlight layer. Most extensions will be below this layer.

Since:
jEdit 4.0pre4
See Also:
Constant Field Values

HIGHEST_LAYER

public static final int HIGHEST_LAYER
Highest possible layer.

Since:
jEdit 4.0pre4
See Also:
Constant Field Values
Constructor Detail

TextAreaPainter

public TextAreaPainter(JEditTextArea textArea)
Creates a new painter. Do not create instances of this class directly.

Method Detail

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)
It is a bad idea to override this, but we need to get the component event before the first repaint.

Overrides:
setBounds in class java.awt.Component

isManagingFocus

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

Overrides:
isManagingFocus in class javax.swing.JComponent

getFocusTraversalKeysEnabled

public boolean getFocusTraversalKeysEnabled()
Makes the tab key work in Java 1.4.

Overrides:
getFocusTraversalKeysEnabled in class java.awt.Component
Since:
jEdit 3.2pre4

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

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

getWrapGuideColor

public final java.awt.Color getWrapGuideColor()
Returns the wrap guide color.


setWrapGuideColor

public final void setWrapGuideColor(java.awt.Color wrapGuideColor)
Sets the wrap guide color.

Parameters:
wrapGuideColor - The wrap guide color

isWrapGuidePainted

public final boolean isWrapGuidePainted()
Returns true if the wrap guide is drawn, false otherwise.

Since:
jEdit 4.0pre4

setWrapGuidePainted

public final void setWrapGuidePainted(boolean wrapGuide)
Sets if the wrap guide is to be drawn.

Parameters:
wrapGuide - True if the wrap guide should be drawn, false otherwise

getFoldLineStyle

public final SyntaxStyle getFoldLineStyle()
Returns the fold line style.


setFoldLineStyle

public final void setFoldLineStyle(SyntaxStyle foldLineStyle)
Sets the fold line style.

Parameters:
foldLineStyle - The fold line style

setAntiAliasEnabled

public void setAntiAliasEnabled(boolean antiAlias)
Sets if anti-aliasing should be enabled. Has no effect when running on Java 1.1.

Since:
jEdit 3.2pre6

isAntiAliasEnabled

public boolean isAntiAliasEnabled()
Returns if anti-aliasing is enabled.

Since:
jEdit 3.2pre6

setFractionalFontMetricsEnabled

public void setFractionalFontMetricsEnabled(boolean fracFontMetrics)
Sets if fractional font metrics should be enabled. Has no effect when running on Java 1.1.

Since:
jEdit 3.2pre6

isFractionalFontMetricsEnabled

public boolean isFractionalFontMetricsEnabled()
Returns if fractional font metrics are enabled.

Since:
jEdit 3.2pre6

getFontRenderContext

public java.awt.font.FontRenderContext getFontRenderContext()
Returns the font render context.

Since:
jEdit 4.0pre4

addExtension

public void addExtension(TextAreaExtension extension)
Adds a text area extension, which can perform custom painting and tool tip handling.

Parameters:
extension - The extension
Since:
jEdit 4.0pre4

addExtension

public void addExtension(int layer,
                         TextAreaExtension extension)
Adds a text area extension, which can perform custom painting and tool tip handling.

Parameters:
layer - The layer to add the extension to. Note that more than extension can share the same layer.
extension - The extension
Since:
jEdit 4.0pre4

removeExtension

public void removeExtension(TextAreaExtension extension)
Removes a text area extension. It will no longer be asked to perform custom painting and tool tip handling.

Parameters:
extension - The extension
Since:
jEdit 4.0pre4

getExtensions

public TextAreaExtension[] getExtensions()
Returns an array of registered text area extensions. Useful for debugging purposes.

Since:
jEdit 4.1pre5

getToolTipText

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

Overrides:
getToolTipText in class javax.swing.JComponent
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.

Overrides:
setFont in class javax.swing.JComponent
Parameters:
font - The font

paintComponent

public void paintComponent(java.awt.Graphics _gfx)
Repaints the text.

Overrides:
paintComponent in class javax.swing.JComponent

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.

Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

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

Overrides:
getMinimumSize in class javax.swing.JComponent