Public Member Functions

TableListBox Class Reference

A table of cells, using a TableHeaderComponent as its header. More...

Inherits ListBox, ListBoxModel, and TableHeaderComponent::Listener.

List of all members.

Public Member Functions

 TableListBox (const String &componentName=String::empty, TableListBoxModel *model=0)
 Creates a TableListBox.
 ~TableListBox ()
 Destructor.
void setModel (TableListBoxModel *newModel)
 Changes the TableListBoxModel that is being used for this table.
TableListBoxModelgetModel () const
 Returns the model currently in use.
TableHeaderComponentgetHeader () const
 Returns the header component being used in this table.
void setHeader (TableHeaderComponent *newHeader)
 Sets the header component to use for the table.
void setHeaderHeight (int newHeight)
 Changes the height of the table header component.
int getHeaderHeight () const
 Returns the height of the table header.
void autoSizeColumn (int columnId)
 Resizes a column to fit its contents.
void autoSizeAllColumns ()
 Calls autoSizeColumn() for all columns in the table.
void setAutoSizeMenuOptionShown (bool shouldBeShown)
 Enables or disables the auto size options on the popup menu.
bool isAutoSizeMenuOptionShown () const
 True if the auto-size options should be shown on the menu.
const Rectangle< int > getCellPosition (int columnId, int rowNumber, bool relativeToComponentTopLeft) const
 Returns the position of one of the cells in the table.
ComponentgetCellComponent (int columnId, int rowNumber) const
 Returns the component that currently represents a given cell.
void scrollToEnsureColumnIsOnscreen (int columnId)
 Scrolls horizontally if necessary to make sure that a particular column is visible.
int getNumRows ()
 This has to return the number of items in the list.
void paintListBoxItem (int, Graphics &, int, int, bool)
 This method must be implemented to draw a row of the list.
ComponentrefreshComponentForRow (int rowNumber, bool isRowSelected, Component *existingComponentToUpdate)
 This is used to create or update a custom component to go in a row of the list.
void selectedRowsChanged (int lastRowSelected)
 Override this to be informed when rows are selected or deselected.
void deleteKeyPressed (int currentSelectedRow)
 Override this to be informed when the delete key is pressed.
void returnKeyPressed (int currentSelectedRow)
 Override this to be informed when the return key is pressed.
void backgroundClicked ()
 This can be overridden to react to the user double-clicking on a part of the list where there are no rows.
void listWasScrolled ()
 Override this to be informed when the list is scrolled.
void tableColumnsChanged (TableHeaderComponent *)
 This is called when some of the table's columns are added, removed, hidden, or rearranged.
void tableColumnsResized (TableHeaderComponent *)
 This is called when one or more of the table's columns are resized.
void tableSortOrderChanged (TableHeaderComponent *)
 This is called when the column by which the table should be sorted is changed.
void tableColumnDraggingChanged (TableHeaderComponent *, int)
 This is called when the user begins or ends dragging one of the columns around.
void resized ()
 Called when this component's size has been changed.

Detailed Description

A table of cells, using a TableHeaderComponent as its header.

This component makes it easy to create a table by providing a TableListBoxModel as the data source.

See also:
TableListBoxModel, TableHeaderComponent

Constructor & Destructor Documentation

TableListBox::TableListBox ( const String componentName = String::empty,
TableListBoxModel model = 0 
)

Creates a TableListBox.

The model pointer passed-in can be null, in which case you can set it later with setModel().

TableListBox::~TableListBox (  )

Destructor.


Member Function Documentation

void TableListBox::setModel ( TableListBoxModel newModel )

Changes the TableListBoxModel that is being used for this table.

TableListBoxModel* TableListBox::getModel (  ) const

Returns the model currently in use.

Reimplemented from ListBox.

TableHeaderComponent& TableListBox::getHeader (  ) const

Returns the header component being used in this table.

void TableListBox::setHeader ( TableHeaderComponent newHeader )

Sets the header component to use for the table.

The table will take ownership of the component that you pass in, and will delete it when it's no longer needed.

void TableListBox::setHeaderHeight ( int  newHeight )

Changes the height of the table header component.

See also:
getHeaderHeight
int TableListBox::getHeaderHeight (  ) const

Returns the height of the table header.

See also:
setHeaderHeight
void TableListBox::autoSizeColumn ( int  columnId )

Resizes a column to fit its contents.

This uses TableListBoxModel::getColumnAutoSizeWidth() to find the best width, and applies that to the column.

See also:
autoSizeAllColumns, TableHeaderComponent::setColumnWidth
void TableListBox::autoSizeAllColumns (  )

Calls autoSizeColumn() for all columns in the table.

void TableListBox::setAutoSizeMenuOptionShown ( bool  shouldBeShown )

Enables or disables the auto size options on the popup menu.

By default, these are enabled.

bool TableListBox::isAutoSizeMenuOptionShown (  ) const

True if the auto-size options should be shown on the menu.

See also:
setAutoSizeMenuOptionsShown
const Rectangle<int> TableListBox::getCellPosition ( int  columnId,
int  rowNumber,
bool  relativeToComponentTopLeft 
) const

Returns the position of one of the cells in the table.

If relativeToComponentTopLeft is true, the co-ordinates are relative to the table component's top-left. The row number isn't checked to see if it's in-range, but the column ID must exist or this will return an empty rectangle.

If relativeToComponentTopLeft is false, the co-ords are relative to the top-left of the table's top-left cell.

Component* TableListBox::getCellComponent ( int  columnId,
int  rowNumber 
) const

Returns the component that currently represents a given cell.

If the component for this cell is off-screen or if the position is out-of-range, this may return 0.

See also:
getCellPosition
void TableListBox::scrollToEnsureColumnIsOnscreen ( int  columnId )

Scrolls horizontally if necessary to make sure that a particular column is visible.

See also:
ListBox::scrollToEnsureRowIsOnscreen
int TableListBox::getNumRows (  ) [virtual]

This has to return the number of items in the list.

See also:
ListBox::getNumRows()

Implements ListBoxModel.

void TableListBox::paintListBoxItem ( int  rowNumber,
Graphics g,
int  width,
int  height,
bool  rowIsSelected 
) [virtual]

This method must be implemented to draw a row of the list.

Implements ListBoxModel.

Component* TableListBox::refreshComponentForRow ( int  rowNumber,
bool  isRowSelected,
Component existingComponentToUpdate 
) [virtual]

This is used to create or update a custom component to go in a row of the list.

Any row may contain a custom component, or can just be drawn with the paintListBoxItem() method and handle mouse clicks with listBoxItemClicked().

This method will be called whenever a custom component might need to be updated - e.g. when the table is changed, or TableListBox::updateContent() is called.

If you don't need a custom component for the specified row, then return 0.

If you do want a custom component, and the existingComponentToUpdate is null, then this method must create a suitable new component and return it.

If the existingComponentToUpdate is non-null, it will be a pointer to a component previously created by this method. In this case, the method must either update it to make sure it's correctly representing the given row (which may be different from the one that the component was created for), or it can delete this component and return a new one.

The component that your method returns will be deleted by the ListBox when it is no longer needed.

Reimplemented from ListBoxModel.

void TableListBox::selectedRowsChanged ( int  lastRowSelected ) [virtual]

Override this to be informed when rows are selected or deselected.

This will be called whenever a row is selected or deselected. If a range of rows is selected all at once, this will just be called once for that event.

Parameters:
lastRowSelectedthe last row that the user selected. If no rows are currently selected, this may be -1.

Reimplemented from ListBoxModel.

void TableListBox::deleteKeyPressed ( int  lastRowSelected ) [virtual]

Override this to be informed when the delete key is pressed.

If no rows are selected when they press the key, this won't be called.

Parameters:
lastRowSelectedthe last row that had been selected when they pressed the key - if there are multiple selections, this might not be very useful

Reimplemented from ListBoxModel.

void TableListBox::returnKeyPressed ( int  lastRowSelected ) [virtual]

Override this to be informed when the return key is pressed.

If no rows are selected when they press the key, this won't be called.

Parameters:
lastRowSelectedthe last row that had been selected when they pressed the key - if there are multiple selections, this might not be very useful

Reimplemented from ListBoxModel.

void TableListBox::backgroundClicked (  ) [virtual]

This can be overridden to react to the user double-clicking on a part of the list where there are no rows.

See also:
listBoxItemClicked

Reimplemented from ListBoxModel.

void TableListBox::listWasScrolled (  ) [virtual]

Override this to be informed when the list is scrolled.

This might be caused by the user moving the scrollbar, or by programmatic changes to the list position.

Reimplemented from ListBoxModel.

void TableListBox::tableColumnsChanged ( TableHeaderComponent tableHeader ) [virtual]

This is called when some of the table's columns are added, removed, hidden, or rearranged.

Implements TableHeaderComponent::Listener.

void TableListBox::tableColumnsResized ( TableHeaderComponent tableHeader ) [virtual]

This is called when one or more of the table's columns are resized.

Implements TableHeaderComponent::Listener.

void TableListBox::tableSortOrderChanged ( TableHeaderComponent tableHeader ) [virtual]

This is called when the column by which the table should be sorted is changed.

Implements TableHeaderComponent::Listener.

void TableListBox::tableColumnDraggingChanged ( TableHeaderComponent tableHeader,
int  columnIdNowBeingDragged 
) [virtual]

This is called when the user begins or ends dragging one of the columns around.

When the user starts dragging a column, this is called with the ID of that column. When they finish dragging, it is called again with 0 as the ID.

Reimplemented from TableHeaderComponent::Listener.

void TableListBox::resized (  ) [virtual]

Called when this component's size has been changed.

A component can implement this method to do things such as laying out its child components when its width or height changes.

The method is called synchronously as a result of the setBounds or setSize methods, so repeatedly changing a components size will repeatedly call its resized method (unlike things like repainting, where multiple calls to repaint are coalesced together).

If the component is a top-level window on the desktop, its size could also be changed by operating-system factors beyond the application's control.

See also:
moved, setSize

Reimplemented from ListBox.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines