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,
netscape.application.FormElement
{
/* Fields
*/
public final static String CARET_COLOR_KEY;
public final static String FONT_KEY;
public final static String LINK_COLOR_KEY;
public final static String LINK_DESTINATION_KEY;
public final static String LINK_KEY;
public final static String PARAGRAPH_FORMAT_KEY;
public final static String PRESSED_LINK_COLOR_KEY;
public final static String TEXT_ATTACHMENT_BASELINE_OFFSET_KEY;
public final static String TEXT_ATTACHMENT_KEY;
public final static String TEXT_ATTACHMENT_STRING;
public final static 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 void addTypingAttribute(String, Object);
public Range appendString(String);
public Hashtable attributesAtIndex(int);
public Color backgroundColor();
public java.net.URL baseURL();
public boolean canBecomeSelectedView();
public boolean canPerformCommand(String);
public Color caretColor();
public void copy();
public int cursorForPoint(int, int);
public void cut();
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 String formElementText();
public boolean hasSelection();
public HTMLParsingRules htmlParsingRules();
public void importHTMLFromURLString(String);
public void importHTMLInRange(InputStream, Range, URL);
public void importHTMLInRange(InputStream, Range, URL, Hashtable);
public int indexForPoint(int, int);
public void insertHTMLElementsInRange(Vector, Range, Hashtable);
public boolean isEditable();
public boolean isResizingEnabled();
public boolean isSelectable();
public boolean isTransparent();
public void keyDown(KeyEvent);
public void keyTyped(KeyEvent);
public int length();
public int lineCount();
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 paste();
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 setBaseURL(URL);
public void setCaretColor(Color);
public void setDefaultAttributes(Hashtable);
public void setEditable(boolean);
public void setFilter(TextFilter);
public void setFont(Font);
public void setHTMLParsingRules(HTMLParsingRules);
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 setTypingAttributes(Hashtable);
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 Hashtable typingAttributes();
public boolean usesSingleFont();
public boolean wantsAutoscrollEvents();
public void willBecomeSelected();
}
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().
Finally, if some typingAttributes have been set, typing attributes are
applied to what have been typed. Typing attributes are used only once,
after the normal attributes propagation mechanism applies.
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
This attributes is static. It is not propagated while typing and
cannot be used as a typing attribute.
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.
This attributes is static. It is not propagated while typing and
cannot be used as a typing attribute.
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
TextViewOwner
to follow the link when the users clicks the region. The value is a
string, containing an URL.
This attributes is static. It is not propagated while typing and
cannot be used as a typing attribute.
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.
This attributes is static. It is not propagated while typing and
cannot be used as a typing attribute.
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
public void didMoveBy(int deltaX,
int deltaY)
- Overridden to take special action when the TextView moves.
- Overrides:
- didMoveBy in class View
public void sizeBy(int deltaWidth,
int deltaHeight)
- Overridden to catch size changes.
- Overrides:
- sizeBy in class View
public void didSizeBy(int dw,
int dh)
- Overridden to catch size changes.
- Overrides:
- didSizeBy in class View
public void setTransparent(boolean flag)
- Sets the TextView to be transparent or opaque.
public boolean isTransparent()
- Overridden to return true if the TextView is transparent.
- Overrides:
- isTransparent in class View
- See Also:
- setTransparent
public boolean wantsAutoscrollEvents()
- Overridden to return true - TextViews can be autoscrolled.
- Overrides:
- wantsAutoscrollEvents in class View
public void drawView(Graphics g)
- Draws the TextView's contents.
- Overrides:
- drawView in class View
public Object filterEvents(Vector events)
- Implemented to allow TextViews to remove KeyEvents from the
EventLoop.
public boolean mouseDown(MouseEvent event)
- Overridden to handle mouse clicks within the TextView.
- Overrides:
- mouseDown in class View
public void mouseDragged(MouseEvent event)
- Overridden to handle mouse drags within the TextView.
- Overrides:
- mouseDragged in class View
public void mouseUp(MouseEvent event)
- Overridden to handle mouse up Events within the TextView.
- Overrides:
- mouseUp in class View
public int cursorForPoint(int x,
int y)
- Overridden to return TEXT_CURSOR when the TextView is
selectable or editable.
- Overrides:
- cursorForPoint in class View
public void performCommand(String command,
Object data)
- Implements TextView's commands. You should never
call this method.
public boolean canPerformCommand(String command)
- Implemented so that TextView can participate in the TargetChain.
- See Also:
- ExtendedTarget
public void keyDown(KeyEvent event)
- Overridden so that TextView can receive KeyEvents.
- Overrides:
- keyDown in class View
public void keyTyped(KeyEvent event)
- Overridden so that TextView can receive KeyEvents.
- Overrides:
- keyTyped in class View
public DragDestination acceptsDrag(DragSession session,
int x,
int y)
- Overridden to let TextViews accepts drags of Colors and Images.
- Overrides:
- acceptsDrag in class View
public boolean dragEntered(DragSession session)
- DragDestination support method.
- See Also:
- dragEntered
public boolean dragMoved(DragSession session)
- DragDestination support method.
- See Also:
- dragMoved
public void dragExited(DragSession session)
- DragDestination support method.
- See Also:
- dragExited
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
public void startFocus()
- Focus management support method.
- Overrides:
- startFocus in class View
public void stopFocus()
- Focus management support method.
- Overrides:
- stopFocus in class View
public void pauseFocus()
- Focus management support method.
- Overrides:
- pauseFocus in class View
public void resumeFocus()
- Focus management support method.
- Overrides:
- resumeFocus in class View
public String toString()
- Converts the TextView's contents to a String containing both the text
and its attributes.
- Overrides:
- toString in class View
public void setFilter(TextFilter aFilter)
- Sets the TextView's filter, the object that examines each KeyEvent
the TextView receives.
public TextFilter filter()
- Returns the TextView's text filter.
- See Also:
- setFilter
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
public TextViewOwner owner()
- Returns the TextField's owner.
- See Also:
- setOwner
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
public void enableResizing()
- Reenables TextView resizing. You should call sizeToMinSize()
to get the TextView to relayout its contents.
@see #disableResizing
public boolean isResizingEnabled()
- Returns true if resizing is enabled.
- See Also:
- enableResizing, disableResizing
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
public void scrollRangeToVisible(Range aRange)
- Scrolls the TextView so that aRange is visible.
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.
public boolean usesSingleFont()
- Returns true if the receiver uses a single font.
- See Also:
- setUseSingleFont
public void setDefaultAttributes(Hashtable attributes)
- Sets the default attributes used by the TextView when new text is
inserted.
public Hashtable defaultAttributes()
- Returns the default attributes.
- See Also:
- setDefaultAttributes
public void addTypingAttribute(String key,
Object value)
- Add an attribute into typingAttributes.
When the user types some character, attributes into typingAttributes
are added.
public Hashtable typingAttributes()
- Return the current typing attributes
public void setTypingAttributes(Hashtable attr)
- Set the typing attributes.
public void setBackgroundColor(Color aColor)
- Sets the TextView's background Color.
public Color backgroundColor()
- Returns the TextView's background Color.
- See Also:
- setBackgroundColor
public void setSelectionColor(Color aColor)
- Sets the TextView's selection Color.
public Color selectionColor()
- Returns the TextView's selection Color.
- See Also:
- setSelectionColor
public void setEditable(boolean flag)
- Sets whether or not the TextView is editable.
public boolean isEditable()
- Returns true if the TextView is editable.
- See Also:
- setEditable
public void setSelectable(boolean flag)
- Sets whether or not the TextView is selectable.
public boolean isSelectable()
- Returns true if the TextView is selectable.
- See Also:
- setSelectable
public void setFont(Font aFont)
- Sets the font associated with the default attributes.
public Font font()
- Returns the font associated with the default attributes.
- See Also:
- setFont
public void setTextColor(Color aColor)
- Sets the TextView's default text Color.
public Color textColor()
- Returns the TextView's default text Color.
- See Also:
- setTextColor
public void setCaretColor(Color aColor)
- Sets the TextView's caret Color. Default is Color.black.
public Color caretColor()
- Returns the TextView's caret Color.
- See Also:
- setCaretColor
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.
public String stringForRange(Range r)
- Returns the string included in r.
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.
public Hashtable attributesAtIndex(int anIndex)
- Returns the attributes for the character at anIndex.
To determine the scope of the attributes, use
runRangeForCharacterAtIndex()
and paragraphRangeForCharacterAtIndex().
public int length()
- Returns the number of characters the TextView contains.
public String string()
- Returns the TextView's contents as a String.
public void setString(String textString)
- Replaces all the text in the TextView with textString.
public Range appendString(String aString)
- Appends aString to the end of the TextView. Returns the range
of the inserted string.
public void replaceRangeWithTextAttachment(Range r,
TextAttachment aTextAttachment)
- Replaces the string enclosed by r with a aTextAttachment.
Inserts an attachment character.
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.
public void addAttributeForRange(String attribute,
Object value,
Range range)
- Adds the attribute attribute with value value to the
Range range.
public void removeAttributeForRange(String attribute,
Range r)
- Removes the attribute attribute from the Range r.
public void addDefaultAttribute(String attribute,
Object value)
- Adds the attribute attribute with value value to the
default attributes.
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.
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.
public Range runForIndex(int anIndex)
- Returns the run Range to which the character at anIndex belongs.
public Range paragraphForIndex(int anIndex)
- Returns the paragraph Range to which the character at anIndex
belongs.
public Range paragraphForPoint(int x,
int y)
- Returns the Range of the paragraph containing the point
(x, y).
public Range runForPoint(int x,
int y)
- Returns the Range of the run containing the point
(x, y).
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).
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.
public Range selectedRange()
- Returns the selected Range. Returns Range.nullRange() if no selection
exists.
public void selectRange(Range aRange)
- Sets the selected Range. If aRange is Range.nullRange(),
removes the TextView's selection.
public boolean hasSelection()
- Returns true if the TextView has a selection.
public void insertHTMLElementsInRange(Vector components,
Range aRange,
Hashtable attributes)
- Primitive to insert some HTML elements into a range. Vector should
contain some TextViewHTMLElement. This method is useful when
extending HTML parsing with some containers producing TextAttachment.
Use importHTMLInRange() or importHTMLFromURLString() in any other
attributes is the attributes that should be used as base to
parse HTML. For example if you set FONT_KEY to be helvetica 18,
all HTML text will be helvetica 18, but if HTML changes the font.
public void importHTMLInRange(java.io.InputStream inputStream,
Range aRange,
java.net.URL baseURL) throws IOException, HTMLParsingException
- Convenience to import HTML from the stream inputStream,
replacing the text defined by aRange. If baseURL is
null, only absolute HTTP references will work.
Default attributes will be used as a base to parse HTML.
Supports HTML v1.0.
public void importHTMLInRange(java.io.InputStream inputStream,
Range aRange,
java.net.URL baseURL,
Hashtable attributes) throws IOException, HTMLParsingException
- Imports HTML from the stream inputStream, replacing the text
defined by aRange. If baseURL is null, only
absolute HTTP references.
attributes is the attributes that should be used as base to
parse HTML. For example if you set FONT_KEY to be helvetica 18,
all HTML text will be helvetica 18, but if HTML changes the font.
Supports HTML v1.0.
public void importHTMLFromURLString(String urlString)
- Imports HTML from the URL urlString.
Scrolls the TextView to the top and sets the selection to (0, 0).
public void setHTMLParsingRules(HTMLParsingRules newRules)
- Set the HTML parsing rules
public HTMLParsingRules htmlParsingRules()
- Return the HTML parsing rules
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.
public void describeClassInfo(ClassInfo info)
- Describes the TextView class' information.
- Overrides:
- describeClassInfo in class View
- See Also:
- describeClassInfo
public void encode(Encoder encoder) throws CodingException
- Encodes the TextView instance.
- Overrides:
- encode in class View
- See Also:
- encode
public void decode(Decoder decoder) throws CodingException
- Decodes the TextView instance.
- Overrides:
- decode in class View
- See Also:
- decode
public void finishDecoding() throws CodingException
- Finishes the TextView instance decoding.
- Overrides:
- finishDecoding in class View
- See Also:
- finishDecoding
public int lineCount()
- Return the number of lines currently in TextView.
public void setBaseURL(java.net.URL baseURL)
- Set the base URL of the displayed document.
public java.net.URL baseURL()
- Return the baseURL for the document. The return value is defined
only while parsing some HTML, or when the value has been set
with setBaseURL()
public boolean canBecomeSelectedView()
- Return whether this view can become the selected view
when the user is moving from view to views with the keyboard
The default implementation returns true if the TextView
is selectable.
- Overrides:
- canBecomeSelectedView in class View
public void willBecomeSelected()
- Inform the view that it is about to become the selected view.
- Overrides:
- willBecomeSelected in class View
public static String stringWithoutCarriageReturns(String aString)
- Converts CR/LF to CR.
public void copy()
- Copys the current selection.
public void cut()
- Cuts the current selection.
public void paste()
- Replaces the current selection.
public String formElementText()
- Implementation of the FormElement interface
All Packages Class Hierarchy This Package Previous Next Index
Copyright © 1997 Netscape Communications Corporation. All rights reserved
Please send any comments or corrections to ifcfeedback@netscape.com
HTML generated on 21 Oct 1997