APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.basic

public abstract Class BasicTextUI

extends TextUI
implements ViewFactory
Class Inheritance
All Implemented Interfaces
javax.swing.text.ViewFactory
Known Direct Subclasses
javax.swing.plaf.basic.BasicTextAreaUI, javax.swing.text.DefaultTextUI, javax.swing.plaf.basic.BasicEditorPaneUI, javax.swing.plaf.basic.BasicTextFieldUI
Annotations
@SuppressWarnings:serial
Imports
java.util.*, java.awt.*, java.awt.event.*, java.awt.datatransfer.*, java.awt.geom.Point2D, .Rectangle2D, java.awt.im.InputContext, java.beans.*, java.io.*, javax.swing.*, javax.swing.plaf.*, .UIResource, javax.swing.text.*, javax.swing.event.*, javax.swing.border.Border, javax.swing.plaf.synth.SynthUI, sun.swing.DefaultLookup, .SwingUtilities2, javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag

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.

  1. One strategy is to simply redefine the ViewFactory interface in the UI. By default, this UI itself acts as the factory for View implementations. This is useful for simple factories. To do this reimplement the create method.
  2. A common strategy for creating more complex types of documents is to have the EditorKit implementation return a factory. Since the EditorKit ties all of the pieces necessary to maintain a type of document, the factory is typically an important part of that and should be produced by the EditorKit implementation.

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 JavaBeans has been added to the java.beans package. Please see java.beans.XMLEncoder.

Authors
Timothy Prinzing, Shannon Hickey (drag and drop)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
BasicTextUI.BasicCaret

Default implementation of the interface Caret.

pack-priv static class
public static class
BasicTextUI.BasicHighlighter

Default implementation of the interface Highlighter.

pack-priv static class
BasicTextUI.DragListener

Listens for mouse events for the purposes of detecting drag gestures.

pack-priv class
BasicTextUI.FocusAction

Registered in the ActionMap.

pack-priv class
BasicTextUI.RootView

Root view that acts as a gateway between the component and the View hierarchy.

pack-priv class
BasicTextUI.TextActionWrapper

Wrapper for text actions to return isEnabled false in case editor is non editable

pack-priv static class
pack-priv class
BasicTextUI.UpdateHandler

Handles updates from various places.

Field Summary

Modifier and TypeField and Description
private int
private static final int
private static final EditorKit
private static final TransferHandler
private static final Position.Bias[]
private final BasicTextUI.DragListener
private static volatile BasicTextUI.DragListener
private DefaultCaret
pack-priv transient JTextComponent
pack-priv transient boolean
pack-priv transient BasicTextUI.RootView
private static BasicTextUI.BasicCursor
pack-priv transient BasicTextUI.UpdateHandler

Constructor Summary

AccessConstructor and Description
public
BasicTextUI()

Creates a new UI.

Method Summary

Modifier and TypeMethod and Description
public View

Returns:

the view
create
(Element
the element
elem
)

Implements javax.swing.text.ViewFactory.create.

Creates a view for an element.

public View

Returns:

the view
create
(Element
the element
elem
,
int
the starting offset >= 0
p0
,
int
the ending offset >= p0
p1
)

Creates a view for an element.

pack-priv ActionMap
createActionMap()

Create a default action map.

protected Caret

Returns:

the caret object
createCaret
()

Creates the object to use for a caret.

protected Highlighter

Returns:

the highlighter
createHighlighter
()

Creates the object to use for adding highlights.

protected Keymap

Returns:

the keymap
createKeymap
()

Creates the keymap to use for the text component, and installs any necessary bindings into it.

public void
damageRange(JTextComponent
the text component for which this UI is installed
tc
,
int
the beginning of the range >= 0
p0
,
int
the end of the range >= p0
p1
)

Implements abstract javax.swing.plaf.TextUI.damageRange.

Causes the portion of the view responsible for the given part of the model to be repainted.

public void
damageRange(JTextComponent t, int
the beginning of the range >= 0
p0
,
int
the end of the range >= p0
p1
,
Position.Bias p0Bias, Position.Bias p1Bias)

Implements abstract javax.swing.plaf.TextUI.damageRange.

Causes the portion of the view responsible for the given part of the model to be repainted.

pack-priv ActionMap
getActionMap()

Fetch an action map to use.

protected final JTextComponent

Returns:

the editor component
getComponent
()

Fetches the text component associated with this UI implementation.

private static BasicTextUI.DragListener
public EditorKit

Returns:

the editor capabilities
getEditorKit
(JTextComponent
the text component for which this UI is installed
tc
)

Implements abstract javax.swing.plaf.TextUI.getEditorKit.

Fetches the EditorKit for the UI.

pack-priv InputMap
getInputMap()

Get the InputMap to use for the UI.

protected String

Returns:

the name
getKeymapName
()

Fetches the name of the keymap that will be installed/used by default for this UI.

public Dimension

Returns:

the size
getMaximumSize
(JComponent
the editor component
c
)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

Gets the maximum size for the editor component.

public Dimension

Returns:

the size
getMinimumSize
(JComponent
the editor component
c
)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

Gets the minimum size for the editor component.

public int
getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet)

Implements abstract javax.swing.plaf.TextUI.getNextVisualPositionFrom.

Provides a way to determine the next visually represented model location that one might place a caret.

public Dimension

Returns:

the size
getPreferredSize
(JComponent
the editor component
c
)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

Gets the preferred size for the editor component.

protected abstract String

Returns:

the name
getPropertyPrefix
()

Gets the name used as a key to look up properties through the UIManager.

public View

Returns:

the view
getRootView
(JTextComponent
the text component for which this UI is installed
tc
)

Implements abstract javax.swing.plaf.TextUI.getRootView.

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.

public String
getToolTipText(JTextComponent t, Point pt)

Overrides javax.swing.plaf.TextUI.getToolTipText.

Returns the string to be used as the tooltip at the passed in location.

pack-priv TransferHandler
getTransferHandler()

Returns the TransferHandler that will be installed if their isn't one installed on the JTextComponent.

protected Rectangle

Returns:

the bounding box for the root view
getVisibleEditorRect
()

Gets the allocation (that is the allocated size) for the root view.

protected void
installDefaults()

Initializes component properties, such as font, foreground, background, caret color, selection color, selected text color, disabled text color, border, and margin.

private void
protected void
installKeyboardActions()

Registers keyboard actions.

protected void
installListeners()

Installs listeners for the UI.

public void
installUI(JComponent
the editor component
c
)

Overrides javax.swing.plaf.ComponentUI.installUI.

Installs the UI for a component.

protected void
modelChanged()

Flags model changes.

public Rectangle

Returns:

the coordinates as a rectangle, null if the model is not painted
modelToView
(JTextComponent
the text component for which this UI is installed
tc
,
int
the local location in the model to translate >= 0
pos
)

Implements abstract javax.swing.plaf.TextUI.modelToView.

Deprecated since 9. replaced by modelToView2D(JTextComponent, int, Position.Bias)

Converts the given location in the model to a place in the view coordinate system.

public Rectangle

Returns:

the coordinates as a rectangle, null if the model is not painted
modelToView
(JTextComponent
the text component for which this UI is installed
tc
,
int
the local location in the model to translate >= 0
pos
,
Position.Bias bias)

Implements abstract javax.swing.plaf.TextUI.modelToView.

Deprecated since 9. replaced by modelToView2D(JTextComponent, int, Position.Bias)

Converts the given location in the model to a place in the view coordinate system.

private Rectangle2D
modelToView(JTextComponent tc, int pos, Position.Bias bias, boolean useFPAPI)

public Rectangle2D
modelToView2D(JTextComponent tc, int pos, Position.Bias bias)

Overrides javax.swing.plaf.TextUI.modelToView2D.

Converts the given location in the model to a place in the view coordinate system.

public final void
paint(Graphics
the graphics context
g
,
JComponent
the editor component
c
)

Overrides javax.swing.plaf.ComponentUI.paint.

Paints the interface.

protected void
paintBackground(Graphics
the graphics context
g
)

Paints a background for the view.

protected void
paintSafely(Graphics
the graphics context
g
)

Paints the interface safely with a guarantee that the model won't change from the view of this thread.

protected void
propertyChange(PropertyChangeEvent
the property change event
evt
)

This method gets called when a bound property is changed on the associated JTextComponent.

protected final void
setView(View
the root view
v
)

Sets the current root of the view hierarchy and calls invalidate().

protected void
uninstallDefaults()

Sets the component properties that have not been explicitly overridden to null.

protected void
uninstallKeyboardActions()

Unregisters keyboard actions.

protected void
uninstallListeners()

Uninstalls listeners for the UI.

public void
uninstallUI(JComponent
the editor component
c
)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Deinstalls the UI for a component.

public void
update(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.update.

Superclass paints background in an uncontrollable way (i.e. one might want an image tiled into the background).

private void
updateBackground(JTextComponent
the JTextComponent that needs its background color updated
c
)

Updates the background of the text component based on whether the text component is editable and/or enabled.

private void
updateCursor()

As needed updates cursor for the target editor.

pack-priv void
updateFocusAcceleratorBinding(boolean changed)

Invoked when the focus accelerator changes, this will update the key bindings as necessary.

pack-priv void
updateFocusTraversalKeys()

Invoked when editable property is changed.

public int

Returns:

the offset from the start of the document >= 0, -1 if not painted
viewToModel
(JTextComponent
the text component for which this UI is installed
tc
,
Point
the location in the view to translate. This should be in the same coordinate system as the mouse events.
pt
)

Implements abstract javax.swing.plaf.TextUI.viewToModel.

Converts the given place in the view coordinate system to the nearest representative location in the model.

public int

Returns:

the offset from the start of the document >= 0, -1 if the component doesn't yet have a positive size.
viewToModel
(JTextComponent
the text component for which this UI is installed
tc
,
Point
the location in the view to translate. This should be in the same coordinate system as the mouse events.
pt
,
Position.Bias[] biasReturn)

Implements abstract javax.swing.plaf.TextUI.viewToModel.

Converts the given place in the view coordinate system to the nearest representative location in the model.

private int
viewToModel(JTextComponent tc, float x, float y, Position.Bias[] biasReturn)

public int
viewToModel2D(JTextComponent tc, Point2D pt, Position.Bias[] biasReturn)

Overrides javax.swing.plaf.TextUI.viewToModel2D.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Inherited from javax.swing.plaf.TextUI:
getToolTipText2D