de.hunsicker.jalopy.swing.syntax
Class SyntaxView

java.lang.Object
  |
  +--javax.swing.text.View
        |
        +--javax.swing.text.PlainView
              |
              +--de.hunsicker.jalopy.swing.syntax.SyntaxView
All Implemented Interfaces:
javax.swing.SwingConstants, javax.swing.text.TabExpander

public final class SyntaxView
extends javax.swing.text.PlainView

A Swing view implementation that colorizes lines of a SyntaxDocument using a TokenMarker. This class should not be used directly; a SyntaxEditorKit should be used instead.

Version:
$Id: SyntaxView.java,v 1.3.2.2 2005/02/18 21:50:20 notzippy Exp $
Author:
Slava Pestov, Bruce Quig, Michael Kolling

Field Summary
 
Fields inherited from class javax.swing.text.PlainView
metrics
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
SyntaxView(javax.swing.text.Element elem)
          Creates a new SyntaxView for painting the specified element.
 
Method Summary
 void drawLine(int lineIndex, java.awt.Graphics g, int x, int y)
          Paints the specified line.
protected  java.awt.Color getDefaultColor()
          Return default foreground colour
 java.awt.Rectangle lineToRect(java.awt.Shape a, int aline)
          redefined from PlainView private method to allow for redefinition of modelToView method
 java.awt.Shape modelToView(int pos, java.awt.Shape a, javax.swing.text.Position.Bias b)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 float nextTabStop(float x, int tabOffset)
          Returns the next tab stop position after a given reference position.
 int viewToModel(float fx, float fy, java.awt.Shape a, javax.swing.text.Position.Bias[] bias)
          Provides a mapping from the view coordinate space to the logical coordinate space of the model.
 
Methods inherited from class javax.swing.text.PlainView
changedUpdate, damageLineRange, drawSelectedText, drawUnselectedText, getLineBuffer, getPreferredSpan, getTabSize, insertUpdate, paint, removeUpdate, setSize, updateDamage, updateMetrics
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, getNextVisualPositionFrom, getParent, getResizeWeight, getStartOffset, getToolTipText, getView, getViewCount, getViewFactory, getViewIndex, getViewIndex, insert, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, replace, setParent, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyntaxView

public SyntaxView(javax.swing.text.Element elem)
Creates a new SyntaxView for painting the specified element.

Parameters:
elem - The element
Method Detail

drawLine

public void drawLine(int lineIndex,
                     java.awt.Graphics g,
                     int x,
                     int y)
Paints the specified line. This method performs the following: - Gets the token marker and color table from the current document, typecast to a SyntaxDocument. - Tokenizes the required line by calling the markTokens() method of the token marker. - Paints each token, obtaining the color by looking up the the Token.id value in the color table. If either the document doesn't implement SyntaxDocument, or if the returned token marker is null, the line will be painted with no colorization. Currently, we assume that the whole document uses the same font. To support font changes, some of the code from "initilise" needs to be here to be done repeatedly for each line.

Overrides:
drawLine in class javax.swing.text.PlainView
Parameters:
lineIndex - The line number
g - The graphics context
x - The x co-ordinate where the line should be painted
y - The y co-ordinate where the line should be painted

lineToRect

public java.awt.Rectangle lineToRect(java.awt.Shape a,
                                     int aline)
redefined from PlainView private method to allow for redefinition of modelToView method

Overrides:
lineToRect in class javax.swing.text.PlainView
Parameters:
a - DOCUMENT ME!
aline - DOCUMENT ME!
Returns:
DOCUMENT ME!

modelToView

public java.awt.Shape modelToView(int pos,
                                  java.awt.Shape a,
                                  javax.swing.text.Position.Bias b)
                           throws javax.swing.text.BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. This is a redefined method from PlainView that adds an offset for the view to allow for a breakpoint area in the associated editor.

Overrides:
modelToView in class javax.swing.text.PlainView
Parameters:
pos - the position to convert >= 0
a - the allocated region to render into
b - DOCUMENT ME!
Returns:
the bounding box of the given position
Throws:
javax.swing.text.BadLocationException - if the given position does not represent a valid location in the associated document
See Also:
View#modelToView

nextTabStop

public float nextTabStop(float x,
                         int tabOffset)
Returns the next tab stop position after a given reference position. This implementation does not support things like centering so it ignores the tabOffset argument.

Specified by:
nextTabStop in interface javax.swing.text.TabExpander
Overrides:
nextTabStop in class javax.swing.text.PlainView
Parameters:
x - the current position >= 0
tabOffset - the position within the text stream that the tab occurred at >= 0.
Returns:
the tab stop, measured in points >= 0

viewToModel

public int viewToModel(float fx,
                       float fy,
                       java.awt.Shape a,
                       javax.swing.text.Position.Bias[] bias)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Overrides:
viewToModel in class javax.swing.text.PlainView
Parameters:
fx - the X coordinate >= 0
fy - the Y coordinate >= 0
a - the allocated region to render into
bias - DOCUMENT ME!
Returns:
the location within the model that best represents the given point in the view >= 0
See Also:
View#viewToModel

getDefaultColor

protected java.awt.Color getDefaultColor()
Return default foreground colour

Returns:
DOCUMENT ME!


Copyright © 1997-2005 Jalopy. All Rights Reserved.