Diamond Control Suite 3.0

diamondedge.swing.grid
Class DsGrid

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by diamondedge.swing.grid.DsTable
                      extended by diamondedge.swing.grid.DsGrid
All Implemented Interfaces:
DsConstants, GridRowListener, FocusListener, MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable, SwingConstants, TableModel

public class DsGrid
extends DsTable
implements MouseListener, FocusListener, TableModel, GridRowListener

DsGrid is a data-aware drop-in replacement for JTable which is used to display and edit regular two-dimensional tables of cells. It provides full and easy formatting and styles for each cell, column, or row. For binding to databases, the ResultSetModel provides a scalable and high performance virtual view of up to 2 billion records from a JDBC ResultSet. The data in the grid can be formatted, sorted, printed and edited using any of the models supplied or any user defined TableModel.

A very easy and flexible object model is available to format and modify the style of cells in the grid. Cells can be individually changed such as:

grid.getCellAt( 1, 2 ).setForeground( Color.blue );
The selected cells can be easily changed such as:
grid.getCells().setBackground( Color.yellow );
All cells in certain columns can be changed easily:
grid.getColumns( 1, 2 ).setHorizontalAlignment( DsConstants.CENTER );
All cells in certain rows can be changed easily:
grid.getRows( 1, 2 ).setFontBold( true );
Cells can be formatted using Java's Format objects such as formatting the 2nd and 3rd column to display as a currency using the default locales currency format:
grid.getColumns( 1, 2 ).setFormat( NumberFormat.getCurrencyInstance() );
Cells can contain calculated values by setting a formula for the cell:
grid.setFormulaAt( "sum(A1:C1)", 0, 3 );
See Formula Functions Reference for a list of the functions available within formulas.

Note that DsTable provides many additional features such as spanning while JTable provides the base implementation.

See Diamond Grid Tutorial (or on the web site) for task-oriented documentation and more examples of using features specific to DsGrid.

See How to Use Tables in The Java Tutorial for task-oriented documentation and examples of using JTable.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class diamondedge.swing.grid.DsTable
DsTable.BooleanEditor, DsTable.BooleanRenderer, DsTable.ComponentEditor, DsTable.ComponentRenderer, DsTable.DateEditor, DsTable.ListEditor, DsTable.TableEditor
 
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int ALTERNATING_ROW_COLOR
           
static int AUTO_LABEL_NONE
           
static int AUTO_LABEL_START_WITH_0
           
static int AUTO_LABEL_START_WITH_1
           
static int AUTO_LABEL_START_WITH_A
           
protected  Paint autoColor1
           
protected  Paint autoColor2
           
protected  Paint autoColor3
           
protected  Paint autoColor4
           
protected  boolean leaveFrozenColumns
          if set to true then the columns remain in the column model when they are frozen and a copy is placed in the row header.
static int SELECTION_BY_COLUMN
          Selections to span entire columns, as if selecting ranges for a chart or fields for sorting.
static int SELECTION_BY_ROW
          Selections to span entire rows, as in a multi-column list box or record-based display.
static int SELECTION_FREE
          Individual cells to be selected, spreadsheet style.
static String version
           
 
Fields inherited from class diamondedge.swing.grid.DsTable
cellsEditable, spannedCells
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface diamondedge.swing.DsConstants
ACCOUNTING, ALL, ASCENDING, ASCENDING_CASE, BORDER_BOTTOM, BORDER_LEFT, BORDER_NONE, BORDER_OUTLINE, BORDER_RIGHT, BORDER_TOP, CROSS_LINES, DASH, DASH_DOT, DASH_DOT_DOT, DEFAULT, DESCENDING, DESCENDING_CASE, DIAGONAL_CROSS_LINES, DOT, DOUBLE, DOUBLE_LINE, DOWNWARD_DIAGONAL_LINES, ETCHED, ETCHED_RAISED, FALSE, FIND_ALL, FIND_EQUALS, FIND_GT, FIND_GTE, FIND_LT, FIND_LTE, FIND_NE, FIND_PREFIX, FIND_REGEX, FIND_STRING, FIRST, FLAT, GRID_DASH, GRID_DASH_DOT, GRID_DASH_DOT_DOT, GRID_DOT, GRID_LINE, HIGHLIGHT_SELECTION_ALWAYS, HIGHLIGHT_SELECTION_NEVER, HIGHLIGHT_SELECTION_WITH_FOCUS, HORIZONTAL_LINES, LOWERED, LOWERED_LIGHT, NONE, RAISED, RAISED_LIGHT, SELECT_CELL, SELECT_NONE, SELECT_ROW, SINGLE, SINGLE_LINE, SOLID, STRETCH, TILE, TRANSPARENT, TRUE, UPWARD_DIAGONAL_LINES, VERTICAL_LINES
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DsGrid()
           
DsGrid(int rows, int cols)
           
DsGrid(TableModel dataModel)
           
 
Method Summary
 void addColumnClickListener(ColumnClickListener listener)
          Add a listener to the list that's notified each time a column is clicked on.
 void addGridEditorListener(GridEditorListener l)
          Adds a listener to the list that's notified each time the editing state has changed.
 void addRow()
          Append a new row.
 void addRow(Object item)
          Append a new row with item being value in the first column.
 void addTableModelListener(TableModelListener l)
           
 void addTabOrder(DsCellRange cells)
           
 void addTabOrder(int row, int col)
           
 void addTabOrder(int firstRow, int firstColumn, int lastRow, int lastColumn)
           
protected  void applyAutoStyle()
           
 void changeSelection(int row, int column, boolean toggle, boolean extend)
          Overriden to not allow mouse to select cells that are not in tab order
 void clear()
          Clears the contents of each cell.
 void clearTabOrder()
           
protected  void configureEnclosingScrollPane()
           
protected  void configureRowHeader()
           
 void copyToClipboard()
           
 void copyToClipboard(boolean all, boolean includeColHeaders)
           
 void editingCanceled(ChangeEvent e)
          Invoked when editing is canceled.
 void editingStopped(ChangeEvent e)
          Invoked when editing is finished.
 void ensureVisible(int row)
          Scroll to make sure the row is visible on the screen
 void ensureVisible(int row, int column)
          Scroll to make sure the cell is visible on the screen
 DsCellRange find(Object searchFor, int matchType, int action)
          Finds a value in a cell or multiple cells.
protected  void fireColumnClicked(MouseEvent e)
          This method notifies the ColumnClickListeners that a column has been clicked on.
protected  boolean fireGridEditorEvent(int eventType, int row, int col, Component editor)
           
 void focusGained(FocusEvent e)
           
 void focusLost(FocusEvent e)
           
 void freezeColumn(int col)
          Turns the specified column into a fixed (non-scrollable) column by moving the columns into the RowHeader.
 Image getBackgroundImage()
          Return the image that is painted on the background surface
 DsCell getCell()
          Returns the active cell.
 DsCellRange getCells()
          Returns a range of cells defined by the user's selection or by the combination of the Row, Col, Row2, Col2 properties.
 DsCellRange getCells(int firstRow, int firstColumn, int lastRow, int lastColumn)
          Returns a range of cells in between and including the specified cell corners.
 Object getCellValue()
          Returns the text contents/object for the active cell.
 String getClipString()
          Returns the selected cells formated into a tab delimited string.
 int getCol()
          Returns the column of the active cell.
 int getCol2()
          Determines the starting or ending column for a range of cells.
 int getColumnAtPoint(Point point)
          Returns the index of the column that point lies in or -1 if not a valid column.
 Class getColumnClass(int column)
          Returns the type of the column appearing in the view at column position column.
protected  JViewport getColumnHeaderViewport()
           
 DsCellRange getColumns(int firstColumn, int lastColumn)
          Returns a range of cells that includes all cells in the specified columns.
 int getFirstVisibleColumn()
          Returns the index of the column that is displayed at the left of the grid
 int getFirstVisibleRow()
          Returns the index of the row that is displayed at the top of the grid
 int getFrozenColumnCount()
          Returns the total number of fixed (non-scrollable) columns.
 GridModel getGridModel()
          Returns the inner most TableModel which is an instance of GridModel.
 int getHighlightPolicy()
          Determines when the selection is highlighted.
 int getNumClicksToSort()
          Returns the number of clicks on the column header required to allow the user to select the column to sort on or to change the sort order.
 int getRow()
          Returns the row of the active cell.
 int getRow2()
          Determines the starting or ending row for a range of cells.
 int getRowAtPoint(Point point)
          Returns the index of the row that point lies in or -1 if not a valid row.
 GridRowHeader getRowHeader()
          Returns fixed columns displaying a row header for each row.
 int getRowHeaderAutoLabel()
          Returns a value that determines the automatic assignment of the row header values.
protected  JViewport getRowHeaderViewport()
           
 int getRowHeaderWidth()
          Returns a value that determines the automatic assignment of the row header values.
 DsCellProperties getRowProperties(int row)
          Returns the default cell containing the default properties for the row.
 DsCellRange getRows(int firstRow, int lastRow)
          Returns a range of cells that includes all cells in the specified rows.
 int getSortColumn()
          Returns the column in the model that is currently being used to sort the rows.
 int getSortOrder()
          Returns whether or not the rows will be sorted in ascending or descending order.
 String getTextAt(int row, int col)
          Returns the text (contents formatted as a string) for the cell at the given row and column.
 int getTopVisibleRow()
          Deprecated. replaced by getFirstVisibleRow()
 void insertRow(int index, String item)
          Adds a new row at run time at the given position.
 boolean isAutoRecalc()
          Returns whether recalcFormulas() automatically called when cell values change.
 boolean isCellEditable(int row, int column)
          Returns true if the cell at row and column is editable.
 boolean isColumnHeaderVisible()
          Returns whether there is a fixed row displaying a column header for each column.
 boolean isRowHeaderVisible()
          Returns whether there are fixed columns displaying a row header for each row.
 boolean isRowStatusIconShowing()
          Returns whether an icon will be shown in the row header indicating the status of the row.
 boolean isSorted()
          Indicates whether the rows are automatically sorted alphabetically.
 void loadCSV(File file, boolean firstRowIsColHeader)
          Load data from a text stream formatted as comma separated values.
 void loadCSV(Reader reader, boolean firstRowIsColHeader, boolean convertData)
          Load data from a text stream formatted as comma separated values.
 void loadResultSet(ResultSet rs, boolean setHeaderColumns)
          Loads data from the ResultSet into the grid.
 void loadResultSet(ResultSet rs, int begRow, int begCol, int endRow, int endCol)
          Loads data from the ResultSet into the grid.
 void loadTabDelim(File file, boolean firstRowIsColHeader)
          Load data from a text stream formatted as tab delimited values.
 void loadTabDelim(Reader reader, boolean firstRowIsColHeader, boolean convertData)
          Load data from a text stream formatted as tab delimited values.
 void loadTextData(Reader reader, int begRow, int begCol, int endRow, int endCol, boolean firstRowIsColHeader, char delim, boolean stripStringDelim, boolean convertData)
          Load data from a text stream.
static void main(String[] args)
           
 void mouseClicked(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void paint(Graphics g)
           
 void paste()
           
 Component prepareEditor(TableCellEditor editor, int row, int column)
          Creates and prepares the editor when an edit is requested.
 boolean print()
          Print data using default properties
 boolean print(boolean showPrintDialog, double scaleFactor, DsCellRange range, String footer, int showColumnHeader, int showRowHeader)
          Print data in the grid.
 void printPreview()
          Preview the data in the grid as it would appear on the printed page.
 void printPreview(boolean showAllPages, double scaleFactor, DsCellRange range, String footer, int showColumnHeader, int showRowHeader)
          Preview the data in the grid as it would appear on the printed page.
 void recalcFormulas()
          Calculate the values of all of the formulas.
 void removeAll()
          Removes all cells including all rows and columns.
 void removeColumnClickListener(ColumnClickListener listener)
          Remove a listener from the list that's notified each time a column is clicked on.
 void removeGridEditorListener(GridEditorListener l)
          Removes a listener from the list that's notified each time the editing state has changed.
 void removeRow(int index)
          Removes a row at run time
 void removeTableModelListener(TableModelListener l)
           
 DsCellRange replace(Object searchFor, int matchType, Object replaceWith)
          Finds values in a cell or multiple cells and replaces the entire value with the value specified.
 void rowChanged(GridEvent e)
           
 void saveAsCSV(File file, boolean saveHeaderColumns)
          Save data to a file with comma separated value format.
 void saveAsHTML(File file, boolean saveHeaderColumns)
          Save data to a HTML formated stream.
 void saveAsHTML(Writer writer, int begRow, int begCol, int endRow, int endCol, boolean saveHeaderColumns)
          Save data to a HTML formated stream.
 void saveAsTabDelim(File file, boolean saveHeaderColumns)
          Save data to a file with tab delimeted text format.
 void saveAsTextData(Writer writer, int begRow, int begCol, int endRow, int endCol, boolean saveHeaderColumns, char delim, boolean addStringDelim)
          Save data to a delimeted stream such as tab-delimeted or csv.
 boolean select(int row, int col)
          Sets the row and column of the active cell.
 boolean select(int row, int col, int row2, int col2)
          Sets the row and column of the active cell which is the beginning of the selection.
 void setAutoRecalc(boolean automaticallyRecalculateFormulas)
          Sets whether recalcFormulas() automatically called when cell values change.
 void setAutoResizeMode(int autoResize)
          Sets the table's auto resize mode when the table is resized.
 void setAutoStyle(int autoStyle)
          Automatically sets the styles for rows and columns using default colors.
 void setAutoStyle(int autoStyle, Paint color1, Paint color2, Paint color3, Paint color4)
          Automatically sets the styles for rows and columns.
 void setBackgroundImage(Image image)
          Set the image that is painted on the background surface.
 void setBackgroundImageStyle(int style)
          Paint the background image using the given style
 void setCellValue(Object value)
          Sets the text contents/object for the active cell.
 void setClipString(String tabDelimtedStr)
          Replaces the selected cells with the values from the tab delimited string.
 void setCol(int col)
          Sets the column of the active cell.
 void setCol2(int val)
          Determines the starting or ending column for the selected range of cells.
 void setColumnClass(int column, Class type)
          Sets the type of the column appearing in the view at column position column.
 void setColumnHeaderVisible(boolean visible)
          Sets whether there is a fixed row displaying a column header for each column.
 void setColumnSelectionAllowed(boolean columnSelectionAllowed)
          Sets whether the columns in this model can be selected.
 void setFormulaAt(String formula, int row, int col)
          Sets the formula for the cell at the given row and column.
 void setFrozenColumnCount(int val)
          Sets the total number of fixed (non-scrollable) columns by moving the specified number of columns into the RowHeader.
 void setHighlightPolicy(int val)
          Determines when the selection is highlighted.
 void setModel(TableModel dataModel)
           
 void setNumClicksToSort(int numClicks)
          Allow the user to interactively select which column to sort on by clicking on the column header.
 void setRow(int row)
          Sets the row of the active cell.
 void setRow2(int row)
          Determines the starting or ending row for a range of cells.
 void setRowCount(int val)
          Sets the total number of rows by adding new blank rows or removing rows.
 void setRowHeaderAutoLabel(int autoLabel)
          Set the automatic assignment of the row header values.
 void setRowHeaderVisible(boolean visible)
          Sets whether there are fixed columns displaying a row header for each row.
 void setRowHeaderWidth(int width)
          Set the total width of all columns in the row header.
 void setRowHeaderWidthToFit(boolean fitColumnNames, boolean fitColumnData, int columnMargin)
          Sets the total width of the row header needed to fit the text for the name of the column and/or the data in cells in that column for each column in the row header.
 void setRowHeight(int rowHeight)
          Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints.
 void setRowHeight(int row, int rowHeight)
          Sets the height for row to rowHeight, revalidates, and repaints.
 void setRowSelectionAllowed(boolean rowSelectionAllowed)
          Sets whether the columns in this model can be selected.
 void setRowStatusIconShowing(boolean showRowIcon)
          Determines whether an icon will be shown in the row header indicating the status of the row.
 void setSelectionPolicy(int val)
          Sets whether it should allow regular cell selection, selection by rows, or selection by columns.
 void setSortColumn(int modelIndex)
          Sets the column index in the model that is to be used to sort the rows.
 void setSorted(boolean sort)
          Sets whether the rows are automatically sorted alphabetically.
 void setSortIcons(Icon ascendingSortIcon, Icon descendingSortIcon)
          Set custom icons that show which direction a column is sorted These are only used if sorting by one column
 void setSortOrder(int sortOrder)
          Sets whether or not the rows will be sorted in ascending or descending order.
 void setValueAt(Object val, int row, int col)
          Sets the text contents/object for the cell at the given row and column.
 void sort()
          Sorts the list items according to the current sort column and order.
 void sort(int column, int sortOrder)
          Sorts the model by comparing values in the given column.
 boolean spanCells(int startRow, int startColumn, int rowsToSpan, int columnsToSpan)
          Makes the cell at position startRow, startColumn span across rowsToSpan rows and columnsToSpan columns.
 void tableChanged(TableModelEvent e)
          Invoked when this table's TableModel generates a TableModelEvent.
 void updateUI()
           
 void valueChanged(ListSelectionEvent e)
           
 
Methods inherited from class diamondedge.swing.grid.DsTable
addColumn, addColumn, addColumn, calculateColumnWidthToFit, calculateWidthToFit, columnAtPoint, columnSelectionChanged, createCell, createDefaultColumnsFromModel, createDefaultEditors, createDefaultRenderers, createDefaultTableHeader, getCellAt, getCellColumnSpan, getCellEditor, getCellRect, getCellRenderer, getCellRowSpan, getCellValueAt, getColumn, getColumn, getColumnCount, getColumnHeader, getColumnHeaderBackground, getColumnHeaderFont, getColumnHeaderForeground, getColumnHeaderHeight, getColumnIndex, getColumnName, getColumnProperties, getColumnWidth, getScrollPane, getToolTipText, hideColumn, isColumnReorderingAllowed, isColumnResizingAllowed, isEditable, removeSpan, rowAtPoint, setColumnCount, setColumnHeaderBackground, setColumnHeaderFont, setColumnHeaderForeground, setColumnHeaderHeight, setColumnHorizontalAlignment, setColumnName, setColumnReorderingAllowed, setColumnResizingAllowed, setColumnVerticalAlignment, setColumnWidth, setColumnWidth, setColumnWidthToFit, setEditable
 
Methods inherited from class javax.swing.JTable
addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnMarginChanged, columnMoved, columnRemoved, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultDataModel, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, editCellAt, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellSelectionEnabled, getColumn, getColumnModel, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareRenderer, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowMargin, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, unconfigureEnclosingScrollPane
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
getColumnCount, getColumnName, getRowCount, getValueAt
 

Field Detail

version

public static String version

SELECTION_FREE

public static final int SELECTION_FREE
Individual cells to be selected, spreadsheet style.

See Also:
Constant Field Values

SELECTION_BY_ROW

public static final int SELECTION_BY_ROW
Selections to span entire rows, as in a multi-column list box or record-based display.

See Also:
Constant Field Values

SELECTION_BY_COLUMN

public static final int SELECTION_BY_COLUMN
Selections to span entire columns, as if selecting ranges for a chart or fields for sorting.

See Also:
Constant Field Values

AUTO_LABEL_NONE

public static final int AUTO_LABEL_NONE
See Also:
Constant Field Values

AUTO_LABEL_START_WITH_0

public static final int AUTO_LABEL_START_WITH_0
See Also:
Constant Field Values

AUTO_LABEL_START_WITH_1

public static final int AUTO_LABEL_START_WITH_1
See Also:
Constant Field Values

AUTO_LABEL_START_WITH_A

public static final int AUTO_LABEL_START_WITH_A
See Also:
Constant Field Values

ALTERNATING_ROW_COLOR

public static final int ALTERNATING_ROW_COLOR
See Also:
Constant Field Values

autoColor1

protected Paint autoColor1

autoColor2

protected Paint autoColor2

autoColor3

protected Paint autoColor3

autoColor4

protected Paint autoColor4

leaveFrozenColumns

protected boolean leaveFrozenColumns
if set to true then the columns remain in the column model when they are frozen and a copy is placed in the row header. if set to false then the columns in the column model are moved to the row header when they are frozen. Warning: this property may not removed in the future.

Constructor Detail

DsGrid

public DsGrid()

DsGrid

public DsGrid(int rows,
              int cols)

DsGrid

public DsGrid(TableModel dataModel)
Method Detail

updateUI

public void updateUI()
Overrides:
updateUI in class DsTable

getBackgroundImage

public final Image getBackgroundImage()
Return the image that is painted on the background surface


setBackgroundImage

public void setBackgroundImage(Image image)
Set the image that is painted on the background surface. The cells must have their opaque property set to false or have some amount of alpha in their background color to see it.

See Also:
DsCellProperties.setOpaque(boolean), DsCellProperties.setBackground(java.awt.Paint)

setBackgroundImageStyle

public void setBackgroundImageStyle(int style)
Paint the background image using the given style

Parameters:
style - One of: LEFT, CENTER, STRETCH, TILE

paint

public void paint(Graphics g)
Overrides:
paint in class JComponent

getGridModel

public GridModel getGridModel()
Returns the inner most TableModel which is an instance of GridModel.


setModel

public void setModel(TableModel dataModel)
Overrides:
setModel in class JTable

isCellEditable

public boolean isCellEditable(int row,
                              int column)
Returns true if the cell at row and column is editable. If the editable property is set to true then the TableModel will determine whether an individual cell can be edited.

Specified by:
isCellEditable in interface TableModel
Overrides:
isCellEditable in class DsTable
See Also:
DsTable.setEditable(boolean)

setValueAt

public void setValueAt(Object val,
                       int row,
                       int col)
Sets the text contents/object for the cell at the given row and column.

Specified by:
setValueAt in interface TableModel
Overrides:
setValueAt in class JTable

setFormulaAt

public void setFormulaAt(String formula,
                         int row,
                         int col)
Sets the formula for the cell at the given row and column. Formulas are calculated in the order they were set.

See Formula Functions Reference for a list of the functions available within formulas..


setRowCount

public void setRowCount(int val)
Sets the total number of rows by adding new blank rows or removing rows.


setAutoStyle

public void setAutoStyle(int autoStyle)
Automatically sets the styles for rows and columns using default colors.

See Also:
setAutoStyle(int,Paint,Paint,Paint,Paint)

setAutoStyle

public void setAutoStyle(int autoStyle,
                         Paint color1,
                         Paint color2,
                         Paint color3,
                         Paint color4)
Automatically sets the styles for rows and columns. If null is passed for any of the color then the default color is used which is indicated for each style in parenthesis. Valid values for autoStyle are :


applyAutoStyle

protected void applyAutoStyle()

setAutoResizeMode

public void setAutoResizeMode(int autoResize)
Sets the table's auto resize mode when the table is resized.

Overrides:
setAutoResizeMode in class JTable
See Also:
JTable.setAutoResizeMode(int)

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()
Overrides:
configureEnclosingScrollPane in class JTable

configureRowHeader

protected void configureRowHeader()

getRowHeader

public final GridRowHeader getRowHeader()
Returns fixed columns displaying a row header for each row. This will be null if it has not been made visible at least once.

See Also:
setRowHeaderVisible(boolean)

getRowHeaderViewport

protected final JViewport getRowHeaderViewport()

isRowHeaderVisible

public final boolean isRowHeaderVisible()
Returns whether there are fixed columns displaying a row header for each row.


setRowHeaderVisible

public void setRowHeaderVisible(boolean visible)
Sets whether there are fixed columns displaying a row header for each row.


getRowHeaderWidth

public int getRowHeaderWidth()
Returns a value that determines the automatic assignment of the row header values.


setRowHeaderWidth

public void setRowHeaderWidth(int width)
Set the total width of all columns in the row header.


setRowHeaderWidthToFit

public void setRowHeaderWidthToFit(boolean fitColumnNames,
                                   boolean fitColumnData,
                                   int columnMargin)
Sets the total width of the row header needed to fit the text for the name of the column and/or the data in cells in that column for each column in the row header. This also resizes each column in the row header to be the size needed to fit the data plus the extra amount specified in the columnMargin parameter.

See Also:
DsTable.calculateWidthToFit(boolean, boolean), setRowHeaderWidth(int)

getRowHeaderAutoLabel

public final int getRowHeaderAutoLabel()
Returns a value that determines the automatic assignment of the row header values.


setRowHeaderAutoLabel

public void setRowHeaderAutoLabel(int autoLabel)
Set the automatic assignment of the row header values. Defaults to numbering starting with 1. Valid values are:


getColumnHeaderViewport

protected final JViewport getColumnHeaderViewport()

isColumnHeaderVisible

public final boolean isColumnHeaderVisible()
Returns whether there is a fixed row displaying a column header for each column.


setColumnHeaderVisible

public void setColumnHeaderVisible(boolean visible)
Sets whether there is a fixed row displaying a column header for each column.


freezeColumn

public void freezeColumn(int col)
Turns the specified column into a fixed (non-scrollable) column by moving the columns into the RowHeader.


getFrozenColumnCount

public final int getFrozenColumnCount()
Returns the total number of fixed (non-scrollable) columns.


setFrozenColumnCount

public void setFrozenColumnCount(int val)
Sets the total number of fixed (non-scrollable) columns by moving the specified number of columns into the RowHeader. If set to 0 all previously frozen columns will be returned to the grid. If set to 1 or greader then the RowHeader will be visible and all frozen columns will be moved to the RowHeader. The frozen columns must be accessed from the RowHeader object. Both the RowHeader and the main part of the grid will share the same TableModel.

See Also:
getRowHeader()

getHighlightPolicy

public final int getHighlightPolicy()
Determines when the selection is highlighted.


setHighlightPolicy

public void setHighlightPolicy(int val)
Determines when the selection is highlighted. Valid values are:


setSelectionPolicy

public void setSelectionPolicy(int val)
Sets whether it should allow regular cell selection, selection by rows, or selection by columns. Valid values are:


setRowSelectionAllowed

public void setRowSelectionAllowed(boolean rowSelectionAllowed)
Sets whether the columns in this model can be selected.

Overrides:
setRowSelectionAllowed in class JTable
See Also:
JTable.setRowSelectionAllowed(boolean)

setColumnSelectionAllowed

public void setColumnSelectionAllowed(boolean columnSelectionAllowed)
Sets whether the columns in this model can be selected.

Overrides:
setColumnSelectionAllowed in class JTable
See Also:
JTable.setColumnSelectionAllowed(boolean)

isRowStatusIconShowing

public final boolean isRowStatusIconShowing()
Returns whether an icon will be shown in the row header indicating the status of the row.


setRowStatusIconShowing

public void setRowStatusIconShowing(boolean showRowIcon)
Determines whether an icon will be shown in the row header indicating the status of the row. If the RowHeader is not currently visible then it will be set to visible and the width will be set to 20 and auto labeling will be turned off.


getRow2

public int getRow2()
Determines the starting or ending row for a range of cells.


setRow2

public void setRow2(int row)
Determines the starting or ending row for a range of cells.

See Also:
setRow(int)

getCol2

public int getCol2()
Determines the starting or ending column for a range of cells.


setCol2

public void setCol2(int val)
Determines the starting or ending column for the selected range of cells.

See Also:
setCol(int)

getRow

public int getRow()
Returns the row of the active cell.


setRow

public void setRow(int row)
Sets the row of the active cell. This also sets the selected cell and resets Row2 to this row.

See Also:
setRow2(int)

select

public boolean select(int row,
                      int col)
Sets the row and column of the active cell. This also resets Row2 to this row and Col2 to this col.

Returns:
false if row or col was not valid row or column.
See Also:
setRow(int), setCol(int), setRow2(int), setCol2(int)

select

public boolean select(int row,
                      int col,
                      int row2,
                      int col2)
Sets the row and column of the active cell which is the beginning of the selection. The selection extends to and includes cell at row, col, and row2, col2. If row2 or col2 is not a valid row or column then row or col argument is used.

Returns:
false if row or col was not valid row or column.
See Also:
setRow(int), setCol(int), setRow2(int), setCol2(int)

getCol

public final int getCol()
Returns the column of the active cell.


setCol

public void setCol(int col)
Sets the column of the active cell. This also sets the selected cells and resets Col2 to this column.

See Also:
setCol2(int)

getRowAtPoint

public int getRowAtPoint(Point point)
Returns the index of the row that point lies in or -1 if not a valid row.

See Also:
JTable.rowAtPoint(java.awt.Point)

getColumnAtPoint

public int getColumnAtPoint(Point point)
Returns the index of the column that point lies in or -1 if not a valid column.

See Also:
JTable.columnAtPoint(java.awt.Point)

getTextAt

public String getTextAt(int row,
                        int col)
Returns the text (contents formatted as a string) for the cell at the given row and column.


getCell

public final DsCell getCell()
Returns the active cell. This is the same as getCellAt( getRow(), getCol() )

See Also:
getRow(), getCol(), DsTable.getCellAt(int, int)

getCellValue

public final Object getCellValue()
Returns the text contents/object for the active cell.

See Also:
getRow(), getCol(), DsTable.getCellValueAt(int, int)

setCellValue

public void setCellValue(Object value)
Sets the text contents/object for the active cell.

See Also:
getRow(), getCol(), setValueAt(java.lang.Object, int, int)

getCells

public DsCellRange getCells()
Returns a range of cells defined by the user's selection or by the combination of the Row, Col, Row2, Col2 properties.

Note: if the selection includes frozen and non-frozen columns then only the non-frozen columns are returned.

See Also:
getRow(), getCol(), getRow2(), getCol2()

getCells

public DsCellRange getCells(int firstRow,
                            int firstColumn,
                            int lastRow,
                            int lastColumn)
Returns a range of cells in between and including the specified cell corners.

Overrides:
getCells in class DsTable
Parameters:
firstRow - the first row in the range of cells
firstColumn - the first column in the range of cells
lastRow - the last row in the range of cells
lastColumn - the last column in the range of cells

getRows

public DsCellRange getRows(int firstRow,
                           int lastRow)
Returns a range of cells that includes all cells in the specified rows.

Overrides:
getRows in class DsTable
Parameters:
firstRow - the first row in the range of cells
lastRow - the last row in the range of cells (inclusive)

getColumns

public DsCellRange getColumns(int firstColumn,
                              int lastColumn)
Returns a range of cells that includes all cells in the specified columns.

Overrides:
getColumns in class DsTable
Parameters:
firstColumn - the first column in the range of cells
lastColumn - the last column in the range of cells (inclusive)

clearTabOrder

public void clearTabOrder()

addTabOrder

public void addTabOrder(int row,
                        int col)

addTabOrder

public void addTabOrder(DsCellRange cells)

addTabOrder

public void addTabOrder(int firstRow,
                        int firstColumn,
                        int lastRow,
                        int lastColumn)

changeSelection

public void changeSelection(int row,
                            int column,
                            boolean toggle,
                            boolean extend)
Overriden to not allow mouse to select cells that are not in tab order

Overrides:
changeSelection in class JTable

find

public DsCellRange find(Object searchFor,
                        int matchType,
                        int action)
Finds a value in a cell or multiple cells. If the searchFor value is a Number, BigDecimal or Date then a numerical or date comparison will be used for FIND_EQUALS, FIND_GTE and FIND_LTE.

Parameters:
searchFor - Object to find.
matchType - One of:
  • FIND_STRING - case insensitive search of a string that is equal to the toString() of the cell value
  • FIND_PREFIX - case insensitive search of a string that matches the first part of the cell value's toString()
  • FIND_REGEX - cell value whose toString() matches the given regular expression
  • FIND_EQUALS - cell value that is equal to the given value. For strings this is case sensitive.
  • FIND_NE - cell value that is not equal to the given value. For strings this is case sensitive.
  • FIND_GTE - cell value that is greater than or equal to the given value
  • FIND_LTE - cell value that is less than or equal to the given value
  • FIND_GT - cell value that is greater than the given value
  • FIND_LT - cell value that is less than the given value
  • FIND_ALL - Search all cells. Otherwise search is stopped on the first match. Should be OR'ed in with one of the above values
action - One of: SELECT_NONE, SELECT_CELL, SELECT_ROW
Returns:
a DsCellRange that is the smallest rectangular range that includes all of the matched cells.

replace

public DsCellRange replace(Object searchFor,
                           int matchType,
                           Object replaceWith)
Finds values in a cell or multiple cells and replaces the entire value with the value specified. If the searchFor value is a Number, BigDecimal or Date then a numerical or date comparison will be used for FIND_EQUALS, FIND_GTE and FIND_LTE.

Parameters:
searchFor - Object to find.
matchType - One of:
  • FIND_STRING - case insensitive search of a string that is equal to the toString() of the cell value
  • FIND_PREFIX - case insensitive search of a string that matches the first part of the cell value's toString()
  • FIND_REGEX - cell value whose toString() matches the given regular expression
  • FIND_EQUALS - cell value that is equal to the given value. For strings this is case sensitive.
  • FIND_NE - cell value that is not equal to the given value. For strings this is case sensitive.
  • FIND_GTE - cell value that is greater than or equal to the given value
  • FIND_LTE - cell value that is less than or equal to the given value
  • FIND_GT - cell value that is greater than the given value
  • FIND_LT - cell value that is less than the given value
  • FIND_ALL - Search all cells. Otherwise search is stopped on the first match. Should be OR'ed in with one of the above values
replaceWith - the new value for each cell that is found
Returns:
a DsCellRange that is the smallest rectangular range that includes all of the matched cells.

getColumnClass

public Class getColumnClass(int column)
Returns the type of the column appearing in the view at column position column.

Specified by:
getColumnClass in interface TableModel
Overrides:
getColumnClass in class JTable
Parameters:
column - the column in the view being queried
Returns:
the type of the column at position column in the view where the first column is column 0

setColumnClass

public void setColumnClass(int column,
                           Class type)
Sets the type of the column appearing in the view at column position column. This can be overriden by the TableModel.getColumnClass method. By default the values in the cells can have any type of value. If all columns need to be coerced to a type then that type can be specified in this method. The type being given must have a constructor that accepts a String argument.

Parameters:
column - the column in the view
type - the type to which to coerce any edited values in the given column

getRowProperties

public DsCellProperties getRowProperties(int row)
Returns the default cell containing the default properties for the row. This has the side effect of allocating a Vector of cells on the first call. When rendering a cell first the default properities for the column are applied. Then the default properities for the row are applied followed by the properties specified on the cell itself.

See Also:
DsTable.getColumnProperties(int), getCell()

setRowHeight

public void setRowHeight(int row,
                         int rowHeight)
Sets the height for row to rowHeight, revalidates, and repaints. The height of the cells in this row will be equal to the row height minus the row margin.

If using a row header it must be made visible prior to changing the row height.

Overrides:
setRowHeight in class JTable
See Also:
setRowHeaderVisible(boolean)

setRowHeight

public void setRowHeight(int rowHeight)
Sets the height, in pixels, of all cells to rowHeight, revalidates, and repaints. The height of the cells will be equal to the row height minus the row margin.

If using a row header it must be made visible prior to changing the row height.

Overrides:
setRowHeight in class JTable
See Also:
setRowHeaderVisible(boolean)

addRow

public void addRow(Object item)
Append a new row with item being value in the first column.


addRow

public void addRow()
Append a new row.


insertRow

public void insertRow(int index,
                      String item)
Adds a new row at run time at the given position.


removeRow

public void removeRow(int index)
Removes a row at run time


removeAll

public void removeAll()
Removes all cells including all rows and columns. The model is also set to a DefaultGridModel if it wasn't already.

Overrides:
removeAll in class Container

clear

public void clear()
Clears the contents of each cell. This includes all text, pictures, and cell formatting. The Clear method does not affect the number of rows and columns on the grid. The model is also set to a DefaultGridModel if it wasn't already.


copyToClipboard

public void copyToClipboard()

copyToClipboard

public void copyToClipboard(boolean all,
                            boolean includeColHeaders)

paste

public void paste()

getClipString

public String getClipString()
Returns the selected cells formated into a tab delimited string.


setClipString

public void setClipString(String tabDelimtedStr)
Replaces the selected cells with the values from the tab delimited string. If no selection or active cell then cells starting will 0, 0 are replaced. The selection must be contiguous


isSorted

public final boolean isSorted()
Indicates whether the rows are automatically sorted alphabetically.


setSorted

public void setSorted(boolean sort)
Sets whether the rows are automatically sorted alphabetically.


getSortColumn

public final int getSortColumn()
Returns the column in the model that is currently being used to sort the rows.


setSortColumn

public void setSortColumn(int modelIndex)
Sets the column index in the model that is to be used to sort the rows. Note: the column specified is the index of the column in the model and not the index of the column in the column header which may have been re-arranged by the user.

Parameters:
modelIndex - The column index in the model to be sorted.

getSortOrder

public final int getSortOrder()
Returns whether or not the rows will be sorted in ascending or descending order.


setSortOrder

public void setSortOrder(int sortOrder)
Sets whether or not the rows will be sorted in ascending or descending order.

Parameters:
sortOrder - One of: ASCENDING, DESCENDING, ASCENDING_CASE, DESCENDING_CASE

sort

public void sort()
Sorts the list items according to the current sort column and order. Normally you should not have to call this method if it is automatically sorting.

See Also:
setSorted(boolean), setSortColumn(int), setSortOrder(int)

sort

public void sort(int column,
                 int sortOrder)
Sorts the model by comparing values in the given column.

Parameters:
column - column in the model to be sorted
sortOrder - One of: DsGrid.ASCENDING, DsGrid.DESCENDING, DsGrid.ASCENDING_CASE, DsGrid.DESCENDING_CASE

setSortIcons

public void setSortIcons(Icon ascendingSortIcon,
                         Icon descendingSortIcon)
Set custom icons that show which direction a column is sorted These are only used if sorting by one column


getNumClicksToSort

public final int getNumClicksToSort()
Returns the number of clicks on the column header required to allow the user to select the column to sort on or to change the sort order.

See Also:
setNumClicksToSort(int), setSorted(boolean)

setNumClicksToSort

public void setNumClicksToSort(int numClicks)
Allow the user to interactively select which column to sort on by clicking on the column header. Clicking again on the same column will reverse the sort order. The Sorted property must be also be set. A value of 0 means the user cannot change the sorting interactively.

Parameters:
numClicks - number of clicks required (either 0, 1, or 2)
See Also:
setSorted(boolean)

loadResultSet

public void loadResultSet(ResultSet rs,
                          boolean setHeaderColumns)
                   throws SQLException
Loads data from the ResultSet into the grid. All data in the grid is cleared first. The data is loaded from the current cursor position of the ResultSet. After the data is loaded the ResultSet will be at the last row.

Throws:
SQLException

loadResultSet

public void loadResultSet(ResultSet rs,
                          int begRow,
                          int begCol,
                          int endRow,
                          int endCol)
                   throws SQLException
Loads data from the ResultSet into the grid. The data is loaded from the current cursor position of the ResultSet. After the data is loaded the ResultSet will be at the last row.

Throws:
SQLException

loadTabDelim

public void loadTabDelim(File file,
                         boolean firstRowIsColHeader)
                  throws FileNotFoundException,
                         IOException
Load data from a text stream formatted as tab delimited values.

Parameters:
file - File that provides the data
firstRowIsColHeader - the first row is used to set the column headers
Throws:
FileNotFoundException
IOException

loadTabDelim

public void loadTabDelim(Reader reader,
                         boolean firstRowIsColHeader,
                         boolean convertData)
                  throws IOException
Load data from a text stream formatted as tab delimited values.

Parameters:
reader - stream that provides the data
firstRowIsColHeader - the first row is used to set the column headers
convertData - attempt to parse the values into a Number, Boolean, Date in that order
Throws:
IOException

loadCSV

public void loadCSV(File file,
                    boolean firstRowIsColHeader)
             throws FileNotFoundException,
                    IOException
Load data from a text stream formatted as comma separated values.

Parameters:
file - File that provides the data
firstRowIsColHeader - the first row is used to set the column headers
Throws:
FileNotFoundException
IOException

loadCSV

public void loadCSV(Reader reader,
                    boolean firstRowIsColHeader,
                    boolean convertData)
             throws IOException
Load data from a text stream formatted as comma separated values.

Parameters:
reader - stream that provides the data
firstRowIsColHeader - the first row is used to set the column headers
convertData - attempt to parse the values into a Number, Boolean, Date in that order
Throws:
IOException

loadTextData

public void loadTextData(Reader reader,
                         int begRow,
                         int begCol,
                         int endRow,
                         int endCol,
                         boolean firstRowIsColHeader,
                         char delim,
                         boolean stripStringDelim,
                         boolean convertData)
                  throws IOException
Load data from a text stream.

Parameters:
reader - stream that provides the data
begRow - row position in model to begin placing data
begCol - column position in model to begin placing data
endRow - ending row position in model to stop setting data. -1 means to load all data.
endCol - ending column position in model to stop setting data. -1 means to load all columns up to model.getColumnCount.
firstRowIsColHeader - the first row is used to set the column headers
delim - delimeter used to separate values. Pass in '\t' for tab delimeted and ',' for csv.
stripStringDelim - removes the " at the beginning and end of strings
convertData - attempt to parse the values into a Number, Boolean, Date in that order
Throws:
IOException

saveAsTabDelim

public void saveAsTabDelim(File file,
                           boolean saveHeaderColumns)
                    throws FileNotFoundException,
                           IOException
Save data to a file with tab delimeted text format.

Parameters:
file - file that the data is saved to
saveHeaderColumns - indicates whether the column names should be saved as the first row in the file
Throws:
FileNotFoundException
IOException

saveAsCSV

public void saveAsCSV(File file,
                      boolean saveHeaderColumns)
               throws FileNotFoundException,
                      IOException
Save data to a file with comma separated value format.

Parameters:
file - file that the data is saved to
saveHeaderColumns - indicates whether the column names should be saved as the first row in the file
Throws:
FileNotFoundException
IOException

saveAsTextData

public void saveAsTextData(Writer writer,
                           int begRow,
                           int begCol,
                           int endRow,
                           int endCol,
                           boolean saveHeaderColumns,
                           char delim,
                           boolean addStringDelim)
                    throws IOException
Save data to a delimeted stream such as tab-delimeted or csv.

Parameters:
writer - stream that the data is saved to
begRow - row position in model to begin saving data
begCol - column position in model to begin saving data
endRow - ending row position in model to stop saving data. -1 means to save all data.
endCol - ending column position in model to stop saving data. -1 means to save all columns up to model.getColumnCount.
delim - delimeter added in between data elements in the same row. Pass in '\t' for tab delimeted and ',' for csv.
addStringDelim - Should a " be added around string data. Pass in false for tab delimeted and true for csv.
Throws:
IOException

saveAsHTML

public void saveAsHTML(File file,
                       boolean saveHeaderColumns)
                throws FileNotFoundException,
                       IOException
Save data to a HTML formated stream. Currently only the data is saved.

Parameters:
file - file that the data is saved to
saveHeaderColumns - indicates whether the column names should be saved as the headers in the html table
Throws:
FileNotFoundException
IOException

saveAsHTML

public void saveAsHTML(Writer writer,
                       int begRow,
                       int begCol,
                       int endRow,
                       int endCol,
                       boolean saveHeaderColumns)
                throws IOException
Save data to a HTML formated stream. Currently only the data is saved.

Parameters:
writer - stream that the data is saved to
begRow - row position in model to begin saving data
begCol - column position in model to begin saving data
endRow - ending row position in model to stop saving data. -1 means to save all data.
endCol - ending column position in model to stop saving data. -1 means to save all columns up to model.getColumnCount.
saveHeaderColumns - indicates whether the column names should be saved as the headers in the html table
Throws:
IOException

print

public boolean print()
              throws PrinterException
Print data using default properties

Overrides:
print in class JTable
Throws:
PrinterException

print

public boolean print(boolean showPrintDialog,
                     double scaleFactor,
                     DsCellRange range,
                     String footer,
                     int showColumnHeader,
                     int showRowHeader)
              throws PrinterException
Print data in the grid.

Parameters:
showPrintDialog - true will display the dialog to select a printer before printing.
scaleFactor - Make the grid smaller or larger when printed. -1 means scale the width to width of page if it is bigger. 1 means keep it the same size.
range - Range of cells to print. null means print entire grid
footer - string the is printed on the bottom center of each page
showColumnHeader - display the ColumnHeader on the pages specified. One of: NONE, FIRST, ALL
showRowHeader - display the RowHeader on the pages specified. One of: NONE, FIRST, ALL

Note: the footer string can include tokens that are replaced by the respective values. The following tokens are supported: &[Page] &[Pages] &[Date] &[Time]. If null is specified for the footer then "Page &[Page] of &[Pages]" is used.

Throws:
PrinterException

printPreview

public void printPreview()
Preview the data in the grid as it would appear on the printed page.


printPreview

public void printPreview(boolean showAllPages,
                         double scaleFactor,
                         DsCellRange range,
                         String footer,
                         int showColumnHeader,
                         int showRowHeader)
Preview the data in the grid as it would appear on the printed page.

Parameters:
showAllPages - true will display all pages in a scrollable window. false will display one page at a time.
scaleFactor - Make the grid smaller or larger when printed. -1 means scale the width to width of page if it is bigger. 1 means keep it the same size.
range - Range of cells to print. null means print entire grid
footer - string the is printed on the bottom center of each page
showColumnHeader - display the ColumnHeader on the pages specified. One of: NONE, FIRST, ALL
showRowHeader - display the RowHeader on the pages specified. One of: NONE, FIRST, ALL

Note: the footer string can include tokens that are replaced by the respective values. The following tokens are supported: &[Page] &[Pages] &[Date] &[Time]. If null is specified for the footer then "Page &[Page] of &[Pages]" is used.


spanCells

public boolean spanCells(int startRow,
                         int startColumn,
                         int rowsToSpan,
                         int columnsToSpan)
Makes the cell at position startRow, startColumn span across rowsToSpan rows and columnsToSpan columns.

Once a cell has been spanned you will not be able to sort or reorder columns in the grid.

Overrides:
spanCells in class DsTable
Parameters:
startRow - The row of the cell which will span multiple rows and/or columns
startColumn - The column of the cell which will span multiple rows and/or columns
rowsToSpan - The number of rows to span.
columnsToSpan - The number of columns to span.
See Also:
DsTable.removeSpan(int, int)

fireColumnClicked

protected void fireColumnClicked(MouseEvent e)
This method notifies the ColumnClickListeners that a column has been clicked on.


addColumnClickListener

public void addColumnClickListener(ColumnClickListener listener)
Add a listener to the list that's notified each time a column is clicked on.

Parameters:
listener - The ColumnClickListener to add.

removeColumnClickListener

public void removeColumnClickListener(ColumnClickListener listener)
Remove a listener from the list that's notified each time a column is clicked on.

Parameters:
listener - The ColumnClickListener to remove.

addGridEditorListener

public void addGridEditorListener(GridEditorListener l)
Adds a listener to the list that's notified each time the editing state has changed.


removeGridEditorListener

public void removeGridEditorListener(GridEditorListener l)
Removes a listener from the list that's notified each time the editing state has changed.


fireGridEditorEvent

protected boolean fireGridEditorEvent(int eventType,
                                      int row,
                                      int col,
                                      Component editor)

isAutoRecalc

public boolean isAutoRecalc()
Returns whether recalcFormulas() automatically called when cell values change.

See Also:
recalcFormulas()

setAutoRecalc

public void setAutoRecalc(boolean automaticallyRecalculateFormulas)
Sets whether recalcFormulas() automatically called when cell values change.

See Also:
recalcFormulas()

recalcFormulas

public void recalcFormulas()
Calculate the values of all of the formulas. Calculates them in the order they were set. This method is automatically called when cell values change.

See Also:
setFormulaAt(java.lang.String, int, int), setAutoRecalc(boolean)

rowChanged

public void rowChanged(GridEvent e)
Specified by:
rowChanged in interface GridRowListener

tableChanged

public void tableChanged(TableModelEvent e)
Invoked when this table's TableModel generates a TableModelEvent.

Application code will not use these methods explicitly, they are used internally by JTable.

Specified by:
tableChanged in interface TableModelListener
Overrides:
tableChanged in class DsTable

valueChanged

public void valueChanged(ListSelectionEvent e)
Specified by:
valueChanged in interface ListSelectionListener
Overrides:
valueChanged in class DsTable

prepareEditor

public Component prepareEditor(TableCellEditor editor,
                               int row,
                               int column)
Creates and prepares the editor when an edit is requested. Overriden to provide an EDIT_STARTED event.

Overrides:
prepareEditor in class JTable
See Also:
JTable.prepareEditor(javax.swing.table.TableCellEditor, int, int)

editingStopped

public void editingStopped(ChangeEvent e)
Invoked when editing is finished. The changes are saved and the editor is discarded. Overriden to provide an EDIT_STOPPED event.

Specified by:
editingStopped in interface CellEditorListener
Overrides:
editingStopped in class JTable
See Also:
JTable.editingStopped(javax.swing.event.ChangeEvent)

editingCanceled

public void editingCanceled(ChangeEvent e)
Invoked when editing is canceled. The editor object is discarded and the cell is rendered once again. Overriden to provide an EDIT_CANCELED event.

Specified by:
editingCanceled in interface CellEditorListener
Overrides:
editingCanceled in class JTable
See Also:
JTable.editingCanceled(javax.swing.event.ChangeEvent)

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

focusGained

public void focusGained(FocusEvent e)
Specified by:
focusGained in interface FocusListener

focusLost

public void focusLost(FocusEvent e)
Specified by:
focusLost in interface FocusListener

ensureVisible

public void ensureVisible(int row)
Scroll to make sure the row is visible on the screen


ensureVisible

public void ensureVisible(int row,
                          int column)
Scroll to make sure the cell is visible on the screen


getFirstVisibleColumn

public int getFirstVisibleColumn()
Returns the index of the column that is displayed at the left of the grid


getFirstVisibleRow

public int getFirstVisibleRow()
Returns the index of the row that is displayed at the top of the grid


getTopVisibleRow

public int getTopVisibleRow()
Deprecated. replaced by getFirstVisibleRow()


addTableModelListener

public void addTableModelListener(TableModelListener l)
Specified by:
addTableModelListener in interface TableModel

removeTableModelListener

public void removeTableModelListener(TableModelListener l)
Specified by:
removeTableModelListener in interface TableModel

main

public static void main(String[] args)

Diamond Control Suite 3.0

Diamond Edge and Diamond Control Suite are trademarks or registered trademarks of Diamond Edge, Inc. Copyright 1999-2005 Diamond Edge, Inc. All Rights Reserved.