javax.swing.plaf.basic
Class BasicTextUI.RootView

java.lang.Object
  extended byjavax.swing.text.View
      extended byjavax.swing.plaf.basic.BasicTextUI.RootView
All Implemented Interfaces:
SwingConstants
Enclosing class:
BasicTextUI

class BasicTextUI.RootView
extends View

Root view that acts as a gateway between the component and the View hierarchy.


Field Summary
private  View view
           
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Constructor Summary
(package private) BasicTextUI.RootView()
           
 
Method Summary
 View breakView(int axis, float len, Shape a)
          Breaks this view on the given axis at the given length.
 void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification from the document that attributes were changed in a location that this view is responsible for.
 float getAlignment(int axis)
          Determines the desired alignment for this view along an axis.
 AttributeSet getAttributes()
          Fetches the attributes to use when rendering.
 Shape getChildAllocation(int index, Shape a)
          Fetches the allocation for the given child view.
 Container getContainer()
          Fetches the container hosting the view.
 Document getDocument()
          Returns the document model underlying the view.
 Element getElement()
          Gets the element that this view is mapped to.
 int getEndOffset()
          Returns the ending offset into the model for this view.
 float getMaximumSpan(int axis)
          Determines the maximum span for this view along an axis.
 float getMinimumSpan(int axis)
          Determines the minimum span for this view along an axis.
 int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
          Provides a way to determine the next visually represented model location that one might place a caret.
 float getPreferredSpan(int axis)
          Determines the preferred span for this view along an axis.
 int getResizeWeight(int axis)
          Determines the resizability of the view along the given axis.
 int getStartOffset()
          Returns the starting offset into the model for this view.
 View getView(int n)
          Gets the n-th view in this container.
 int getViewCount()
          Returns the number of views in this view.
 ViewFactory getViewFactory()
          Fetches the factory to be used for building the various view fragments that make up the view that represents the model.
 int getViewIndex(int pos, Position.Bias b)
          Returns the child view index representing the given position in the model.
 void insertUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification that something was inserted into the document in a location that this view is responsible for.
 Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 Shape modelToView(int pos, Shape a, Position.Bias b)
          Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.
 void paint(Graphics g, Shape allocation)
          Renders the view.
 void preferenceChanged(View child, boolean width, boolean height)
          Specifies that a preference has changed.
 void removeUpdate(DocumentEvent e, Shape a, ViewFactory f)
          Gives notification that something was removed from the document in a location that this view is responsible for.
 void setParent(View parent)
          Sets the view parent.
 void setSize(float width, float height)
          Sets the view size.
(package private)  void setView(View v)
           
 int viewToModel(float x, float y, Shape a, Position.Bias[] bias)
          Provides a mapping from the view coordinate space to the logical coordinate space of the model.
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getBreakWeight, getGraphics, getParent, getToolTipText, getViewIndex, insert, isVisible, modelToView, remove, removeAll, replace, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

view

private View view
Constructor Detail

BasicTextUI.RootView

BasicTextUI.RootView()
Method Detail

setView

void setView(View v)

getAttributes

public AttributeSet getAttributes()
Fetches the attributes to use when rendering. At the root level there are no attributes. If an attribute is resolved up the view hierarchy this is the end of the line.

Overrides:
getAttributes in class View

getPreferredSpan

public float getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.

Specified by:
getPreferredSpan in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
See Also:
View.getPreferredSpan(int)

getMinimumSpan

public float getMinimumSpan(int axis)
Determines the minimum span for this view along an axis.

Overrides:
getMinimumSpan in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
See Also:
View.getPreferredSpan(int)

getMaximumSpan

public float getMaximumSpan(int axis)
Determines the maximum span for this view along an axis.

Overrides:
getMaximumSpan in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the span the view would like to be rendered into. Typically the view is told to render into the span that is returned, although there is no guarantee. The parent may choose to resize or break the view.
See Also:
View.getPreferredSpan(int)

preferenceChanged

public void preferenceChanged(View child,
                              boolean width,
                              boolean height)
Specifies that a preference has changed. Child views can call this on the parent to indicate that the preference has changed. The root view routes this to invalidate on the hosting component.

This can be called on a different thread from the event dispatching thread and is basically unsafe to propagate into the component. To make this safe, the operation is transferred over to the event dispatching thread for completion. It is a design goal that all view methods be safe to call without concern for concurrency, and this behavior helps make that true.

Overrides:
preferenceChanged in class View
Parameters:
child - the child view
width - true if the width preference has changed
height - true if the height preference has changed
See Also:
JComponent.revalidate()

getAlignment

public float getAlignment(int axis)
Determines the desired alignment for this view along an axis.

Overrides:
getAlignment in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the desired alignment, where 0.0 indicates the origin and 1.0 the full span away from the origin

paint

public void paint(Graphics g,
                  Shape allocation)
Renders the view.

Specified by:
paint in class View
Parameters:
g - the graphics context
allocation - the region to render into
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

setParent

public void setParent(View parent)
Sets the view parent.

Overrides:
setParent in class View
Parameters:
parent - the parent view

getViewCount

public int getViewCount()
Returns the number of views in this view. Since this view simply wraps the root of the view hierarchy it has exactly one child.

Overrides:
getViewCount in class View
Returns:
the number of views
See Also:
getView(int)

getView

public View getView(int n)
Gets the n-th view in this container.

Overrides:
getView in class View
Parameters:
n - the number of the view to get
Returns:
the view

getViewIndex

public int getViewIndex(int pos,
                        Position.Bias b)
Returns the child view index representing the given position in the model. This is implemented to return the index of the only child.

Overrides:
getViewIndex in class View
Parameters:
pos - the position >= 0
Returns:
index of the view representing the given position, or -1 if no view represents that position
Since:
1.3

getChildAllocation

public Shape getChildAllocation(int index,
                                Shape a)
Fetches the allocation for the given child view. This enables finding out where various views are located, without assuming the views store their location. This returns the given allocation since this view simply acts as a gateway between the view hierarchy and the associated component.

Overrides:
getChildAllocation in class View
Parameters:
index - the index of the child
a - the allocation to this view.
Returns:
the allocation to the child

modelToView

public Shape modelToView(int pos,
                         Shape a,
                         Position.Bias b)
                  throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

Specified by:
modelToView in class View
Parameters:
pos - the position to convert
a - the allocated region to render into
b - the bias toward the previous character or the next character represented by the offset, in case the position is a boundary of two views; b will have one of these values:
  • Position.Bias.Forward
  • Position.Bias.Backward
Returns:
the bounding box of the given position
Throws:
BadLocationException - if the specified position does not represent a valid location in the associated document
See Also:
View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])

modelToView

public Shape modelToView(int p0,
                         Position.Bias b0,
                         int p1,
                         Position.Bias b1,
                         Shape a)
                  throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

Overrides:
modelToView in class View
Parameters:
p0 - the position to convert >= 0
b0 - the bias toward the previous character or the next character represented by p0, in case the position is a boundary of two views.
p1 - the position to convert >= 0
b1 - the bias toward the previous character or the next character represented by p1, in case the position is a boundary of two views.
a - the allocated region to render into
Returns:
the bounding box of the given position is returned
Throws:
BadLocationException - if the given position does not represent a valid location in the associated document
IllegalArgumentException - for an invalid bias argument
See Also:
View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])

viewToModel

public int viewToModel(float x,
                       float y,
                       Shape a,
                       Position.Bias[] bias)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Specified by:
viewToModel in class View
Parameters:
x - x coordinate of the view location to convert
y - y coordinate of the view location to convert
a - the allocated region to render into
Returns:
the location within the model that best represents the given point in the view

getNextVisualPositionFrom

public int getNextVisualPositionFrom(int pos,
                                     Position.Bias b,
                                     Shape a,
                                     int direction,
                                     Position.Bias[] biasRet)
                              throws BadLocationException
Provides a way to determine the next visually represented model location that one might place a caret. Some views may not be visible, they might not be in the same order found in the model, or they just might not allow access to some of the locations in the model.

Overrides:
getNextVisualPositionFrom in class View
Parameters:
pos - the position to convert >= 0
a - the allocated region to render into
direction - the direction from the current position that can be thought of as the arrow keys typically found on a keyboard. This may be SwingConstants.WEST, SwingConstants.EAST, SwingConstants.NORTH, or SwingConstants.SOUTH.
Returns:
the location within the model that best represents the next location visual position.
Throws:
BadLocationException
IllegalArgumentException - for an invalid direction

insertUpdate

public void insertUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
Gives notification that something was inserted into the document in a location that this view is responsible for.

Overrides:
insertUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

removeUpdate

public void removeUpdate(DocumentEvent e,
                         Shape a,
                         ViewFactory f)
Gives notification that something was removed from the document in a location that this view is responsible for.

Overrides:
removeUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

changedUpdate

public void changedUpdate(DocumentEvent e,
                          Shape a,
                          ViewFactory f)
Gives notification from the document that attributes were changed in a location that this view is responsible for.

Overrides:
changedUpdate in class View
Parameters:
e - the change information from the associated document
a - the current allocation of the view
f - the factory to use to rebuild if the view has children
See Also:
View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

getDocument

public Document getDocument()
Returns the document model underlying the view.

Overrides:
getDocument in class View
Returns:
the model
See Also:
View.getDocument()

getStartOffset

public int getStartOffset()
Returns the starting offset into the model for this view.

Overrides:
getStartOffset in class View
Returns:
the starting offset
See Also:
View.getStartOffset()

getEndOffset

public int getEndOffset()
Returns the ending offset into the model for this view.

Overrides:
getEndOffset in class View
Returns:
the ending offset
See Also:
View.getEndOffset()

getElement

public Element getElement()
Gets the element that this view is mapped to.

Overrides:
getElement in class View
Returns:
the view
See Also:
View.getElement()

breakView

public View breakView(int axis,
                      float len,
                      Shape a)
Breaks this view on the given axis at the given length.

Parameters:
axis - may be either X_AXIS or Y_AXIS
len - specifies where a break is desired in the span
Returns:
the fragment of the view that represents the given span if the view can be broken, otherwise null

getResizeWeight

public int getResizeWeight(int axis)
Determines the resizability of the view along the given axis. A value of 0 or less is not resizable.

Overrides:
getResizeWeight in class View
Parameters:
axis - may be either X_AXIS or Y_AXIS
Returns:
the weight

setSize

public void setSize(float width,
                    float height)
Sets the view size.

Overrides:
setSize in class View
Parameters:
width - the width
height - the height

getContainer

public Container getContainer()
Fetches the container hosting the view. This is useful for things like scheduling a repaint, finding out the host components font, etc. The default implementation of this is to forward the query to the parent view.

Overrides:
getContainer in class View
Returns:
the container

getViewFactory

public ViewFactory getViewFactory()
Fetches the factory to be used for building the various view fragments that make up the view that represents the model. This is what determines how the model will be represented. This is implemented to fetch the factory provided by the associated EditorKit unless that is null, in which case this simply returns the BasicTextUI itself which allows subclasses to implement a simple factory directly without creating extra objects.

Overrides:
getViewFactory in class View
Returns:
the factory