APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.text

public Class FieldView

extends PlainView
Class Inheritance
Known Direct Subclasses
javax.swing.text.PasswordView
Imports
java.awt.*, javax.swing.*, javax.swing.event.*

Extends the multi-line plain text view to be suitable for a single-line editor view. If the view is allocated extra space, the field must adjust for it. If the hosting component is a JTextField, this view will manage the ranges of the associated BoundedRangeModel and will adjust the horizontal allocation to match the current visibility settings of the JTextField.
Author
Timothy Prinzing
See Also
View

Field Summary

Inherited from javax.swing.text.PlainView:
drawLineOverriddendrawSelectedTextOverriddendrawUnselectedTextOverriddenfirstLineOffsetfontlineBufferlongLinemetricssel0sel1selectedtabBasetabSizeunselecteduseFloatingPointAPI

Constructor Summary

AccessConstructor and Description
public
FieldView(Element
the element
elem
)

Constructs a new FieldView wrapped on an element.

Method Summary

Modifier and TypeMethod and Description
protected Shape

Returns:

the allocation that the superclass should use.
adjustAllocation
(Shape
the allocation given to the view, which may need to be adjusted.
a
)

Adjusts the allocation given to the view to be a suitable allocation for a text field.

pack-priv Shape
adjustPaintRegion(Shape a)

Overrides javax.swing.text.PlainView.adjustPaintRegion.

Adjusts a based on the visible region and returns it.

protected FontMetrics

Returns:

the metrics
getFontMetrics
()

Fetches the font metrics associated with the component hosting this view.

public float

Returns:

the span the view would like to be rendered into >= 0. 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.
getPreferredSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.PlainView.getPreferredSpan.

Determines the preferred span for this view along an axis.

public int

Returns:

the weight -> 1 for View.X_AXIS, else 0
getResizeWeight
(int
View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getResizeWeight.

Determines the resizability of the view along the given axis.

public void
insertUpdate(DocumentEvent
the change information from the associated document
changes
,
Shape
the current allocation of the view
a
,
ViewFactory
the factory to use to rebuild if the view has children
f
)

Overrides javax.swing.text.PlainView.insertUpdate.

Gives notification that something was inserted into the document in a location that this view is responsible for.

public Shape

Returns:

the bounding box of the given position
modelToView
(int
the position to convert >= 0
pos
,
Shape
the allocated region to render into
a
,
Position.Bias b)

Overrides javax.swing.text.PlainView.modelToView.

Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

public void
paint(Graphics
the rendering surface to use
g
,
Shape
the allocated region to render into
a
)

Overrides javax.swing.text.PlainView.paint.

Renders using the given rendering surface and area on that surface.

public void
removeUpdate(DocumentEvent
the change information from the associated document
changes
,
Shape
the current allocation of the view
a
,
ViewFactory
the factory to use to rebuild if the view has children
f
)

Overrides javax.swing.text.PlainView.removeUpdate.

Gives notification that something was removed from the document in a location that this view is responsible for.

pack-priv void
updateVisibilityModel()

Update the visibility model with the associated JTextField (if there is one) to reflect the current visibility as a result of changes to the document model.

public int

Returns:

the location within the model that best represents the given point in the view
viewToModel
(float
the X coordinate >= 0.0f
fx
,
float
the Y coordinate >= 0.0f
fy
,
Shape
the allocated region to render into
a
,
Position.Bias[] bias)

Overrides javax.swing.text.PlainView.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Inherited from javax.swing.text.PlainView:
callDrawSelectedTextchangedUpdatedamageLineRangedrawLinedrawLinedrawSelectedTextdrawSelectedTextdrawUnselectedTextdrawUnselectedTextgetFPMethodOverriddengetLineBuffergetTabSizelineToRectnextTabStopsetSizeupdateDamageupdateMetrics

Constructor Detail

FieldViewback to summary
public FieldView(Element elem)

Constructs a new FieldView wrapped on an element.

Parameters
elem:Element

the element

Method Detail

adjustAllocationback to summary
protected Shape adjustAllocation(Shape a)

Adjusts the allocation given to the view to be a suitable allocation for a text field. If the view has been allocated more than the preferred span vertically, the allocation is changed to be centered vertically. Horizontally the view is adjusted according to the horizontal alignment property set on the associated JTextField (if that is the type of the hosting component).

Parameters
a:Shape

the allocation given to the view, which may need to be adjusted.

Returns:Shape

the allocation that the superclass should use.

adjustPaintRegionback to summary
pack-priv Shape adjustPaintRegion(Shape a)

Overrides javax.swing.text.PlainView.adjustPaintRegion.

Adjusts a based on the visible region and returns it.

getFontMetricsback to summary
protected FontMetrics getFontMetrics()

Fetches the font metrics associated with the component hosting this view.

Returns:FontMetrics

the metrics

getPreferredSpanback to summary
public float getPreferredSpan(int axis)

Overrides javax.swing.text.PlainView.getPreferredSpan.

Determines the preferred span for this view along an axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >= 0. 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.

Annotations
@SuppressWarnings:deprecation
getResizeWeightback to summary
public int getResizeWeight(int axis)

Overrides javax.swing.text.View.getResizeWeight.

Determines the resizability of the view along the given axis. A value of 0 or less is not resizable.

Parameters
axis:int

View.X_AXIS or View.Y_AXIS

Returns:int

the weight -> 1 for View.X_AXIS, else 0

insertUpdateback to summary
public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f)

Overrides javax.swing.text.PlainView.insertUpdate.

Gives notification that something was inserted into the document in a location that this view is responsible for.

Parameters
changes:DocumentEvent

the change information from the associated document

a:Shape

the current allocation of the view

f:ViewFactory

the factory to use to rebuild if the view has children

See Also
View#insertUpdate
modelToViewback to summary
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException

Overrides javax.swing.text.PlainView.modelToView.

Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

Parameters
pos:int

the position to convert >= 0

a:Shape

the allocated region to render into

Returns:Shape

the bounding box of the given position

Exceptions
BadLocationException:
if the given position does not represent a valid location in the associated document
See Also
View#modelToView
paintback to summary
public void paint(Graphics g, Shape a)

Overrides javax.swing.text.PlainView.paint.

Renders using the given rendering surface and area on that surface. The view may need to do layout and create child views to enable itself to render into the given allocation.

Parameters
g:Graphics

the rendering surface to use

a:Shape

the allocated region to render into

See Also
View#paint
removeUpdateback to summary
public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f)

Overrides javax.swing.text.PlainView.removeUpdate.

Gives notification that something was removed from the document in a location that this view is responsible for.

Parameters
changes:DocumentEvent

the change information from the associated document

a:Shape

the current allocation of the view

f:ViewFactory

the factory to use to rebuild if the view has children

See Also
View#removeUpdate
updateVisibilityModelback to summary
pack-priv void updateVisibilityModel()

Update the visibility model with the associated JTextField (if there is one) to reflect the current visibility as a result of changes to the document model. The bounded range properties are updated. If the view hasn't yet been shown the extent will be zero and we just set it to be full until determined otherwise.

viewToModelback to summary
public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias)

Overrides javax.swing.text.PlainView.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Parameters
fx:float

the X coordinate >= 0.0f

fy:float

the Y coordinate >= 0.0f

a:Shape

the allocated region to render into

Returns:int

the location within the model that best represents the given point in the view

See Also
View#viewToModel