javax.swing.plaf.basic

Class BasicTextUI

public abstract class BasicTextUI extends TextUI implements ViewFactory

The abstract base class from which the UI classes for Swings text components are derived. This provides most of the functionality for the UI classes.
Nested Class Summary
static classBasicTextUI.BasicCaret
A {@link DefaultCaret} that implements {@link UIResource}.
static classBasicTextUI.BasicHighlighter
A {@link DefaultHighlighter} that implements {@link UIResource}.
Constructor Summary
BasicTextUI()
Creates a new BasicTextUI instance.
Method Summary
Viewcreate(Element elem)
Creates a {@link View} for the specified {@link Element}.
Viewcreate(Element elem, int p0, int p1)
Creates a {@link View} for the specified {@link Element}.
protected CaretcreateCaret()
Creates a {@link Caret} that should be installed into the text component.
protected HighlightercreateHighlighter()
Creates a {@link Highlighter} that should be installed into the text component.
protected KeymapcreateKeymap()
Creates the {@link Keymap} that is installed on the text component.
voiddamageRange(JTextComponent t, int p0, int p1)
Marks the specified range inside the text component's model as damaged and queues a repaint request.
voiddamageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias)
Marks the specified range inside the text component's model as damaged and queues a repaint request.
protected JTextComponentgetComponent()
The text component that is managed by this UI.
EditorKitgetEditorKit(JTextComponent t)
Returns the {@link EditorKit} used for the text component that is managed by this UI.
protected StringgetKeymapName()
Returns the name of the keymap for this type of TextUI.
DimensiongetMaximumSize(JComponent c)
Returns the maximum size for text components that use this UI.
DimensiongetMinimumSize(JComponent c)
Returns the minimum size for text components.
intgetNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet)
Gets the next position inside the document model that is visible on screen, starting from pos.
DimensiongetPreferredSize(JComponent c)
Returns the preferred size of the text component.
protected abstract StringgetPropertyPrefix()
Returns the property prefix by which the text component's UIDefaults are looked up.
ViewgetRootView(JTextComponent t)
Returns the root {@link View} of a text component.
protected RectanglegetVisibleEditorRect()
Returns the allocation to give the root view.
protected voidinstallDefaults()
Installs UI defaults on the text components.
protected voidinstallKeyboardActions()
Installs the keyboard actions on the text components.
protected voidinstallListeners()
Install all listeners on the text component.
voidinstallUI(JComponent c)
Installs this UI on the text component.
protected voidmodelChanged()
Indicates that the model of a text component has changed.
RectanglemodelToView(JTextComponent t, int pos)
Maps a position in the document into the coordinate space of the View.
RectanglemodelToView(JTextComponent t, int pos, Position.Bias bias)
Maps a position in the document into the coordinate space of the View.
voidpaint(Graphics g, JComponent c)
Paints the text component.
protected voidpaintBackground(Graphics g)
Paints the background of the text component.
protected voidpaintSafely(Graphics g)
This paints the text component while beeing sure that the model is not modified while painting.
protected voidpropertyChange(PropertyChangeEvent ev)
Receives notification whenever one of the text component's bound properties changes.
protected voidsetView(View view)
Sets the root view for the text component.
protected voiduninstallDefaults()
Uninstalls all default properties that have previously been installed by this UI.
protected voiduninstallKeyboardActions()
Uninstalls all keyboard actions that have previously been installed by this UI.
protected voiduninstallListeners()
Uninstalls all listeners that have previously been installed by this UI.
voiduninstallUI(JComponent component)
Uninstalls this TextUI from the text component.
voidupdate(Graphics g, JComponent c)
Overridden for better control over background painting.
intviewToModel(JTextComponent t, Point pt)
Maps a point in the View coordinate space to a position inside a document model.
intviewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn)
Maps a point in the View coordinate space to a position inside a document model.

Constructor Detail

BasicTextUI

public BasicTextUI()
Creates a new BasicTextUI instance.

Method Detail

create

public View create(Element elem)
Creates a {@link View} for the specified {@link Element}.

Parameters: elem the Element to create a View for

See Also: ViewFactory

create

public View create(Element elem, int p0, int p1)
Creates a {@link View} for the specified {@link Element}.

Parameters: elem the Element to create a View for p0 the start offset p1 the end offset

See Also: ViewFactory

createCaret

protected Caret createCaret()
Creates a {@link Caret} that should be installed into the text component.

Returns: a caret that should be installed into the text component

createHighlighter

protected Highlighter createHighlighter()
Creates a {@link Highlighter} that should be installed into the text component.

Returns: a Highlighter for the text component

createKeymap

protected Keymap createKeymap()
Creates the {@link Keymap} that is installed on the text component.

Returns: the {@link Keymap} that is installed on the text component

damageRange

public void damageRange(JTextComponent t, int p0, int p1)
Marks the specified range inside the text component's model as damaged and queues a repaint request.

Parameters: t the text component p0 the start location inside the document model of the range that is damaged p1 the end location inside the document model of the range that is damaged

damageRange

public void damageRange(JTextComponent t, int p0, int p1, Position.Bias firstBias, Position.Bias secondBias)
Marks the specified range inside the text component's model as damaged and queues a repaint request. This variant of this method allows a {@link Position.Bias} object to be specified for the start and end location of the range.

Parameters: t the text component p0 the start location inside the document model of the range that is damaged p1 the end location inside the document model of the range that is damaged firstBias the bias for the start location secondBias the bias for the end location

getComponent

protected final JTextComponent getComponent()
The text component that is managed by this UI.

Returns: the text component that is managed by this UI

getEditorKit

public EditorKit getEditorKit(JTextComponent t)
Returns the {@link EditorKit} used for the text component that is managed by this UI.

Parameters: t the text component

Returns: the {@link EditorKit} used for the text component that is managed by this UI

getKeymapName

protected String getKeymapName()
Returns the name of the keymap for this type of TextUI. This is implemented so that the classname of this TextUI without the package prefix is returned. This way subclasses don't have to override this method.

Returns: the name of the keymap for this TextUI

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Returns the maximum size for text components that use this UI. This returns (Integer.MAX_VALUE, Integer.MAX_VALUE).

Parameters: c not used here

Returns: the maximum size for text components that use this UI

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Returns the minimum size for text components. This returns the size of the component's insets.

Returns: the minimum size for text components

getNextVisualPositionFrom

public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet)
Gets the next position inside the document model that is visible on screen, starting from pos.

Parameters: t the text component pos the start positionn b the bias for pos direction the search direction biasRet filled by the method to indicate the bias of the return value

Returns: the next position inside the document model that is visible on screen

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns the preferred size of the text component.

Parameters: c not used here

Returns: the preferred size of the text component

getPropertyPrefix

protected abstract String getPropertyPrefix()
Returns the property prefix by which the text component's UIDefaults are looked up.

Returns: the property prefix by which the text component's UIDefaults are looked up

getRootView

public View getRootView(JTextComponent t)
Returns the root {@link View} of a text component.

Returns: the root {@link View} of a text component

getVisibleEditorRect

protected Rectangle getVisibleEditorRect()
Returns the allocation to give the root view.

Returns: the allocation to give the root view

UNKNOWN: The allocation has nothing to do with visibility. According to the specs the naming of this method is unfortunate and has historical reasons

installDefaults

protected void installDefaults()
Installs UI defaults on the text components.

installKeyboardActions

protected void installKeyboardActions()
Installs the keyboard actions on the text components.

installListeners

protected void installListeners()
Install all listeners on the text component.

installUI

public void installUI(JComponent c)
Installs this UI on the text component.

Parameters: c the text component on which to install the UI

modelChanged

protected void modelChanged()
Indicates that the model of a text component has changed. This triggers a rebuild of the view hierarchy.

modelToView

public Rectangle modelToView(JTextComponent t, int pos)
Maps a position in the document into the coordinate space of the View. The output rectangle usually reflects the font height but has a width of zero. A bias of {@link Position.Bias#Forward} is used in this method.

Parameters: t the text component pos the position of the character in the model

Returns: a rectangle that gives the location of the document position inside the view coordinate space

Throws: BadLocationException if pos is invalid IllegalArgumentException if b is not one of the above listed valid values

modelToView

public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias)
Maps a position in the document into the coordinate space of the View. The output rectangle usually reflects the font height but has a width of zero.

Parameters: t the text component pos the position of the character in the model bias either {@link Position.Bias#Forward} or {@link Position.Bias#Backward} depending on the preferred direction bias. If null this defaults to Position.Bias.Forward

Returns: a rectangle that gives the location of the document position inside the view coordinate space

Throws: BadLocationException if pos is invalid IllegalArgumentException if b is not one of the above listed valid values

paint

public final void paint(Graphics g, JComponent c)
Paints the text component. This acquires a read lock on the model and then calls {@link #paintSafely(Graphics)} in order to actually perform the painting.

Parameters: g the Graphics context to paint to c not used here

paintBackground

protected void paintBackground(Graphics g)
Paints the background of the text component.

Parameters: g the Graphics context to paint to

paintSafely

protected void paintSafely(Graphics g)
This paints the text component while beeing sure that the model is not modified while painting. The following is performed in this order:
  1. If the text component is opaque, the background is painted by calling {@link #paintBackground(Graphics)}.
  2. If there is a highlighter, the highlighter is painted.
  3. The view hierarchy is painted.
  4. The Caret is painter.

Parameters: g the Graphics context to paint to

propertyChange

protected void propertyChange(PropertyChangeEvent ev)
Receives notification whenever one of the text component's bound properties changes. This default implementation does nothing. It is a hook that enables subclasses to react to property changes on the text component.

Parameters: ev the property change event

setView

protected final void setView(View view)
Sets the root view for the text component.

Parameters: view the View to be set as root view

uninstallDefaults

protected void uninstallDefaults()
Uninstalls all default properties that have previously been installed by this UI.

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls all keyboard actions that have previously been installed by this UI.

uninstallListeners

protected void uninstallListeners()
Uninstalls all listeners that have previously been installed by this UI.

uninstallUI

public void uninstallUI(JComponent component)
Uninstalls this TextUI from the text component.

Parameters: component the text component to uninstall the UI from

update

public void update(Graphics g, JComponent c)
Overridden for better control over background painting. This now simply calls {@link #paint} and this delegates the background painting to {@link #paintBackground}.

Parameters: g the graphics to use c the component to be painted

viewToModel

public int viewToModel(JTextComponent t, Point pt)
Maps a point in the View coordinate space to a position inside a document model.

Parameters: t the text component pt the point to be mapped

Returns: the position inside the document model that corresponds to pt

viewToModel

public int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn)
Maps a point in the View coordinate space to a position inside a document model.

Parameters: t the text component pt the point to be mapped biasReturn filled in by the method to indicate the bias of the return value

Returns: the position inside the document model that corresponds to pt