Skip to content

Commit

Permalink
Table
Browse files Browse the repository at this point in the history
- WebTableHeader.java, TableHeaderPainter.java - Added `tooltipProvider` client property support [ #202 #471 ]
- WebTable.java - Added a small note on the header tooltip provider option
  • Loading branch information
mgarin committed Sep 23, 2019
1 parent 66e3c66 commit cf98a71
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 7 deletions.
33 changes: 27 additions & 6 deletions modules/ui/src/com/alee/laf/table/TableHeaderPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,18 @@ private void updateRolloverCell ( final TableHeaderCellArea oldCell, final Table
rolloverCell = newCell;

// Updating custom WebLaF tooltip display state
final TableHeaderToolTipProvider provider = getToolTipProvider ();
if ( provider != null )
final TableHeaderToolTipProvider tableProvider = getTableToolTipProvider ();
if ( tableProvider != null )
{
provider.hoverAreaChanged ( component, oldCell, newCell );
tableProvider.hoverAreaChanged ( component, oldCell, newCell );
}
else
{
final TableHeaderToolTipProvider headerProvider = getHeaderToolTipProvider ();
if ( headerProvider != null )
{
headerProvider.hoverAreaChanged ( component, oldCell, newCell );
}
}
}
};
Expand All @@ -179,18 +187,31 @@ protected void uninstallTableMouseListeners ()
}

/**
* Returns {@link TableHeaderToolTipProvider} for {@link JTableHeader} that uses this {@link TableHeaderPainter}.
* Returns {@link TableHeaderToolTipProvider} for {@link JTable} that uses {@link JTableHeader}.
*
* @return {@link TableHeaderToolTipProvider} for {@link JTableHeader} that uses this {@link TableHeaderPainter}
* @return {@link TableHeaderToolTipProvider} for {@link JTable} that uses {@link JTableHeader}
*/
@Nullable
protected TableHeaderToolTipProvider getToolTipProvider ()
protected TableHeaderToolTipProvider getTableToolTipProvider ()
{
return component != null && component.getTable () != null ?
( TableHeaderToolTipProvider ) component.getTable ().getClientProperty ( WebTable.HEADER_TOOLTIP_PROVIDER_PROPERTY ) :
null;
}

/**
* Returns {@link TableHeaderToolTipProvider} for {@link JTableHeader} that uses this {@link TableHeaderPainter}.
*
* @return {@link TableHeaderToolTipProvider} for {@link JTableHeader} that uses this {@link TableHeaderPainter}
*/
@Nullable
protected TableHeaderToolTipProvider getHeaderToolTipProvider ()
{
return component != null ?
( TableHeaderToolTipProvider ) component.getClientProperty ( WebTableHeader.TOOLTIP_PROVIDER_PROPERTY ) :
null;
}

/**
* Installs language listeners.
*/
Expand Down
2 changes: 2 additions & 0 deletions modules/ui/src/com/alee/laf/table/WebTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ public TableHeaderToolTipProvider getHeaderToolTipProvider ()

/**
* Sets header {@link TableHeaderToolTipProvider}.
* You can also set this provider directly into {@link JTableHeader}, but this one will always be prioritized.
* This method is added for convenience as {@link JTableHeader} might be replaced.
*
* @param provider header {@link TableHeaderToolTipProvider}
*/
Expand Down
28 changes: 27 additions & 1 deletion modules/ui/src/com/alee/laf/table/WebTableHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.alee.api.annotations.Nullable;
import com.alee.managers.hotkey.HotkeyData;
import com.alee.managers.language.*;
import com.alee.managers.language.LanguageUpdater;
import com.alee.managers.settings.Configuration;
import com.alee.managers.settings.SettingsMethods;
import com.alee.managers.settings.SettingsProcessor;
Expand Down Expand Up @@ -54,6 +53,13 @@
public class WebTableHeader extends JTableHeader implements Styleable, Paintable, ShapeMethods, MarginMethods, PaddingMethods,
EventMethods, LanguageMethods, LanguageEventMethods, SettingsMethods, FontMethods<WebTableHeader>, SizeMethods<WebTableHeader>
{
/**
* Client properties used for backward compatibility with Swing {@link JTableHeader}.
*
* @see TableHeaderToolTipProvider
*/
public static final String TOOLTIP_PROVIDER_PROPERTY = "tooltipProvider";

/**
* Constructs a {@code JTableHeader} with a default {@code TableColumnModel}.
*
Expand Down Expand Up @@ -108,6 +114,26 @@ public StyleId getDefaultStyleId ()
return StyleId.tableheader;
}

/**
* Returns {@link TableHeaderToolTipProvider}.
*
* @return {@link TableHeaderToolTipProvider}
*/
public TableHeaderToolTipProvider getToolTipProvider ()
{
return ( TableHeaderToolTipProvider ) getClientProperty ( TOOLTIP_PROVIDER_PROPERTY );
}

/**
* Sets {@link TableHeaderToolTipProvider}.
*
* @param provider {@link TableHeaderToolTipProvider}
*/
public void setToolTipProvider ( final TableHeaderToolTipProvider provider )
{
putClientProperty ( TOOLTIP_PROVIDER_PROPERTY, provider );
}

@NotNull
@Override
public StyleId getStyleId ()
Expand Down

0 comments on commit cf98a71

Please sign in to comment.