com.dlsc.flexgantt.swing.treetable

## Class CellFocusManager

- java.lang.Object
- - com.dlsc.flexgantt.swing.treetable.CellFocusManager

- All Implemented Interfaces:
    MouseListener, PropertyChangeListener, EventListener

      public class CellFocusManager
      extends Object
      implements MouseListener, PropertyChangeListener

  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 occur 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
  Version:
    $Revision: 1.4 $
  Author:
    Dirk Lemmermann

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CellFocusManager(TreeTable table)` Constructs a new focus manager.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `focusOnCell(int row, int col)` Sets the cell focus on the specified cell.
    `void` | `focusOnCell(int row, TreeTableColumn column)` 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` | `focusOnFirstVisibleCell()` Changes the focus to the first visible cell (in the first visible row) of the same column.
    `void` | `focusOnLastCell()` Sets the cell focus on the last cell.
    `void` | `focusOnPageDown()` Changes the focus in such a way that the tree table will scroll down one page.
    `void` | `focusOnPageUp()` Changes the focus in such a way that the tree table will scroll up one page.
    `TreeTableColumn` | `getFocusedColumn()` Returns the tree table column that contains the focused cell.
    `int` | `getFocusedColumnIndex()` Returns the column of the currently focused cell.
    `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` | `looseFocus()` Forces the tree table to loose the cell focus.
    `void` | `mouseClicked(MouseEvent e)`
    `void` | `mouseEntered(MouseEvent e)`
    `void` | `mouseExited(MouseEvent e)`
    `void` | `mousePressed(MouseEvent e)`
    `void` | `mouseReleased(MouseEvent e)`
    `void` | `propertyChange(PropertyChangeEvent evt)`
    `void` | `setFocusedColumn(TreeTableColumn column)` Sets the tree table column that contains the focused cell and updates the tree table.
    `void` | `setFocusedPath(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.

    - ### 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

    - #### focusOnCell

          public void focusOnCell(int row,
                                  TreeTableColumn column)

      Sets the cell focus on the specified cell.
      Parameters:
        `row` - the row where the cell is located
        `column` - the column where the cell is located
      Since:
        1.1

    - #### 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

    - #### focusOnPageUp

          public void focusOnPageUp()

      Changes the focus in such a way that the tree table will scroll up one page.
      Since:
        1.1

    - #### focusOnPageDown

          public void focusOnPageDown()

      Changes the focus in such a way that the tree table will scroll down one page.
      Since:
        1.1

    - #### focusOnFirstVisibleCell

          public void focusOnFirstVisibleCell()

      Changes the focus to the first visible cell (in the first visible row) of the same column.
      Since:
        1.1

    - #### 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 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(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

    - #### 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`

    - #### propertyChange

          public void propertyChange(PropertyChangeEvent evt)

      Specified by:
        `propertyChange` in interface `PropertyChangeListener`

Copyright © 2006–2020 Dirk Lemmermann Software & Consulting. All rights reserved.