javax.swing.plaf.basic

Class BasicTextUI

Implemented Interfaces:
ViewFactory
Known Direct 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 Caret 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

damageRange, damageRange, getEditorKit, getNextVisualPositionFrom, getRootView, getToolTipText, modelToView, modelToView, viewToModel, viewToModel

Methods inherited from class javax.swing.plaf.ComponentUI

contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

BasicTextUI

public BasicTextUI()
Creates a new BasicTextUI instance.

Method Details

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

createCaret

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

createKeymap

protected Keymap createKeymap()
Creates the Keymap that is installed on the text component.
Returns:
the 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.
Overrides:
damageRange in interface 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.
Overrides:
damageRange in interface 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

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 EditorKit used for the text component that is managed by this UI.
Overrides:
getEditorKit in interface TextUI
Parameters:
t - the text component
Returns:
the 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).
Overrides:
getMaximumSize in interface 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 interface ComponentUI
Returns:
the minimum size for text components

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.
Overrides:
getNextVisualPositionFrom in interface 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

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns the preferred size of the text component.
Overrides:
getPreferredSize in interface ComponentUI
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 View of a text component.
Overrides:
getRootView in interface TextUI
Returns:
the root 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

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.
Overrides:
installUI in interface ComponentUI
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)
            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.
Overrides:
modelToView in interface 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

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.
Overrides:
modelToView in interface 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

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 interface ComponentUI
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 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.
Overrides:
uninstallUI in interface ComponentUI
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 paint(Graphics,JComponent) and this delegates the background painting to paintBackground(Graphics).
Overrides:
update in interface ComponentUI
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.
Overrides:
viewToModel in interface TextUI
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.
Overrides:
viewToModel in interface 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

BasicTextUI.java -- Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.