mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
Window decorations: allow enabling/disabling custom window decorations via system properties "flatlaf.useWindowDecorations", "flatlaf.useJetBrainsCustomDecorations" and "flatlaf.menuBarEmbedded" (all boolean)
This commit is contained in:
@@ -88,6 +88,9 @@ public abstract class FlatLaf
|
||||
|
||||
private Consumer<UIDefaults> postInitialization;
|
||||
|
||||
private Boolean oldFrameWindowDecorated;
|
||||
private Boolean oldDialogWindowDecorated;
|
||||
|
||||
public static boolean install( LookAndFeel newLookAndFeel ) {
|
||||
try {
|
||||
UIManager.setLookAndFeel( newLookAndFeel );
|
||||
@@ -242,6 +245,16 @@ public abstract class FlatLaf
|
||||
String.format( "a { color: #%06x; }", linkColor.getRGB() & 0xffffff ) );
|
||||
}
|
||||
};
|
||||
|
||||
// enable/disable window decorations, but only if system property is either
|
||||
// "true" or "false"; in other cases it is not changed
|
||||
Boolean useWindowDecorations = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null );
|
||||
if( useWindowDecorations != null ) {
|
||||
oldFrameWindowDecorated = JFrame.isDefaultLookAndFeelDecorated();
|
||||
oldDialogWindowDecorated = JDialog.isDefaultLookAndFeelDecorated();
|
||||
JFrame.setDefaultLookAndFeelDecorated( useWindowDecorations );
|
||||
JDialog.setDefaultLookAndFeelDecorated( useWindowDecorations );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -274,6 +287,14 @@ public abstract class FlatLaf
|
||||
new HTMLEditorKit().getStyleSheet().addRule( "a { color: blue; }" );
|
||||
postInitialization = null;
|
||||
|
||||
// restore enable/disable window decorations
|
||||
if( oldFrameWindowDecorated != null ) {
|
||||
JFrame.setDefaultLookAndFeelDecorated( oldFrameWindowDecorated );
|
||||
JDialog.setDefaultLookAndFeelDecorated( oldDialogWindowDecorated );
|
||||
oldFrameWindowDecorated = null;
|
||||
oldDialogWindowDecorated = null;
|
||||
}
|
||||
|
||||
super.uninitialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.formdev.flatlaf;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* Defines/documents own system properties used in FlatLaf.
|
||||
*
|
||||
@@ -46,6 +49,41 @@ public interface FlatSystemProperties
|
||||
*/
|
||||
String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont";
|
||||
|
||||
/**
|
||||
* Specifies whether custom look and feel window decorations should be used
|
||||
* when creating {@code JFrame} or {@code JDialog}.
|
||||
* <p>
|
||||
* If this system property is set, FlatLaf invokes {@link JFrame#setDefaultLookAndFeelDecorated(boolean)}
|
||||
* and {@link JDialog#setDefaultLookAndFeelDecorated(boolean)} on LaF initialization.
|
||||
* <p>
|
||||
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||
* <strong>Default</strong> none
|
||||
*/
|
||||
String USE_WINDOW_DECORATIONS = "flatlaf.useWindowDecorations";
|
||||
|
||||
/**
|
||||
* Specifies whether JetBrains Runtime custom window decorations should be used
|
||||
* when creating {@code JFrame} or {@code JDialog}.
|
||||
* Requires that the application runs in a
|
||||
* <a href="https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime">JetBrains Runtime</a>
|
||||
* (based on OpenJDK).
|
||||
* <p>
|
||||
* Setting this to {@code true} forces using JetBrains Runtime custom window decorations
|
||||
* even if they are not enabled by the application.
|
||||
* <p>
|
||||
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||
* <strong>Default</strong> {@code true}
|
||||
*/
|
||||
String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations";
|
||||
|
||||
/**
|
||||
* Specifies whether menubar is embedded into custom window decorations.
|
||||
* <p>
|
||||
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
|
||||
* <strong>Default</strong> {@code true}
|
||||
*/
|
||||
String MENUBAR_EMBEDDED = "flatlaf.menuBarEmbedded";
|
||||
|
||||
/**
|
||||
* Specifies whether vertical text position is corrected when UI is scaled on HiDPI screens.
|
||||
* <p>
|
||||
@@ -63,4 +101,18 @@ public interface FlatSystemProperties
|
||||
String value = System.getProperty( key );
|
||||
return (value != null) ? Boolean.parseBoolean( value ) : defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a system property is set and returns {@code Boolean.TRUE} if its value
|
||||
* is {@code "true"} (case-insensitive) or returns {@code Boolean.FALSE} if its value
|
||||
* is {@code "false"} (case-insensitive). Otherwise {@code defaultValue} is returned.
|
||||
*/
|
||||
static Boolean getBooleanStrict( String key, Boolean defaultValue ) {
|
||||
String value = System.getProperty( key );
|
||||
if( "true".equalsIgnoreCase( value ) )
|
||||
return Boolean.TRUE;
|
||||
if( "false".equalsIgnoreCase( value ) )
|
||||
return Boolean.FALSE;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ import javax.swing.UIManager;
|
||||
import javax.swing.border.AbstractBorder;
|
||||
import javax.swing.border.Border;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.FlatSystemProperties;
|
||||
import com.formdev.flatlaf.ui.JBRCustomDecorations.JBRWindowTopBorder;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
@@ -320,8 +321,9 @@ class FlatTitlePane
|
||||
}
|
||||
|
||||
boolean isMenuBarEmbedded() {
|
||||
return menuBarEmbedded && FlatClientProperties.clientPropertyBoolean(
|
||||
rootPane, FlatClientProperties.MENU_BAR_EMBEDDED, true );
|
||||
return menuBarEmbedded &&
|
||||
FlatClientProperties.clientPropertyBoolean( rootPane, FlatClientProperties.MENU_BAR_EMBEDDED, true ) &&
|
||||
FlatSystemProperties.getBoolean( FlatSystemProperties.MENUBAR_EMBEDDED, true );
|
||||
}
|
||||
|
||||
Rectangle getMenuBarBounds() {
|
||||
@@ -376,7 +378,7 @@ class FlatTitlePane
|
||||
// (if not running in JBR and if not modified from the application)
|
||||
if( !hasJBRCustomDecoration() &&
|
||||
(frame.getMaximizedBounds() == null ||
|
||||
Objects.equals( frame.getMaximizedBounds(), rootPane.getClientProperty( "flatlaf.maximizedBounds" ) )) )
|
||||
Objects.equals( frame.getMaximizedBounds(), rootPane.getClientProperty( "_flatlaf.maximizedBounds" ) )) )
|
||||
{
|
||||
GraphicsConfiguration gc = window.getGraphicsConfiguration();
|
||||
|
||||
@@ -428,7 +430,7 @@ class FlatTitlePane
|
||||
|
||||
// remember maximized bounds in client property to be able to detect
|
||||
// whether maximized bounds are modified from the application
|
||||
rootPane.putClientProperty( "flatlaf.maximizedBounds", maximizedBounds );
|
||||
rootPane.putClientProperty( "_flatlaf.maximizedBounds", maximizedBounds );
|
||||
}
|
||||
|
||||
// maximize window
|
||||
|
||||
@@ -39,6 +39,7 @@ import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.BorderUIResource;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import com.formdev.flatlaf.FlatSystemProperties;
|
||||
import com.formdev.flatlaf.util.HiDPIUtils;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
|
||||
@@ -111,8 +112,10 @@ public class JBRCustomDecorations
|
||||
JFrame frame = (JFrame) window;
|
||||
|
||||
// do not enable JBR decorations if JFrame should use system window decorations
|
||||
if( !JFrame.isDefaultLookAndFeelDecorated() )
|
||||
return;
|
||||
// and if not forced to use JBR decorations
|
||||
if( !JFrame.isDefaultLookAndFeelDecorated() &&
|
||||
!FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, false ))
|
||||
return;
|
||||
|
||||
// do not enable JBR decorations if frame is undecorated
|
||||
if( frame.isUndecorated() )
|
||||
@@ -128,8 +131,10 @@ public class JBRCustomDecorations
|
||||
JDialog dialog = (JDialog) window;
|
||||
|
||||
// do not enable JBR decorations if JDialog should use system window decorations
|
||||
if( !JDialog.isDefaultLookAndFeelDecorated() )
|
||||
return;
|
||||
// and if not forced to use JBR decorations
|
||||
if( !JDialog.isDefaultLookAndFeelDecorated() &&
|
||||
!FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, false ))
|
||||
return;
|
||||
|
||||
// do not enable JBR decorations if dialog is undecorated
|
||||
if( dialog.isUndecorated() )
|
||||
@@ -189,6 +194,9 @@ public class JBRCustomDecorations
|
||||
if( !SystemInfo.IS_JETBRAINS_JVM_11_OR_LATER || !SystemInfo.IS_WINDOWS_10_OR_LATER )
|
||||
return;
|
||||
|
||||
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ) )
|
||||
return;
|
||||
|
||||
try {
|
||||
Class<?> awtAcessorClass = Class.forName( "sun.awt.AWTAccessor" );
|
||||
Class<?> compAccessorClass = Class.forName( "sun.awt.AWTAccessor$ComponentAccessor" );
|
||||
|
||||
Reference in New Issue
Block a user