javax.swing.plaf.basic
Class BasicTextUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by javax.swing.plaf.TextUI
          extended by javax.swing.plaf.basic.BasicTextUI
All Implemented Interfaces:
ViewFactory
Direct Known Subclasses:
BasicEditorPaneUI, BasicTextAreaUI, BasicTextFieldUI, DefaultTextUI

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 class BasicTextUI.BasicCaret
          A DefaultCaret that implements UIResource.
static class BasicTextUI.BasicHighlighter
          A DefaultHighlighter that implements UIResource.
 
Constructor Summary
BasicTextUI()
          Creates a new BasicTextUI instance.
 
Method Summary
 View create(Element elem)
          Creates a View for the specified Element.
 View create(Element elem, int p0, int p1)
          Creates a View for the specified Element.
protected  Caret createCaret()
          Creates a BasicTextUI.BasicCaret that should be installed into the text component.
protected  Highlighter createHighlighter()
          Creates a Highlighter that should be installed into the text component.
protected  Keymap createKeymap()
          Creates the Keymap that is installed on the text component.
 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.
 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.
protected  JTextComponent getComponent()
          The text component that is managed by this UI.
 EditorKit getEditorKit(JTextComponent t)
          Returns the EditorKit used for the text component that is managed by this UI.
protected  String getKeymapName()
          Returns the name of the keymap for this type of TextUI.
 Dimension getMaximumSize(JComponent c)
          Returns the maximum size for text components that use this UI.
 Dimension getMinimumSize(JComponent c)
          Returns the minimum size for text components.
 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.
 Dimension getPreferredSize(JComponent c)
          Returns the preferred size of the text component.
protected abstract  String getPropertyPrefix()
          Returns the property prefix by which the text component's UIDefaults are looked up.
 View getRootView(JTextComponent t)
          Returns the root View of a text component.
protected  Rectangle getVisibleEditorRect()
          Returns the allocation to give the root view.
protected  void installDefaults()
          Installs UI defaults on the text components.
protected  void installKeyboardActions()
          Installs the keyboard actions on the text components.
protected  void installListeners()
          Install all listeners on the text component.
 void installUI(JComponent c)
          Installs this UI on the text component.
protected  void modelChanged()
          Indicates that the model of a text component has changed.
 Rectangle modelToView(JTextComponent t, int pos)
          Maps a position in the document into the coordinate space of the View.
 Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias)
          Maps a position in the document into the coordinate space of the View.
 void paint(Graphics g, JComponent c)
          Paints the text component.
protected  void paintBackground(Graphics g)
          Paints the background of the text component.
protected  void paintSafely(Graphics g)
          This paints the text component while beeing sure that the model is not modified while painting.
protected  void propertyChange(PropertyChangeEvent ev)
          Receives notification whenever one of the text component's bound properties changes.
protected  void setView(View view)
          Sets the root view for the text component.
protected  void uninstallDefaults()
          Uninstalls all default properties that have previously been installed by this UI.
protected  void uninstallKeyboardActions()
          Uninstalls all keyboard actions that have previously been installed by this UI.
protected  void uninstallListeners()
          Uninstalls all listeners that have previously been installed by this UI.
 void uninstallUI(JComponent component)
          Uninstalls this TextUI from the text component.
 void update(Graphics g, JComponent c)
          Overridden for better control over background painting.
 int viewToModel(JTextComponent t, Point pt)
          Maps a point in the View coordinate space to a position inside a document model.
 int viewToModel(JTextComponent t, Point pt, Position.Bias[] biasReturn)
          Maps a point in the View coordinate space to a position inside a document model.
 
Methods inherited from class javax.swing.plaf.TextUI
getToolTipText
 
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

BasicTextUI

public BasicTextUI()
Creates a new BasicTextUI instance.

Method Detail

createCaret

protected Caret createCaret()
Creates a BasicTextUI.BasicCaret 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 Highlighter that should be installed into the text component.

Returns:
a Highlighter for the text component

getComponent

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

Returns:
the text component that is managed by this UI

installUI

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

Overrides:
installUI in class ComponentUI
Parameters:
c - the text component on which to install the UI
See Also:
ComponentUI.uninstallUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

installDefaults

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


installListeners

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


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

createKeymap

protected Keymap createKeymap()
Creates the Keymap that is installed on the text component.

Returns:
the Keymap that is installed on the text component

installKeyboardActions

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


uninstallUI

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

Overrides:
uninstallUI in class ComponentUI
Parameters:
component - the text component to uninstall the UI from
See Also:
ComponentUI.installUI(javax.swing.JComponent), JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

uninstallDefaults

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


uninstallListeners

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


uninstallKeyboardActions

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


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

getPreferredSize

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

Overrides:
getPreferredSize in class ComponentUI
Parameters:
c - not used here
Returns:
the preferred size of the text component

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).

Overrides:
getMaximumSize in class ComponentUI
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.

Overrides:
getMinimumSize in class ComponentUI
Parameters:
c - the component for which this delegate performs services.
Returns:
the minimum size for text components

paint

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

Overrides:
paint in class ComponentUI
Parameters:
g - the Graphics context to paint to
c - not used here

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 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

paintBackground

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

Parameters:
g - the Graphics context to paint to

update

public void update(Graphics g,
                   JComponent c)
Overridden for better control over background painting. This now simply calls paint(java.awt.Graphics, javax.swing.JComponent) and this delegates the background painting to paintBackground(java.awt.Graphics).

Overrides:
update in class ComponentUI
Parameters:
g - the graphics to use
c - the component to be painted
See Also:
ComponentUI.paint(java.awt.Graphics, javax.swing.JComponent), JComponent.paintComponent(java.awt.Graphics)

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.

Specified by:
damageRange in class TextUI
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 Position.Bias object to be specified for the start and end location of the range.

Specified by:
damageRange in class TextUI
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

getEditorKit

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

Specified by:
getEditorKit in class TextUI
Parameters:
t - the text component
Returns:
the EditorKit used for the text component that is managed by this UI

getNextVisualPositionFrom

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

Specified by:
getNextVisualPositionFrom in class TextUI
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
Throws:
BadLocationException - if pos does not designate a valid position in the document model.

getRootView

public View getRootView(JTextComponent t)
Returns the root View of a text component.

Specified by:
getRootView in class TextUI
Parameters:
t - the JTextComponent for which this delegate object provides the user interface.
Returns:
the root View of a text component

modelToView

public Rectangle modelToView(JTextComponent t,
                             int pos)
                      throws BadLocationException
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 Position.Bias#Forward is used in this method.

Specified by:
modelToView in class TextUI
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
See Also:
ComponentView.modelToView(int, Shape, Position.Bias)

modelToView

public Rectangle modelToView(JTextComponent t,
                             int pos,
                             Position.Bias bias)
                      throws BadLocationException
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.

Specified by:
modelToView in class TextUI
Parameters:
t - the text component
pos - the position of the character in the model
bias - either Position.Bias#Forward or 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
See Also:
ComponentView.modelToView(int, Shape, Position.Bias)

viewToModel

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

Specified by:
viewToModel in class TextUI
Parameters:
t - the text component
pt - the point to be mapped
Returns:
the position inside the document model that corresponds to pt
See Also:
TextUI.viewToModel(JTextComponent, Point, Position.Bias[])

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.

Specified by:
viewToModel in class TextUI
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

create

public View create(Element elem)
Creates a View for the specified Element.

Specified by:
create in interface ViewFactory
Parameters:
elem - the Element to create a View for
Returns:
a new created view
See Also:
ViewFactory

create

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

Parameters:
elem - the Element to create a View for
p0 - the start offset
p1 - the end offset
See Also:
ViewFactory

getVisibleEditorRect

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

Returns:
the allocation to give the root view

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

modelChanged

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


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