net.xoetrope.deprecated.swing
Class XTableRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by net.xoetrope.deprecated.swing.XTableRenderer
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class XTableRenderer
extends javax.swing.JComponent
implements java.awt.event.MouseListener, java.awt.event.KeyListener, java.awt.ItemSelectable

Provides a simple read-only tables/grid component.

Copyright (c) Xoetrope Ltd., 1998-2004
License: see license.txt $Revision: 2.5 $

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
XTableRenderer(XTable parent)
          Create a new table renderer
 
Method Summary
 void addItemListener(java.awt.event.ItemListener l)
          Adds the specified item listener to receive item events from this list.
 java.awt.Dimension calcSize()
          Calcualte the size of the content.
 int getCurrentRow()
          Gets the index in the model of the currently selected row.
 int getFirstRow()
          Gets the offset in the model of the first row of data.
 java.lang.Object[] getSelectedObjects()
          Returns the selected items on the list in an array of objects.
 int getSelectedRow()
          Get the index of the selected row
 boolean isInteractiveTable()
          Check the if the table is interactive
 void keyPressed(java.awt.event.KeyEvent e)
          Event fired on a key event, changes the selection
 void keyReleased(java.awt.event.KeyEvent e)
          Event fired on a key event, changes the selection
 void keyTyped(java.awt.event.KeyEvent e)
          Event fired on a key event, changes the selection
 void mouseClicked(java.awt.event.MouseEvent e)
          Handles the mouse click by changeing the selected row.
 void mouseEntered(java.awt.event.MouseEvent e)
          Unused
 void mouseExited(java.awt.event.MouseEvent e)
          Unused
 void mousePressed(java.awt.event.MouseEvent e)
          Unused
 void mouseReleased(java.awt.event.MouseEvent e)
          Event fired when the mouse is released
 void paintComponent(java.awt.Graphics g)
          Initialise the currentY coordinate and call the render function with the Graphics object.
 void removeItemListener(java.awt.event.ItemListener l)
          Removes the specified item listener so that it no longer receives item events from this list.
 void setBorderStyle(java.lang.String styleName)
          Set teh style for the border
 void setColWidth(int fieldIdx, int w)
          Set the table column width.
 void setComponentAt(int col, java.lang.String compName)
          Set the type of component for a column
 void setContent(XModel xmodel)
          Set the XModel which we will be generating the table from
 void setFont(java.awt.Font f)
           
 void setHeaderStyle(java.lang.String style)
          Set the style of the header data
 void setInteractiveTable(boolean state)
          Set the user interaction state
 void setSelectedRow(int idx)
          Sets the indexof the selected row
 void setSelectedStyle(java.lang.String style)
          Set the style of the selected row
 void setStyle(java.lang.String style)
          Set the general style of the XTable
 void setUpdateModelSelection(boolean doUpdate)
          Tie the model selection to this table's selection
 void update(java.awt.Graphics g)
          Update teh display
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, 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, removeAll, 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
 

Constructor Detail

XTableRenderer

public XTableRenderer(XTable parent)
Create a new table renderer

Parameters:
parent - the parent/owner table
Method Detail

setContent

public void setContent(XModel xmodel)
Set the XModel which we will be generating the table from

Parameters:
xmodel - The XModel of data

setComponentAt

public void setComponentAt(int col,
                           java.lang.String compName)
Set the type of component for a column

Parameters:
compName - the owner component name
col - the field index

setStyle

public void setStyle(java.lang.String style)
Set the general style of the XTable

Parameters:
style - XStyle

setHeaderStyle

public void setHeaderStyle(java.lang.String style)
Set the style of the header data

Parameters:
style - XStyle

setSelectedStyle

public void setSelectedStyle(java.lang.String style)
Set the style of the selected row

Parameters:
style - XStyle

setBorderStyle

public void setBorderStyle(java.lang.String styleName)
Set teh style for the border

Parameters:
styleName - the border style name

isInteractiveTable

public boolean isInteractiveTable()
Check the if the table is interactive

Returns:
true if the table supports user interaction

setInteractiveTable

public void setInteractiveTable(boolean state)
Set the user interaction state

Parameters:
state - true for an user interactive table.

paintComponent

public void paintComponent(java.awt.Graphics g)
Initialise the currentY coordinate and call the render function with the Graphics object. When finished draw a line around the XTable.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the graphics context

setSelectedRow

public void setSelectedRow(int idx)
Sets the indexof the selected row

Parameters:
idx - the new selected row

getSelectedRow

public int getSelectedRow()
Get the index of the selected row

Returns:
the index of the selected row

setUpdateModelSelection

public void setUpdateModelSelection(boolean doUpdate)
Tie the model selection to this table's selection

Parameters:
doUpdate - true to tie the selections together, false to ignore

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Handles the mouse click by changeing the selected row.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the mouse event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Unused

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the mouse event

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Unused

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the mouse event

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Unused

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the mouse event

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Event fired when the mouse is released

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the mouse event

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Event fired on a key event, changes the selection

Specified by:
keyPressed in interface java.awt.event.KeyListener
Parameters:
e - the key event

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Event fired on a key event, changes the selection

Specified by:
keyTyped in interface java.awt.event.KeyListener
Parameters:
e - the key event

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Event fired on a key event, changes the selection

Specified by:
keyReleased in interface java.awt.event.KeyListener
Parameters:
e - the key event

update

public void update(java.awt.Graphics g)
Update teh display

Overrides:
update in class javax.swing.JComponent
Parameters:
g - The graphics context

calcSize

public java.awt.Dimension calcSize()
Calcualte the size of the content. This method is called from within the paint method and recalculates the required size for display of the content. If a scrollpane is the parent then this control is resized so that all the content will be visible. The scrollpane may initially have no scrollbar so to avoid flicker and multiple repaints as the control is sized and offscreen graphics context is used for the sizing.

Returns:
The display size

setFont

public void setFont(java.awt.Font f)
Overrides:
setFont in class javax.swing.JComponent

setColWidth

public void setColWidth(int fieldIdx,
                        int w)
Set the table column width.

Parameters:
fieldIdx - the field index
w - the new column width

getCurrentRow

public int getCurrentRow()
Gets the index in the model of the currently selected row.

Returns:
the row offset

getFirstRow

public int getFirstRow()
Gets the offset in the model of the first row of data. This takes account of how the table header is stored in the model. In the static data or XML representations the header is recorded with a row of elements, whereas when the data has originated in a database then a custom node type may be used instead.

Returns:
the row offset

addItemListener

public void addItemListener(java.awt.event.ItemListener l)
Adds the specified item listener to receive item events from this list. Item events are sent in response to user input, but not in response to calls to select or deselect. If listener l is null, no exception is thrown and no action is performed.

Specified by:
addItemListener in interface java.awt.ItemSelectable
Parameters:
l - the item listener
Since:
JDK1.1
See Also:
removeItemListener( ItemListener ), ItemEvent, ItemListener

removeItemListener

public void removeItemListener(java.awt.event.ItemListener l)
Removes the specified item listener so that it no longer receives item events from this list. If listener l is null, no exception is thrown and no action is performed.

Specified by:
removeItemListener in interface java.awt.ItemSelectable
Parameters:
l - the item listener
Since:
JDK1.1
See Also:
addItemListener( ItemListener ), ItemEvent, ItemListener

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Returns the selected items on the list in an array of objects.

Specified by:
getSelectedObjects in interface java.awt.ItemSelectable
Returns:
The selected object
See Also:
ItemSelectable