javax.swing.text.html
Class TableView

java.lang.Object
  extended byjavax.swing.text.View
      extended byjavax.swing.text.CompositeView
          extended byjavax.swing.text.BoxView
              extended byjavax.swing.text.html.TableView
All Implemented Interfaces:
SwingConstants, ViewFactory

class TableView
extends BoxView
implements ViewFactory

HTML table view.

Author:
Timothy Prinzing
See Also:
View

Nested Class Summary
(package private)  class TableView.CellView
          Default view of an html table cell.
(package private)  class TableView.ColumnIterator
           
(package private)  class TableView.RowIterator
           
 class TableView.RowView
          View of a row in a row-centric table.
 
Field Summary
private  AttributeSet attr
           
private  int captionIndex
          The index of the caption view if there is a caption.
private  int cellSpacing
           
(package private)  TableView.ColumnIterator colIterator
           
(package private)  int[] columnOffsets
           
(package private)  SizeRequirements[] columnRequirements
           
(package private)  int[] columnSpans
           
private static BitSet EMPTY
           
(package private)  boolean gridValid
           
private  boolean multiRowCells
          Do any of the table cells span multiple rows?
private  StyleSheet.BoxPainter painter
           
private  boolean relativeCells
          Do any of the table cells contain a relative size specification?
(package private)  TableView.RowIterator rowIterator
           
(package private)  Vector rows
           
(package private)  SizeRequirements totalColumnRequirements
          SizeRequirements for all the columns.
 
Fields inherited from class javax.swing.text.BoxView
 
Fields inherited from class javax.swing.text.CompositeView
 
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
TableView(Element elem)
          Constructs a TableView for the given element.
 
Method Summary
(package private)  void addFill(int row, int col)
          Mark a grid location as filled in for a cells overflow.
(package private)  void calculateColumnRequirements(int axis)
          Calculate the requirements for each column.
protected  SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r)
          Calculate the requirements for the major axis.
protected  SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r)
          Calculate the requirements for the minor axis.
 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.
(package private)  void checkMultiColumnCell(int axis, int col, int ncols, View v)
          check the requirements of a table cell that spans multiple columns.
(package private)  void checkSingleColumnCell(int axis, int col, View v)
          check the requirements of a table cell that spans a single column.
 View create(Element elem)
          The table itself acts as a factory for the various views that actually represent pieces of the table.
protected  TableView.RowView createTableRow(Element elem)
          Creates a new table row.
protected  void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory f)
          Forwards the given DocumentEvent to the child views that need to be notified of the change to the model.
 AttributeSet getAttributes()
          Fetches the attributes to use when rendering.
 int getColumnCount()
          The number of columns in the table.
protected  int getColumnsOccupied(View v)
          Determines the number of columns occupied by the table cell represented by given element.
 int getColumnSpan(int col)
          Fetches the span (width) of the given column.
 int getMultiRowSpan(int row0, int row1)
          Fetch the span of multiple rows.
(package private)  TableView.RowView getRow(int row)
           
 int getRowCount()
          The number of rows in the table.
protected  int getRowsOccupied(View v)
          Determines the number of rows occupied by the table cell represented by given element.
 int getRowSpan(int row)
          Fetches the span (height) of the given row.
protected  StyleSheet getStyleSheet()
           
protected  View getViewAtPoint(int x, int y, Rectangle alloc)
          Fetches the child view at the given coordinates.
protected  View getViewAtPosition(int pos, Rectangle a)
          Fetches the child view that represents the given position in the model.
 ViewFactory getViewFactory()
          Fetches the ViewFactory implementation that is feeding the view hierarchy.
 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.
protected  void invalidateGrid()
           
protected  void layoutColumns(int targetSpan, int[] offsets, int[] spans, SizeRequirements[] reqs)
          Layout the columns to fit within the given target span.
protected  void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans)
          Perform layout for the major axis of the box (i.e. the axis that it represents).
protected  void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans)
          Perform layout for the minor axis of the box (i.e. the axis orthoginal to the axis that it represents).
 void paint(Graphics g, Shape allocation)
          Renders using the given rendering surface and area on that surface.
 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 replace(int offset, int length, View[] views)
          Change the child views.
 void setParent(View parent)
          Establishes the parent view for this view.
protected  void setPropertiesFromAttributes()
          Update any cached values that come from attributes.
(package private)  void updateGrid()
          Fill in the grid locations that are placeholders for multi-column, multi-row, and missing grid locations.
(package private)  void updateInsets()
          Update the insets, which contain the caption if there is a caption.
 
Methods inherited from class javax.swing.text.BoxView
baselineLayout, baselineRequirements, childAllocation, flipEastAndWestAtEnds, getAlignment, getAxis, getChildAllocation, getHeight, getMaximumSpan, getMinimumSpan, getOffset, getPreferredSpan, getResizeWeight, getSpan, getWidth, isAfter, isAllocationValid, isBefore, isLayoutValid, layout, layoutChanged, modelToView, paintChild, preferenceChanged, setAxis, setSize, viewToModel
 
Methods inherited from class javax.swing.text.CompositeView
getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewCount, getViewIndex, getViewIndexAtPosition, loadChildren, modelToView, setInsets, setParagraphInsets
 
Methods inherited from class javax.swing.text.View
append, breakView, createFragment, forwardUpdateToView, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewIndex, insert, isVisible, modelToView, remove, removeAll, updateChildren, updateLayout, viewToModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attr

private AttributeSet attr

painter

private StyleSheet.BoxPainter painter

cellSpacing

private int cellSpacing

captionIndex

private int captionIndex
The index of the caption view if there is a caption. This has a value of -1 if there is no caption. The caption lives in the inset area of the table, and is updated with each time the grid is recalculated.


relativeCells

private boolean relativeCells
Do any of the table cells contain a relative size specification? This is updated with each call to updateGrid(). If this is true, the ColumnIterator will do extra work to calculate relative cell specifications.


multiRowCells

private boolean multiRowCells
Do any of the table cells span multiple rows? If true, the RowRequirementIterator will do additional work to adjust the requirements of rows spanned by a single table cell. This is updated with each call to updateGrid().


columnSpans

int[] columnSpans

columnOffsets

int[] columnOffsets

totalColumnRequirements

SizeRequirements totalColumnRequirements
SizeRequirements for all the columns.


columnRequirements

SizeRequirements[] columnRequirements

rowIterator

TableView.RowIterator rowIterator

colIterator

TableView.ColumnIterator colIterator

rows

Vector rows

gridValid

boolean gridValid

EMPTY

private static final BitSet EMPTY
Constructor Detail

TableView

public TableView(Element elem)
Constructs a TableView for the given element.

Parameters:
elem - the element that this view is responsible for
Method Detail

createTableRow

protected TableView.RowView createTableRow(Element elem)
Creates a new table row.

Parameters:
elem - an element
Returns:
the row

getColumnCount

public int getColumnCount()
The number of columns in the table.


getColumnSpan

public int getColumnSpan(int col)
Fetches the span (width) of the given column. This is used by the nested cells to query the sizes of grid locations outside of themselves.


getRowCount

public int getRowCount()
The number of rows in the table.


getMultiRowSpan

public int getMultiRowSpan(int row0,
                           int row1)
Fetch the span of multiple rows. This includes the border area.


getRowSpan

public int getRowSpan(int row)
Fetches the span (height) of the given row.


getRow

TableView.RowView getRow(int row)

getViewAtPoint

protected View getViewAtPoint(int x,
                              int y,
                              Rectangle alloc)
Description copied from class: BoxView
Fetches the child view at the given coordinates.

Overrides:
getViewAtPoint in class BoxView
Parameters:
x - the X coordinate >= 0
y - the Y coordinate >= 0
alloc - the parents inner allocation on entry, which should be changed to the childs allocation on exit
Returns:
the view

getColumnsOccupied

protected int getColumnsOccupied(View v)
Determines the number of columns occupied by the table cell represented by given element.


getRowsOccupied

protected int getRowsOccupied(View v)
Determines the number of rows occupied by the table cell represented by given element.


invalidateGrid

protected void invalidateGrid()

getStyleSheet

protected StyleSheet getStyleSheet()

updateInsets

void updateInsets()
Update the insets, which contain the caption if there is a caption.


setPropertiesFromAttributes

protected void setPropertiesFromAttributes()
Update any cached values that come from attributes.


updateGrid

void updateGrid()
Fill in the grid locations that are placeholders for multi-column, multi-row, and missing grid locations.


addFill

void addFill(int row,
             int col)
Mark a grid location as filled in for a cells overflow.


layoutColumns

protected void layoutColumns(int targetSpan,
                             int[] offsets,
                             int[] spans,
                             SizeRequirements[] reqs)
Layout the columns to fit within the given target span.

Parameters:
targetSpan - the given span for total of all the table columns
reqs - the requirements desired for each column. This is the column maximum of the cells minimum, preferred, and maximum requested span
spans - the return value of how much to allocated to each column
offsets - the return value of the offset from the origin for each column
Returns:
the offset from the origin and the span for each column in the offsets and spans parameters

calculateColumnRequirements

void calculateColumnRequirements(int axis)
Calculate the requirements for each column. The calculation is done as two passes over the table. The table cells that occupy a single column are scanned first to determine the maximum of minimum, preferred, and maximum spans along the give axis. Table cells that span multiple columns are excluded from the first pass. A second pass is made to determine if the cells that span multiple columns are satisfied. If the column requirements are not satisified, the needs of the multi-column cell is mixed into the existing column requirements. The calculation of the multi-column distribution is based upon the proportions of the existing column requirements and taking into consideration any constraining maximums.


checkSingleColumnCell

void checkSingleColumnCell(int axis,
                           int col,
                           View v)
check the requirements of a table cell that spans a single column.


checkMultiColumnCell

void checkMultiColumnCell(int axis,
                          int col,
                          int ncols,
                          View v)
check the requirements of a table cell that spans multiple columns.


calculateMinorAxisRequirements

protected SizeRequirements calculateMinorAxisRequirements(int axis,
                                                          SizeRequirements r)
Calculate the requirements for the minor axis. This is called by the superclass whenever the requirements need to be updated (i.e. a preferenceChanged was messaged through this view).

This is implemented to calculate the requirements as the sum of the requirements of the columns and then adjust it if the CSS width or height attribute is specified and applicable to the axis.

Overrides:
calculateMinorAxisRequirements in class BoxView
Parameters:
axis - the axis being studied
r - the SizeRequirements object; if null one will be created
Returns:
the newly initialized SizeRequirements object
See Also:
SizeRequirements

calculateMajorAxisRequirements

protected SizeRequirements calculateMajorAxisRequirements(int axis,
                                                          SizeRequirements r)
Calculate the requirements for the major axis. This is called by the superclass whenever the requirements need to be updated (i.e. a preferenceChanged was messaged through this view).

This is implemented to provide the superclass behavior adjusted for multi-row table cells.

Overrides:
calculateMajorAxisRequirements in class BoxView
Parameters:
axis - the axis being studied
r - the SizeRequirements object; if null one will be created
Returns:
the newly initialized SizeRequirements object
See Also:
SizeRequirements

layoutMinorAxis

protected void layoutMinorAxis(int targetSpan,
                               int axis,
                               int[] offsets,
                               int[] spans)
Perform layout for the minor axis of the box (i.e. the axis orthoginal to the axis that it represents). The results of the layout should be placed in the given arrays which represent the allocations to the children along the minor axis. This is called by the superclass whenever the layout needs to be updated along the minor axis.

This is implemented to call the layoutColumns method, and then forward to the superclass to actually carry out the layout of the tables rows.

Overrides:
layoutMinorAxis in class BoxView
Parameters:
targetSpan - the total span given to the view, which whould be used to layout the children
axis - the axis being layed out
offsets - 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 - the span of each child view; this is a return value and is filled in by the implementation of this method
Returns:
the offset and span for each child view in the offsets and spans parameters

layoutMajorAxis

protected void layoutMajorAxis(int targetSpan,
                               int axis,
                               int[] offsets,
                               int[] spans)
Perform layout for the major axis of the box (i.e. the axis that it represents). The results of the layout should be placed in the given arrays which represent the allocations to the children along the minor axis. This is called by the superclass whenever the layout needs to be updated along the minor axis.

This method is where the layout of the table rows within the table takes place. This method is implemented to call the use the RowIterator and the CSS collapsing tile to layout with border spacing and border collapsing capabilities.

Overrides:
layoutMajorAxis in class BoxView
Parameters:
targetSpan - the total span given to the view, which whould be used to layout the children
axis - the axis being layed out
offsets - 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 - the span of each child view; this is a return value and is filled in by the implementation of this method
Returns:
the offset and span for each child view in the offsets and spans parameters

getViewAtPosition

protected View getViewAtPosition(int pos,
                                 Rectangle a)
Fetches the child view that represents the given position in the model. This is implemented to walk through the children looking for a range that contains the given position. In this view the children do not necessarily have a one to one mapping with the child elements.

Overrides:
getViewAtPosition in class CompositeView
Parameters:
pos - the search position >= 0
a - the allocation to the table on entry, and the allocation of the view containing the position on exit
Returns:
the view representing the given position, or null if there isn't one

getAttributes

public AttributeSet getAttributes()
Fetches the attributes to use when rendering. This is implemented to multiplex the attributes specified in the model with a StyleSheet.

Overrides:
getAttributes in class View

paint

public void paint(Graphics g,
                  Shape allocation)
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. The superclass culls rendering the children that don't directly intersect the clip and the row may have cells hanging from a row above in it. The table does not use the superclass rendering behavior and instead paints all of the rows and lets the rows cull those cells not intersecting the clip region.

Overrides:
paint in class BoxView
Parameters:
g - the rendering surface to use
allocation - the allocated region to render into
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

setParent

public void setParent(View parent)
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.

Overrides:
setParent in class CompositeView
Parameters:
parent - the new parent, or null if the view is being removed from a parent it was previously added to

getViewFactory

public ViewFactory getViewFactory()
Fetches the ViewFactory implementation that is feeding the view hierarchy. This replaces the ViewFactory with an implementation that calls through to the createTableRow and createTableCell methods. If the element given to the factory isn't a table row or cell, the request is delegated to the factory produced by the superclass behavior.

Overrides:
getViewFactory in class View
Returns:
the factory, null if none

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. This replaces the ViewFactory with an implementation that calls through to the createTableRow and createTableCell methods. If the element given to the factory isn't a table row or cell, the request is delegated to the factory passed as an argument.

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. This replaces the ViewFactory with an implementation that calls through to the createTableRow and createTableCell methods. If the element given to the factory isn't a table row or cell, the request is delegated to the factory passed as an argument.

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. This replaces the ViewFactory with an implementation that calls through to the createTableRow and createTableCell methods. If the element given to the factory isn't a table row or cell, the request is delegated to the factory passed as an argument.

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)

forwardUpdate

protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e,
                             Shape a,
                             ViewFactory f)
Description copied from class: BoxView
Forwards the given DocumentEvent to the child views that need to be notified of the change to the model. If a child changed its requirements and the allocation was valid prior to forwarding the portion of the box from the starting child to the end of the box will be repainted.

Overrides:
forwardUpdate in class BoxView
Parameters:
ec - changes to the element this view is responsible for (may be null if there were no changes)
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), View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory), View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

replace

public void replace(int offset,
                    int length,
                    View[] views)
Change the child views. This is implemented to provide the superclass behavior and invalidate the grid so that rows and columns will be recalculated.

Overrides:
replace in class BoxView
Parameters:
offset - the starting index into the child views to insert the new views; this should be a value >= 0 and <= getViewCount
length - the number of existing child views to remove; This should be a value >= 0 and <= (getViewCount() - offset)
views - the child views to add; this value can be nullto indicate no children are being added (useful to remove)

create

public View create(Element elem)
The table itself acts as a factory for the various views that actually represent pieces of the table. All other factory activity is delegated to the factory returned by the parent of the table.

Specified by:
create in interface ViewFactory
Parameters:
elem - the piece of the document to build a view of
Returns:
the view
See Also:
View