com.dlsc.flexgantt.swing.treetable
Class CellFocusManager

java.lang.Object
  extended by com.dlsc.flexgantt.swing.treetable.CellFocusManager
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.util.EventListener, javax.swing.event.TreeWillExpandListener

public class CellFocusManager
extends java.lang.Object
implements java.awt.event.KeyListener, java.awt.event.MouseListener, javax.swing.event.TreeWillExpandListener

The cell focus manager is concerned with anything related to tracking and changing the focus of tree table cells. The manager always knows which cell is currently focused on. It also knows which cell to focus on when the user wants to change the focus on the previous cell, the next cell, the cell above or below the currently focused cell. This manager class listens to mouse and keyboard events that occure on the table and reacts appropriately. Note: an instance of FocusTraversalPolicy could not be used for this task as it works on containers and components, but the cells of a tree table are not components.

Since:
1.0
Author:
Dirk Lemmermann

Constructor Summary
CellFocusManager(TreeTable table)
          Constructs a new focus manager.
 
Method Summary
 void focusOnCell(int row, int col)
          Sets the cell focus on the specified cell.
 void focusOnCellAbove()
          Moves the focus to the cell above the currently focused cell.
 void focusOnCellBelow()
          Moves the focus to the cell below the currently focused cell.
 void focusOnCellNext()
          Changes the focus from one cell to the next cell.
 void focusOnCellPrevious()
          Changes the focus from one cell to the previous cell.
 void focusOnFirstCell()
          Sets the cell focus on the first cell.
 void focusOnLastCell()
          Sets the cell focus on the last cell.
 TreeTableColumn getFocusedColumn()
          Returns the tree table column that contains the focused cell.
 int getFocusedColumnIndex()
          Returns the column of the currently focused cell.
 javax.swing.tree.TreePath getFocusedPath()
          Returns the tree path of the focused cell.
 int getFocusedRow()
          Returns the row of the currently focused cell.
 TreeTable getTreeTable()
          Returns the tree table to which the cell focus manager belongs.
 boolean hasFocus()
          Checks whether any cell is currently focused.
 boolean hasFocus(int row, int column)
          Checks whether the cell at the given row and column is currently focused.
 void keyPressed(java.awt.event.KeyEvent e)
           
 void keyReleased(java.awt.event.KeyEvent e)
           
 void keyTyped(java.awt.event.KeyEvent e)
           
 void looseFocus()
          Forces the tree table to loose the cell focus.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void setFocusedColumn(TreeTableColumn column)
          Sets the tree table column that contains the focused cell and updates the tree table.
 void setFocusedPath(javax.swing.tree.TreePath path)
          Sets the tree path of the focused cell and updates the tree table.
 void setFocusedRow(int row)
          Sets the row of the focused cell.
 void treeWillCollapse(javax.swing.event.TreeExpansionEvent event)
           
 void treeWillExpand(javax.swing.event.TreeExpansionEvent event)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CellFocusManager

public CellFocusManager(TreeTable table)
Constructs a new focus manager.

Parameters:
table - is the table which will be controlled by this manager. The manager attaches itself via a KeyListener and via a MouseListener.
Since:
1.0
Method Detail

getFocusedRow

public int getFocusedRow()
Returns the row of the currently focused cell.

Returns:
the focused cell's row index
Since:
1.0

getFocusedColumnIndex

public int getFocusedColumnIndex()
Returns the column of the currently focused cell.

Returns:
the focused cell's row index
Since:
1.0

hasFocus

public boolean hasFocus(int row,
                        int column)
Checks whether the cell at the given row and column is currently focused.

Parameters:
row - the cell's row
column - the cell's column
Returns:
TRUE if the specified cell is the focus owner
Since:
1.0

hasFocus

public boolean hasFocus()
Checks whether any cell is currently focused.

Returns:
TRUE if a cell within the tree table does have the focus
Since:
1.0

looseFocus

public void looseFocus()
Forces the tree table to loose the cell focus. The table keeps its focus state, but no cell will be focused.

Since:
1.0

focusOnCell

public void focusOnCell(int row,
                        int col)
Sets the cell focus on the specified cell.

Parameters:
row - the row where the cell is located
col - the column where the cell is located
Since:
1.0

focusOnFirstCell

public void focusOnFirstCell()
Sets the cell focus on the first cell. The first cell is the cell in the upper left corner of the table.

Since:
1.0

focusOnLastCell

public void focusOnLastCell()
Sets the cell focus on the last cell. The last cell is the cell in the lower right corner of the table.

Since:
1.0

focusOnCellNext

public void focusOnCellNext()
Changes the focus from one cell to the next cell. The next cell is usually the cell to the right of the currently focused cell. If the currently focused cell is in the last column of the tree table then the focus will move to the cell in the first column of the next row.

Since:
1.0

focusOnCellPrevious

public void focusOnCellPrevious()
Changes the focus from one cell to the previous cell. The previous cell is usually the cell to the left of the currently focused cell. If the currently focused cell is in the first column of the tree table then the focus will move to the cell in the last column of the previous row.

Since:
1.0

focusOnCellAbove

public void focusOnCellAbove()
Moves the focus to the cell above the currently focused cell.

Since:
1.0

focusOnCellBelow

public void focusOnCellBelow()
Moves the focus to the cell below the currently focused cell.

Since:
1.0

getFocusedColumn

public TreeTableColumn getFocusedColumn()
Returns the tree table column that contains the focused cell.

Returns:
the column of the focused cell
Since:
1.0

setFocusedColumn

public void setFocusedColumn(TreeTableColumn column)
Sets the tree table column that contains the focused cell and updates the tree table.

Parameters:
column - the column of the focused cell
Since:
1.0

getFocusedPath

public javax.swing.tree.TreePath getFocusedPath()
Returns the tree path of the focused cell.

Returns:
the tree path of the focused cell
Since:
1.0

setFocusedPath

public void setFocusedPath(javax.swing.tree.TreePath path)
Sets the tree path of the focused cell and updates the tree table.

Parameters:
path - the tree path of the focused cell
Since:
1.0

setFocusedRow

public void setFocusedRow(int row)
Sets the row of the focused cell. The row gets translated to a tree path and the method delegates to setFocusedPath(TreePath).

Parameters:
row - the row of the focused cell
Since:
1.0

getTreeTable

public TreeTable getTreeTable()
Returns the tree table to which the cell focus manager belongs.

Returns:
the focus manager's tree table
Since:
1.0

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Specified by:
keyReleased in interface java.awt.event.KeyListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

treeWillCollapse

public void treeWillCollapse(javax.swing.event.TreeExpansionEvent event)
Specified by:
treeWillCollapse in interface javax.swing.event.TreeWillExpandListener

treeWillExpand

public void treeWillExpand(javax.swing.event.TreeExpansionEvent event)
Specified by:
treeWillExpand in interface javax.swing.event.TreeWillExpandListener