Class BaseTable

    • Field Detail

      • m_TableHelper

        protected JTableHelper m_TableHelper
        for setting the optimal column width.
      • m_HeaderPopupMenuListeners

        protected HashSet<PopupMenuListener> m_HeaderPopupMenuListeners
        the popup menu listeners for the header row.
      • m_CellPopupMenuListeners

        protected HashSet<PopupMenuListener> m_CellPopupMenuListeners
        the popup menu listeners for the cells.
      • m_ShowSimpleHeaderPopupMenu

        protected boolean m_ShowSimpleHeaderPopupMenu
        whether to show a simple header popup menu.
      • m_ShowSimpleCellPopupMenu

        protected boolean m_ShowSimpleCellPopupMenu
        whether to show a simple cell popup menu.
      • m_SimpleHeaderPopupMenuListener

        protected PopupMenuListener m_SimpleHeaderPopupMenuListener
        the simple header popup menu listener.
      • m_SimpleCellPopupMenuListener

        protected PopupMenuListener m_SimpleCellPopupMenuListener
        the simple cell popup menu listener.
      • m_MaxColumnOptimalColumnWidthCalc

        protected int m_MaxColumnOptimalColumnWidthCalc
        the maximum number of columns for optimal column width calculation.
      • m_MaxColumnOptimalHeaderWidthCalc

        protected int m_MaxColumnOptimalHeaderWidthCalc
        the maximum number of columns for optimal header width calculation.
      • m_TooManyColumnsDefaultWidth

        protected int m_TooManyColumnsDefaultWidth
        the column width to use when too many columns present.
    • Constructor Detail

      • BaseTable

        public BaseTable()
        Constructs a default BaseTable that is initialized with a default data model, a default column model, and a default selection model.
      • BaseTable

        public BaseTable​(int numRows,
                         int numColumns)
        Constructs a BaseTable with numRows and numColumns of empty cells using DefaultTableModel. The columns will have names of the form "A", "B", "C", etc.
        Parameters:
        numRows - the number of rows the table holds
        numColumns - the number of columns the table holds
      • BaseTable

        public BaseTable​(Object[][] rowData,
                         Object[] columnNames)
        Constructs a BaseTable to display the values in the two dimensional array, rowData, with column names, columnNames. rowData is an array of rows, so the value of the cell at row 1, column 5 can be obtained with the following code:

         rowData[1][5]; 

        All rows must be of the same length as columnNames.

        Parameters:
        rowData - the data for the new table
        columnNames - names of each column
      • BaseTable

        public BaseTable​(Vector rowData,
                         Vector columnNames)
        Constructs a BaseTable to display the values in the Vector of Vectors, rowData, with column names, columnNames. The Vectors contained in rowData should contain the values for that row. In other words, the value of the cell at row 1, column 5 can be obtained with the following code:

        ((Vector)rowData.elementAt(1)).elementAt(5);

        Parameters:
        rowData - the data for the new table
        columnNames - names of each column
      • BaseTable

        public BaseTable​(TableModel dm)
        Constructs a BaseTable that is initialized with dm as the data model, a default column model, and a default selection model.
        Parameters:
        dm - the data model for the table
      • BaseTable

        public BaseTable​(TableModel dm,
                         TableColumnModel cm)
        Constructs a BaseTable that is initialized with dm as the data model, cm as the column model, and a default selection model.
        Parameters:
        dm - the data model for the table
        cm - the column model for the table
      • BaseTable

        public BaseTable​(TableModel dm,
                         TableColumnModel cm,
                         ListSelectionModel sm)
        Constructs a BaseTable that is initialized with dm as the data model, cm as the column model, and sm as the selection model. If any of the parameters are null this method will initialize the table with the corresponding default model. The autoCreateColumnsFromModel flag is set to false if cm is non-null, otherwise it is set to true and the column model is populated with suitable TableColumns for the columns in dm.
        Parameters:
        dm - the data model for the table
        cm - the column model for the table
        sm - the row selection model for the table
    • Method Detail

      • getTableHelper

        protected JTableHelper getTableHelper()
        Returns the table helper instance. Instantiates it if necessary.
        Returns:
        the table helper
      • initGUI

        protected void initGUI()
        Initializes some GUI-related things.
      • finishInit

        protected void finishInit()
        Finishes the initialization.
      • initialUseOptimalColumnWidths

        protected BaseTable.ColumnWidthApproach initialUseOptimalColumnWidths()
        Returns the initial setting of whether to set optimal column widths. Default implementation returns "false", since large tables might take too long to be displayed otherwise.
        Returns:
        true if optimal column widths are used by default
      • setColumnWidthApproach

        public void setColumnWidthApproach​(BaseTable.ColumnWidthApproach value)
        Sets whether to automatically set optimal column widths.
        Parameters:
        value - if true then optimal column widths are used
      • getColumnWidthApproach

        public BaseTable.ColumnWidthApproach getColumnWidthApproach()
        Returns how to set the optimal column widths. Default implementation is initialized with "NONE".
        Returns:
        the optimal column widths strategy
      • selectAll

        public void selectAll()
        Selects all rows.
        Overrides:
        selectAll in class JTable
      • selectNone

        public void selectNone()
        Deselects all rows.
      • invertSelection

        public void invertSelection()
        Inverts the selection.
      • setSelectedRow

        public void setSelectedRow​(int row)
        Sets the selected row (clears all others).
        Parameters:
        row - the row to select
      • setSelectedRows

        public void setSelectedRows​(int[] rows)
        Sets the selected rows (clears all others).
        Parameters:
        rows - the rows to select
      • setMaxColumnOptimalColumnWidthCalc

        public void setMaxColumnOptimalColumnWidthCalc​(int value)
        Sets the maximum number of columns before no longer attempting to calculate the optimal column width.
        Parameters:
        value - the maximum number of columns (incl)
      • getMaxColumnOptimalColumnWidthCalc

        public int getMaxColumnOptimalColumnWidthCalc()
        Returns the maximum number of columns before no longer attempting to calculate the optimal column width.
        Returns:
        the maximum number of columns (incl)
        See Also:
        adaptiveOptimalColumnWidth()
      • setMaxColumnOptimalHeaderWidthCalc

        public void setMaxColumnOptimalHeaderWidthCalc​(int value)
        Sets the maximum number of columns before no longer attempting to calculate the optimal header width.
        Parameters:
        value - the maximum number of columns (incl)
        See Also:
        adaptiveOptimalColumnWidth()
      • getMaxColumnOptimalHeaderWidthCalc

        public int getMaxColumnOptimalHeaderWidthCalc()
        Returns the maximum number of columns before no longer attempting to calculate the optimal header width.
        Returns:
        the maximum number of columns (incl)
        See Also:
        adaptiveOptimalColumnWidth()
      • setTooManyColumnsDefaultWidth

        public void setTooManyColumnsDefaultWidth​(int value)
        Sets the default width to use if there are too many column to neither calculate the optimal column or header width.
        Parameters:
        value - the default width
        See Also:
        adaptiveOptimalColumnWidth()
      • getTooManyColumnsDefaultWidth

        public int getTooManyColumnsDefaultWidth()
        Returns the default width to use if there are too many column to neither calculate the optimal column or header width.
        Returns:
        the default width
        See Also:
        adaptiveOptimalColumnWidth()
      • setOptimalColumnWidth

        public void setOptimalColumnWidth()
        Sets the optimal column width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
      • setOptimalColumnWidthBounded

        public void setOptimalColumnWidthBounded​(int max)
        Sets the optimal column width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        max - the maximum width
      • setOptimalColumnWidth

        public void setOptimalColumnWidth​(int column)
        Sets the optimal column width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
      • setOptimalColumnWidthBounded

        public void setOptimalColumnWidthBounded​(int column,
                                                 int max)
        Sets the optimal column width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
        max - the maximum width
      • setOptimalColumnWidths

        public void setOptimalColumnWidths​(int[] columns)
        Sets the optimal column widths for the specified columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        columns - the columns to resize
      • setOptimalColumnWidthsBounded

        public void setOptimalColumnWidthsBounded​(int[] columns,
                                                  int max)
        Sets the optimal columns width for the specified columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        columns - the columns to resize
        max - the maximum width
      • setOptimalHeaderWidth

        public void setOptimalHeaderWidth()
        Sets the optimal header width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
      • setOptimalHeaderWidth

        public void setOptimalHeaderWidth​(int column)
        Sets the optimal header width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
      • enterColumnWidth

        protected int enterColumnWidth()
        Prompts the user to enter a column width.
        Returns:
        the column width, -1 if not to proceed
      • setColumnWidths

        public void setColumnWidths()
        Prompts the user for a col width value and sets the column width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
      • setColumnWidths

        public void setColumnWidths​(int width)
        Sets the specified column width for all columns. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        width - the width for all columns
      • setColumnWidth

        public void setColumnWidth​(int column)
        Prompts the user for a col width value and sets the column width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
      • setColumnWidth

        public void setColumnWidth​(int column,
                                   int width)
        Sets the specified column width for the specified column. AutoResize must be set to BaseTable.AUTO_RESIZE_OFF.
        Parameters:
        column - the column to resize
        width - the width to use
      • scrollRowToVisible

        public void scrollRowToVisible​(int row)
        Scrolls the row into view.
        Parameters:
        row - the row to scroll into view
      • scrollColumnToVisible

        public void scrollColumnToVisible​(int col)
        Scrolls the column into view.
        Parameters:
        col - the column to scroll into view
      • addRemoveItemsListener

        public void addRemoveItemsListener​(RemoveItemsListener l)
        Adds the remove items listener to its internal list.
        Parameters:
        l - the listener to add
      • removeRemoveItemsListener

        public void removeRemoveItemsListener​(RemoveItemsListener l)
        Removes the remove items listener from its internal list.
        Parameters:
        l - the listener to remove
      • notifyRemoveItemsListeners

        protected void notifyRemoveItemsListeners​(int[] indices)
        Notifies the remove items listeners about the indices that are to be removed.
        Parameters:
        indices - the indices that should get removed
      • addHeaderPopupMenuListener

        public void addHeaderPopupMenuListener​(PopupMenuListener l)
        Adds the popup menu listeners for the header.
        Parameters:
        l - the listener to add
      • removeHeaderPopupMenuListener

        public void removeHeaderPopupMenuListener​(PopupMenuListener l)
        Removes the popup menu listener for the header from its internal list.
        Parameters:
        l - the listener to remove
      • notifyHeaderPopupMenuListener

        protected void notifyHeaderPopupMenuListener​(MouseEvent e)
        Notifies the popup menu listeners (header).
        Parameters:
        e - the mouse event
      • addCellPopupMenuListener

        public void addCellPopupMenuListener​(PopupMenuListener l)
        Adds the popup menu listeners for the cell.
        Parameters:
        l - the listener to add
      • removeCellPopupMenuListener

        public void removeCellPopupMenuListener​(PopupMenuListener l)
        Removes the popup menu listener for the cell from its internal list.
        Parameters:
        l - the listener to remove
      • notifyCellPopupMenuListener

        protected void notifyCellPopupMenuListener​(MouseEvent e)
        Notifies the popup menu listeners (cell).
        Parameters:
        e - the mouse event
      • copyToClipboard

        public void copyToClipboard()
        Copies either the selected rows to the clipboard.
      • showCell

        public void showCell​(int row,
                             int column)
        Displays the specified cell.
        Parameters:
        row - the row of the cell
        column - the column of the cell
      • setShowSimplePopupMenus

        public void setShowSimplePopupMenus​(boolean value)
        Sets whether to show a simple header/cell popup menu.
        Parameters:
        value - true if to show menus
      • setShowSimpleHeaderPopupMenu

        public void setShowSimpleHeaderPopupMenu​(boolean value)
        Sets whether to show a simple header popup menu.
        Parameters:
        value - true if to show menu
      • getShowSimpleHeaderPopupMenu

        public boolean getShowSimpleHeaderPopupMenu()
        Returns whether to show a simple header popup menu.
        Returns:
        true if to show menu
      • showSimpleHeaderPopupMenu

        protected void showSimpleHeaderPopupMenu​(MouseEvent e)
        Pops up a simple header menu.
        Parameters:
        e - the trigger event
      • createSimpleHeaderPopupMenu

        protected BasePopupMenu createSimpleHeaderPopupMenu​(MouseEvent e)
        Creates a simple header popup menu.
        Parameters:
        e - the trigger event
        Returns:
        the popup menu
      • setShowSimpleCellPopupMenu

        public void setShowSimpleCellPopupMenu​(boolean value)
        Sets whether to show a simple cell popup menu.
        Parameters:
        value - true if to show menu
      • getShowSimpleCellPopupMenu

        public boolean getShowSimpleCellPopupMenu()
        Returns whether to show a simple cell popup menu.
        Returns:
        true if to show menu
      • showSimpleCellPopupMenu

        protected void showSimpleCellPopupMenu​(MouseEvent e)
        Pops up a simple cell menu.
        Parameters:
        e - the trigger event
      • createSimpleCellPopupMenu

        protected BasePopupMenu createSimpleCellPopupMenu​(MouseEvent e)
        Creates a simple cell popup menu.
        Parameters:
        e - the trigger event
        Returns:
        the popup menu
      • modelToSpreadSheet

        protected SpreadSheet modelToSpreadSheet()
        Returns the underlying sheet.
        Returns:
        the spread sheet
      • selectionRowToModelRow

        protected int selectionRowToModelRow​(int index)
        Determines the actual row index.
        Parameters:
        index - the selected row
        Returns:
        the actual model row
      • toSpreadSheet

        public SpreadSheet toSpreadSheet​(TableRowRange range)
        Returns the underlying sheet.
        Parameters:
        range - the type of rows to return
        Returns:
        the spread sheet
      • toSpreadSheet

        public SpreadSheet toSpreadSheet​(TableRowRange range,
                                         boolean view)
        Returns the underlying sheet.
        Parameters:
        range - the type of rows to return
        view - whether to return only a view (ignored if TableRowRange.ALL)
        Returns:
        the spread sheet
      • invertRowSelection

        public void invertRowSelection()
        Inverts the selected rows.
      • getSelectedRow

        public int getSelectedRow()
        Returns the index of the first selected row, -1 if no row is selected.
        Overrides:
        getSelectedRow in class JTable
        Returns:
        the index of the first selected row
      • getSelectedRows

        public int[] getSelectedRows()
        Returns the indices of all selected rows.
        Overrides:
        getSelectedRows in class JTable
        Returns:
        an array of integers containing the indices of all selected rows, or an empty array if no row is selected
        See Also:
        getSelectedRow()
      • getColumnWidths

        public int[] getColumnWidths()
        Returns the column widths.
        Returns:
        the current widths
      • setColumnWidths

        public void setColumnWidths​(int[] value)
        Sets the column widths.
        Parameters:
        value - the widths
      • getFileChooser

        protected SpreadSheetFileChooser getFileChooser()
        Returns the filechooser for saving the table as spreadsheet.
        Returns:
        the filechooser
      • saveAs

        protected void saveAs​(TableRowRange range)
        Pops up a save dialog for saving the data to a file.
        Parameters:
        range - the type of data to save