Drop shadows: support enabling/disabling drop shadows per component (issue #94)

This commit is contained in:
Karl Tauber
2020-05-14 11:39:09 +02:00
parent ace07cd9cb
commit bf0ffc6ac2
2 changed files with 31 additions and 1 deletions

View File

@@ -103,6 +103,15 @@ public interface FlatClientProperties
*/ */
String MINIMUM_HEIGHT = "JComponent.minimumHeight"; String MINIMUM_HEIGHT = "JComponent.minimumHeight";
/**
* Specifies whether a drop shadow is painted if the component is shown in a popup
* or if the component is the owner of another component that is shown in a popup.
* <p>
* <strong>Component</strong> {@link javax.swing.JComponent}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*/
String POPUP_DROP_SHADOW_PAINTED = "Popup.dropShadowPainted";
/** /**
* Specifies whether the progress bar has always the larger height even if no string is painted. * Specifies whether the progress bar has always the larger height even if no string is painted.
* <p> * <p>

View File

@@ -31,6 +31,7 @@ import javax.swing.PopupFactory;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.Border; import javax.swing.border.Border;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
/** /**
@@ -50,7 +51,7 @@ public class FlatPopupFactory
public Popup getPopup( Component owner, Component contents, int x, int y ) public Popup getPopup( Component owner, Component contents, int x, int y )
throws IllegalArgumentException throws IllegalArgumentException
{ {
if( !UIManager.getBoolean( "Popup.dropShadowPainted" ) ) if( !isDropShadowPainted( owner, contents ) )
return super.getPopup( owner, contents, x, y ); return super.getPopup( owner, contents, x, y );
// macOS and Linux adds drop shadow to heavy weight popups // macOS and Linux adds drop shadow to heavy weight popups
@@ -70,6 +71,26 @@ public class FlatPopupFactory
return new DropShadowPopup( popup, owner, contents ); return new DropShadowPopup( popup, owner, contents );
} }
private boolean isDropShadowPainted( Component owner, Component contents ) {
Boolean b = isDropShadowPainted( owner );
if( b != null )
return b;
b = isDropShadowPainted( contents );
if( b != null )
return b;
return UIManager.getBoolean( "Popup.dropShadowPainted" );
}
private Boolean isDropShadowPainted( Component c ) {
if( !(c instanceof JComponent) )
return null;
Object value = ((JComponent)c).getClientProperty( FlatClientProperties.POPUP_DROP_SHADOW_PAINTED );
return (value instanceof Boolean ) ? (Boolean) value : null;
}
/** /**
* There is no API in Java 8 to force creation of heavy weight popups, * There is no API in Java 8 to force creation of heavy weight popups,
* but it is possible with reflection. Java 9 provides a new method. * but it is possible with reflection. Java 9 provides a new method.