com.ibm.as400.util.html
Class HTMLTable
- java.lang.Object
-
- com.ibm.as400.util.html.HTMLTagAttributes
-
- com.ibm.as400.util.html.HTMLTable
-
- All Implemented Interfaces:
- HTMLConstants, HTMLTagElement, java.io.Serializable
public class HTMLTable extends HTMLTagAttributes implements HTMLConstants, java.io.Serializable
The HTMLTable class represents an HTML table tag.This example creates an HTMLTable object and sets its attributes.
HTMLTable table = new HTMLTable(); table.setAlignment(HTMLTable.CENTER); table.setHeaderInUse(false); table.setBorderWidth(1); table.setCellSpacing(2); table.setCellPadding(2); // Add the rows to the table (Assume that the HTMLTableRow objects are already created). table.addRow(row1); table.addRow(row2); table.addRow(row3); System.out.println(table.getTag());
Here is the output of the table tag:
<table border="1" align="center" cellspacing="2" cellpadding="2"> <tr> <td>row1data1</td> <td>row1data2</td> </tr> <tr> <td>row2data1</td> <td>row2data2</td> </tr> <tr> <td>row3data1</td> <td>row3data2</td> </tr> </table>
The output generated by calling getFOTag() looks like the following:
<fo:block text-align='center'> <fo:table> <fo:table-column column-width='3pt'/> <fo:table-column column-width='3pt'/> <fo:table-column column-width='3pt'/> <fo:table-body> <fo:table-row> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row1data1</fo:block> </fo:block-container> </fo:table-cell> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row1data2</fo:block> </fo:block-container> </fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row2data1</fo:block> </fo:block-container> </fo:table-cell> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row2data2</fo:block> </fo:block-container> </fo:table-cell> </fo:table-row> <fo:table-row> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row3data1</fo:block> </fo:block-container> </fo:table-cell> <fo:table-cell border-style='solid' border-width='1px' padding='2px'><fo:block-container> <fo:block>row3data2</fo:block> </fo:block-container> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> </fo:block>
HTMLTable objects generate the following events:
- ElementEvent - The events fired are:
- elementAdded
- elementChanged
- elementRemoved
- PropertyChangeEvent
- VetoableChangeEvent
-
-
Field Summary
-
Fields inherited from interface com.ibm.as400.util.html.HTMLConstants
ABSBOTTOM, ABSMIDDLE, BASELINE, BOTTOM, CAPITALS, CENTER, CIRCLE, DISC, JUSTIFY, LARGE_ROMAN, LEFT, LOWER_CASE, LTR, MIDDLE, NUMBERS, RIGHT, RTL, SMALL_ROMAN, SQUARE, TARGET_BLANK, TARGET_PARENT, TARGET_SELF, TARGET_TOP, TEXTTOP, TOP
-
-
Constructor Summary
Constructors Constructor and Description HTMLTable()Constructs a default HTMLTable object.HTMLTable(HTMLTableRow[] rows)Constructs an HTMLTable object with the specified rows.
-
Method Summary
Methods Modifier and Type Method and Description voidaddColumn(HTMLTableCell[] column)Adds a column to the end of the table.voidaddColumnHeader(HTMLTableHeader header)Adds a column header to the end of the table header.voidaddColumnHeader(java.lang.String header)Adds a column header to the end of the table header.voidaddRow(HTMLTableRow row)Adds a row to the end of the table.voidaddRowListener(ElementListener listener)Adds an ElementListener for the rows.voidaddVetoableChangeListener(java.beans.VetoableChangeListener listener)Adds the VetoableChangeListener.java.lang.StringgetAlignment()Returns the table horizontal alignment.intgetBorderWidth()Returns the border width.HTMLTableCaptiongetCaption()Returns the table caption.intgetCellPadding()Returns the global table cell padding.intgetCellSpacing()Returns the global table cell spacing.HTMLTableCell[]getColumn(int columnIndex)Returns a column in the table as an array of HTMLTableCell objects.HTMLTableHeadergetColumnHeader(int columnIndex)Returns the table header tag for the specified columnIndex.java.lang.StringgetDirection()Returns the direction of the text interpretation.java.lang.StringgetFOTag()Returns the XSL-FO table tag.HTMLTableHeader[]getHeader()Returns the table column header tags.java.lang.StringgetHeaderTag()Returns the HTML tag for the table column headers.java.lang.StringgetLanguage()Returns the language of the caption.HTMLTableRowgetRow(int rowIndex)Returns the HTMLTableRow object for the specified rowIndex.intgetRowCount()Returns the number of rows in the table.java.lang.StringgetTag()Returns the HTML table tag.intgetWidth()Returns the table width in pixels or percent.booleanisHeaderInUse()Indicates if the table column header should be used.booleanisUseFO()Returns if Formatting Object tags are outputted.booleanisWidthInPercent()Indicates if the table width is in percent or pixels.voidremoveAllRows()Removes all the rows from the table.voidremoveColumn(int columnIndex)Removes a column from the table at the specified columnIndex.voidremoveColumnHeader(HTMLTableHeader header)Removes a column header from the table header.voidremoveColumnHeader(int columnIndex)Removes the column header at the specified columnIndex.voidremoveRow(HTMLTableRow row)Removes the row from the table.voidremoveRow(int rowIndex)Removes the row at the specified rowIndex.voidremoveRowListener(ElementListener listener)Removes this row ElementListener from the internal list.voidremoveVetoableChangeListener(java.beans.VetoableChangeListener listener)Removes the VetoableChangeListener from the internal list.voidsetAlignment(java.lang.String alignment)Sets the table horizontal alignment.voidsetBorderWidth(int borderWidth)Sets the border width in pixels.voidsetCaption(HTMLTableCaption caption)Sets the table caption.voidsetCaption(java.lang.String caption)Sets the table caption.voidsetCellPadding(int cellPadding)Sets the global table cell padding.voidsetCellSpacing(int cellSpacing)Sets the global table cell spacing.voidsetColumn(HTMLTableCell[] column, int columnIndex)Sets a column in the table at the specified columnIndex.voidsetColumnHeader(HTMLTableHeader header, int columnIndex)Sets the table column header tag at the specified columnIndex.voidsetColumnHeader(java.lang.String header, int columnIndex)Sets the table column header tag.voidsetDirection(java.lang.String dir)Sets the direction of the text interpretation.voidsetHeader(HTMLTableHeader[] header)Sets the table column headers.voidsetHeader(java.lang.String[] header)Sets the table column headers.voidsetHeaderInUse(boolean headerInUse)Sets if table column headers should be used.voidsetLanguage(java.lang.String lang)Sets the language of the caption.voidsetRow(HTMLTableRow row, int rowIndex)Sets the table row at the specified rowIndex.voidsetUseFO(boolean useFO)Sets if Formatting Object tags should be used.voidsetWidth(int width)Sets the table width.voidsetWidth(int width, boolean widthInPercent)Sets the table width in percent or pixels.voidsetWidthInPercent(boolean widthInPercent)Sets the table width unit in percent or pixels.java.lang.StringtoString()Returns the HTML table tag.-
Methods inherited from class com.ibm.as400.util.html.HTMLTagAttributes
addPropertyChangeListener, getAttributes, getAttributeString, removePropertyChangeListener, setAttributes
-
-
-
-
Constructor Detail
-
HTMLTable
public HTMLTable()
Constructs a default HTMLTable object.
-
HTMLTable
public HTMLTable(HTMLTableRow[] rows)
Constructs an HTMLTable object with the specified rows.- Parameters:
rows- An array of HTMLTableRow objects.
-
-
Method Detail
-
addColumn
public void addColumn(HTMLTableCell[] column)
Adds a column to the end of the table.- Parameters:
column- An array of HTMLTableCell objects containing the data.
-
addColumnHeader
public void addColumnHeader(java.lang.String header)
Adds a column header to the end of the table header.- Parameters:
header- The column header.
-
addColumnHeader
public void addColumnHeader(HTMLTableHeader header)
Adds a column header to the end of the table header.- Parameters:
header- The column header.
-
addRow
public void addRow(HTMLTableRow row)
Adds a row to the end of the table.- Parameters:
row- An HTMLTableRow object containing the row data.
-
addRowListener
public void addRowListener(ElementListener listener)
Adds an ElementListener for the rows. The ElementListener object is added to an internal list of RowListeners; it can be removed with removeRowListener.- Parameters:
listener- The ElementListener.- See Also:
removeRowListener(com.ibm.as400.util.html.ElementListener)
-
addVetoableChangeListener
public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds the VetoableChangeListener. The specified VetoableChangeListener's vetoableChange method is called each time the value of any constrained property is changed.- Parameters:
listener- The VetoableChangeListener.- See Also:
removeVetoableChangeListener(java.beans.VetoableChangeListener)
-
getAlignment
public java.lang.String getAlignment()
Returns the table horizontal alignment.- Returns:
- The table alignment.
-
getBorderWidth
public int getBorderWidth()
Returns the border width. A value of zero indicates no border.- Returns:
- The border width.
-
getCaption
public HTMLTableCaption getCaption()
Returns the table caption.- Returns:
- An HTMLTableCaption object containing the table caption.
-
getCellPadding
public int getCellPadding()
Returns the global table cell padding. The cell padding is the spacing between data in a table cell and the border of the cell.- Returns:
- The cell padding.
-
getCellSpacing
public int getCellSpacing()
Returns the global table cell spacing. The cell spacing is the spacing between the cells.- Returns:
- The cell spacing.
-
getColumn
public HTMLTableCell[] getColumn(int columnIndex)
Returns a column in the table as an array of HTMLTableCell objects.- Parameters:
columnIndex- The index of the table column (0-based).- Returns:
- An array of HTMLTableCell objects.
-
getColumnHeader
public HTMLTableHeader getColumnHeader(int columnIndex)
Returns the table header tag for the specified columnIndex.- Parameters:
columnIndex- The index of the column header (0-based).- Returns:
- The table header tag.
-
getDirection
public java.lang.String getDirection()
Returns the direction of the text interpretation.- Returns:
- The direction of the text.
-
getHeader
public HTMLTableHeader[] getHeader()
Returns the table column header tags.- Returns:
- The header tags or null if the header is not set.
-
getHeaderTag
public java.lang.String getHeaderTag()
Returns the HTML tag for the table column headers.- Returns:
- The HTML table header tag or an empty String if the header is not set.
-
getLanguage
public java.lang.String getLanguage()
Returns the language of the caption.- Returns:
- The language of the caption.
-
getRowCount
public int getRowCount()
Returns the number of rows in the table.- Returns:
- The number of rows.
-
getRow
public HTMLTableRow getRow(int rowIndex)
Returns the HTMLTableRow object for the specified rowIndex.- Parameters:
rowIndex- The index of the table row (0-based).- Returns:
- The table row object.
-
getTag
public java.lang.String getTag()
Returns the HTML table tag.- Specified by:
getTagin interfaceHTMLTagElement- Returns:
- The tag.
-
getFOTag
public java.lang.String getFOTag()
Returns the XSL-FO table tag. The language, cell spacing, and table width attributes are not supported in XSL-FO.- Specified by:
getFOTagin interfaceHTMLTagElement- Returns:
- The tag.
-
getWidth
public int getWidth()
Returns the table width in pixels or percent.- Returns:
- The table width.
- See Also:
isWidthInPercent()
-
isHeaderInUse
public boolean isHeaderInUse()
Indicates if the table column header should be used.- Returns:
- true if column header should be used; false otherwise.
-
isWidthInPercent
public boolean isWidthInPercent()
Indicates if the table width is in percent or pixels.- Returns:
- true if percent, false if pixels.
- See Also:
getWidth()
-
isUseFO
public boolean isUseFO()
Returns if Formatting Object tags are outputted. The default value is false.- Returns:
- true if the output generated is an XSL formatting object, false if the output generated is HTML.
-
removeAllRows
public void removeAllRows()
Removes all the rows from the table.
-
removeColumn
public void removeColumn(int columnIndex)
Removes a column from the table at the specified columnIndex. If the column header exists it is also removed.- Parameters:
columnIndex- The index of the column to be removed (0-based).
-
removeColumnHeader
public void removeColumnHeader(int columnIndex)
Removes the column header at the specified columnIndex.- Parameters:
columnIndex- The index of the column header to be removed (0-based).
-
removeColumnHeader
public void removeColumnHeader(HTMLTableHeader header)
Removes a column header from the table header.- Parameters:
header- The column header.
-
removeRow
public void removeRow(HTMLTableRow row)
Removes the row from the table.- Parameters:
row- An HTMLTableRow object containing the row data.
-
removeRow
public void removeRow(int rowIndex)
Removes the row at the specified rowIndex.- Parameters:
rowIndex- The index of the row to be removed (0-based).
-
removeRowListener
public void removeRowListener(ElementListener listener)
Removes this row ElementListener from the internal list. If the ElementListener is not on the list, nothing is done.- Parameters:
listener- The ElementListener.- See Also:
addRowListener(com.ibm.as400.util.html.ElementListener)
-
removeVetoableChangeListener
public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes the VetoableChangeListener from the internal list. If the VetoableChangeListener is not on the list, nothing is done.- Parameters:
listener- The VetoableChangeListener.- See Also:
addVetoableChangeListener(java.beans.VetoableChangeListener)
-
setAlignment
public void setAlignment(java.lang.String alignment) throws java.beans.PropertyVetoExceptionSets the table horizontal alignment. The default value is LEFT.- Parameters:
alignment- The table alignment. One of the following constants defined in HTMLConstants: LEFT, CENTER, or RIGHT.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.- See Also:
HTMLConstants
-
setBorderWidth
public void setBorderWidth(int borderWidth) throws java.beans.PropertyVetoExceptionSets the border width in pixels. A value of zero indicates no border. The default value is zero.- Parameters:
borderWidth- The border width.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setCaption
public void setCaption(java.lang.String caption) throws java.beans.PropertyVetoExceptionSets the table caption.- Parameters:
caption- The table caption.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setCaption
public void setCaption(HTMLTableCaption caption) throws java.beans.PropertyVetoException
Sets the table caption.- Parameters:
caption- An HTMLTableCaption object containing the table caption.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setCellPadding
public void setCellPadding(int cellPadding) throws java.beans.PropertyVetoExceptionSets the global table cell padding. The cell padding is the spacing between data in a table cell and the border of the cell. The default value is -1 (browser default used).- Parameters:
cellPadding- The cell padding.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setCellSpacing
public void setCellSpacing(int cellSpacing) throws java.beans.PropertyVetoExceptionSets the global table cell spacing. The cell spacing is the spacing between the cells. The default value is -1 (browser default used).- Parameters:
cellSpacing- The cell spacing.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setColumn
public void setColumn(HTMLTableCell[] column, int columnIndex)
Sets a column in the table at the specified columnIndex.- Parameters:
column- An array of HTMLTableCell objects containing the column data.columnIndex- The index of the column (0-based).
-
setColumnHeader
public void setColumnHeader(java.lang.String header, int columnIndex) throws java.beans.PropertyVetoExceptionSets the table column header tag.- Parameters:
header- The table column header.columnIndex- The index of the column to be changed (0-based).- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setColumnHeader
public void setColumnHeader(HTMLTableHeader header, int columnIndex) throws java.beans.PropertyVetoException
Sets the table column header tag at the specified columnIndex.- Parameters:
header- The table column header.columnIndex- The index of the column to be changed (0-based).- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setDirection
public void setDirection(java.lang.String dir) throws java.beans.PropertyVetoExceptionSets the direction of the text interpretation.- Parameters:
dir- The direction. One of the following constants defined in HTMLConstants: LTR or RTL.- Throws:
java.beans.PropertyVetoException- If a change is vetoed.- See Also:
HTMLConstants
-
setHeader
public void setHeader(HTMLTableHeader[] header) throws java.beans.PropertyVetoException
Sets the table column headers.- Parameters:
header- The column headers.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.- See Also:
setHeaderInUse(boolean)
-
setHeader
public void setHeader(java.lang.String[] header) throws java.beans.PropertyVetoExceptionSets the table column headers.- Parameters:
header- The column headers.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setHeaderInUse
public void setHeaderInUse(boolean headerInUse) throws java.beans.PropertyVetoExceptionSets if table column headers should be used. The default value is true.- Parameters:
headerInUse- true if the column headers should be used; false otherwise.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setLanguage
public void setLanguage(java.lang.String lang) throws java.beans.PropertyVetoExceptionSets the language of the caption.- Parameters:
lang- The language. Example language tags include: en and en-US.- Throws:
java.beans.PropertyVetoException- If a change is vetoed.
-
setRow
public void setRow(HTMLTableRow row, int rowIndex)
Sets the table row at the specified rowIndex.- Parameters:
row- An HTMLTableRow object with the row data.rowIndex- The index of the row (0-based).
-
setWidth
public void setWidth(int width) throws java.beans.PropertyVetoExceptionSets the table width. The default width unit is pixels.- Parameters:
width- The table width.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.- See Also:
setWidthInPercent(boolean)
-
setWidth
public void setWidth(int width, boolean widthInPercent) throws java.beans.PropertyVetoExceptionSets the table width in percent or pixels.- Parameters:
width- The table width.widthInPercent- true if width is specified as a percent; false if width is specified in pixels.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.
-
setWidthInPercent
public void setWidthInPercent(boolean widthInPercent) throws java.beans.PropertyVetoExceptionSets the table width unit in percent or pixels. The default is false.- Parameters:
widthInPercent- true if width is specified as a percent; false if width is specified in pixels.- Throws:
java.beans.PropertyVetoException- If the change is vetoed.- See Also:
setWidth(int)
-
setUseFO
public void setUseFO(boolean useFO)
Sets if Formatting Object tags should be used. The default value is false.- Parameters:
useFO- - true if output generated is an XSL formatting object, false if the output generated is HTML.
-
toString
public java.lang.String toString()
Returns the HTML table tag.- Overrides:
toStringin classjava.lang.Object- Returns:
- The tag.
-
-