Class JXTableHeader.HeaderListener
- java.lang.Object
-
- org.jdesktop.swingx.JXTableHeader.HeaderListener
-
- All Implemented Interfaces:
java.awt.event.MouseListener
,java.awt.event.MouseMotionListener
,java.io.Serializable
,java.util.EventListener
,javax.swing.event.MouseInputListener
- Enclosing class:
- JXTableHeader
private class JXTableHeader.HeaderListener extends java.lang.Object implements javax.swing.event.MouseInputListener, java.io.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 Summary
Fields Modifier and Type Field Description private javax.swing.table.TableColumn
cachedResizingColumn
private javax.swing.SortOrder[]
cachedSortOrderCycle
private int
sortColumn
-
Constructor Summary
Constructors Modifier Constructor Description private
HeaderListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
cacheResizingColumn(java.awt.event.MouseEvent e)
Caches the resizing column if set.private void
cacheSortColumn(java.awt.event.MouseEvent e)
private boolean
canCacheSortColumn(java.awt.event.MouseEvent e)
private void
disableToggleSortOrder(java.awt.event.MouseEvent e)
private void
doDoubleSort(java.awt.event.MouseEvent e)
private void
doResize(java.awt.event.MouseEvent e)
Packs caches resizing column on double click, if available.private boolean
hasCachedSortColumn()
private boolean
hasSortController()
private boolean
isInResizeRegion(java.awt.event.MouseEvent e)
Returns true if the mouseEvent happened in the resizing region.void
mouseClicked(java.awt.event.MouseEvent e)
Packs column on double click in resize region.void
mouseDragged(java.awt.event.MouseEvent e)
Resets all cached state.void
mouseEntered(java.awt.event.MouseEvent e)
void
mouseExited(java.awt.event.MouseEvent e)
Resets all cached state.void
mouseMoved(java.awt.event.MouseEvent e)
Resets all cached state.void
mousePressed(java.awt.event.MouseEvent e)
Resets sort enablement always, set resizing marker if available.void
mouseReleased(java.awt.event.MouseEvent e)
Sets resizing marker if available, disables table sorting if in resize region and sort gesture (aka: single click).private void
resetToggleSortOrder(java.awt.event.MouseEvent e)
private boolean
shouldIgnore(java.awt.event.MouseEvent e)
Returns a boolean indication if the mouse event should be ignored.private void
uncacheResizingColumn()
Sets the cached resizing column to null.private void
uncacheSortColumn()
-
-
-
Method Detail
-
mouseClicked
public void mouseClicked(java.awt.event.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 interfacejava.awt.event.MouseListener
-
doDoubleSort
private void doDoubleSort(java.awt.event.MouseEvent e)
-
hasCachedSortColumn
private boolean hasCachedSortColumn()
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)
Resets sort enablement always, set resizing marker if available.- Specified by:
mousePressed
in interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)
Sets resizing marker if available, disables table sorting if in resize region and sort gesture (aka: single click).- Specified by:
mouseReleased
in interfacejava.awt.event.MouseListener
-
cacheSortColumn
private void cacheSortColumn(java.awt.event.MouseEvent e)
-
uncacheSortColumn
private void uncacheSortColumn()
-
canCacheSortColumn
private boolean canCacheSortColumn(java.awt.event.MouseEvent e)
-
shouldIgnore
private boolean shouldIgnore(java.awt.event.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(java.awt.event.MouseEvent e)
Packs caches resizing column on double click, if available. Does nothing otherwise.- Parameters:
e
-
-
disableToggleSortOrder
private void disableToggleSortOrder(java.awt.event.MouseEvent e)
- Parameters:
e
-
-
hasSortController
private boolean hasSortController()
- Returns:
-
resetToggleSortOrder
private void resetToggleSortOrder(java.awt.event.MouseEvent e)
-
cacheResizingColumn
private void cacheResizingColumn(java.awt.event.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(java.awt.event.MouseEvent e)
Returns true if the mouseEvent happened in the resizing region.- Parameters:
e
-- Returns:
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)
- Specified by:
mouseEntered
in interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)
Resets all cached state.- Specified by:
mouseExited
in interfacejava.awt.event.MouseListener
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent e)
Resets all cached state.- Specified by:
mouseDragged
in interfacejava.awt.event.MouseMotionListener
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent e)
Resets all cached state.- Specified by:
mouseMoved
in interfacejava.awt.event.MouseMotionListener
-
-