com.borland.primetime.editor
Class BasicStyleMap

java.lang.Object
  |
  +--com.borland.primetime.editor.BasicStyleMap

public class BasicStyleMap
extends java.lang.Object

A BasicStyleMap keeps track of basic style names used by scanner implementations.

Each EditorDocument has an associated BasicStyleMap and matching Scanner. The Scanner fills in the EditorDocument.RunInfo structure, using constants from the BasicStyleMap (or subclass) to refer to particular Styles. When rendering the document, the EditorView uses the BasicStyleMap associated with the document to resolve the Style references into actual styles.

This class does not actually store the information for the styles it references; instead, they should be stored in the StyleContext retrieved from the EditorManager.

See Also:
AbstractScanner, EditorDocument, EditorView, Scanner, EditorManager

Field Summary
static int CARET
          The Caret style index
static java.lang.String CARET_KEY
          Internal name of the Caret element.
static int COMMENT
          The comment style index
protected  javax.swing.text.StyleContext context
          If context is null, the shared styleContext from the EditorManager is used to retrieve styles, otherwise this member is used.
static int DIFFADDITION
          The diff color that indicates an addition
static int DIFFDELETION
          The diff color that indicates a deletion
static int EXTRA_KEYWORD
          The extended keyword style index
static int IDENTIFIER
          The identifier style index
static int ILLEGAL
          The illegal element style index
static int INPUT_METHOD
          The input method style index
static java.lang.String INPUT_METHOD_KEY
          Internal name of the input method element.
static int MERGECONFLICT
          The merge conflict style index
static int NUMBER
          The number style index
static int PLAIN
          The plain text style index
static int PREPROCESSOR
          The preprocessor element style index
static int RESERVED_WORD
          The reserved word style index
static int SELECTION
          The selected text style index
static java.lang.String SELECTION_KEY
          Internal name of the selection element.
static int STRING
          The string style index
static int SYMBOL
          The symbol style index
static int TOTAL_BASIC_STYLES
          How many basic style elements are defined.
static int WHITESPACE
          The white space style index
static java.lang.String WHITESPACE_KEY
          Internal name of the white space element.
 
Constructor Summary
BasicStyleMap()
          The default constructor will leave member 'context' null, which causes the context to be retrieved from the EditorManager.
BasicStyleMap(javax.swing.text.StyleContext context)
          Create a new instance, using the specified context to resolve Styles.
 
Method Summary
static java.lang.String[] getElement(int index)
          Return the style name and attribute string of a member of the style element map.
 java.awt.Font getFont(javax.swing.text.AttributeSet attr)
          Get the Font for a particular AttributeSet (Style).
 javax.swing.text.Style getStyle(int styleType)
          Get a particular style by integer reference.
static void initOpenTool(byte majorVersion, byte minorVersion)
          Initialize the default BasicStyleMap by registering all of the styles we know about and storing them in the 'context' retrieved from the EditorManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected javax.swing.text.StyleContext context
If context is null, the shared styleContext from the EditorManager is used to retrieve styles, otherwise this member is used.

CARET

public static final int CARET
The Caret style index

SELECTION

public static final int SELECTION
The selected text style index

INPUT_METHOD

public static final int INPUT_METHOD
The input method style index

PLAIN

public static final int PLAIN
The plain text style index

WHITESPACE

public static final int WHITESPACE
The white space style index

COMMENT

public static final int COMMENT
The comment style index

RESERVED_WORD

public static final int RESERVED_WORD
The reserved word style index

IDENTIFIER

public static final int IDENTIFIER
The identifier style index

SYMBOL

public static final int SYMBOL
The symbol style index

STRING

public static final int STRING
The string style index

NUMBER

public static final int NUMBER
The number style index

EXTRA_KEYWORD

public static final int EXTRA_KEYWORD
The extended keyword style index

ILLEGAL

public static final int ILLEGAL
The illegal element style index

PREPROCESSOR

public static final int PREPROCESSOR
The preprocessor element style index

MERGECONFLICT

public static final int MERGECONFLICT
The merge conflict style index

DIFFADDITION

public static final int DIFFADDITION
The diff color that indicates an addition

DIFFDELETION

public static final int DIFFDELETION
The diff color that indicates a deletion

TOTAL_BASIC_STYLES

public static final int TOTAL_BASIC_STYLES
How many basic style elements are defined.

CARET_KEY

public static final java.lang.String CARET_KEY
Internal name of the Caret element.

SELECTION_KEY

public static final java.lang.String SELECTION_KEY
Internal name of the selection element.

INPUT_METHOD_KEY

public static final java.lang.String INPUT_METHOD_KEY
Internal name of the input method element.

WHITESPACE_KEY

public static final java.lang.String WHITESPACE_KEY
Internal name of the white space element.
Constructor Detail

BasicStyleMap

public BasicStyleMap()
The default constructor will leave member 'context' null, which causes the context to be retrieved from the EditorManager.

BasicStyleMap

public BasicStyleMap(javax.swing.text.StyleContext context)
Create a new instance, using the specified context to resolve Styles.
Method Detail

initOpenTool

public static void initOpenTool(byte majorVersion,
                                byte minorVersion)
Initialize the default BasicStyleMap by registering all of the styles we know about and storing them in the 'context' retrieved from the EditorManager. Subclasses should not reregister styles inherited from BasicStyleMap.
See Also:
EditorManager.getStyleContext()

getElement

public static java.lang.String[] getElement(int index)
Return the style name and attribute string of a member of the style element map.
Parameters:
index - The relevant element in the range 0 - (TOTAL_BASIC_STYLES-1)
Returns:
Returns an array with two strings: first string is the attribute name second string is the style name On error, returns an array of two "" strings.

getStyle

public javax.swing.text.Style getStyle(int styleType)
Get a particular style by integer reference. The View uses this when painting text using data stored in a EditorDocument.RunInfo structure. This function will only retrieve styles defined in BasicStyleMap, meaning styles with indices of 0 through (TOTAL_BASIC_STYLES-1). If a class is derived from BasicStyleMap, it should implement its own getStyle function which should either call BasicStyleMap.getStyle to retrieve the basic styles, or it should call BasicStyleMap.getElement repeatedly to add the basic elements to its own elementMap. By default, when context == null, the style context from the EditorManager is used to retrieve styles.
Parameters:
styleType - Style index in the range 0 - (TOTAL_BASIC_STYLES-1)
Returns:
the Style corresponding to the int type.

getFont

public java.awt.Font getFont(javax.swing.text.AttributeSet attr)
Get the Font for a particular AttributeSet (Style).
Parameters:
attr - The AttributeSet (Style) to get the font for.
Returns:
the font to use for the specified AttributeSet (Style).