Tuesday, 9 July 2013

9th july

The ProgressRenderer Class
The ProgressRenderer class is a small utility class that is used to render the current progress of a download listed in the GUI’s “Downloads” JTable instance. In the Download Manager’s case, we want to render each of the table’s Progress column cells as progress bars.

 javax.swing.JProgressBar
JProgressBar uses a BoundedRangeModel as its data model, with the value property representing the "current" state of the task, and the minimum and maximum properties representing the beginning and end points, respectively.
public interface TableCellRenderer
javax.swing.table
This interface defines the method required by any object that would like to be a renderer for cells in a JTable.
Component getTableCellRendererComponent(JTable table, Object value,  boolean isSelected, boolean hasFocus, int row,int column)
Returns the component used for drawing the cell. This method is used to configure the renderer appropriately before drawing.
Parameters:
table - the JTable that is asking the renderer to draw; can be null
value - the value of the cell to be rendered. It is up to the specific renderer to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
hasFocus - if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing
row - the row index of the cell being drawn. When drawing the header, the value of row is -1
column - the column index of the cell being drawn.

The DownloadsTableModel Class
The DownloadsTableModel class houses the Download Manager’s list of downloads
and is the backing data source for the GUI’s “Downloads” JTable instance.

The addDownload( ) Method -This method first registers itself with the new Download as an Observer interested in receiving change notifications. Next, the Download is added to the internal list of downloads being managed. Finally, a table row insertion event notification is fired to alert the table that a new row has been added.

The clearDownload( ) Method -After removing the Download from the internal list, a table row deleted event notification is fired to alert the table that a row has been deleted.

The getColumnClass( ) Method- All columns are displayed as text (that is, String objects) except for the Progress column, which is displayed as a progress bar (which is an object of type JProgressBar).

The getValueAt( ) Method -This method first looks up the Download corresponding to the row specified. Next, the column specified is used to determine which one of the Download’s property values to return.

The update( ) Method -This method is passed a reference to the Download that has changed, in the form of an Observable object. Next, an index to that download is looked up in the list of downloads, and that index is then used to fire a table row update event notification, which alerts the table that the given row has been updated. The table will then renderer the row with the given index, reflecting its new values.


javax.swing.table
Class AbstractTableModel -

This abstract class provides default implementations for most of the methods in the TableModel interface. It takes care of the management of listeners and provides some conveniences for generating TableMonmnmmmmdelEvents and dispatching them to the listeners. To create a concrete TableModel as a subclass of AbstractTableModel you need only provide implementations for the following three methods:
  public int getRowCount();
  public int getColumnCount();
  public Object getValueAt(int row, int column);

Ø  fireTableRowsInserted

public void fireTableRowsInserted(int firstRow, int lastRow)
Notifies all listeners that rows in the range [firstRow, lastRow], inclusive, have been inserted.

Ø  fireTableRowsUpdated

public void fireTableRowsUpdated(int firstRow, int lastRow)
Notifies all listeners that rows in the range [firstRow, lastRow], inclusive, have been updated.

Ø  fireTableRowsDeleted

public void fireTableRowsDeleted(int firstRow,int lastRow)

Notifies all listeners that rows in the range [firstRow, lastRow], inclusive, have been deleted. 

No comments:

Post a Comment