com.borland.primetime.editor
Class MasterStyleContext
java.lang.Object
|
+--javax.swing.text.StyleContext
|
+--com.borland.primetime.editor.MasterStyleContext
- public class MasterStyleContext
- extends javax.swing.text.StyleContext
This class manages styles that are used to paint text within the editor.
In general, these styles are used to paint elements in a certain way
depending on syntax highlighting, code insight, or some other criteria.
New styles may be registered by addins, if they choose.
One important thing to note is that the editor is a source code editor,
thus it assumes that all styles will have the same font family and size,
though things such as bold and italic attributes may vary. As such,
modifying the font for this style context changes the settings for the
default style, which is referenced by every other style.
- See Also:
- Serialized Form
Inner classes inherited from class javax.swing.text.StyleContext |
javax.swing.text.StyleContext.NamedStyle,
javax.swing.text.StyleContext.SmallAttributeSet |
Fields inherited from class javax.swing.text.StyleContext |
DEFAULT_STYLE |
Method Summary |
javax.swing.text.Style |
addStyle(java.lang.String nm,
javax.swing.text.Style parent)
Adds a new style into the style hierarchy. |
MasterStyleContext |
createCopy()
|
java.awt.Font |
getFont(javax.swing.text.AttributeSet attr)
Get the font to use for a particular attribute set. |
java.awt.Font |
getFont(java.lang.String family,
int style,
int size)
Gets a new font. |
void |
setFontFamily(java.lang.String fontFamily)
Setting the font family changes the family for the default style, which all
of the other styles will pick up, unless they were explicitly set. |
void |
setFontSize(int fontSize)
Setting the font size changes the size for the default style, which all
of the other styles will pick up, unless they were explicitly set. |
Methods inherited from class javax.swing.text.StyleContext |
addAttribute,
addAttributes,
addChangeListener,
createLargeAttributeSet,
createSmallAttributeSet,
getBackground,
getCompressionThreshold,
getDefaultStyleContext,
getEmptySet,
getFontMetrics,
getForeground,
getStaticAttribute,
getStaticAttributeKey,
getStyle,
getStyleNames,
readAttributes,
readAttributeSet,
reclaim,
registerStaticAttributeKey,
removeAttribute,
removeAttributes,
removeAttributes,
removeChangeListener,
removeStyle,
toString,
writeAttributes,
writeAttributeSet |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
DISPLAY_NAME
public static final java.lang.String DISPLAY_NAME
- The key used for storing a short description for the action,
used for tooltip text.
sourceElements
public static java.util.ArrayList sourceElements
fontFamily
protected java.lang.String fontFamily
fontSize
protected int fontSize
fontSearch
protected MasterStyleContext.FontKey fontSearch
fontMap
protected java.util.HashMap fontMap
styleSuffix
protected java.lang.String[] styleSuffix
MasterStyleContext
public MasterStyleContext()
createCopy
public MasterStyleContext createCopy()
setFontFamily
public void setFontFamily(java.lang.String fontFamily)
- Setting the font family changes the family for the default style, which all
of the other styles will pick up, unless they were explicitly set.
- Parameters:
fontFamily
- The font family to use for the default style.
setFontSize
public void setFontSize(int fontSize)
- Setting the font size changes the size for the default style, which all
of the other styles will pick up, unless they were explicitly set.
- Parameters:
fontSize
- The size of the font for the default style.
addStyle
public javax.swing.text.Style addStyle(java.lang.String nm,
javax.swing.text.Style parent)
- Adds a new style into the style hierarchy. Style attributes
resolve from bottom up so an attribute specified in a child
will override an attribute specified in the parent.
For our purposes, we'll want to add the name of the style to our
ordered list of sourceElement names. We'll also want to initialize
both the bold and italic attributes of the style so that getting
the font style attributes of the style won't have to check the
resolve parent.
- Overrides:
- addStyle in class javax.swing.text.StyleContext
- Parameters:
nm
- the name of the style (must be unique within the
collection of named styles in the document). The name may
be null if the style is unnamed, but the caller is responsible
for managing the reference returned as an unnamed style can't
be fetched by name. An unnamed style may be useful for things
like character attribute overrides such as found in a style
run.parent
- the parent style. For this subclass, we'll set the
to the DEFAULT_STYLE if the specified parent is null.- Returns:
- the created style
getFont
public java.awt.Font getFont(javax.swing.text.AttributeSet attr)
- Get the font to use for a particular attribute set. For our purposes,
the font size and font family are the same through every style, so we'll
just used the saved values instead of having to look them up. Furthermore,
we only use PLAIN, BOLD, and ITALIC styles, so we won't bother to look up
underline, strikethrough, superscript, or subsript styles. This means that
we'll make a maxiumum of three hashmap fetches to get a font instead of
the older maximum of 13!
- Overrides:
- getFont in class javax.swing.text.StyleContext
- Parameters:
attr
- The Style to get the font for.- Returns:
- The Font to use for the specified style.
getFont
public java.awt.Font getFont(java.lang.String family,
int style,
int size)
- Gets a new font. This returns a Font from a cache
if a cached font exists. If not, a Font is added to
the cache. This is basically a low-level cache for
1.1 font features.
Note: This code was taken from javax.swing.text.StyleContext
because the font cache isn't accessible there.
- Overrides:
- getFont in class javax.swing.text.StyleContext
- Parameters:
family
- the font family (such as "Monospaced")style
- the style of the font (such as Font.PLAIN)size
- the point size >= 1- Returns:
- the new font