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

public Class BlockView

extends BoxView
Class Inheritance
Known Direct Subclasses
javax.swing.text.html.HTMLEditorKit.HTMLFactory.BodyBlockView, javax.swing.text.html.ListView, javax.swing.text.html.NoFramesView, javax.swing.text.html.TableView.CellView
Imports
java.util.Enumeration, java.awt.*, javax.swing.SizeRequirements, javax.swing.border.*, javax.swing.event.DocumentEvent, javax.swing.text.*

A view implementation to display a block (as a box) with CSS specifications.
Author
Timothy Prinzing

Field Summary

Modifier and TypeField and Description
private AttributeSet
private CSS.LengthValue
private CSS.LengthValue
private StyleSheet.BoxPainter

Constructor Summary

AccessConstructor and Description
public
BlockView(Element
the element to create a view for
elem
,
int
either View.X_AXIS or View.Y_AXIS
axis
)

Creates a new view that represents an html box.

Method Summary

Modifier and TypeMethod and Description
protected SizeRequirements
calculateMajorAxisRequirements(int axis, SizeRequirements r)

Overrides javax.swing.text.BoxView.calculateMajorAxisRequirements.

Calculate the requirements of the block along the major axis (i.e. the axis along with it tiles).

protected SizeRequirements
calculateMinorAxisRequirements(int axis, SizeRequirements r)

Overrides javax.swing.text.BoxView.calculateMinorAxisRequirements.

Calculate the requirements of the block along the minor axis (i.e. the axis orthogonal to the axis along with it tiles).

public void
changedUpdate(DocumentEvent changes, Shape a, ViewFactory f)

Overrides javax.swing.text.View.changedUpdate.

Gives notification from the document that attributes were changed in a location that this view is responsible for.

private void
constrainSize(int axis, SizeRequirements want, SizeRequirements min)

Constrains want to fit in the minimum size specified by min.

public float

Returns:

the alignment
getAlignment
(int
may be either X_AXIS or Y_AXIS
axis
)

Overrides javax.swing.text.BoxView.getAlignment.

Gets the alignment.

public AttributeSet
getAttributes()

Overrides javax.swing.text.View.getAttributes.

Fetches the attributes to use when rendering.

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
getMaximumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.BoxView.getMaximumSpan.

Determines the maximum span for this view along an axis.

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
getMinimumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.BoxView.getMinimumSpan.

Determines the minimum span for this view along an axis.

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.BoxView.getPreferredSpan.

Determines the preferred span for this view along an axis.

public int

Returns:

the weight
getResizeWeight
(int
may be either X_AXIS or Y_AXIS
axis
)

Overrides javax.swing.text.BoxView.getResizeWeight.

Gets the resize weight.

protected StyleSheet

Returns:

the StyleSheet
getStyleSheet
()

Convenient method to get the StyleSheet.

pack-priv boolean
protected void
layoutMinorAxis(int
the total span given to the view, which would be used to layout the children.
targetSpan
,
int
the axis being laid out
axis
,
int[]
the offsets from the origin of the view for each of the child views; this is a return value and is filled in by the implementation of this method
offsets
,
int[]
the span of each child view; this is a return value and is filled in by the implementation of this method
spans
)

Overrides javax.swing.text.BoxView.layoutMinorAxis.

Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it represents).

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

Overrides javax.swing.text.BoxView.paint.

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

public void
setParent(View
the new parent, or null if the view is being removed from a parent it was previously added to
parent
)

Overrides javax.swing.text.CompositeView.setParent.

Establishes the parent view for this view.

protected void
setPropertiesFromAttributes()

Update any cached values that come from attributes.

pack-priv static boolean
spanSetFromAttributes(int axis, SizeRequirements r, CSS.LengthValue cssWidth, CSS.LengthValue cssHeight)

Adjust the given requirements to the CSS width or height if it is specified along the applicable axis.

Inherited from javax.swing.text.BoxView:
baselineLayoutbaselineRequirementschildAllocationflipEastAndWestAtEndsforwardUpdategetAxisgetChildAllocationgetHeightgetOffsetgetSpangetViewAtPointgetWidthisAfterisAllocationValidisBeforeisLayoutValidlayoutlayoutChangedlayoutMajorAxismodelToViewpaintChildpreferenceChangedreplacesetAxissetSizeviewToModel

Field Detail

attrback to summary
private AttributeSet attr
cssHeightback to summary
private CSS.LengthValue cssHeight
cssWidthback to summary
private CSS.LengthValue cssWidth
painterback to summary
private StyleSheet.BoxPainter painter

Constructor Detail

BlockViewback to summary
public BlockView(Element elem, int axis)

Creates a new view that represents an html box. This can be used for a number of elements.

Parameters
elem:Element

the element to create a view for

axis:int

either View.X_AXIS or View.Y_AXIS

Method Detail

calculateMajorAxisRequirementsback to summary
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r)

Overrides javax.swing.text.BoxView.calculateMajorAxisRequirements.

Calculate the requirements of the block along the major axis (i.e. the axis along with it tiles). This is implemented to provide the superclass behavior and then adjust it if the CSS width or height attribute is specified and applicable to the axis.

calculateMinorAxisRequirementsback to summary
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r)

Overrides javax.swing.text.BoxView.calculateMinorAxisRequirements.

Calculate the requirements of the block along the minor axis (i.e. the axis orthogonal to the axis along with it tiles). This is implemented to provide the superclass behavior and then adjust it if the CSS width or height attribute is specified and applicable to the axis.

changedUpdateback to summary
public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f)

Overrides javax.swing.text.View.changedUpdate.

Doc from javax.swing.text.View.changedUpdate.

Gives notification from the document that attributes were changed in a location that this view is responsible for. To reduce the burden to subclasses, this functionality is spread out into the following calls that subclasses can reimplement:

  1. updateChildren is called if there were any changes to the element this view is responsible for. If this view has child views that are represent the child elements, then this method should do whatever is necessary to make sure the child views correctly represent the model.
  2. forwardUpdate is called to forward the DocumentEvent to the appropriate child views.
  3. updateLayout is called to give the view a chance to either repair its layout, to reschedule layout, or do nothing.
constrainSizeback to summary
private void constrainSize(int axis, SizeRequirements want, SizeRequirements min)

Constrains want to fit in the minimum size specified by min.

getAlignmentback to summary
public float getAlignment(int axis)

Overrides javax.swing.text.BoxView.getAlignment.

Gets the alignment.

Parameters
axis:int

may be either X_AXIS or Y_AXIS

Returns:float

the alignment

getAttributesback to summary
public AttributeSet getAttributes()

Overrides javax.swing.text.View.getAttributes.

Fetches the attributes to use when rendering. This is implemented to multiplex the attributes specified in the model with a StyleSheet.

getMaximumSpanback to summary
public float getMaximumSpan(int axis)

Overrides javax.swing.text.BoxView.getMaximumSpan.

Determines the maximum 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

Exceptions
IllegalArgumentException:
for an invalid axis type
getMinimumSpanback to summary
public float getMinimumSpan(int axis)

Overrides javax.swing.text.BoxView.getMinimumSpan.

Determines the minimum 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

Exceptions
IllegalArgumentException:
for an invalid axis type
getPreferredSpanback to summary
public float getPreferredSpan(int axis)

Overrides javax.swing.text.BoxView.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

Exceptions
IllegalArgumentException:
for an invalid axis type
getResizeWeightback to summary
public int getResizeWeight(int axis)

Overrides javax.swing.text.BoxView.getResizeWeight.

Gets the resize weight.

Parameters
axis:int

may be either X_AXIS or Y_AXIS

Returns:int

the weight

Exceptions
IllegalArgumentException:
for an invalid axis
getStyleSheetback to summary
protected StyleSheet getStyleSheet()

Convenient method to get the StyleSheet.

Returns:StyleSheet

the StyleSheet

isPercentageback to summary
pack-priv boolean isPercentage(int axis, AttributeSet a)
layoutMinorAxisback to summary
protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans)

Overrides javax.swing.text.BoxView.layoutMinorAxis.

Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it represents). The results of the layout (the offset and span for each children) are placed in the given arrays which represent the allocations to the children along the minor axis.

Parameters
targetSpan:int

the total span given to the view, which would be used to layout the children.

axis:int

the axis being laid out

offsets:int[]

the offsets from the origin of the view for each of the child views; this is a return value and is filled in by the implementation of this method

spans:int[]

the span of each child view; this is a return value and is filled in by the implementation of this method

paintback to summary
public void paint(Graphics g, Shape allocation)

Overrides javax.swing.text.BoxView.paint.

Renders using the given rendering surface and area on that surface. This is implemented to delegate to the css box painter to paint the border and background prior to the interior.

Parameters
g:Graphics

the rendering surface to use

allocation:Shape

the allocated region to render into

See Also
View#paint
setParentback to summary
public void setParent(View parent)

Overrides javax.swing.text.CompositeView.setParent.

Establishes the parent view for this view. This is guaranteed to be called before any other methods if the parent view is functioning properly.

This is implemented to forward to the superclass as well as call the setPropertiesFromAttributes() method to set the paragraph properties from the css attributes. The call is made at this time to ensure the ability to resolve upward through the parents view attributes.

Parameters
parent:View

the new parent, or null if the view is being removed from a parent it was previously added to

setPropertiesFromAttributesback to summary
protected void setPropertiesFromAttributes()

Update any cached values that come from attributes.

spanSetFromAttributesback to summary
pack-priv static boolean spanSetFromAttributes(int axis, SizeRequirements r, CSS.LengthValue cssWidth, CSS.LengthValue cssHeight)

Adjust the given requirements to the CSS width or height if it is specified along the applicable axis. Return true if the size is exactly specified, false if the span is not specified in an attribute or the size specified is a percentage.