All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.text.DefaultTextUI
java.lang.Object
|
+----com.sun.java.swing.plaf.ComponentUI
|
+----com.sun.java.swing.plaf.TextUI
|
+----com.sun.java.swing.text.DefaultTextUI
- public class DefaultTextUI
- extends TextUI
- implements ViewFactory, Serializable
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.
To minimize the effort required to build a text UI, this class
does a number of things on the programmers behalf. To build a
view of the model, one of the strategies can be employed.
-
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.
-
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.
-
A less common way to create more complex types is to have
the UI implementation create a.
seperate object for the factory. To do this, the
createViewFactory
method should be reimplemented to return some factory.
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.
-
DefaultTextUI()
- Creates a new UI.
-
create(Element)
- If a subclass wishes to directly implement the factory
producing the view(s), it should reimplement this
method.
-
create(Element, int, int)
- If a subclass wishes to directly implement the factory
producing the view(s), it should reimplement this
method.
-
createCaret()
- Creates the object to use for a caret.
-
createController(JTextComponent)
- Creates the controller responsible for binding
events to actions in the text component.
-
createHighlighter()
- Creates the object to use for adding highlights.
-
damageRange(int, int)
- Causes the portion of the view responsible for the
given part of the model to be repainted.
-
getComponent()
- Fetch the text component associated with this
UI implementation.
-
getDefaultMargin()
- Fetches the default margin space for the text ui.
-
getEditorKit()
- Fetches the EditorKit for the UI.
-
getMaximumSize(JComponent)
-
-
getMinimumSize(JComponent)
-
-
getPreferredSize(JComponent)
-
-
getRootView()
- Fetch a View with the allocation of the associated
text component (ie the root of the hierarchy) that
can be traversed to determine how the model is being
represented spatially.
-
getVisibleEditorRect()
-
-
installUI(JComponent)
- Installs the UI for a component.
-
modelChanged()
- This is called whenever the model has changed.
-
modelToView(int)
- Converts the given location in the model to a place in
the view coordinate system.
-
paint(Graphics, JComponent)
- Paint the interface.
-
paintBackground(Graphics)
- Paint a background for the view.
-
setView(View)
- Set the current root of the view hierarchy.
-
uninstallUI(JComponent)
- Deinstalls the UI for a component.
-
viewToModel(Point)
- Converts the given place in the view coordinate system
to the nearest representative location in the model.
DefaultTextUI
public DefaultTextUI()
- Creates a new UI.
createController
protected TextController createController(JTextComponent c)
- Creates the controller responsible for binding
events to actions in the text component. By default this
is an instance of JTextController.
- Returns:
- the controller
createCaret
protected Caret createCaret()
- Creates the object to use for a caret. By default an
instance of JCaret is created. This method
can be redefined to provide something else that implements
the InputPosition interface or a subclass of JCaret.
- Returns:
- the caret object
createHighlighter
protected Highlighter createHighlighter()
- Creates the object to use for adding highlights. By default
an instance of JHighlighter is created. This method
can be redefined to provide something else that implements
the Highlighter interface or a subclass of JHighlighter.
- Returns:
- the highlighter
paintBackground
protected void paintBackground(Graphics g)
- Paint a background for the view. This will only be
called if isOpaque() on the associated component is
true. The default is to paint the background color
of the component.
getComponent
protected final JTextComponent getComponent()
- Fetch the text component associated with this
UI implementation. This will be null until
the ui has been installed.
modelChanged
protected void modelChanged()
- This is called whenever the model has changed.
It is implemented to rebuild the view hierarchy
to represent the default root element of the
associated model.
setView
protected final void setView(View v)
- Set the current root of the view hierarchy.
installUI
public void installUI(JComponent c)
- Installs the UI for a component. This does the following
things.
-
Set the associated component to opaque (can be changed
easily by a subclass or on JTextComponent directly),
which is the most common case. This will cause the
component's background color to be painted.
-
Install the default caret and highlighter into the
associated component.
-
Attach to the editor and model. If there is no
model, a default one is created.
-
create the view factory and the view hierarchy used
to represent the model.
-
Create and wire up the controller.
- Parameters:
- c - the component
- Overrides:
- installUI in class ComponentUI
- See Also:
- installUI
uninstallUI
public void uninstallUI(JComponent c)
- Deinstalls the UI for a component.
- Parameters:
- c - the component
- Overrides:
- uninstallUI in class ComponentUI
- See Also:
- uninstallUI
paint
public synchronized void paint(Graphics g,
JComponent c)
- Paint the interface. This does the following things,
rendering from back to front.
-
If the component is marked as opaque, the background
is painted in the current background color of the
component.
-
The highlights (if any) are painted.
-
The view hierarchy is painted.
-
The caret is painted.
- Overrides:
- paint in class ComponentUI
getPreferredSize
public Dimension getPreferredSize(JComponent c)
- Overrides:
- getPreferredSize in class ComponentUI
getMinimumSize
public Dimension getMinimumSize(JComponent c)
- Overrides:
- getMinimumSize in class ComponentUI
getMaximumSize
public Dimension getMaximumSize(JComponent c)
- Overrides:
- getMaximumSize in class ComponentUI
getVisibleEditorRect
protected Rectangle getVisibleEditorRect()
modelToView
public Rectangle modelToView(int pos) throws BadLocationException
- Converts the given location in the model to a place in
the view coordinate system.
- Parameters:
- pos - the local location in the model to translate
- Returns:
- the coordinates as a rectangle
- Throws: BadLocation
- if the given position does not represent a
valid location in the associated document
- Overrides:
- modelToView in class TextUI
- See Also:
- modelToView
viewToModel
public int viewToModel(Point pt)
- Converts the given place in the view coordinate system
to the nearest representative location in the model.
- Parameters:
- pt - the location in the view to translate. This
should be in the same coordinate system as the mouse events.
- Returns:
- the offset from the start of the document
- Overrides:
- viewToModel in class TextUI
- See Also:
- viewToModel
damageRange
public void damageRange(int p0,
int p1)
- Causes the portion of the view responsible for the
given part of the model to be repainted.
- Parameters:
- p0 - the beginning of the range
- p1 - the end of the range
- Overrides:
- damageRange in class TextUI
- See Also:
- damageRange
getEditorKit
public EditorKit getEditorKit()
- Fetches the EditorKit for the UI.
- Returns:
- the editor capabilities
- Overrides:
- getEditorKit in class TextUI
- See Also:
- getEditorKit
getRootView
public View getRootView()
- Fetch a View with the allocation of the associated
text component (ie the root of the hierarchy) that
can be traversed to determine how the model is being
represented spatially.
- Overrides:
- getRootView in class TextUI
- See Also:
- getRootView
getDefaultMargin
public Insets getDefaultMargin()
- Fetches the default margin space for the text ui.
- Overrides:
- getDefaultMargin in class TextUI
create
public View create(Element elem)
- If a subclass wishes to directly implement the factory
producing the view(s), it should reimplement this
method. By default it simply returns null indicating
it is unable to represent the element.
create
public View create(Element elem,
int p0,
int p1)
- If a subclass wishes to directly implement the factory
producing the view(s), it should reimplement this
method. By default it simply returns null indicating
it is unable to represent the part of the element.
All Packages Class Hierarchy This Package Previous Next Index