Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.awt.swing.text.DefaultTextUI

java.lang.Object
    |
    +----java.awt.swing.plaf.ComponentUI
            |
            +----java.awt.swing.plaf.TextUI
                    |
                    +----java.awt.swing.text.DefaultTextUI

public abstract class DefaultTextUI
extends java.awt.swing.plaf.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.

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

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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.


Constructor Summary
 DefaultTextUI()
Creates a new UI.
 

Method Summary
View  create(Element elem)
Creates a view for an element.
View  create(Element elem, int p0, int p1)
Creates a view for an element.
Caret  createCaret()
Creates the object to use for a caret.
Highlighter  createHighlighter()
Creates the object to use for adding highlights.
Keymap  createKeymap()
Creates the keymap to use for the text component, and installs any necessary bindings into it.
void  damageRange(int p0, int p1)
Causes the portion of the view responsible for the given part of the model to be repainted.
JTextComponent  getComponent()
Fetches the text component associated with this UI implementation.
Insets  getDefaultMargin()
Fetches the default margin space for the text ui.
EditorKit  getEditorKit()
Fetches the EditorKit for the UI.
Dimension  getMaximumSize(JComponent c)
Gets the maximum size for the editor component.
Dimension  getMinimumSize(JComponent c)
Gets the minimum size for the editor component.
Dimension  getPreferredSize(JComponent c)
Gets the preferred size for the editor component.
String  getPropertyPrefix()
Gets the name used as a key to lookup properties through the UIManager.
View  getRootView()
Fetches 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.
Rectangle  getVisibleEditorRect()
Gets the portion of the editor visibile on the screen.
void  installDefaults(JComponent c)
Initializes component properties, e.g.
void  installListeners(JComponent c)
 
void  installUI(JComponent c)
Installs the UI for a component.
void  modelChanged()
Flags model changes.
Rectangle  modelToView(int pos)
Converts the given location in the model to a place in the view coordinate system.
void  paint(Graphics g, JComponent c)
Paints the interface.
void  paintBackground(Graphics g)
Paints a background for the view.
void  paintSafely(Graphics g)
Paints the interface safely with a guarantee that the model won't change from the view of this thread.
void  propertyChange(PropertyChangeEvent evt)
This method gets called when a bound property is changed on the associated JTextComponent.
void  setView(View v)
Sets the current root of the view hierarchy.
void  uninstallDefaults(JComponent c)
Sets the component properties that haven't been explicitly overriden to null.
void  uninstallListeners(JComponent c)
 
void  uninstallUI(JComponent c)
Deinstalls the UI for a component.
int  viewToModel(Point pt)
Converts the given place in the view coordinate system to the nearest representative location in the model.
 
Methods inherited from class java.awt.swing.plaf.TextUI
 damageRange, getDefaultMargin, getEditorKit, getRootView, modelToView, viewToModel
 
Methods inherited from class java.awt.swing.plaf.ComponentUI
 contains, createUI, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTextUI

public DefaultTextUI()
Creates a new UI.
Method Detail

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

createKeymap

protected abstract Keymap createKeymap()
Creates the keymap to use for the text component, and installs any necessary bindings into it.
Returns:
the keymap

propertyChange

protected void propertyChange(PropertyChangeEvent evt)
This method gets called when a bound property is changed on the associated JTextComponent. This is a hook which UI implementations may change to reflect how the UI displays bound properties of JTextComponent subclasses. This is implemented to do nothing (ie. the response to properties in JTextComponent itself are handled prior to calling this method).

getPropertyPrefix

protected abstract String getPropertyPrefix()
Gets the name used as a key to lookup properties through the UIManager. This is used as a prefix to all the standard text properties.
Returns:
the name

installDefaults

protected void installDefaults(JComponent c)
Initializes component properties, e.g. font, foreground, and background. The font, foreground, and background properties are only set if their current value is either null or a UIResource, other properties are set if the current value is null.
See Also:
uninstallDefaults, installUI

uninstallDefaults

protected void uninstallDefaults(JComponent c)
Sets the component properties that haven't been explicitly overriden to null. A property is considered overridden if its current value is not a UIResource.
See Also:
installDefaults, uninstallUI

installListeners

protected void installListeners(JComponent c)

uninstallListeners

protected void uninstallListeners(JComponent c)

paintBackground

protected void paintBackground(Graphics g)
Paints 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.
Parameters:
g - the graphics context

getComponent

protected final JTextComponent getComponent()
Fetches the text component associated with this UI implementation. This will be null until the ui has been installed.
Returns:
the component

modelChanged

protected void modelChanged()
Flags model changes. 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)
Sets the current root of the view hierarchy.
Parameters:
v - the root view

paintSafely

protected void paintSafely(Graphics g)
Paints the interface safely with a guarantee that the model won't change from the view of this thread. This does the following things, rendering from back to front.
  1. If the component is marked as opaque, the background is painted in the current background color of the component.
  2. The highlights (if any) are painted.
  3. The view hierarchy is painted.
  4. The caret is painted.
Parameters:
g - the graphics context
c - the editor component

installUI

public void installUI(JComponent c)
Installs the UI for a component. This does the following things.
  1. 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.
  2. Install the default caret and highlighter into the associated component.
  3. Attach to the editor and model. If there is no model, a default one is created.
  4. create the view factory and the view hierarchy used to represent the model.
Parameters:
c - the component
Overrides:
installUI in class java.awt.swing.plaf.ComponentUI
See Also:
installUI

uninstallUI

public void uninstallUI(JComponent c)
Deinstalls the UI for a component.
Parameters:
c - the component
Overrides:
uninstallUI in class java.awt.swing.plaf.ComponentUI
See Also:
uninstallUI

paint

public final void paint(Graphics g,
                        JComponent c)
Paints the interface. This is routed to paintSafely under the guarantee that the model won't change from the view of this thread while it's rendering. This enables the model to potentially be updated asynchronously.
Parameters:
g - the graphics context
c - the editor component
Overrides:
paint in class java.awt.swing.plaf.ComponentUI

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Gets the preferred size for the editor component.
Parameters:
c - the editor component
Returns:
the size
Overrides:
getPreferredSize in class java.awt.swing.plaf.ComponentUI

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Gets the minimum size for the editor component.
Parameters:
c - the editor component
Returns:
the size
Overrides:
getMinimumSize in class java.awt.swing.plaf.ComponentUI

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Gets the maximum size for the editor component.
Parameters:
c - the editor component
Returns:
the size
Overrides:
getMaximumSize in class java.awt.swing.plaf.ComponentUI

getVisibleEditorRect

protected Rectangle getVisibleEditorRect()
Gets the portion of the editor visibile on the screen.
Returns:
the bounding box for the visible portion

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:
BadLocationException - if the given position does not represent a valid location in the associated document
Overrides:
modelToView in class java.awt.swing.plaf.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 java.awt.swing.plaf.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 java.awt.swing.plaf.TextUI
See Also:
damageRange

getEditorKit

public EditorKit getEditorKit()
Fetches the EditorKit for the UI.
Returns:
the editor capabilities
Overrides:
getEditorKit in class java.awt.swing.plaf.TextUI
See Also:
getEditorKit

getRootView

public View getRootView()
Fetches 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.
Returns:
the view
Overrides:
getRootView in class java.awt.swing.plaf.TextUI
See Also:
getRootView

getDefaultMargin

public Insets getDefaultMargin()
Fetches the default margin space for the text ui.
Returns:
the margins
Overrides:
getDefaultMargin in class java.awt.swing.plaf.TextUI

create

public View create(Element elem)
Creates a view for an element. 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.
Implements:
create in interface ViewFactory
Parameters:
elem - the element
Returns:
the view

create

public View create(Element elem,
                   int p0,
                   int p1)
Creates a view for an element. 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.
Implements:
create in interface ViewFactory
Parameters:
elem - the element
p0 - the starting offset
p1 - the ending offset
Returns:
the view

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.