Watcher.v2_1
Class Table

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--Watcher.v2_1.Table
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Table
extends javax.swing.JPanel

Table is a component class which inherits JPanel. It contains a JTable in a JScrollpane and methods for getting and setting both the data in the JTable and the column headers. You can also edit the look-and-feel of the table by for example setting the font in a table cell and the background color of the table.

Version:
December 2001
Author:
Lars Erik Liljebäck
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent, javax.swing.JComponent.ActionStandin, javax.swing.JComponent.IntVector, javax.swing.JComponent.KeyboardState
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
private  boolean autoresize
           
private  java.awt.Color background
           
private  boolean cellEditable
           
private  java.awt.Dimension defDim
           
private  java.awt.Font defFont
           
private  int defRowHeight
           
private  java.awt.Dimension defViewport
           
private  int numOfRows
           
private  javax.swing.JScrollPane scroll
           
private  javax.swing.JTable table
           
private  TableModell tableModell
           
private  WatcherWindow window
           
 
Fields inherited from class javax.swing.JPanel
defaultLayout, uiClassID
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, actionMap, ACTIONMAP_CREATED, alignmentX, alignmentY, ANCESTOR_INPUTMAP_CREATED, ANCESTOR_USING_BUFFER, ancestorInputMap, ancestorNotifier, autoscroller, border, changeSupport, clientProperties, CREATED_DOUBLE_BUFFER, flags, FOCUS_INPUTMAP_CREATED, focusInputMap, HAS_FOCUS, htmlKey, htmlView, inputVerifier, IS_DOUBLE_BUFFERED, IS_OPAQUE, IS_PAINTING_TILE, IS_PRINTING, IS_PRINTING_ALL, KEY_EVENTS_ENABLED, KEYBOARD_BINDINGS_KEY, listenerList, maximumSize, minimumSize, NEXT_FOCUS, paintImmediatelyClip, paintingChild, preferredSize, readObjectCallbacks, REQUEST_FOCUS_DISABLED, tmpRect, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, verifyInputWhenFocusTarget, vetoableChangeSupport, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, WHEN_IN_FOCUSED_WINDOW_BINDINGS, WIF_INPUTMAP_CREATED, windowInputMap
 
Fields inherited from class java.awt.Container
component, containerListener, containerSerializedDataVersion, dbg, dispatcher, layoutMgr, listeningBoundsChildren, listeningChildren, maxSize, ncomponents, printing, printingThreads, serialVersionUID
 
Fields inherited from class java.awt.Component
actionListenerK, adjustmentListenerK, appContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, font, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, width, windowClosingException, windowListenerK, visible, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Table(java.lang.Object[] headers, int[] widths, int numOfRows)
          Instantiates a new Table with the specified column headers and column widths, as well as the number of empty rows which is added.
Table(java.lang.Object[] headers, int[] widths, java.lang.Object[][] data)
          Instantiates a new Table with the specified column headers and column widths, and sets the table data to be the data in the specified array.
 
Method Summary
private  void dbg(java.lang.String dbg)
          Adds a new debug-string to the DebugView with the classname as prefix.
 java.lang.Object getData(int row, int column)
          Returs the data in the specified cell or null if an Exception is caught.
 int getFirstEmptyRowNumber()
          Checks the first cell in every row, starting from the top, and returns the row number of the first row without any data.
 int getRowCount()
          Returns the number of rows in the table's model.
 int getRowForGAI(java.lang.String GAI)
          Searches through the JTable for the specified GAI.
 int getSelectedRow()
          Returns the row number of the selected row.
 boolean isCellEditable()
          Returns True if the cells are editable, False otherwise.
 void removeData()
          Removes all the data in the table by removing all the rows and adding a predefined number of empty rows afterwards.
 void removeRow(int rowNumber)
          Removes the specified row from the table modell.
 void setBackgroundColor(java.awt.Color background)
          Sets the background color of the table.
 void setCellEditable(boolean editable)
          Sets wether the cells are editable.
 void setCellFont(java.awt.Font newFont)
          Sets the font of the table cells.
 void setCellSpaceDimension(java.awt.Dimension newCellDim)
          Sets the spacing between the table cells.
 void setColumnWidths(int[] widths)
          Sets the column widths.
 void setData(int row, int column, java.lang.Object data)
          Sets the data in the specified cell.
 void setDefaultValues()
          Sets the properties of the table to the predefined values.
 void setHeaderFont(java.awt.Font newFont)
          Sets the font of the headers.
 void setHeaders(java.lang.Object[] headers)
          Sets the column headers.
 void setPanelBackgroundColor(java.awt.Color background)
          Sets the background color of the JPanel.
 void setResizeMode(boolean automatic)
          Sets the resize mode.
 void setRowHeight(int newHeight)
          Sets the row height.
 void setRowSelectable(boolean selectable)
          Sets wether user is allowed to select a row or not.
 void setScrollViewport(java.awt.Dimension newViewport)
          Sets the viewport of the scrollpane.
 void setSelectedRow(int row)
          Sets the specified row in the JTable as selected.
 void setToolTipText(java.lang.String tooltip)
          Sets the ToolTipText of the table.
 
Methods inherited from class javax.swing.JPanel
, getAccessibleContext, getUIClassID, paramString, updateUI, writeObject
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, adjustPaintFlags, alwaysOnTop, checkIfChildObscuredBySibling, clearFocusOwners, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperties, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getFlag, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getWidth, getVisibleRect, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paintWithBuffer, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseMotionEvent, putClientProperty, readObject, rectangleIsObscured, rectangleIsObscuredBySibling, registerKeyboardAction, registerKeyboardAction, registerWithKeyboardManager, registerWithKeyboardManager, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFlag, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setUI, setVerifyInputWhenFocusTarget, setVisible, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, unregisterWithKeyboardManager, unregisterWithKeyboardManager, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, adjustListeningChildren, applyOrientation, checkGD, countComponents, createChildHierarchyEvents, createHierarchyEvents, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents_NoClientCode, getComponents, getLayout, getMouseEventTarget, getWindow, initIDs, insets, invalidate, invalidateTree, isAncestorOf, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, nextFocus, numListening, paintComponents, paintHeavyweightComponents, postProcessKeyEvent, postsOldMouseEvents, preferredSize, preProcessKeyEvent, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, proxyRequestFocus, remove, remove, removeAll, removeContainerListener, setFocusOwner, setLayout, transferFocus, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, areInputMethodsEnabled, bounds, checkImage, checkImage, checkWindowClosingException, coalesceEvents, constructComponentName, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getAccessibleIndexInParent, getAccessibleStateSet, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getSize, getToolkit, getToolkitImpl, getTreeLock, getWindowForObject, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isEnabledImpl, isLightweight, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resetGC, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

table

private javax.swing.JTable table

tableModell

private TableModell tableModell

scroll

private javax.swing.JScrollPane scroll

window

private WatcherWindow window

defFont

private java.awt.Font defFont

defDim

private java.awt.Dimension defDim

defViewport

private java.awt.Dimension defViewport

defRowHeight

private int defRowHeight

autoresize

private boolean autoresize

cellEditable

private boolean cellEditable

background

private java.awt.Color background

numOfRows

private int numOfRows
Constructor Detail

Table

public Table(java.lang.Object[] headers,
             int[] widths,
             int numOfRows)
Instantiates a new Table with the specified column headers and column widths, as well as the number of empty rows which is added.
Parameters:
headers - Array of objects which are the column headers.
widths - Array of integers which are the column widths.
numOfRows - The number of rows which are added.

Table

public Table(java.lang.Object[] headers,
             int[] widths,
             java.lang.Object[][] data)
Instantiates a new Table with the specified column headers and column widths, and sets the table data to be the data in the specified array.
Parameters:
headers - Array of objects which are the column headers.
widths - Array of integers which are the column widths.
data - A 2D-table of objects which is the table data to be added.
Method Detail

getData

public java.lang.Object getData(int row,
                                int column)
Returs the data in the specified cell or null if an Exception is caught.
Parameters:
row - The cell's row number.
column - The cell's column number.
Returns:
The data in the table cell.

getFirstEmptyRowNumber

public int getFirstEmptyRowNumber()
Checks the first cell in every row, starting from the top, and returns the row number of the first row without any data. If none of the added rows (0 -> rowCount-1) is empty it returns rowCount.
Returns:
The row number of the first empty row in the table.

getRowCount

public int getRowCount()
Returns the number of rows in the table's model.
Returns:
The number of rows.

getRowForGAI

public int getRowForGAI(java.lang.String GAI)
Searches through the JTable for the specified GAI. If a matching GAI is found it returns the row number, else it returns -1.
Parameters:
GAI - The wanted GAI.
Returns:
The row number where the GAI was found or -1.

getSelectedRow

public int getSelectedRow()
Returns the row number of the selected row.

isCellEditable

public boolean isCellEditable()
Returns True if the cells are editable, False otherwise.

removeData

public void removeData()
Removes all the data in the table by removing all the rows and adding a predefined number of empty rows afterwards.

removeRow

public void removeRow(int rowNumber)
Removes the specified row from the table modell. If an ArrayIndexOutOfBoundsException is caught no row is removed.
Parameters:
rowNumber - The row to be removed.

setBackgroundColor

public void setBackgroundColor(java.awt.Color background)
Sets the background color of the table.
Parameters:
background - The new background color.

setCellEditable

public void setCellEditable(boolean editable)
Sets wether the cells are editable.
Parameters:
editable - If True the cells are editable, if false they are not.

setCellFont

public void setCellFont(java.awt.Font newFont)
Sets the font of the table cells.
Parameters:
newFont - The new font.

setCellSpaceDimension

public void setCellSpaceDimension(java.awt.Dimension newCellDim)
Sets the spacing between the table cells.
Parameters:
newCellDim - The dimension of the cell spacing.

setColumnWidths

public void setColumnWidths(int[] widths)
Sets the column widths. If the number of columns do not match the length of the array columns are either added or removed before the column widths are set.
Parameters:
widths - An array of integers which specifies the column widths.

setData

public void setData(int row,
                    int column,
                    java.lang.Object data)
Sets the data in the specified cell. If either the specified row number or column number points to a non-existing cell, more rows are added until the they point to a valid cell.
Parameters:
row - The cell's row number.
column - The cell's column number.
data - The cell's new data.

setDefaultValues

public void setDefaultValues()
Sets the properties of the table to the predefined values.

setHeaderFont

public void setHeaderFont(java.awt.Font newFont)
Sets the font of the headers.
Parameters:
newFont - The new header font.

setHeaders

public void setHeaders(java.lang.Object[] headers)
Sets the column headers. If the number of columns do not match the length of the array columns are either added or removed before the column headers are set.
Parameters:
headers - An array of objects which are the column headers.

setPanelBackgroundColor

public void setPanelBackgroundColor(java.awt.Color background)
Sets the background color of the JPanel.
Parameters:
background - The new background color.

setResizeMode

public void setResizeMode(boolean automatic)
Sets the resize mode. There are currently only two resize modes allowed; AUTO_RESIZE_ALL_COLUMNS and AUTO_RESIZE_OFF.
Parameters:
automatic - Specifies which of the two resize modes to use.

setRowSelectable

public void setRowSelectable(boolean selectable)
Sets wether user is allowed to select a row or not. The table only allows one row to be selected at a time if rowselection is allowed.
Parameters:
selectable - Specifies wether rowselection is allowed or not.

setRowHeight

public void setRowHeight(int newHeight)
Sets the row height.
Parameters:
newHeight - The new row height.

setScrollViewport

public void setScrollViewport(java.awt.Dimension newViewport)
Sets the viewport of the scrollpane.

setSelectedRow

public void setSelectedRow(int row)
Sets the specified row in the JTable as selected. If an Exception is caught, no row is selected.
Parameters:
row - The row to be selected.

setToolTipText

public void setToolTipText(java.lang.String tooltip)
Sets the ToolTipText of the table.
Overrides:
setToolTipText in class javax.swing.JComponent
Parameters:
tooltip - The table's tooltiptext.

dbg

private void dbg(java.lang.String dbg)
Adds a new debug-string to the DebugView with the classname as prefix.
Parameters:
dbg - The debug-string to be added.