Class ViewHugeTableModel

java.lang.Object
uk.ac.starlink.table.gui.ViewHugeTableModel
All Implemented Interfaces:
TableModel

public class ViewHugeTableModel extends Object implements TableModel
Swing TableModel implementation which provides a view on a very large table model.

The point of this is for displaying tables with very large row counts in a JTable. Since the default height of a JTable row is 16 pixels (see JTable.getRowHeight()) a JTable component with more than 2^27 rows (about 134 million) will have a height in pixels which is too large to represent in a 32-bit int. In that case Swing gives up and just doesn't display the thing.

This class implements a model of a fixed (large but not too large) size, VIEWSIZE rows, which at any one time gives a view of a contiguous sequence of rows from the base table, starting at a mutable value given by getViewBase(). It works out the value of viewBase by reference to a scrollbar which is owned by this model, and assumed to control vertical scrolling of the scroll panel displaying the JTable that views it. The viewBase value is updated dynamically according to the current state (position) of the scrollbar. Whenever the viewBase changes, listeners (most importantly the client JTable) are notified.

In principle, every time the scrollbar position, or equivalently the set of currently visible rows, changes, the viewBase should change. But since the scrollbar has only pixel resolution, smallish changes can be accommodated without needing to take the somewhat expensive step of changing the viewBase.

The underlying table model can still only have up to 2^31 rows. The general approach used here would work for larger underlying row data, but it would be necessary to define a new long-capable TableModel interface to accommodate such data.

It is not recommended to use this class for underlying table models which are not in fact huge.

Note this class will only help you for displaying a JTable within a scrollpane. If you want to display a giga-row JTable unscrolled on a 100km tall VDU, you're on your own.

Since:
16 Jul 2014
Author:
Mark Taylor
  • Field Details

    • VIEWBASE_PROPERTY

      public static final String VIEWBASE_PROPERTY
      Name of property giving underlying value of first row of this model.
      See Also:
    • VIEWSIZE

      public static final int VIEWSIZE
      Fixed number of rows displayed by this model.
      See Also:
  • Constructor Details

    • ViewHugeTableModel

      public ViewHugeTableModel()
      Constructs an empty model.
    • ViewHugeTableModel

      public ViewHugeTableModel(TableModel hugeModel, JScrollBar vbar)
      Constructs a configured model.
      Parameters:
      hugeModel - table model with more than VIEWSIZE rows
      vbar - scrollbar used to control vertical scrolling of table view
  • Method Details

    • configureModel

      public void configureModel(TableModel hugeModel, JScrollBar vbar)
      Sets this mode up for use with a given underlying table model and scroll bar.
      Parameters:
      hugeModel - table model with more than VIEWSIZE rows
      vbar - scrollbar used to control vertical scrolling of table view
    • getRowCount

      public int getRowCount()
      Specified by:
      getRowCount in interface TableModel
    • getValueAt

      public Object getValueAt(int irow, int icol)
      Specified by:
      getValueAt in interface TableModel
    • setValueAt

      public void setValueAt(Object value, int irow, int icol)
      Specified by:
      setValueAt in interface TableModel
    • isCellEditable

      public boolean isCellEditable(int irow, int icol)
      Specified by:
      isCellEditable in interface TableModel
    • getColumnCount

      public int getColumnCount()
      Specified by:
      getColumnCount in interface TableModel
    • getColumnName

      public String getColumnName(int icol)
      Specified by:
      getColumnName in interface TableModel
    • getColumnClass

      public Class<?> getColumnClass(int icol)
      Specified by:
      getColumnClass in interface TableModel
    • addTableModelListener

      public void addTableModelListener(TableModelListener lnr)
      Specified by:
      addTableModelListener in interface TableModel
    • removeTableModelListener

      public void removeTableModelListener(TableModelListener lnr)
      Specified by:
      removeTableModelListener in interface TableModel
    • getViewBase

      public int getViewBase()
      Returns the offset from which this view views the underlying table model. Changes in this value will be notified to registered PropertyChangeListeners.
      Returns:
      view base
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener lnr)
      Adds a listener that will be notified about ViewBase changes. These have the property name VIEWBASE_PROPERTY.
      Parameters:
      lnr - listener to add
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener lnr)
      Removes a listener added earlier.
      Parameters:
      lnr - listener to remove
    • fireTableChanged

      protected void fireTableChanged(TableModelEvent evt)
      Notifies table model listeners of a table model event.
      Parameters:
      evt - event
    • firePropertyChanged

      protected void firePropertyChanged(PropertyChangeEvent evt)
      Notifies property change listeners of a property change.
      Parameters:
      evt - event
    • getHugeRow

      public int getHugeRow(int iViewRow)
      Returns the row in the underlying huge model corresponding to a given row in this view.
      Returns:
      iViewRow + viewBase