Get Bounce at SourceForge.net. Fast secure and Free Open Source software downloads

org.bounce.text
Class SyntaxHighlightingView

java.lang.Object
  extended by javax.swing.text.View
      extended by javax.swing.text.PlainView
          extended by org.bounce.text.FoldingPlainView
              extended by org.bounce.text.SyntaxHighlightingView
All Implemented Interfaces:
javax.swing.SwingConstants, javax.swing.text.TabExpander
Direct Known Subclasses:
XMLView

public abstract class SyntaxHighlightingView
extends FoldingPlainView

The View uses the syntax highlighting scanner to determine the style (font, color) of the text that it renders.

Note: The Editor package is based on the JavaEditorKit example as described in the article 'Customizing a Text Editor' by Timothy Prinzing . See: http://java.sun.com/products/jfc/tsc/articles/text/editor_kit/

Version:
$Revision: 1.4 $, $Date: 2008/04/16 19:36:18 $
Author:
Edwin Dankert

Field Summary
 
Fields inherited from class org.bounce.text.FoldingPlainView
firstLineOffset, font, lineBuffer, longLine, metrics, sel0, sel1, tabBase, tabSize, unselected
 
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
SyntaxHighlightingView(SyntaxHighlightingScanner scanner, javax.swing.text.StyleContext context, javax.swing.text.Element elem)
          Construct a colorized view of xml text for the element.
 
Method Summary
protected  int drawSelectedText(java.awt.Graphics g, int x, int y, int start, int end)
          Renders the given range in the model as selected text.
protected  int drawUnselectedText(java.awt.Graphics g, int x, int y, int start, int end)
          Renders the given range in the model as normal unselected text.
static int getFontStyle(javax.swing.text.Style style)
          Fetch the font to use for a lexical token with the given scan value.
protected abstract  boolean isErrorHighlighting()
           
 void paint(java.awt.Graphics g, java.awt.Shape a)
          Invalidates the scanner, to make sure a new range is set later.
protected abstract  void updateScanner(SyntaxHighlightingScanner scanner, javax.swing.text.Document doc, int start, int end)
           
 
Methods inherited from class org.bounce.text.FoldingPlainView
calculateLongestLine, changedUpdate, damageLineRange, drawLine, getNextVisualPositionFrom, getPreferredSpan, insertUpdate, lineToRect, modelToView, nextTabStop, removeUpdate, setSize, updateDamage, updateMetrics, viewToModel
 
Methods inherited from class javax.swing.text.PlainView
getLineBuffer, getTabSize
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getChildAllocation, getContainer, getDocument, getElement, getEndOffset, getGraphics, getMaximumSpan, getMinimumSpan, 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

SyntaxHighlightingView

public SyntaxHighlightingView(SyntaxHighlightingScanner scanner,
                              javax.swing.text.StyleContext context,
                              javax.swing.text.Element elem)
                       throws java.io.IOException
Construct a colorized view of xml text for the element. Gets the current document and creates a new Scanner object.

Parameters:
context - the styles used to colorize the view.
elem - the element to create the view for.
Throws:
java.io.IOException - input/output exception while reading document
Method Detail

paint

public void paint(java.awt.Graphics g,
                  java.awt.Shape a)
Invalidates the scanner, to make sure a new range is set later.

Overrides:
paint in class FoldingPlainView
Parameters:
g - the graphics context.
a - the shape.
See Also:
View.paint(Graphics g, Shape a)

drawUnselectedText

protected int drawUnselectedText(java.awt.Graphics g,
                                 int x,
                                 int y,
                                 int start,
                                 int end)
                          throws javax.swing.text.BadLocationException
Renders the given range in the model as normal unselected text. This will paint the text according to the styles..

Overrides:
drawUnselectedText in class FoldingPlainView
Parameters:
g - the graphics context
x - the starting X coordinate
y - the starting Y coordinate
start - the beginning position in the model
end - the ending position in the model
Returns:
the location of the end of the range
Throws:
javax.swing.text.BadLocationException - if the range is invalid

isErrorHighlighting

protected abstract boolean isErrorHighlighting()

drawSelectedText

protected int drawSelectedText(java.awt.Graphics g,
                               int x,
                               int y,
                               int start,
                               int end)
                        throws javax.swing.text.BadLocationException
Renders the given range in the model as selected text. This will paint the text according to the font as found in the styles..

Overrides:
drawSelectedText in class FoldingPlainView
Parameters:
g - the graphics context
x - the starting X coordinate
y - the starting Y coordinate
start - the beginning position in the model
end - the ending position in the model
Returns:
the location of the end of the range
Throws:
javax.swing.text.BadLocationException - if the range is invalid

updateScanner

protected abstract void updateScanner(SyntaxHighlightingScanner scanner,
                                      javax.swing.text.Document doc,
                                      int start,
                                      int end)

getFontStyle

public static int getFontStyle(javax.swing.text.Style style)
Fetch the font to use for a lexical token with the given scan value.

Parameters:
style - the style.
Returns:
the font style

Get Bounce at SourceForge.net. Fast secure and Free Open Source software downloads

Copyright 2002-2002-2009 Edwin Dankert. All Rights Reserved.