API Reference 0.3.24dart_web_toolkit_uiCellFormatter

CellFormatter class

This class contains methods used to format a table's cells.

class CellFormatter {

 HtmlTable _table;

 CellFormatter(this._table);

 /**
  * Adds a style to the specified cell.
  *
  * @param row the cell's row
  * @param column the cell's column
  * @param styleName the style name to be added
  * @see UiObject#addStyleName(String)
  */
 void addStyleName(int row, int column, String styleName) {
   _table.prepareCell(row, column);
   dart_html.Element td = getCellElement(_table.bodyElem, row, column);
   UiObject.manageElementStyleName(td, styleName, true);
 }

 /**
  * Gets the TD element representing the specified cell.
  *
  * @param row the row of the cell to be retrieved
  * @param column the column of the cell to be retrieved
  * @return the column's TD element
  * @throws IndexOutOfBoundsException
  */
 dart_html.Element getElement(int row, int column) {
   _table.checkCellBounds(row, column);
   return getCellElement(_table.bodyElem, row, column);
 }

 /**
  * Gets the style of a specified cell.
  *
  * @param row the cell's row
  * @param column the cell's column
  * @see UiObject#getStyleName()
  * @return returns the style name
  * @throws IndexOutOfBoundsException
  */
 String getStyleName(int row, int column) {
   return UiObject.getElementStyleName(getElement(row, column));
 }

 /**
  * Gets the primary style of a specified cell.
  *
  * @param row the cell's row
  * @param column the cell's column
  * @see UiObject#getStylePrimaryName()
  * @return returns the style name
  * @throws IndexOutOfBoundsException
  */
 String getStylePrimaryName(int row, int column) {
   return UiObject.getElementStylePrimaryName(getElement(row, column));
 }

 /**
  * Determines whether or not this cell is visible.
  *
  * @param row the row of the cell whose visibility is to be set
  * @param column the column of the cell whose visibility is to be set
  * @return <code>true</code> if the object is visible
  */
 bool isVisible(int row, int column) {
   dart_html.Element e = getElement(row, column);
   return UiObject.isVisible(e);
 }

 /**
  * Removes a style from the specified cell.
  *
  * @param row the cell's row
  * @param column the cell's column
  * @param styleName the style name to be removed
  * @see UiObject#removeStyleName(String)
  * @throws IndexOutOfBoundsException
  */
 void removeStyleName(int row, int column, String styleName) {
   _table.checkCellBounds(row, column);
   dart_html.Element td = getCellElement(_table.bodyElem, row, column);
   UiObject.manageElementStyleName(td, styleName, false);
 }

 /**
  * Sets the horizontal and vertical alignment of the specified cell's
  * contents.
  *
  * @param row the row of the cell whose alignment is to be set
  * @param column the column of the cell whose alignment is to be set
  * @param hAlign the cell's new horizontal alignment as specified in
  *          {@link HasHorizontalAlignment}
  * @param vAlign the cell's new vertical alignment as specified in
  *          {@link HasVerticalAlignment}
  * @throws IndexOutOfBoundsException
  */
 void setAlignment(int row, int column,
                          HorizontalAlignmentConstant hAlign, VerticalAlignmentConstant vAlign) {
   setHorizontalAlignment(row, column, hAlign);
   setVerticalAlignment(row, column, vAlign);
 }

 /**
  * Sets the height of the specified cell.
  *
  * @param row the row of the cell whose height is to be set
  * @param column the column of the cell whose height is to be set
  * @param height the cell's new height, in CSS units
  * @throws IndexOutOfBoundsException
  */
 void setHeight(int row, int column, String height) {
   _table.prepareCell(row, column);
   dart_html.Element elem = getCellElement(_table.bodyElem, row, column);
   Dom.setElementProperty(elem, "height", height);
 }

 /**
  * Sets the horizontal alignment of the specified cell.
  *
  * @param row the row of the cell whose alignment is to be set
  * @param column the column of the cell whose alignment is to be set
  * @param align the cell's new horizontal alignment as specified in
  *          {@link HasHorizontalAlignment}.
  * @throws IndexOutOfBoundsException
  */
 void setHorizontalAlignment(int row, int column,
                                    HorizontalAlignmentConstant align) {
   _table.prepareCell(row, column);
   dart_html.Element elem = getCellElement(_table.bodyElem, row, column);
   Dom.setElementProperty(elem, "align", align.getTextAlignString());
 }

 /**
  * Sets the style name associated with the specified cell.
 *
  * @param row the row of the cell whose style name is to be set
  * @param column the column of the cell whose style name is to be set
  * @param styleName the new style name
  * @see UiObject#setStyleName(String)
  * @throws IndexOutOfBoundsException
  */
 void setStyleName(int row, int column, String styleName) {
   _table.prepareCell(row, column);
   UiObject.setElementStyleName(getCellElement(_table.bodyElem, row, column), styleName);
 }

 /**
  * Sets the primary style name associated with the specified cell.
  *
  * @param row the row of the cell whose style name is to be set
  * @param column the column of the cell whose style name is to be set
  * @param styleName the new style name
  * @see UiObject#setStylePrimaryName(String)
  * @throws IndexOutOfBoundsException
  */
 void setStylePrimaryName(int row, int column, String styleName) {
   UiObject.setElementStylePrimaryName(getCellElement(_table.bodyElem, row, column), styleName);
 }

 /**
  * Sets the vertical alignment of the specified cell.
  *
  * @param row the row of the cell whose alignment is to be set
  * @param column the column of the cell whose alignment is to be set
  * @param align the cell's new vertical alignment as specified in
  *          {@link HasVerticalAlignment}.
  * @throws IndexOutOfBoundsException
  */
 void setVerticalAlignment(int row, int column,
                                  VerticalAlignmentConstant align) {
   _table.prepareCell(row, column);
   Dom.setStyleAttribute(getCellElement(_table.bodyElem, row, column),
       "verticalAlign", align.getVerticalAlignString());
 }

 /**
  * Sets whether this cell is visible via the display style property. The
  * other cells in the row will all shift left to fill the cell's space. So,
  * for example a table with (0,1,2) will become (1,2) if cell 1 is hidden.
  *
  * @param row the row of the cell whose visibility is to be set
  * @param column the column of the cell whose visibility is to be set
  * @param visible <code>true</code> to show the cell, <code>false</code> to
  *          hide it
  */
 void setVisible(int row, int column, bool visible) {
   dart_html.Element e = ensureElement(row, column);
   UiObject.setVisible(e, visible);
 }

 /**
  * Sets the width of the specified cell.
  *
  * @param row the row of the cell whose width is to be set
  * @param column the column of the cell whose width is to be set
  * @param width the cell's new width, in CSS units
  * @throws IndexOutOfBoundsException
  */
 void setWidth(int row, int column, String width) {
   // Give the subclass a chance to prepare the cell.
   _table.prepareCell(row, column);
   Dom.setElementProperty(getCellElement(_table.bodyElem, row, column), "width",
       width);
 }

 /**
  * Sets whether the specified cell will allow word wrapping of its contents.
  *
  * @param row the row of the cell whose word-wrap is to be set
  * @param column the column of the cell whose word-wrap is to be set
  * @param wrap <code>false </code> to disable word wrapping in this cell
  * @throws IndexOutOfBoundsException
  */
 void setWordWrap(int row, int column, bool wrap) {
   _table.prepareCell(row, column);
   String wrapValue = wrap ? "" : "nowrap";
   Dom.setStyleAttribute(getElement(row, column), "whiteSpace", wrapValue);
 }

 /**
  * Gets the element associated with a cell. If it does not exist and the
  * subtype allows creation of elements, creates it.
  *
  * @param row the cell's row
  * @param column the cell's column
  * @return the cell's element
  * @throws IndexOutOfBoundsException
  */
 dart_html.Element ensureElement(int row, int column) {
   _table.prepareCell(row, column);
   return getCellElement(_table.bodyElem, row, column);
 }

 /**
  * Convenience methods to get an attribute on a cell.
  *
  * @param row cell's row
  * @param column cell's column
  * @param attr attribute to get
  * @return the attribute's value
  * @throws IndexOutOfBoundsException
  */
 String getAttr(int row, int column, String attr) {
   dart_html.Element elem = getElement(row, column);
   return elem.attributes[attr];
 }

 /**
  * Convenience methods to set an attribute on a cell.
  *
  * @param row cell's row
  * @param column cell's column
  * @param attrName attribute to set
  * @param value value to set
  * @throws IndexOutOfBoundsException
  */
 void setAttr(int row, int column, String attrName, String value) {
   dart_html.Element elem = ensureElement(row, column);
   Dom.setElementAttribute(elem, attrName, value);
 }

 /**
  * Native method to get a cell's element.
  *
  * @param table the table element
  * @param row the row of the cell
  * @param col the column of the cell
  * @return the element
  */
 dart_html.Element getCellElement(dart_html.Element table, int row, int col) {
   if (table is! dart_html.TableElement) {
     table = table.parent as dart_html.TableElement;
   }
   assert (table is dart_html.TableElement);
   return (table as dart_html.TableElement).rows[row].cells[col];
 }

 /**
  * Gets the TD element representing the specified cell unsafely (meaning
  * that it doesn't ensure that <code>row</code> and <code>column</code> are
  * valid).
  *
  * @param row the row of the cell to be retrieved
  * @param column the column of the cell to be retrieved
  * @return the cell's TD element
  */
 dart_html.Element getRawElement(int row, int column) {
   return getCellElement(_table.bodyElem, row, column);
 }
}

Subclasses

FlexCellFormatter

Constructors

new CellFormatter(HtmlTable _table) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
CellFormatter(this._table);

Methods

void addStyleName(int row, int column, String styleName) #

Adds a style to the specified cell.

@param row the cell's row @param column the cell's column @param styleName the style name to be added @see UiObject#addStyleName(String)

void addStyleName(int row, int column, String styleName) {
 _table.prepareCell(row, column);
 dart_html.Element td = getCellElement(_table.bodyElem, row, column);
 UiObject.manageElementStyleName(td, styleName, true);
}

Element ensureElement(int row, int column) #

Gets the element associated with a cell. If it does not exist and the subtype allows creation of elements, creates it.

@param row the cell's row @param column the cell's column @return the cell's element @throws IndexOutOfBoundsException

dart_html.Element ensureElement(int row, int column) {
 _table.prepareCell(row, column);
 return getCellElement(_table.bodyElem, row, column);
}

String getAttr(int row, int column, String attr) #

Convenience methods to get an attribute on a cell.

@param row cell's row @param column cell's column @param attr attribute to get @return the attribute's value @throws IndexOutOfBoundsException

String getAttr(int row, int column, String attr) {
 dart_html.Element elem = getElement(row, column);
 return elem.attributes[attr];
}

Element getCellElement(Element table, int row, int col) #

Native method to get a cell's element.

@param table the table element @param row the row of the cell @param col the column of the cell @return the element

dart_html.Element getCellElement(dart_html.Element table, int row, int col) {
 if (table is! dart_html.TableElement) {
   table = table.parent as dart_html.TableElement;
 }
 assert (table is dart_html.TableElement);
 return (table as dart_html.TableElement).rows[row].cells[col];
}

Element getElement(int row, int column) #

Gets the TD element representing the specified cell.

@param row the row of the cell to be retrieved @param column the column of the cell to be retrieved @return the column's TD element @throws IndexOutOfBoundsException

dart_html.Element getElement(int row, int column) {
 _table.checkCellBounds(row, column);
 return getCellElement(_table.bodyElem, row, column);
}

Element getRawElement(int row, int column) #

Gets the TD element representing the specified cell unsafely (meaning that it doesn't ensure that <code>row</code> and <code>column</code> are valid).

@param row the row of the cell to be retrieved @param column the column of the cell to be retrieved @return the cell's TD element

dart_html.Element getRawElement(int row, int column) {
 return getCellElement(_table.bodyElem, row, column);
}

String getStyleName(int row, int column) #

Gets the style of a specified cell.

@param row the cell's row @param column the cell's column @see UiObject#getStyleName() @return returns the style name @throws IndexOutOfBoundsException

String getStyleName(int row, int column) {
 return UiObject.getElementStyleName(getElement(row, column));
}

String getStylePrimaryName(int row, int column) #

Gets the primary style of a specified cell.

@param row the cell's row @param column the cell's column @see UiObject#getStylePrimaryName() @return returns the style name @throws IndexOutOfBoundsException

String getStylePrimaryName(int row, int column) {
 return UiObject.getElementStylePrimaryName(getElement(row, column));
}

bool isVisible(int row, int column) #

Determines whether or not this cell is visible.

@param row the row of the cell whose visibility is to be set @param column the column of the cell whose visibility is to be set @return <code>true</code> if the object is visible

bool isVisible(int row, int column) {
 dart_html.Element e = getElement(row, column);
 return UiObject.isVisible(e);
}

void removeStyleName(int row, int column, String styleName) #

Removes a style from the specified cell.

@param row the cell's row @param column the cell's column @param styleName the style name to be removed @see UiObject#removeStyleName(String) @throws IndexOutOfBoundsException

void removeStyleName(int row, int column, String styleName) {
 _table.checkCellBounds(row, column);
 dart_html.Element td = getCellElement(_table.bodyElem, row, column);
 UiObject.manageElementStyleName(td, styleName, false);
}

void setAlignment(int row, int column, HorizontalAlignmentConstant hAlign, VerticalAlignmentConstant vAlign) #

Sets the horizontal and vertical alignment of the specified cell's contents.

@param row the row of the cell whose alignment is to be set @param column the column of the cell whose alignment is to be set @param hAlign the cell's new horizontal alignment as specified in

     {@link HasHorizontalAlignment}

@param vAlign the cell's new vertical alignment as specified in

     {@link HasVerticalAlignment}

@throws IndexOutOfBoundsException

void setAlignment(int row, int column,
                        HorizontalAlignmentConstant hAlign, VerticalAlignmentConstant vAlign) {
 setHorizontalAlignment(row, column, hAlign);
 setVerticalAlignment(row, column, vAlign);
}

void setAttr(int row, int column, String attrName, String value) #

Convenience methods to set an attribute on a cell.

@param row cell's row @param column cell's column @param attrName attribute to set @param value value to set @throws IndexOutOfBoundsException

void setAttr(int row, int column, String attrName, String value) {
 dart_html.Element elem = ensureElement(row, column);
 Dom.setElementAttribute(elem, attrName, value);
}

void setHeight(int row, int column, String height) #

Sets the height of the specified cell.

@param row the row of the cell whose height is to be set @param column the column of the cell whose height is to be set @param height the cell's new height, in CSS units @throws IndexOutOfBoundsException

void setHeight(int row, int column, String height) {
 _table.prepareCell(row, column);
 dart_html.Element elem = getCellElement(_table.bodyElem, row, column);
 Dom.setElementProperty(elem, "height", height);
}

void setHorizontalAlignment(int row, int column, HorizontalAlignmentConstant align) #

Sets the horizontal alignment of the specified cell.

@param row the row of the cell whose alignment is to be set @param column the column of the cell whose alignment is to be set @param align the cell's new horizontal alignment as specified in

     {@link HasHorizontalAlignment}.

@throws IndexOutOfBoundsException

void setHorizontalAlignment(int row, int column,
                                  HorizontalAlignmentConstant align) {
 _table.prepareCell(row, column);
 dart_html.Element elem = getCellElement(_table.bodyElem, row, column);
 Dom.setElementProperty(elem, "align", align.getTextAlignString());
}

void setStyleName(int row, int column, String styleName) #

Sets the style name associated with the specified cell.

@param row the row of the cell whose style name is to be set @param column the column of the cell whose style name is to be set @param styleName the new style name @see UiObject#setStyleName(String) @throws IndexOutOfBoundsException

void setStyleName(int row, int column, String styleName) {
 _table.prepareCell(row, column);
 UiObject.setElementStyleName(getCellElement(_table.bodyElem, row, column), styleName);
}

void setStylePrimaryName(int row, int column, String styleName) #

Sets the primary style name associated with the specified cell.

@param row the row of the cell whose style name is to be set @param column the column of the cell whose style name is to be set @param styleName the new style name @see UiObject#setStylePrimaryName(String) @throws IndexOutOfBoundsException

void setStylePrimaryName(int row, int column, String styleName) {
 UiObject.setElementStylePrimaryName(getCellElement(_table.bodyElem, row, column), styleName);
}

void setVerticalAlignment(int row, int column, VerticalAlignmentConstant align) #

Sets the vertical alignment of the specified cell.

@param row the row of the cell whose alignment is to be set @param column the column of the cell whose alignment is to be set @param align the cell's new vertical alignment as specified in

     {@link HasVerticalAlignment}.

@throws IndexOutOfBoundsException

void setVerticalAlignment(int row, int column,
                                VerticalAlignmentConstant align) {
 _table.prepareCell(row, column);
 Dom.setStyleAttribute(getCellElement(_table.bodyElem, row, column),
     "verticalAlign", align.getVerticalAlignString());
}

void setVisible(int row, int column, bool visible) #

Sets whether this cell is visible via the display style property. The other cells in the row will all shift left to fill the cell's space. So, for example a table with (0,1,2) will become (1,2) if cell 1 is hidden.

@param row the row of the cell whose visibility is to be set @param column the column of the cell whose visibility is to be set @param visible <code>true</code> to show the cell, <code>false</code> to

     hide it
void setVisible(int row, int column, bool visible) {
 dart_html.Element e = ensureElement(row, column);
 UiObject.setVisible(e, visible);
}

void setWidth(int row, int column, String width) #

Sets the width of the specified cell.

@param row the row of the cell whose width is to be set @param column the column of the cell whose width is to be set @param width the cell's new width, in CSS units @throws IndexOutOfBoundsException

void setWidth(int row, int column, String width) {
 // Give the subclass a chance to prepare the cell.
 _table.prepareCell(row, column);
 Dom.setElementProperty(getCellElement(_table.bodyElem, row, column), "width",
     width);
}

void setWordWrap(int row, int column, bool wrap) #

Sets whether the specified cell will allow word wrapping of its contents.

@param row the row of the cell whose word-wrap is to be set @param column the column of the cell whose word-wrap is to be set @param wrap <code>false </code> to disable word wrapping in this cell @throws IndexOutOfBoundsException

void setWordWrap(int row, int column, bool wrap) {
 _table.prepareCell(row, column);
 String wrapValue = wrap ? "" : "nowrap";
 Dom.setStyleAttribute(getElement(row, column), "whiteSpace", wrapValue);
}