net.xoetrope.awt
Class XTableRenderer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by net.xoetrope.awt.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, javax.accessibility.Accessible

public class XTableRenderer
extends java.awt.Canvas
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.3 $

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
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 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()
          Calculate 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)
          Key event handler or the key press event
 void keyReleased(java.awt.event.KeyEvent e)
          Key event handler or the key released event
 void keyTyped(java.awt.event.KeyEvent e)
          Key event handler or the key typed event
 void mouseClicked(java.awt.event.MouseEvent e)
          Handles the mouse click by changeing the selected row.
 void mouseEntered(java.awt.event.MouseEvent e)
          Mouse event handler for mouse enter event
 void mouseExited(java.awt.event.MouseEvent e)
          Mouse event handler for mouse exit event
 void mousePressed(java.awt.event.MouseEvent e)
          Mouse event handler for mouse pressed event
 void mouseReleased(java.awt.event.MouseEvent e)
          Mouse event handler for mouse released event
 void paint(java.awt.Graphics g)
          Initialise the currentY coordinate and call the render function with the Graphics object.
 void removeCurrentComponent()
          Remove the current component
 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 the 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 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 the display
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
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 container/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:
col - the field index
compName - the component name

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 the style for the border

Parameters:
styleName - the 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.

paint

public void paint(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:
paint in class java.awt.Canvas
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)
Mouse event handler for mouse enter event

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

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Mouse event handler for mouse exit event

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

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Mouse event handler for mouse pressed event

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

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Mouse event handler for mouse released event

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

removeCurrentComponent

public void removeCurrentComponent()
Remove the current component


keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Key event handler or the key press event

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

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Key event handler or the key typed event

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

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Key event handler or the key released event

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

update

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

Overrides:
update in class java.awt.Canvas
Parameters:
g - the graphics context

calcSize

public java.awt.Dimension calcSize()
Calculate 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 table size

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(java.awt.event.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/row
See Also:
ItemSelectable