|
JavaTM 2 Platform Std. Ed. v1.3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.swing.plaf.ComponentUI | +--javax.swing.plaf.TextUI | +--javax.swing.plaf.basic.BasicTextUI
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 aquire 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(javax.swing.text.Element)
method.
#createViewFactory
method should be reimplemented to
return some factory.
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. A future release of Swing will provide support for long term persistence.
Inner Class Summary | |
static class |
BasicTextUI.BasicCaret
|
static class |
BasicTextUI.BasicHighlighter
|
Constructor Summary | |
BasicTextUI()
Creates a new UI. |
Method Summary | |
View |
create(Element elem)
Creates a view for an element. |
View |
create(Element elem,
int p0,
int p1)
Creates a view for an element. |
protected Caret |
createCaret()
Creates the object to use for a caret. |
protected Highlighter |
createHighlighter()
Creates the object to use for adding highlights. |
protected Keymap |
createKeymap()
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 |
getComponent()
Fetches the text component associated with this UI implementation. |
EditorKit |
getEditorKit(JTextComponent tc)
Fetches the EditorKit for the UI. |
protected String |
getKeymapName()
Fetches the name of the keymap that will be installed/used by default for this UI. |
Dimension |
getMaximumSize(JComponent c)
Gets the maximum size for the editor component. |
Dimension |
getMinimumSize(JComponent c)
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 |
getPreferredSize(JComponent c)
Gets the preferred size for the editor component. |
protected abstract String |
getPropertyPrefix()
Gets the name used as a key to look up properties through the UIManager. |
View |
getRootView(JTextComponent tc)
Fetches a View with the allocation of the associated text component (i.e. |
protected Rectangle |
getVisibleEditorRect()
Gets the allocation to give the root View. |
protected void |
installDefaults()
Initializes component properties, e.g. |
protected void |
installKeyboardActions()
|
protected void |
installListeners()
Installs listeners for the UI. |
void |
installUI(JComponent c)
Installs the UI for a component. |
protected void |
modelChanged()
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 |
paintBackground(Graphics g)
Paints a background for the view. |
protected void |
paintSafely(Graphics g)
Paints the interface safely with a guarantee that the model won't change from the view of this thread. |
protected void |
propertyChange(PropertyChangeEvent evt)
This method gets called when a bound property is changed on the associated JTextComponent. |
protected void |
setView(View v)
Sets the current root of the view hierarchy and calls invalidate(). |
protected void |
uninstallDefaults()
Sets the component properties that haven't been explicitly overriden to null. |
protected void |
uninstallKeyboardActions()
|
protected void |
uninstallListeners()
Uninstalls listeners for the UI. |
void |
uninstallUI(JComponent c)
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.ComponentUI |
contains, createUI, getAccessibleChild, getAccessibleChildrenCount |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public BasicTextUI()
Method Detail |
protected Caret createCaret()
protected Highlighter createHighlighter()
protected String getKeymapName()
protected Keymap createKeymap()
The set of bindings used to create the keymap is fetched
from the UIManager using a key formed by combining the
getPropertyPrefix()
method
and the string .keyBindings
. The type is expected
to be JTextComponent.KeyBinding[]
.
getKeymapName()
,
JTextComponent
protected void propertyChange(PropertyChangeEvent evt)
evt
- the property change eventprotected abstract String getPropertyPrefix()
protected void installDefaults()
uninstallDefaults()
,
installUI(javax.swing.JComponent)
protected void uninstallDefaults()
installDefaults()
,
uninstallUI(javax.swing.JComponent)
protected void installListeners()
protected void uninstallListeners()
protected void installKeyboardActions()
protected void uninstallKeyboardActions()
protected void paintBackground(Graphics g)
g
- the graphics contextprotected final JTextComponent getComponent()
protected void modelChanged()
protected final void setView(View v)
v
- the root viewprotected void paintSafely(Graphics g)
g
- the graphics contextpublic void installUI(JComponent c)
installUI
in class ComponentUI
c
- the editor componentComponentUI.installUI(javax.swing.JComponent)
public void uninstallUI(JComponent c)
uninstallUI
in class ComponentUI
c
- the editor componentComponentUI.uninstallUI(javax.swing.JComponent)
public 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
public final void paint(Graphics g, JComponent c)
paint
in class ComponentUI
g
- the graphics contextc
- the editor componentpublic Dimension getPreferredSize(JComponent c)
getPreferredSize
in class ComponentUI
c
- the editor componentpublic Dimension getMinimumSize(JComponent c)
getMinimumSize
in class ComponentUI
c
- the editor componentpublic Dimension getMaximumSize(JComponent c)
getMaximumSize
in class ComponentUI
c
- the editor componentprotected Rectangle getVisibleEditorRect()
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 documentTextUI.modelToView(javax.swing.text.JTextComponent, int)
public 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 >= 0BadLocationException
- if the given position does not
represent a valid location in the associated documentTextUI.modelToView(javax.swing.text.JTextComponent, int)
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.TextUI.viewToModel(javax.swing.text.JTextComponent, java.awt.Point)
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.TextUI.viewToModel(javax.swing.text.JTextComponent, java.awt.Point)
public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException
getNextVisualPositionFrom
in class TextUI
pos
- the position to convert >= 0a
- the allocated region to render intodirection
- the direction from the current position that can
be thought of as the arrow keys typically found on a keyboard.
This may be SwingConstants.WEST, SwingConstants.EAST,
SwingConstants.NORTH, or SwingConstants.SOUTH.BadLocationException
- IllegalArgumentException
- for an invalid directionpublic 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 >= p0TextUI.damageRange(javax.swing.text.JTextComponent, int, int)
public void damageRange(JTextComponent t, int p0, int p1, Position.Bias p0Bias, Position.Bias p1Bias)
damageRange
in class TextUI
p0
- the beginning of the range >= 0p1
- the end of the range >= p0public EditorKit getEditorKit(JTextComponent tc)
getEditorKit
in class TextUI
tc
- the text component for which this UI is installedTextUI.getEditorKit(javax.swing.text.JTextComponent)
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 installedTextUI.getRootView(javax.swing.text.JTextComponent)
public View create(Element elem)
create
in interface ViewFactory
elem
- the elementpublic View create(Element elem, int p0, int p1)
elem
- the elementp0
- the starting offset >= 0p1
- the ending offset >= p0
|
JavaTM 2 Platform Std. Ed. v1.3 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.