edu.rice.cs.drjava.model.definitions
Class ColoringView

java.lang.Object
  |
  +--javax.swing.text.View
        |
        +--javax.swing.text.PlainView
              |
              +--edu.rice.cs.drjava.model.definitions.ColoringView
All Implemented Interfaces:
OptionConstants, SwingConstants, TabExpander

public class ColoringView
extends PlainView
implements OptionConstants

This view class renders text on the screen using the reduced model info. By extending WrappedPlainView, we only have to override the parts we want to. Here we only override drawUnselectedText. We may want to override drawSelectedText at some point. As of 2002/06/17, we now extend PlainView because WrappedPlainView was causing bugs related to resizing the viewport of the definitions scroll pane.

Version:
$Id: ColoringView.java,v 1.9 2002/09/02 21:24:11 csreis Exp $

Inner Class Summary
private  class ColoringView.ColorOptionListener
          The OptionListeners for DEFINITIONS COLORs
 
Field Summary
private  DefinitionsDocument _doc
           
private static Color COMMENTED_COLOR
           
private static Color DOUBLE_QUOTED_COLOR
           
private static Color KEYWORD_COLOR
           
private static Color NORMAL_COLOR
           
private static Color NUMBER_COLOR
           
private static Color SINGLE_QUOTED_COLOR
           
private static Color TYPE_COLOR
           
 
Fields inherited from class javax.swing.text.PlainView
font, lineBuffer, longLine, metrics, sel0, sel1, selected, tabBase, tabSize, unselected
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, elem, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, parent, sharedBiasReturn, X_AXIS, Y_AXIS
 
Fields inherited from interface edu.rice.cs.drjava.config.OptionConstants
COMPILER_ERROR_COLOR, DEBUG_BREAKPOINT_COLOR, DEBUG_SHOW_THREADS, DEBUG_SOURCEPATH, DEBUG_STEP_DRJAVA, DEBUG_STEP_INTERPRETER, DEBUG_STEP_JAVA, DEBUG_THREAD_COLOR, DEFINITIONS_BACKGROUND_COLOR, DEFINITIONS_COMMENT_COLOR, DEFINITIONS_DOUBLE_QUOTED_COLOR, DEFINITIONS_KEYWORD_COLOR, DEFINITIONS_MATCH_COLOR, DEFINITIONS_NORMAL_COLOR, DEFINITIONS_NUMBER_COLOR, DEFINITIONS_SINGLE_QUOTED_COLOR, DEFINITIONS_TYPE_COLOR, EXTRA_CLASSPATH, FONT_DOCLIST, FONT_MAIN, FONT_TOOLBAR, HISTORY_MAX_SIZE, INDENT_LEVEL, INTERACTIONS_EXIT_PROMPT, JAVAC_ALLOW_ASSERT, JAVAC_LOCATION, JSR14_COLLECTIONSPATH, JSR14_LOCATION, KEY_BACKWARD, KEY_BEGIN_DOCUMENT, KEY_BEGIN_LINE, KEY_CLOSE_FILE, KEY_COMPILE, KEY_COMPILE_ALL, KEY_COPY, KEY_CUT, KEY_CUT_LINE, KEY_DEBUG_BREAKPOINT_TOGGLE, KEY_DEBUG_MODE_TOGGLE, KEY_DEBUG_RESUME, KEY_DEBUG_STEP_INTO, KEY_DEBUG_STEP_OUT, KEY_DEBUG_STEP_OVER, KEY_DELETE_NEXT, KEY_DELETE_PREVIOUS, KEY_DOWN, KEY_END_DOCUMENT, KEY_END_LINE, KEY_FIND_NEXT, KEY_FIND_REPLACE, KEY_FORWARD, KEY_GOTO_LINE, KEY_NEW_FILE, KEY_NEXT_DOCUMENT, KEY_NEXT_WORD, KEY_OPEN_FILE, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_PREVIOUS_DOCUMENT, KEY_PREVIOUS_WORD, KEY_PRINT, KEY_PRINT_PREVIEW, KEY_QUIT, KEY_REDO, KEY_SAVE_FILE, KEY_SAVE_FILE_AS, KEY_SELECT_ALL, KEY_UNDO, KEY_UP, LINEENUM_ENABLED, mask, QUIT_PROMPT, RECENT_FILES, RECENT_FILES_MAX_SIZE, TOOLBAR_ICONS_ENABLED, TOOLBAR_TEXT_ENABLED, WORKING_DIRECTORY
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NORTH, NORTH_EAST, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
(package private) ColoringView(Element elem)
          Constructor.
 
Method Summary
 void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f)
          Called when a change occurs.
protected  int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
          put your documentation comment here
protected  int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
          Renders the given range in the model as normal unselected text.
private  void setFormattingForState(Graphics g, int state)
          Given a particular state, assign it a color.
 void updateColors()
          Called when an OptionListener perceives a change in any of the colors
 
Methods inherited from class javax.swing.text.PlainView
adjustPaintRegion, calculateLongestLine, damageLineRange, drawElement, drawLine, getLineBuffer, getLineWidth, getPreferredSpan, getTabSize, insertUpdate, lineToRect, modelToView, nextTabStop, paint, removeUpdate, 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, getView, getViewCount, getViewFactory, getViewIndex, insert, isVisible, modelToView, modelToView, preferenceChanged, remove, removeAll, replace, setParent, setSize, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

_doc

private DefinitionsDocument _doc

COMMENTED_COLOR

private static Color COMMENTED_COLOR

DOUBLE_QUOTED_COLOR

private static Color DOUBLE_QUOTED_COLOR

SINGLE_QUOTED_COLOR

private static Color SINGLE_QUOTED_COLOR

NORMAL_COLOR

private static Color NORMAL_COLOR

KEYWORD_COLOR

private static Color KEYWORD_COLOR

NUMBER_COLOR

private static Color NUMBER_COLOR

TYPE_COLOR

private static Color TYPE_COLOR
Constructor Detail

ColoringView

ColoringView(Element elem)
Constructor.
Parameters:
Element - elem
Method Detail

drawUnselectedText

protected int drawUnselectedText(Graphics g,
                                 int x,
                                 int y,
                                 int p0,
                                 int p1)
                          throws BadLocationException
Renders the given range in the model as normal unselected text. Note that this is text that's all on one line. The superclass deals with breaking lines and such. So all we have to do here is draw the text on [p0,p1) in the model. We have to start drawing at (x,y), and the function returns the x coordinate when we're done.
Overrides:
drawUnselectedText in class PlainView
Parameters:
g - the graphics context
x - the starting X coordinate
y - the starting Y coordinate
p0 - the beginning position in the model
p1 - the ending position in the model
Throws:
BadLocationException - if the range is invalid

drawSelectedText

protected int drawSelectedText(Graphics g,
                               int x,
                               int y,
                               int p0,
                               int p1)
                        throws BadLocationException
put your documentation comment here
Overrides:
drawSelectedText in class PlainView
Parameters:
g -  
x -  
y -  
p0 -  
p1 -  
Returns:
 
Throws:
BadLocationException -  

setFormattingForState

private void setFormattingForState(Graphics g,
                                   int state)
Given a particular state, assign it a color.
Parameters:
g - Graphics object
state - a given state

changedUpdate

public void changedUpdate(DocumentEvent changes,
                          Shape a,
                          ViewFactory f)
Called when a change occurs.
Overrides:
changedUpdate in class PlainView
Parameters:
changes - document changes
a - a Shape
f - a ViewFactory

updateColors

public void updateColors()
Called when an OptionListener perceives a change in any of the colors