| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public abstract class BasicTextUI extends TextUI implements ViewFactory
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 {@link #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.
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 {@link java.beans.XMLEncoder}.
Nested Class Summary | |
---|---|
static class |
|
static class |
|
Constructor Summary | |
---|---|
Creates a new UI. |
Method Summary | |
---|---|
View |
Creates a view for an element. |
View |
Creates a view for an element. |
protected Caret |
Creates the object to use for a caret. |
protected Highlighter |
Creates the object to use for adding highlights. |
protected Keymap |
Creates the keymap to use for the text component, and installs any necessary bindings into it. |
void |
damageRange(JTextComponent tc, int p0, int p1) Causes the portion of the view responsible for the given part of the model to be repainted. |
void |
damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias) Causes the portion of the view responsible for the given part of the model to be repainted. |
protected JTextComponent |
Fetches the text component associated with this UI implementation. |
EditorKit |
Fetches the EditorKit for the UI. |
protected String |
Fetches the name of the keymap that will be installed/used by default for this UI. |
Dimension |
Gets the maximum size for the editor component. |
Dimension |
Gets the minimum size for the editor component. |
int |
getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) Provides a way to determine the next visually represented model location that one might place a caret. |
Dimension |
Gets the preferred size for the editor component. |
protected abstract String |
Gets the name used as a key to look up properties through the UIManager. |
View |
Fetches a View with the allocation of the associated text component (i.e. |
String |
getToolTipText(JTextComponent t, Point pt) Returns the string to be used as the tooltip at the passed in location. |
protected Rectangle |
Gets the allocation to give the root View. |
protected void |
Initializes component properties, e.g. |
protected void |
|
protected void |
Installs listeners for the UI. |
void |
Installs the UI for a component. |
protected void |
Flags model changes. |
Rectangle |
modelToView(JTextComponent tc, int pos) Converts the given location in the model to a place in the view coordinate system. |
Rectangle |
modelToView(JTextComponent tc, int pos, Position.Bias bias) Converts the given location in the model to a place in the view coordinate system. |
void |
paint(Graphics g, JComponent c) Paints the interface. |
protected void |
Paints a background for the view. |
protected void |
Paints the interface safely with a guarantee that the model won't change from the view of this thread. |
protected void |
This method gets called when a bound property is changed on the associated JTextComponent. |
protected void |
Sets the current root of the view hierarchy and calls invalidate(). |
protected void |
Sets the component properties that haven't been explicitly overridden to null. |
protected void |
|
protected void |
Uninstalls listeners for the UI. |
void |
Deinstalls the UI for a component. |
void |
update(Graphics g, JComponent c) Superclass paints background in an uncontrollable way (i.e. |
int |
viewToModel(JTextComponent tc, Point pt) Converts the given place in the view coordinate system to the nearest representative location in the model. |
int |
viewToModel(JTextComponent tc, Point pt, Position.Bias[] biasReturn) Converts the given place in the view coordinate system to the nearest representative location in the model. |
Methods inherited from class javax.swing.plaf.TextUI |
---|
damageRange, damageRange, getEditorKit, getNextVisualPositionFrom, getRootView, getToolTipText, modelToView, modelToView, viewToModel, viewToModel |
Methods inherited from class javax.swing.plaf.ComponentUI |
---|
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BasicTextUI()
Method Detail |
---|
public View create(Element elem)
elem
- the elementpublic View create(Element elem, int p0, int p1)
elem
- the elementp0
- the starting offset >= 0p1
- the ending offset >= p0protected Caret createCaret()
protected Highlighter createHighlighter()
protected Keymap createKeymap()
The set of bindings used to create the keymap is fetched
from the UIManager using a key formed by combining the
{@link #getPropertyPrefix} method
and the string .keyBindings
. The type is expected
to be JTextComponent.KeyBinding[]
.
public void damageRange(JTextComponent tc, int p0, int p1)
damageRange
in class TextUI
tc
- the text component for which this UI is installedp0
- the beginning of the range >= 0p1
- the end of the range >= p0public void damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias)
damageRange
in class TextUI
t
p0
- the beginning of the range >= 0p1
- the end of the range >= p0p0Bias
p1Bias
protected final JTextComponent getComponent()
public EditorKit getEditorKit(JTextComponent tc)
getEditorKit
in class TextUI
tc
- the text component for which this UI is installedprotected String getKeymapName()
public Dimension getMaximumSize(JComponent c)
getMaximumSize
in class ComponentUI
c
- the editor componentpublic Dimension getMinimumSize(JComponent c)
getMinimumSize
in class ComponentUI
c
- the editor componentpublic int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException
getNextVisualPositionFrom
in class TextUI
t
pos
b
direction
biasRet
BadLocationException
public Dimension getPreferredSize(JComponent c)
getPreferredSize
in class ComponentUI
c
- the editor componentprotected abstract String getPropertyPrefix()
public View getRootView(JTextComponent tc)
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!
getRootView
in class TextUI
tc
- the text component for which this UI is installedpublic String getToolTipText(JTextComponent t, Point pt)
getToolTipText
in class TextUI
t
pt
protected Rectangle getVisibleEditorRect()
protected void installDefaults()
protected void installKeyboardActions()
protected void installListeners()
public void installUI(JComponent c)
installUI
in class ComponentUI
c
- the editor componentprotected void modelChanged()
public Rectangle modelToView(JTextComponent tc, int pos) throws BadLocationException
modelToView
in class TextUI
tc
- the text component for which this UI is installedpos
- the local location in the model to translate >= 0BadLocationException
- if the given position does not
represent a valid location in the associated documentpublic Rectangle modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException
modelToView
in class TextUI
tc
- the text component for which this UI is installedpos
- the local location in the model to translate >= 0bias
BadLocationException
- if the given position does not
represent a valid location in the associated documentpublic final void paint(Graphics g, JComponent c)
paint
in class ComponentUI
g
- the graphics contextc
- the editor componentprotected void paintBackground(Graphics g)
g
- the graphics contextprotected void paintSafely(Graphics g)
g
- the graphics contextprotected void propertyChange(PropertyChangeEvent evt)
evt
- the property change eventprotected final void setView(View v)
v
- the root viewprotected void uninstallDefaults()
protected void uninstallKeyboardActions()
protected void uninstallListeners()
public void uninstallUI(JComponent c)
uninstallUI
in class ComponentUI
c
- the editor componentpublic void update(Graphics g, JComponent c)
NOTE: Superclass is also not thread-safe in it's rendering of the background, although that's not an issue with the default rendering.
update
in class ComponentUI
g
c
public int viewToModel(JTextComponent tc, Point pt)
viewToModel
in class TextUI
tc
- the text component for which this UI is installedpt
- the location in the view to translate. This
should be in the same coordinate system as the mouse events.public int viewToModel(JTextComponent tc, Point pt, Position.Bias[] biasReturn)
viewToModel
in class TextUI
tc
- the text component for which this UI is installedpt
- the location in the view to translate. This
should be in the same coordinate system as the mouse events.biasReturn
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |