Class TextView
All Packages Class Hierarchy This Package Previous Next Index
Class TextView
public class netscape.application.TextView
extends netscape.application.View
implements netscape.application.ExtendedTarget,
netscape.application.EventFilter,
netscape.application.DragDestination
{
/* Fields
*/
public final static java.lang.String CARET_COLOR_KEY;
public final static java.lang.String FONT_KEY;
public final static java.lang.String LINK_COLOR_KEY;
public final static java.lang.String LINK_DESTINATION_KEY;
public final static java.lang.String LINK_KEY;
public final static java.lang.String PARAGRAPH_FORMAT_KEY;
public final static java.lang.String PRESSED_LINK_COLOR_KEY;
public final static java.lang.String TEXT_ATTACHMENT_BASELINE_OFFSET_KEY;
public final static java.lang.String TEXT_ATTACHMENT_KEY;
public final static java.lang.String TEXT_ATTACHMENT_STRING;
public final static java.lang.String TEXT_COLOR_KEY;
/* Constructors
*/
public TextView();
public TextView(Rect);
public TextView(int, int, int, int);
/* Methods
*/
public static String stringWithoutCarriageReturns(String);
public DragDestination acceptsDrag(DragSession, int, int);
public void addAttributeForRange(String, Object, Range);
public void addAttributesForRange(Hashtable, Range);
public void addDefaultAttribute(String, Object);
public Range appendString(String);
public Hashtable attributesAtIndex(int);
public Color backgroundColor();
public boolean canPerformCommand(String);
public Color caretColor();
public int cursorForPoint(int, int);
public void decode(Decoder);
public Hashtable defaultAttributes();
public void describeClassInfo(ClassInfo);
public void didMoveBy(int, int);
public void didSizeBy(int, int);
public void disableResizing();
public boolean dragDropped(DragSession);
public boolean dragEntered(DragSession);
public void dragExited(DragSession);
public boolean dragMoved(DragSession);
public void drawView(Graphics);
public void enableResizing();
public void encode(Encoder);
public TextFilter filter();
public Object filterEvents(Vector);
public void finishDecoding();
public Font font();
public boolean hasSelection();
public void importHTMLFromURLString(String);
public void importHTMLInRange(InputStream, Range, URL);
public int indexForPoint(int, int);
public boolean isEditable();
public boolean isResizingEnabled();
public boolean isSelectable();
public boolean isTransparent();
public void keyDown(KeyEvent);
public int length();
public boolean mouseDown(MouseEvent);
public void mouseDragged(MouseEvent);
public void mouseUp(MouseEvent);
public TextViewOwner owner();
public Range paragraphForIndex(int);
public Range paragraphForPoint(int, int);
public Vector paragraphsForRange(Range);
public void pauseFocus();
public void performCommand(String, Object);
public Vector rectsForRange(Range);
public void removeAttributeForRange(String, Range);
public void replaceRangeWithString(Range, String);
public void replaceRangeWithTextAttachment(Range, TextAttachment);
public void resumeFocus();
public Range runForIndex(int);
public Range runForPoint(int, int);
public Range runWithLinkDestinationNamed(String);
public Vector runsForRange(Range);
public void scrollRangeToVisible(Range);
public void selectRange(Range);
public Range selectedRange();
public Color selectionColor();
public void setAttributesForRange(Hashtable, Range);
public void setBackgroundColor(Color);
public void setCaretColor(Color);
public void setDefaultAttributes(Hashtable);
public void setEditable(boolean);
public void setFilter(TextFilter);
public void setFont(Font);
public void setOwner(TextViewOwner);
public void setSelectable(boolean);
public void setSelectionColor(Color);
public void setString(String);
public void setTextColor(Color);
public void setTransparent(boolean);
public void setUseSingleFont(boolean);
public void sizeBy(int, int);
public void sizeToMinSize();
public void startFocus();
public void stopFocus();
public String string();
public String stringForRange(Range);
public Color textColor();
public String toString();
public boolean usesSingleFont();
public boolean wantsAutoscrollEvents();
}
View subclass that displays zero or more paragraphs of multi-font text
or embedded Images. TextView stores the displayed text as a collection
of Strings and a Hashtable that describes the attributes associated with
each String. Each Hashtable applies to a character range. A character
range containing the same attributes is called a "run." Paragraphs
are defined as collections of runs ending with a carriage return.
Any attribute can be associated with a character range, however
TextView defines some special attributes that are interpreted by the
layout engine when formatting and displaying the text. When one or more
characters are inserted into the TextView by typing or by using the
insertion methods, the following rules apply to determine how attributes
apply to the new ranges:
- If there is a run after the inserted range, the inserted characters'
attributes will be defaultAttributes() UNION the following run's
attributes.
- If a run appears before the inserted range, the inserted characters'
attributes will be defaultAttributes() UNION the previous run's
attributes.
- If the previous two conditions don't apply, the inserted characters'
attributes will be defaultAttributes().
Fields
TEXT_ATTACHMENT_STRING
public final static String TEXT_ATTACHMENT_STRING
- String used to store a TextAttachment instance in the text.
- See Also:
- TextAttachment
PARAGRAPH_FORMAT_KEY
public final static String PARAGRAPH_FORMAT_KEY
- ParagraphFormat attribute. Value is a ParagraphFormat instance.
FONT_KEY
public final static String FONT_KEY
- Font attribute. Value is a Font instance.
TEXT_COLOR_KEY
public final static String TEXT_COLOR_KEY
- TextColor attribute. Value is a Color instance.
TEXT_ATTACHMENT_KEY
public final static String TEXT_ATTACHMENT_KEY
- TextAttachment attribute. A TextAttachment is an attachment, and this
attribute is generally set on a single character. The character will be
replaced by the TextAttachment
TEXT_ATTACHMENT_BASELINE_OFFSET_KEY
public final static String TEXT_ATTACHMENT_BASELINE_OFFSET_KEY
- TextAttachment baseline offset attribute. The value of this attribute
is the distance between the bottom of the attachment and the text
baseline. This attribute makes sense only when used with
TEXT_ATTACHMENT_KEY. The distance is stored as an
Integer instance and is a number of pixels.
The default value of this attribute is 0.
CARET_COLOR_KEY
public final static String CARET_COLOR_KEY
- Caret Color attribute.
LINK_KEY
public final static String LINK_KEY
- "Link" attribute. A range that has this attribute will tell the
TextViewLinkObserver
to follow the link when the users clicks the region. The value is a
string, containing an URL.
LINK_DESTINATION_KEY
public final static String LINK_DESTINATION_KEY
- Local link destination attribute. A range that has this attribute
will be marked as the destination a link. The value is the link's
name.
LINK_COLOR_KEY
public final static String LINK_COLOR_KEY
- Link color attribute. Usually, you use this attribute
only on the default attribute. You can however use it on a single link.
PRESSED_LINK_COLOR_KEY
public final static String PRESSED_LINK_COLOR_KEY
- Link pressed attribute.
Constructors
TextView
public TextView()
- Constructs a TextView.
TextView
public TextView(Rect rect)
- Constructs a TextView with bounds rect.
TextView
public TextView(int x,
int y,
int width,
int height)
- Constructs a TextView with bounds
(x, y, width, height).
Methods
didMoveBy
public void didMoveBy(int deltaX,
int deltaY)
- Overridden to take special action when the TextView moves.
- Overrides:
- didMoveBy in class View
sizeBy
public void sizeBy(int deltaWidth,
int deltaHeight)
- Overridden to catch size changes.
- Overrides:
- sizeBy in class View
didSizeBy
public void didSizeBy(int dw,
int dh)
- Overridden to catch size changes.
- Overrides:
- didSizeBy in class View
setTransparent
public void setTransparent(boolean flag)
- Sets the TextView to be transparent or opaque.
isTransparent
public boolean isTransparent()
- Overridden to return true if the TextView is transparent.
- Overrides:
- isTransparent in class View
- See Also:
- setTransparent
wantsAutoscrollEvents
public boolean wantsAutoscrollEvents()
- Overridden to return true - TextViews can be autoscrolled.
- Overrides:
- wantsAutoscrollEvents in class View
drawView
public void drawView(Graphics g)
- Draws the TextView's contents.
- Overrides:
- drawView in class View
filterEvents
public Object filterEvents(Vector events)
- Implemented to allow TextViews to remove KeyEvents from the
EventLoop.
mouseDown
public boolean mouseDown(MouseEvent event)
- Overridden to handle mouse clicks within the TextView.
- Overrides:
- mouseDown in class View
mouseDragged
public void mouseDragged(MouseEvent event)
- Overridden to handle mouse drags within the TextView.
- Overrides:
- mouseDragged in class View
mouseUp
public void mouseUp(MouseEvent event)
- Overridden to handle mouse up Events within the TextView.
- Overrides:
- mouseUp in class View
cursorForPoint
public int cursorForPoint(int x,
int y)
- Overridden to return TEXT_CURSOR when the TextView is
selectable or editable.
- Overrides:
- cursorForPoint in class View
performCommand
public void performCommand(String command,
Object data)
- Implements TextView's commands. You should never
call this method.
canPerformCommand
public boolean canPerformCommand(String command)
- Implemented so that TextView can participate in the TargetChain.
- See Also:
- ExtendedTarget
keyDown
public void keyDown(KeyEvent event)
- Overridden so that TextView can receive KeyEvents.
- Overrides:
- keyDown in class View
acceptsDrag
public DragDestination acceptsDrag(DragSession session,
int x,
int y)
- Overridden to let TextViews accepts drags of Colors and Images.
- Overrides:
- acceptsDrag in class View
dragEntered
public boolean dragEntered(DragSession session)
- DragDestination support method.
- See Also:
- dragEntered
dragMoved
public boolean dragMoved(DragSession session)
- DragDestination support method.
- See Also:
- dragMoved
dragExited
public void dragExited(DragSession session)
- DragDestination support method.
- See Also:
- dragExited
dragDropped
public boolean dragDropped(DragSession session)
- Drag and drop destination support method, called when the user
releases a DragSession's Image over the TextView. If the DragSession
represents a Color, changes the currently selected text's Color to that
Color. If the DragSession represents an Image, replaces the selected
text with the Image.
- See Also:
- dragExited
startFocus
public void startFocus()
- Focus management support method.
- Overrides:
- startFocus in class View
stopFocus
public void stopFocus()
- Focus management support method.
- Overrides:
- stopFocus in class View
pauseFocus
public void pauseFocus()
- Focus management support method.
- Overrides:
- pauseFocus in class View
resumeFocus
public void resumeFocus()
- Focus management support method.
- Overrides:
- resumeFocus in class View
toString
public String toString()
- Converts the TextView's contents to a String containing both the text
and its attributes.
- Overrides:
- toString in class View
setFilter
public void setFilter(TextFilter aFilter)
- Sets the TextView's filter, the object that examines each KeyEvent
the TextView receives.
filter
public TextFilter filter()
- Returns the TextView's text filter.
- See Also:
- setFilter
setOwner
public void setOwner(TextViewOwner owner)
- Sets the TextField's owner, the object that it notifies of important
events such as the selection changing.
- See Also:
- TextViewOwner
owner
public TextViewOwner owner()
- Returns the TextField's owner.
- See Also:
- setOwner
disableResizing
public void disableResizing()
- Disables TextView resizing. If you are about to perform several
changes to the TextView, call this method to disable the auto-resizing,
to avoid recomputing the TextView's size.
- See Also:
- enableResizing
enableResizing
public void enableResizing()
- Reenables TextView resizing. You should call sizeToMinSize()
to get the TextView to relayout its contents.
@see #disableResizing
isResizingEnabled
public boolean isResizingEnabled()
- Returns true if resizing is enabled.
- See Also:
- enableResizing, disableResizing
sizeToMinSize
public void sizeToMinSize()
- Calculates the minimum size needed to display the text and
resizes the TextView to this minimum size.
- Overrides:
- sizeToMinSize in class View
scrollRangeToVisible
public void scrollRangeToVisible(Range aRange)
- Scrolls the TextView so that aRange is visible.
setUseSingleFont
public void setUseSingleFont(boolean flag)
- If flag is true, TextView ignores all the font
attributes but the default one, which it uses to display the
text.
usesSingleFont
public boolean usesSingleFont()
- Returns true if the receiver uses a single font.
- See Also:
- setUseSingleFont
setDefaultAttributes
public void setDefaultAttributes(Hashtable attributes)
- Sets the default attributes used by the TextView when new text is
inserted.
defaultAttributes
public Hashtable defaultAttributes()
- Returns the default attributes.
- See Also:
- setDefaultAttributes
setBackgroundColor
public void setBackgroundColor(Color aColor)
- Sets the TextView's background Color.
backgroundColor
public Color backgroundColor()
- Returns the TextView's background Color.
- See Also:
- setBackgroundColor
setSelectionColor
public void setSelectionColor(Color aColor)
- Sets the TextView's selection Color.
selectionColor
public Color selectionColor()
- Returns the TextView's selection Color.
- See Also:
- setSelectionColor
setEditable
public void setEditable(boolean flag)
- Sets whether or not the TextView is editable.
isEditable
public boolean isEditable()
- Returns true if the TextView is editable.
- See Also:
- setEditable
setSelectable
public void setSelectable(boolean flag)
- Sets whether or not the TextView is selectable.
isSelectable
public boolean isSelectable()
- Returns true if the TextView is selectable.
- See Also:
- setSelectable
setFont
public void setFont(Font aFont)
- Sets the font associated with the default attributes.
font
public Font font()
- Returns the font associated with the default attributes.
- See Also:
- setFont
setTextColor
public void setTextColor(Color aColor)
- Sets the TextView's default text Color.
textColor
public Color textColor()
- Returns the TextView's default text Color.
- See Also:
- setTextColor
setCaretColor
public void setCaretColor(Color aColor)
- Sets the TextView's caret Color. Default is Color.black.
caretColor
public Color caretColor()
- Returns the TextView's caret Color.
- See Also:
- setCaretColor
replaceRangeWithString
public void replaceRangeWithString(Range r,
String aString)
- Replaces the string enclosed by r with aString. If
r is a null range, this method inserts aString into
the text. If aString is
null or "", this method removes the text defined by r.
The inserted text will have the attributes set for the first
index of the range. If the index is 0, default attributes will be used.
stringForRange
public String stringForRange(Range r)
- Returns the string included in r.
setAttributesForRange
public void setAttributesForRange(Hashtable attributes,
Range r)
- Sets the attributes for the Range r. attributes is a
Hashtable containing any attributes. TextView defines some special
attributes that it interprets when laying out and displaying the text.
attributesAtIndex
public Hashtable attributesAtIndex(int anIndex)
- Returns the attributes for the character at anIndex.
To determine the scope of the attributes, use
runRangeForCharacterAtIndex()
and paragraphRangeForCharacterAtIndex().
length
public int length()
- Returns the number of characters the TextView contains.
string
public String string()
- Returns the TextView's contents as a String.
setString
public void setString(String textString)
- Replaces all the text in the TextView with textString.
appendString
public Range appendString(String aString)
- Appends aString to the end of the TextView. Returns the range
of the inserted string.
replaceRangeWithTextAttachment
public void replaceRangeWithTextAttachment(Range r,
TextAttachment aTextAttachment)
- Replaces the string enclosed by r with a aTextAttachment.
Inserts an attachment character.
addAttributesForRange
public void addAttributesForRange(Hashtable attributes,
Range range)
- Adds attributes for the text in the Range range.
Merges the contents of attributes with the current attributes
of the range.
addAttributeForRange
public void addAttributeForRange(String attribute,
Object value,
Range range)
- Adds the attribute attribute with value value to the
Range range.
removeAttributeForRange
public void removeAttributeForRange(String attribute,
Range r)
- Removes the attribute attribute from the Range r.
addDefaultAttribute
public void addDefaultAttribute(String attribute,
Object value)
- Adds the attribute attribute with value value to the
default attributes.
runsForRange
public Vector runsForRange(Range aRange)
- Decomposes aRange into a Vector of ranges. Each Range represents
a run. The Vector includes the left-most and right-most Ranges, even
if they are not fully included in aRange.
paragraphsForRange
public Vector paragraphsForRange(Range aRange)
- Decomposes aRange into a Vector of Ranges, with each Range
representing a paragraph. The Vector includes the left-most and
right-most Ranges, even if they are not fully included in
aRange.
runForIndex
public Range runForIndex(int anIndex)
- Returns the run Range to which the character at anIndex belongs.
paragraphForIndex
public Range paragraphForIndex(int anIndex)
- Returns the paragraph Range to which the character at anIndex
belongs.
paragraphForPoint
public Range paragraphForPoint(int x,
int y)
- Returns the Range of the paragraph containing the point
(x, y).
runForPoint
public Range runForPoint(int x,
int y)
- Returns the Range of the run containing the point
(x, y).
indexForPoint
public int indexForPoint(int x,
int y)
- Returns the index of the character under the point
(x, y).
Returns -1 if there is no character under (x, y).
rectsForRange
public Vector rectsForRange(Range aRange)
- Returns the Vector of Rects enclosing aRange.
Rectangles are ordered from top to bottom.
If the Range length is null or the Range is completely out of bounds,
this method returns an empty Vector. If the Range is partially out of
bounds, this method returns the Rects for the intersection
of the given Range and the Range of the text.
selectedRange
public Range selectedRange()
- Returns the selected Range. Returns Range.nullRange() if no selection
exists.
selectRange
public void selectRange(Range aRange)
- Sets the selected Range. If aRange is Range.nullRange(),
removes the TextView's selection.
hasSelection
public boolean hasSelection()
- Returns true if the TextView has a selection.
importHTMLInRange
public void importHTMLInRange(InputStream inputStream,
Range aRange,
URL baseURL) throws IOException, HTMLParsingException
- Imports HTML from the stream inputStream, replacing the text
defined by aRange. If baseURL is null, only
absolute HTTP references will work for Images.
Supports HTML v1.0.
importHTMLFromURLString
public void importHTMLFromURLString(String urlString)
- Imports HTML from the URL urlString.
Scrolls the TextView to the top and sets the selection to (0, 0).
runWithLinkDestinationNamed
public Range runWithLinkDestinationNamed(String aName)
- Returns the Range of the run with the attribute
LINK_DESTINATION_KEY set to aName.
Returns a null Range if not found. Use scrollRangeToVisible()
to scroll the TextView to make the link destination visible.
describeClassInfo
public void describeClassInfo(ClassInfo info)
- Describes the TextView class' information.
- Overrides:
- describeClassInfo in class View
- See Also:
- describeClassInfo
encode
public void encode(Encoder encoder) throws CodingException
- Encodes the TextView instance.
- Overrides:
- encode in class View
- See Also:
- encode
decode
public void decode(Decoder decoder) throws CodingException
- Decodes the TextView instance.
- Overrides:
- decode in class View
- See Also:
- decode
finishDecoding
public void finishDecoding() throws CodingException
- Finishes the TextView instance decoding.
- Overrides:
- finishDecoding in class View
- See Also:
- finishDecoding
stringWithoutCarriageReturns
public static String stringWithoutCarriageReturns(String aString)
- Converts CR/LF to CR.
All Packages Class Hierarchy This Package Previous Next Index