Class JXTableHeader.HeaderListener

java.lang.Object
org.jdesktop.swingx.JXTableHeader.HeaderListener
All Implemented Interfaces:
MouseListener, MouseMotionListener, Serializable, EventListener, MouseInputListener
Enclosing class:
JXTableHeader

private class JXTableHeader.HeaderListener extends Object implements MouseInputListener, Serializable
A MouseListener implementation to support enhanced tableHeader functionality. Supports column "packing" by double click in resize region. Works around core issue #6862170 (must not sort column by click into resize region).

Note that the logic is critical, mostly because it must be independent of sequence of listener notification. So we check whether or not a pressed happens in the resizing region in both pressed and released, taking the header's resizingColumn property as a marker. The inResize flag can only be turned on in those. At the end of the released, we check if we are in resize and disable core sorting - which happens in clicked - if appropriate. In our clicked we hook the pack action (happens only on double click) and reset the resizing region flag always. Pressed (and all other methods) restore sorting enablement.

Supports resort on double click if enabled in the JXTableHeader (Issue #271-swingx). Is fully effective only if JXTable has control over the row sorter, that is if the row sorter is of type SortController.

  • Field Details

    • cachedResizingColumn

      private TableColumn cachedResizingColumn
    • cachedSortOrderCycle

      private SortOrder[] cachedSortOrderCycle
    • sortColumn

      private int sortColumn
  • Constructor Details

    • HeaderListener

      private HeaderListener()
  • Method Details

    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Packs column on double click in resize region. Resorts column on double click if enabled and not in resize region.
      Specified by:
      mouseClicked in interface MouseListener
    • doDoubleSort

      private void doDoubleSort(MouseEvent e)
    • hasCachedSortColumn

      private boolean hasCachedSortColumn()
    • mousePressed

      public void mousePressed(MouseEvent e)
      Resets sort enablement always, set resizing marker if available.
      Specified by:
      mousePressed in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Sets resizing marker if available, disables table sorting if in resize region and sort gesture (aka: single click).
      Specified by:
      mouseReleased in interface MouseListener
    • cacheSortColumn

      private void cacheSortColumn(MouseEvent e)
    • uncacheSortColumn

      private void uncacheSortColumn()
    • canCacheSortColumn

      private boolean canCacheSortColumn(MouseEvent e)
    • shouldIgnore

      private boolean shouldIgnore(MouseEvent e)
      Returns a boolean indication if the mouse event should be ignored. Here: returns true if table not enabled or not an event from the left mouse button.
      Parameters:
      e -
      Returns:
    • doResize

      private void doResize(MouseEvent e)
      Packs caches resizing column on double click, if available. Does nothing otherwise.
      Parameters:
      e -
    • disableToggleSortOrder

      private void disableToggleSortOrder(MouseEvent e)
      Parameters:
      e -
    • hasSortController

      private boolean hasSortController()
      Returns:
    • resetToggleSortOrder

      private void resetToggleSortOrder(MouseEvent e)
    • cacheResizingColumn

      private void cacheResizingColumn(MouseEvent e)
      Caches the resizing column if set. Does nothing if null.
      Parameters:
      e -
    • uncacheResizingColumn

      private void uncacheResizingColumn()
      Sets the cached resizing column to null.
    • isInResizeRegion

      private boolean isInResizeRegion(MouseEvent e)
      Returns true if the mouseEvent happened in the resizing region.
      Parameters:
      e -
      Returns:
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Resets all cached state.
      Specified by:
      mouseExited in interface MouseListener
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Resets all cached state.
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Resets all cached state.
      Specified by:
      mouseMoved in interface MouseMotionListener