kawigi.editor
Class CPPView

java.lang.Object
  extended by javax.swing.text.View
      extended by javax.swing.text.PlainView
          extended by kawigi.editor.GenericView
              extended by kawigi.editor.CPPView
All Implemented Interfaces:
javax.swing.SwingConstants, javax.swing.text.TabExpander

public class CPPView
extends GenericView

C++ Implementation of a View that takes care of syntax hilighting when rendering text.


Field Summary
protected static java.util.Hashtable<java.lang.String,java.awt.Color> colorHash
          A map from token to its color.
 
Fields inherited from class kawigi.editor.GenericView
classColor, commentColor, directiveColor, highlightKey1, highlightKey2, keywordColor, lineIndex, operatorColor, parseIndex, stringColor, tagColor, typeColor
 
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
CPPView(javax.swing.text.Element e)
          Creates a new C++ View to render this Element.
 
Method Summary
protected  int drawSelectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
          Overridden from PlainView - this method gets called to render every element of selected text, so that I could change how it's displayed if I want.
protected  int drawTabbedText(java.lang.String s, int x, int y, java.awt.Graphics g, int startOffset, boolean selected, boolean inComment)
          Renders the text segment onto the given Grapnics context.
protected  int drawUnselectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
          Overridden from PlainView - this method gets called to render every element of unselected text.
protected  java.awt.Color getColor(java.lang.String word)
          Returns the color to use on the given token.
 java.util.ArrayList<Interval> getIntervals()
          Extension of the generic getIntervals() method that includes compiler directive matches.
static void initColors()
          Initializes the keywords/tokens and their colors.
 
Methods inherited from class kawigi.editor.GenericView
findIntervals, findName, getColors, getTabSize, paint, readKeywords, resetTabStop, updateDamage
 
Methods inherited from class javax.swing.text.PlainView
changedUpdate, damageLineRange, drawLine, getLineBuffer, getPreferredSpan, insertUpdate, lineToRect, modelToView, nextTabStop, removeUpdate, setSize, 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
 

Field Detail

colorHash

protected static java.util.Hashtable<java.lang.String,java.awt.Color> colorHash
A map from token to its color.

Constructor Detail

CPPView

public CPPView(javax.swing.text.Element e)
Creates a new C++ View to render this Element.

Method Detail

initColors

public static void initColors()
Initializes the keywords/tokens and their colors. What this basically does is calls GenericView.getColors and GenericView.readKeywords. It is called when the class is loaded and any time when the color settings might have changed.


drawUnselectedText

protected int drawUnselectedText(java.awt.Graphics g,
                                 int x,
                                 int y,
                                 int p0,
                                 int p1)
                          throws javax.swing.text.BadLocationException
Overridden from PlainView - this method gets called to render every element of unselected text.

Overrides:
drawUnselectedText in class javax.swing.text.PlainView
Throws:
javax.swing.text.BadLocationException

drawSelectedText

protected int drawSelectedText(java.awt.Graphics g,
                               int x,
                               int y,
                               int p0,
                               int p1)
                        throws javax.swing.text.BadLocationException
Overridden from PlainView - this method gets called to render every element of selected text, so that I could change how it's displayed if I want.

Overrides:
drawSelectedText in class javax.swing.text.PlainView
Throws:
javax.swing.text.BadLocationException

drawTabbedText

protected int drawTabbedText(java.lang.String s,
                             int x,
                             int y,
                             java.awt.Graphics g,
                             int startOffset,
                             boolean selected,
                             boolean inComment)
Renders the text segment onto the given Grapnics context. Originally, this looked a lot like drawTabbedText in the javax.swing.text.Utilities class with a little bit of tokenizing, but now it's pretty much modified to my own style. Unfortunately, at some point in time, my indentation got all weird (probably as a result of me using tabs and the original implementation mixing spaces and tabs), so there may be some weird-looking parts left in the code. It's possible that I'll eventually change this to work differently with compiler directives. This is the magic of my syntax hilighting in C++.


getColor

protected java.awt.Color getColor(java.lang.String word)
Returns the color to use on the given token. This will return the default foreground color, if no special color is assigned to that token.


getIntervals

public java.util.ArrayList<Interval> getIntervals()
Extension of the generic getIntervals() method that includes compiler directive matches.

Overrides:
getIntervals in class GenericView