SMACS

smacs.xngr.browser.editor
Class XmlView

java.lang.Object
  extended byjavax.swing.text.View
      extended byjavax.swing.text.PlainView
          extended bysmacs.xngr.browser.editor.XmlView
All Implemented Interfaces:
SwingConstants, TabExpander

public class XmlView
extends PlainView

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

Note: The XML 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/

Author:
Edwin Dankert

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
XmlView(XmlContext context, Element elem)
          Construct a colorized view of xml text for the element.
 
Method Summary
protected  int drawSelectedText(Graphics g, int x, int y, int start, int end)
          Renders the given range in the model as selected text.
protected  int drawUnselectedText(Graphics g, int x, int y, int start, int end)
          Renders the given range in the model as normal unselected text.
 void paint(Graphics g, Shape a)
          Invalidates the scanner, to make sure a new range is set later.
 
Methods inherited from class javax.swing.text.PlainView
changedUpdate, damageLineRange, drawLine, getLineBuffer, getPreferredSpan, getTabSize, insertUpdate, lineToRect, modelToView, nextTabStop, removeUpdate, setSize, updateDamage, updateMetrics, viewToModel
 
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

XmlView

public XmlView(XmlContext context,
               Element elem)
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.
Method Detail

paint

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

See Also:
PlainView.paint(Graphics,Shape)

drawUnselectedText

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

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:
BadLocationException - if the range is invalid

drawSelectedText

protected int drawSelectedText(Graphics g,
                               int x,
                               int y,
                               int start,
                               int end)
                        throws 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..

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:
BadLocationException - if the range is invalid

SMACS