Native window decorations:

- enabled by default (via UI property `TitlePane.useWindowDecorations`)
- dropped system property `flatlaf.useNativeWindowDecorations` and replaced with `flatlaf.useWindowDecorations`
- old functionality of system property `flatlaf.useWindowDecorations` removed
This commit is contained in:
Karl Tauber
2021-03-11 10:54:23 +01:00
parent f730848928
commit 73487ccf65
13 changed files with 28 additions and 78 deletions

View File

@@ -3,6 +3,13 @@ FlatLaf Change Log
## 1.1-SNAPSHOT
#### New features and improvements
- Native window decorations for Windows 10 enables dark frame/dialog title bar
and embedded menu bar with all JREs, while still having native Windows 10
border drop shadows, resize behavior, window snapping and system window menu.
(PR #267)
#### Fixed bugs
- IntelliJ Themes: Fixed text color of CheckBoxMenuItem and RadioButtonMenuItem

View File

@@ -46,7 +46,6 @@ import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JRootPane;
import javax.swing.LookAndFeel;
import javax.swing.PopupFactory;
import javax.swing.SwingUtilities;
@@ -92,9 +91,6 @@ public abstract class FlatLaf
private Consumer<UIDefaults> postInitialization;
private Boolean oldFrameWindowDecorated;
private Boolean oldDialogWindowDecorated;
/**
* Sets the application look and feel to the given LaF
* using {@link UIManager#setLookAndFeel(javax.swing.LookAndFeel)}.
@@ -146,35 +142,20 @@ public abstract class FlatLaf
* Returns whether FlatLaf supports custom window decorations.
* This depends on the operating system and on the used Java runtime.
* <p>
* To use custom window decorations in your application, enable them with
* following code (before creating any frames or dialogs).
* <pre>
* JFrame.setDefaultLookAndFeelDecorated( true );
* JDialog.setDefaultLookAndFeelDecorated( true );
* </pre>
* <p>
* Then custom window decorations are only enabled if this method returns {@code true}.
* In this case, when creating a {@link JFrame} or {@link JDialog}, the frame/dialog will be made
* undecorated ({@link JFrame#setUndecorated(boolean)} / {@link JDialog#setUndecorated(boolean)}),
* the window decoration style of the {@link JRootPane} will
* {@link JRootPane#FRAME} / {@link JRootPane#PLAIN_DIALOG}
* (see {@link JRootPane#setWindowDecorationStyle(int)}) and the look and feel
* is responsible for the whole frame/dialog border (including window resizing).
* <p>
* This method returns {@code true} on Windows 10 (see exception below), {@code false} otherwise.
* <p>
* Returns also {@code false} on Windows 10 if:
* <ul>
* <li>FlatLaf native window border support is available (requires Windows 10 64bit)</li>
* <li>FlatLaf native window border support is available (requires Windows 10 64-bit)</li>
* <li>running in
* <a href="https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime">JetBrains Runtime 11 (or later)</a>
* (<a href="https://github.com/JetBrains/JetBrainsRuntime">source code on github</a>)
* and JBR supports custom window decorations
* </li>
* </ul>
* In this case, custom decorations are enabled by the root pane
* if {@link JFrame#isDefaultLookAndFeelDecorated()} or
* {@link JDialog#isDefaultLookAndFeelDecorated()} return {@code true}.
* In this cases, custom decorations are enabled by the root pane.
* Usage of {@link JFrame#setDefaultLookAndFeelDecorated(boolean)} or
* {@link JDialog#setDefaultLookAndFeelDecorated(boolean)} is not necessary.
*/
@Override
public boolean getSupportsWindowDecorations() {
@@ -278,16 +259,6 @@ public abstract class FlatLaf
String.format( "a, address { 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
@@ -320,14 +291,6 @@ public abstract class FlatLaf
new HTMLEditorKit().getStyleSheet().addRule( "a, address { color: blue; }" );
postInitialization = null;
// restore enable/disable window decorations
if( oldFrameWindowDecorated != null ) {
JFrame.setDefaultLookAndFeelDecorated( oldFrameWindowDecorated );
JDialog.setDefaultLookAndFeelDecorated( oldDialogWindowDecorated );
oldFrameWindowDecorated = null;
oldDialogWindowDecorated = null;
}
super.uninitialize();
}

View File

@@ -16,9 +16,6 @@
package com.formdev.flatlaf;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
* Defines/documents own system properties used in FlatLaf.
*
@@ -57,20 +54,6 @@ 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>
* (requires Window 10)
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> none
*/
String USE_WINDOW_DECORATIONS = "flatlaf.useWindowDecorations";
/**
* Specifies whether FlatLaf native window decorations should be used
* when creating {@code JFrame} or {@code JDialog}.
@@ -80,14 +63,12 @@ public interface FlatSystemProperties
* <p>
* Setting this to {@code false} disables using FlatLaf native window decorations.
* <p>
* (requires Window 10 64bit)
* (requires Window 10 64-bit)
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> none
*
* @since 1.1
*/
String USE_NATIVE_WINDOW_DECORATIONS = "flatlaf.useNativeWindowDecorations";
String USE_WINDOW_DECORATIONS = "flatlaf.useWindowDecorations";
/**
* Specifies whether JetBrains Runtime custom window decorations should be used

View File

@@ -69,7 +69,7 @@ public class FlatNativeWindowBorder
// It could be also be a window that is currently hidden, but may be shown later.
Window window = SwingUtilities.windowForComponent( rootPane );
if( window != null && window.isDisplayable() ) {
install( window, FlatSystemProperties.USE_NATIVE_WINDOW_DECORATIONS );
install( window, FlatSystemProperties.USE_WINDOW_DECORATIONS );
return null;
}
@@ -79,7 +79,7 @@ public class FlatNativeWindowBorder
PropertyChangeListener ancestorListener = e -> {
Object newValue = e.getNewValue();
if( newValue instanceof Window )
install( (Window) newValue, FlatSystemProperties.USE_NATIVE_WINDOW_DECORATIONS );
install( (Window) newValue, FlatSystemProperties.USE_WINDOW_DECORATIONS );
else if( newValue == null && e.getOldValue() instanceof Window )
uninstall( (Window) e.getOldValue() );
};
@@ -101,7 +101,8 @@ public class FlatNativeWindowBorder
// do not enable native window border if JFrame should use system window decorations
// and if not forced to use FlatLaf/JBR native window decorations
if( !JFrame.isDefaultLookAndFeelDecorated() &&
!FlatSystemProperties.getBoolean( systemPropertyKey, false ))
!UIManager.getBoolean( "TitlePane.useWindowDecorations" ) &&
!FlatSystemProperties.getBoolean( systemPropertyKey, false ) )
return;
// do not enable native window border if frame is undecorated
@@ -120,7 +121,8 @@ public class FlatNativeWindowBorder
// do not enable native window border if JDialog should use system window decorations
// and if not forced to use FlatLaf/JBR native window decorations
if( !JDialog.isDefaultLookAndFeelDecorated() &&
!FlatSystemProperties.getBoolean( systemPropertyKey, false ))
!UIManager.getBoolean( "TitlePane.useWindowDecorations" ) &&
!FlatSystemProperties.getBoolean( systemPropertyKey, false ) )
return;
// do not enable native window border if dialog is undecorated
@@ -223,7 +225,8 @@ public class FlatNativeWindowBorder
if( !SystemInfo.isWindows_10_orLater || !SystemInfo.isX86_64 )
return;
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_NATIVE_WINDOW_DECORATIONS, true ) )
// check whether disabled via system property
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_WINDOW_DECORATIONS, true ) )
return;
try {

View File

@@ -166,6 +166,7 @@ public class JBRCustomDecorations
if( !SystemInfo.isJetBrainsJVM_11_orLater || !SystemInfo.isWindows_10_orLater )
return;
// check whether disabled via system property
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ) )
return;

View File

@@ -685,6 +685,7 @@ TitledBorder.border = 1,1,1,1,$Separator.foreground
#---- TitlePane ----
TitlePane.useWindowDecorations = true
TitlePane.menuBarEmbedded = true
TitlePane.iconSize = 16,16
TitlePane.iconMargins = 3,8,3,0

View File

@@ -155,8 +155,7 @@ class DemoFrame
menuBarEmbeddedCheckBoxMenuItem.setEnabled( windowDecorations );
// enable/disable window decoration for later created frames/dialogs
JFrame.setDefaultLookAndFeelDecorated( windowDecorations );
JDialog.setDefaultLookAndFeelDecorated( windowDecorations );
UIManager.put( "TitlePane.useWindowDecorations", windowDecorations );
}
private void menuBarEmbeddedChanged() {

View File

@@ -17,8 +17,6 @@
package com.formdev.flatlaf.demo;
import java.awt.Dimension;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.extras.FlatInspector;
@@ -46,10 +44,6 @@ public class FlatLafDemo
SwingUtilities.invokeLater( () -> {
DemoPrefs.init( PREFS_ROOT_PATH );
// enable window decorations
JFrame.setDefaultLookAndFeelDecorated( true );
JDialog.setDefaultLookAndFeelDecorated( true );
// application specific UI defaults
FlatLaf.registerCustomDefaultsSource( "com.formdev.flatlaf.demo" );

View File

@@ -1143,6 +1143,7 @@ TitlePane.menuBarEmbedded true
TitlePane.menuBarMargins 0,8,0,22 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI]
TitlePane.titleMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.useWindowDecorations true
#---- TitledBorder ----

View File

@@ -1148,6 +1148,7 @@ TitlePane.menuBarEmbedded true
TitlePane.menuBarMargins 0,8,0,22 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI]
TitlePane.titleMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.useWindowDecorations true
#---- TitledBorder ----

View File

@@ -1140,6 +1140,7 @@ TitlePane.menuBarEmbedded true
TitlePane.menuBarMargins 0,8,0,22 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.restoreIcon [lazy] 44,30 com.formdev.flatlaf.icons.FlatWindowRestoreIcon [UI]
TitlePane.titleMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI]
TitlePane.useWindowDecorations true
#---- TitledBorder ----

View File

@@ -50,9 +50,6 @@ public class FlatNativeWindowBorderTest
FlatLightLaf.install();
FlatInspector.install( "ctrl shift alt X" );
JFrame.setDefaultLookAndFeelDecorated( true );
JDialog.setDefaultLookAndFeelDecorated( true );
mainFrame = showFrame();
} );
}

View File

@@ -853,6 +853,7 @@ TitlePane.menuBarEmbedded
TitlePane.menuBarMargins
TitlePane.restoreIcon
TitlePane.titleMargins
TitlePane.useWindowDecorations
TitledBorder.border
TitledBorder.font
TitledBorder.titleColor