| public abstract class javax.swing.plaf.basic BasicTextUI
|
Java SE 6 |
Basis of a text components look-and-feel. This provides the
basic editor view and controller services that may be useful
when creating a look-and-feel for an extension of
JTextComponent.
Most state is held in the associated JTextComponent
as bound properties, and the UI installs default values for the
various properties. This default will install something for
all of the properties. Typically, a LAF implementation will
do more however. At a minimum, a LAF would generally install
key bindings.
This class also provides some concurrency support if the
Document associated with the JTextComponent is a subclass of
AbstractDocument. Access to the View (or View hierarchy) is
serialized between any thread mutating the model and the Swing
event thread (which is expected to render, do model/view coordinate
translation, etc). Any access to the root view should first
acquire a read-lock on the AbstractDocument and release that lock
in a finally block.
An important method to define is the #getPropertyPrefix method
which is used as the basis of the keys used to fetch defaults
from the UIManager. The string should reflect the type of
TextUI (eg. TextField, TextArea, etc) without the particular
LAF part of the name (eg Metal, Motif, etc).
To build a view of the model, one of the following strategies can be employed.
#create method.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see java.beans.XMLEncoder.
| version | 1.120 08/25/06 |
| Constructors | |
|---|---|
| public | BasicTextUI() Creates a new UI. |
| Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| public View | create(Element elem) Details
Creates a view for an element.
If a subclass wishes to directly implement the factory
producing the view(s), it should reimplement this
method. By default it simply returns null indicating
it is unable to represent the element.
| ||||||||||
| public View | create(Element elem, int p0, int p1) Details
Creates a view for an element.
If a subclass wishes to directly implement the factory
producing the view(s), it should reimplement this
method. By default it simply returns null indicating
it is unable to represent the part of the element.
| ||||||||||
| protected Caret | createCaret() Details
Creates the object to use for a caret. By default an
instance of BasicCaret is created. This method
can be redefined to provide something else that implements
the InputPosition interface or a subclass of JCaret.
| ||||||||||
| protected Highlighter | createHighlighter() Details
Creates the object to use for adding highlights. By default
an instance of BasicHighlighter is created. This method
can be redefined to provide something else that implements
the Highlighter interface or a subclass of DefaultHighlighter.
| ||||||||||
| protected Keymap | createKeymap() Details
Creates the keymap to use for the text component, and installs
any necessary bindings into it. By default, the keymap is
shared between all instances of this type of TextUI. The
keymap has the name defined by the getKeymapName method. If the
keymap is not found, then DEFAULT_KEYMAP from JTextComponent is used.
The set of bindings used to create the keymap is fetched
from the UIManager using a key formed by combining the
| ||||||||||
| public void | damageRange(JTextComponent tc, int p0, int p1) Details
Causes the portion of the view responsible for the
given part of the model to be repainted. Does nothing if
the view is not currently painted.
| ||||||||||
| public void | damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias) Details
Causes the portion of the view responsible for the
given part of the model to be repainted.
| ||||||||||
| protected void | installDefaults() Details
Initializes component properties, e.g. font, foreground,
background, caret color, selection color, selected text color,
disabled text color, and border color. The font, foreground, and
background properties are only set if their current value is either null
or a UIResource, other properties are set if the current
value is null.
| ||||||||||
| protected void | installKeyboardActions() | ||||||||||
| protected void | installListeners() Installs listeners for the UI. | ||||||||||
| public void | installUI(JComponent c) Details
Installs the UI for a component. This does the following
things.
| ||||||||||
| protected void | modelChanged() Flags model changes. This is called whenever the model has changed. It is implemented to rebuild the view hierarchy to represent the default root element of the associated model. | ||||||||||
| public Rectangle | modelToView(JTextComponent tc, int pos) throws BadLocationException Details
Converts the given location in the model to a place in
the view coordinate system.
The component must have a non-zero positive size for
this translation to be computed.
| ||||||||||
| public Rectangle | modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException Details
Converts the given location in the model to a place in
the view coordinate system.
The component must have a non-zero positive size for
this translation to be computed.
| ||||||||||
| final public void | paint(Graphics g, JComponent c) Details
Paints the interface. This is routed to the
paintSafely method under the guarantee that
the model won't change from the view of this thread
while it's rendering (if the associated model is
derived from AbstractDocument). This enables the
model to potentially be updated asynchronously.
| ||||||||||
| protected void | paintBackground(Graphics g) Details
Paints a background for the view. This will only be
called if isOpaque() on the associated component is
true. The default is to paint the background color
of the component.
| ||||||||||
| protected void | paintSafely(Graphics g) Details
Paints the interface safely with a guarantee that
the model won't change from the view of this thread.
This does the following things, rendering from
back to front.
| ||||||||||
| protected void | propertyChange(PropertyChangeEvent evt) Details
This method gets called when a bound property is changed
on the associated JTextComponent. This is a hook
which UI implementations may change to reflect how the
UI displays bound properties of JTextComponent subclasses.
This is implemented to do nothing (i.e. the response to
properties in JTextComponent itself are handled prior
to calling this method).
This implementation updates the background of the text
component if the editable and/or enabled state changes.
| ||||||||||
| protected void | uninstallDefaults() Details
Sets the component properties that haven't been explicitly overridden to
null. A property is considered overridden if its current value
is not a UIResource.
| ||||||||||
| protected void | uninstallKeyboardActions() | ||||||||||
| protected void | uninstallListeners() Uninstalls listeners for the UI. | ||||||||||
| public void | uninstallUI(JComponent c) Details
Deinstalls the UI for a component. This removes the listeners,
uninstalls the highlighter, removes views, and nulls out the keymap.
| ||||||||||
| public void | update(Graphics g, JComponent c) Superclass paints background in an uncontrollable way (i.e. one might want an image tiled into the background). To prevent this from happening twice, this method is reimplemented to simply paint. NOTE: Superclass is also not thread-safe in it's rendering of the background, although that's not an issue with the default rendering. | ||||||||||
| public int | viewToModel(JTextComponent tc, Point pt) Details
Converts the given place in the view coordinate system
to the nearest representative location in the model.
The component must have a non-zero positive size for
this translation to be computed.
| ||||||||||
| public int | viewToModel(JTextComponent tc, Point pt, Position.Bias[] biasReturn) Details
Converts the given place in the view coordinate system
to the nearest representative location in the model.
The component must have a non-zero positive size for
this translation to be computed.
| ||||||||||
| Properties | |||||||
|---|---|---|---|---|---|---|---|
| final protected JTextComponent | getComponent() Details
Fetches the text component associated with this
UI implementation. This will be null until
the ui has been installed.
| ||||||
| public EditorKit | getEditorKit(JTextComponent tc) Details
Fetches the EditorKit for the UI.
| ||||||
| protected String | getKeymapName() Details
Fetches the name of the keymap that will be installed/used
by default for this UI. This is implemented to create a
name based upon the classname. The name is the the name
of the class with the package prefix removed.
| ||||||
| public Dimension | getMaximumSize(JComponent c) Details
Gets the maximum size for the editor component.
| ||||||
| public Dimension | getMinimumSize(JComponent c) Details
Gets the minimum size for the editor component.
| ||||||
| public int | getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException Provides a way to determine the next visually represented model location that one might place a caret. Some views may not be visible, they might not be in the same order found in the model, or they just might not allow access to some of the locations in the model. | ||||||
| public Dimension | getPreferredSize(JComponent c) Details
Gets the preferred size for the editor component. If the component
has been given a size prior to receiving this request, it will
set the size of the view hierarchy to reflect the size of the component
before requesting the preferred size of the view hierarchy. This
allows formatted views to format to the current component size before
answering the request. Other views don't care about currently formatted
size and give the same answer either way.
| ||||||
| abstract protected String | getPropertyPrefix() Details
Gets the name used as a key to look up properties through the
UIManager. This is used as a prefix to all the standard
text properties.
| ||||||
| public View | getRootView(JTextComponent tc) Details
Fetches a View with the allocation of the associated
text component (i.e. the root of the hierarchy) that
can be traversed to determine how the model is being
represented spatially.
NOTE:The View hierarchy can be traversed from the root view, and other things can be done as well. Things done in this way cannot be protected like simple method calls through the TextUI. Therefore, proper operation in the presence of concurrency must be arranged by any logic that calls this method!
| ||||||
| public String | getToolTipText(JTextComponent t, Point pt) Details
Returns the string to be used as the tooltip at the passed in location.
This forwards the method onto the root View.
| ||||||
| final protected void | setView(View v) Details
Sets the current root of the view hierarchy and calls invalidate().
If there were any child components, they will be removed (i.e.
there are assumed to have come from components embedded in views).
| ||||||
| protected Rectangle | getVisibleEditorRect() Details
Gets the allocation to give the root View. Due
to an unfortunate set of historical events this
method is inappropriately named. The Rectangle
returned has nothing to do with visibility.
The component must have a non-zero positive size for
this translation to be computed.
| ||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2013 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|