Skip to content

Commit

Permalink
Window decorations: enabling/disabling menu bar embedding via system …
Browse files Browse the repository at this point in the history
…and client properties now works the same way as for window decorations

(previously it was only possible to disable menu bar embedding)
  • Loading branch information
DevCharly committed Apr 3, 2021
1 parent 63639f8 commit eee177e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,15 @@ public interface FlatClientProperties
String USE_WINDOW_DECORATIONS = "JRootPane.useWindowDecorations";

/**
* Specifies whether the menu bar is embedded into the title pane if custom
* window decorations are enabled. Default is {@code true}.
* Specifies whether the menu bar is embedded into the window title pane
* if window decorations are enabled.
* <p>
* Setting this enables/disables embedding
* for the window that contains the root pane.
* <p>
* This client property has lower priority than system property
* {@link FlatSystemProperties#MENUBAR_EMBEDDED}, but higher priority
* than UI default {@code TitlePane.menuBarEmbedded}.
* <p>
* (requires Window 10)
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public interface FlatSystemProperties
* when creating {@code JFrame} or {@code JDialog}.
* <p>
* Setting this to {@code true} forces using native window decorations
* even if they are not enabled by the application.
* <p>
* even if they are not enabled by the application.<br>
* Setting this to {@code false} disables using native window decorations.
* <p>
* This system property has higher priority than client property
Expand Down Expand Up @@ -92,12 +91,20 @@ public interface FlatSystemProperties
String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations";

/**
* Specifies whether menubar is embedded into custom window decorations.
* Specifies whether the menu bar is embedded into the window title pane
* if window decorations are enabled.
* <p>
* Setting this to {@code true} forces embedding.<br>
* Setting this to {@code false} disables embedding.
* <p>
* This system property has higher priority than client property
* {@link FlatClientProperties#MENU_BAR_EMBEDDED} and
* UI default {@code TitlePane.menuBarEmbedded}.
* <p>
* (requires Window 10)
* <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> {@code true}
* <strong>Default</strong> none
*/
String MENUBAR_EMBEDDED = "flatlaf.menuBarEmbedded";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,11 @@ private static void uninstall( Window window ) {
}

private static boolean useWindowDecorations( JRootPane rootPane ) {
// check whether forced to enabled/disabled via system property
Boolean enabled = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null );
if( enabled != null )
return enabled;

// check whether forced to enabled/disabled via client property
enabled = FlatClientProperties.clientPropertyBooleanStrict( rootPane, FlatClientProperties.USE_WINDOW_DECORATIONS, null );
if( enabled != null )
return enabled;

return UIManager.getBoolean( "TitlePane.useWindowDecorations" );
return FlatUIUtils.getBoolean( rootPane,
FlatSystemProperties.USE_WINDOW_DECORATIONS,
FlatClientProperties.USE_WINDOW_DECORATIONS,
"TitlePane.useWindowDecorations",
false );
}

public static boolean hasCustomDecoration( Window window ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,11 @@ protected boolean hasVisibleEmbeddedMenuBar( JMenuBar menuBar ) {
*/
protected boolean isMenuBarEmbedded() {
// not storing value of "TitlePane.menuBarEmbedded" in class to allow changing at runtime
return UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) &&
FlatClientProperties.clientPropertyBoolean( rootPane, FlatClientProperties.MENU_BAR_EMBEDDED, true ) &&
FlatSystemProperties.getBoolean( FlatSystemProperties.MENUBAR_EMBEDDED, true );
return FlatUIUtils.getBoolean( rootPane,
FlatSystemProperties.MENUBAR_EMBEDDED,
FlatClientProperties.MENU_BAR_EMBEDDED,
"TitlePane.menuBarEmbedded",
false );
}

protected Rectangle getMenuBarBounds() {
Expand Down
20 changes: 20 additions & 0 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.util.DerivedColor;
import com.formdev.flatlaf.util.Graphics2DProxy;
import com.formdev.flatlaf.util.HiDPIUtils;
Expand Down Expand Up @@ -140,6 +141,25 @@ public static float getUIFloat( String key, float defaultValue ) {
return (value instanceof Number) ? ((Number)value).floatValue() : defaultValue;
}

/**
* @since 1.1.2
*/
public static boolean getBoolean( JComponent c, String systemPropertyKey,
String clientPropertyKey, String uiKey, boolean defaultValue )
{
// check whether forced to true/false via system property
Boolean value = FlatSystemProperties.getBooleanStrict( systemPropertyKey, null );
if( value != null )
return value;

// check whether forced to true/false via client property
value = FlatClientProperties.clientPropertyBooleanStrict( c, clientPropertyKey, null );
if( value != null )
return value;

return getUIBoolean( uiKey, defaultValue );
}

public static boolean isChevron( String arrowType ) {
return !"triangle".equals( arrowType );
}
Expand Down

0 comments on commit eee177e

Please sign in to comment.