mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-13 07:17:13 -06:00
macOS fullWindowContent mode:
- added title bar buttons placeholder
- added client property to root pane that contains title bar buttons bounds
- undone toolbar extensions from commit ea2447dcb7
This commit is contained in:
@@ -270,6 +270,76 @@ public interface FlatClientProperties
|
||||
String COMPONENT_TITLE_BAR_CAPTION = "JComponent.titleBarCaption";
|
||||
|
||||
|
||||
//---- Panel --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Marks the panel as placeholder for the iconfify/maximize/close buttons
|
||||
* in fullWindowContent mode.
|
||||
* <p>
|
||||
* If fullWindowContent mode is enabled, the preferred size of the panel is equal
|
||||
* to the size of the iconfify/maximize/close buttons. Otherwise is is {@code 0,0}.
|
||||
* <p>
|
||||
* You're responsible to layout that panel at the top-left or top-right corner,
|
||||
* depending on platform, where the iconfify/maximize/close buttons are located.
|
||||
* <p>
|
||||
* Syntax of the value string is: {@code "win|mac [horizontal|vertical]"}.
|
||||
* <p>
|
||||
* The string must start with {@code "win"} (for Windows or Linux) or
|
||||
* with {@code "mac"} (for macOS) and specifies the platform where the placeholder
|
||||
* should be used. On macOS, you need the placeholder in the top-left corner,
|
||||
* but on Windows/Linux you need it in the top-right corner. So if fullWindowContent mode
|
||||
* is supported on both platforms, you can add two placeholders to your layout
|
||||
* and FlatLaf automatically uses only one of them. The other gets size {@code 0,0}.
|
||||
* <p>
|
||||
* Optionally, you can append {@code " horizontal"} or {@code " vertical"} to the value string
|
||||
* to specify that the placeholder preferred size should be limited to one orientation.
|
||||
* E.g. {@code "win horizontal"} means that the placeholder preferred width is
|
||||
* equal to iconfify/maximize/close buttons width, but preferred height is zero.
|
||||
* <p>
|
||||
* Example for adding placeholder to top-left corner on macOS:
|
||||
* <pre>{@code
|
||||
* JPanel placeholder = new JPanel();
|
||||
* placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" );
|
||||
*
|
||||
* JToolBar toolBar = new JToolBar();
|
||||
* // add tool bar items
|
||||
*
|
||||
* JPanel toolBarPanel = new JPanel( new BorderLayout() );
|
||||
* toolBarPanel.add( placeholder, BorderLayout.WEST );
|
||||
* toolBarPanel.add( toolBar, BorderLayout.CENTER );
|
||||
*
|
||||
* frame.getContentPane().add( toolBarPanel, BorderLayout.NORTH );
|
||||
* }</pre>
|
||||
*
|
||||
* Or add placeholder as first item to the tool bar:
|
||||
* <pre>{@code
|
||||
* JPanel placeholder = new JPanel();
|
||||
* placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" );
|
||||
*
|
||||
* JToolBar toolBar = new JToolBar();
|
||||
* toolBar.add( placeholder );
|
||||
* // add tool bar items
|
||||
*
|
||||
* frame.getContentPane().add( toolBar, BorderLayout.NORTH );
|
||||
* }</pre>
|
||||
*
|
||||
* If a tabbed pane is located at the top, you can add the placeholder
|
||||
* as leading component to that tabbed pane:
|
||||
* <pre>{@code
|
||||
* JPanel placeholder = new JPanel();
|
||||
* placeholder.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER, "mac" );
|
||||
*
|
||||
* tabbedPane.putClientProperty( FlatClientProperties.TABBED_PANE_LEADING_COMPONENT, placeholder );
|
||||
* }</pre>
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JPanel}<br>
|
||||
* <strong>Value type</strong> {@link java.lang.String}
|
||||
*
|
||||
* @since 3.4
|
||||
*/
|
||||
String FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER = "FlatLaf.fullWindowContent.buttonsPlaceholder";
|
||||
|
||||
|
||||
//---- Popup --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -388,6 +458,20 @@ public interface FlatClientProperties
|
||||
*/
|
||||
String MENU_BAR_EMBEDDED = "JRootPane.menuBarEmbedded";
|
||||
|
||||
/**
|
||||
* Contains the current bounds of the iconfify/maximize/close buttons
|
||||
* (in root pane coordinates) if fullWindowContent mode is enabled.
|
||||
* Otherwise its value is {@code null}.
|
||||
* <p>
|
||||
* <b>Note</b>: Do not set this client property. It is set by FlatLaf.
|
||||
* <p>
|
||||
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
|
||||
* <strong>Value type</strong> {@link java.awt.Rectangle}
|
||||
*
|
||||
* @since 3.4
|
||||
*/
|
||||
String FULL_WINDOW_CONTENT_BUTTONS_BOUNDS = "FlatLaf.fullWindowContent.buttonsBounds";
|
||||
|
||||
/**
|
||||
* Specifies whether the window icon should be shown in the window title bar
|
||||
* (requires enabled window decorations). Default is UI property {@code TitlePane.showIcon}.
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
|
||||
/**
|
||||
@@ -54,14 +55,14 @@ public class FlatNativeMacLibrary
|
||||
|
||||
public native static boolean setWindowRoundedBorder( Window window, float radius, float borderWidth, int borderColor );
|
||||
|
||||
/** @since 3.4 */
|
||||
public static final int
|
||||
BUTTON_STYLE_DEFAULT = 0,
|
||||
BUTTON_STYLE_MEDIUM = 1,
|
||||
BUTTON_STYLE_LARGE = 2;
|
||||
|
||||
public native static boolean setWindowButtonStyle( Window window, int buttonStyle );
|
||||
public native static int getWindowButtonAreaWidth( Window window );
|
||||
public native static int getWindowTitleBarHeight( Window window );
|
||||
public native static boolean isWindowFullScreen( Window window );
|
||||
public native static boolean windowToggleFullScreen( Window window );
|
||||
/** @since 3.4 */ public native static boolean setWindowButtonStyle( Window window, int buttonStyle );
|
||||
/** @since 3.4 */ public native static Rectangle getWindowButtonsBounds( Window window );
|
||||
/** @since 3.4 */ public native static boolean isWindowFullScreen( Window window );
|
||||
/** @since 3.4 */ public native static boolean toggleWindowFullScreen( Window window );
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
@@ -23,6 +24,7 @@ import java.beans.PropertyChangeListener;
|
||||
import java.util.Map;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicPanelUI;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
@@ -69,6 +71,8 @@ public class FlatPanelUI
|
||||
super.installUI( c );
|
||||
|
||||
c.addPropertyChangeListener( this );
|
||||
if( c.getClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER ) != null )
|
||||
FullWindowContentSupport.registerPlaceholder( c );
|
||||
|
||||
installStyle( (JPanel) c );
|
||||
}
|
||||
@@ -78,10 +82,20 @@ public class FlatPanelUI
|
||||
super.uninstallUI( c );
|
||||
|
||||
c.removePropertyChangeListener( this );
|
||||
if( c.getClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER ) != null )
|
||||
FullWindowContentSupport.unregisterPlaceholder( c );
|
||||
|
||||
oldStyleValues = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void installDefaults( JPanel p ) {
|
||||
super.installDefaults( p );
|
||||
|
||||
if( p.getClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER ) != null )
|
||||
LookAndFeel.installProperty( p, "opaque", false );
|
||||
}
|
||||
|
||||
/** @since 2.0.1 */
|
||||
@Override
|
||||
public void propertyChange( PropertyChangeEvent e ) {
|
||||
@@ -98,6 +112,17 @@ public class FlatPanelUI
|
||||
c.revalidate();
|
||||
c.repaint();
|
||||
break;
|
||||
|
||||
case FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER:
|
||||
JPanel p = (JPanel) e.getSource();
|
||||
if( e.getOldValue() != null )
|
||||
FullWindowContentSupport.unregisterPlaceholder( p );
|
||||
if( e.getNewValue() != null )
|
||||
FullWindowContentSupport.registerPlaceholder( p );
|
||||
|
||||
// make panel non-opaque for placeholders
|
||||
LookAndFeel.installProperty( p, "opaque", e.getNewValue() == null );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,4 +187,19 @@ public class FlatPanelUI
|
||||
|
||||
paint( g, c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize( JComponent c ) {
|
||||
Object value = c.getClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER );
|
||||
if( value != null )
|
||||
return FullWindowContentSupport.getPlaceholderPreferredSize( c, (String) value );
|
||||
|
||||
return super.getPreferredSize( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
if( c.getClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_PLACEHOLDER ) != null )
|
||||
FullWindowContentSupport.debugPaint( g, c );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ public class FlatRootPaneUI
|
||||
private LayoutManager oldLayout;
|
||||
private PropertyChangeListener ancestorListener;
|
||||
private ComponentListener componentListener;
|
||||
private ComponentListener macFullWindowContentListener;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
return new FlatRootPaneUI();
|
||||
@@ -207,6 +208,9 @@ public class FlatRootPaneUI
|
||||
};
|
||||
root.addPropertyChangeListener( "ancestor", ancestorListener );
|
||||
}
|
||||
|
||||
if( SystemInfo.isMacFullWindowContentSupported )
|
||||
macFullWindowContentListener = FullWindowContentSupport.macInstallListeners( root );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,6 +227,11 @@ public class FlatRootPaneUI
|
||||
root.removePropertyChangeListener( "ancestor", ancestorListener );
|
||||
ancestorListener = null;
|
||||
}
|
||||
|
||||
if( SystemInfo.isMacFullWindowContentSupported ) {
|
||||
FullWindowContentSupport.macUninstallListeners( root, macFullWindowContentListener );
|
||||
macFullWindowContentListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
/** @since 1.1.2 */
|
||||
@@ -359,6 +368,10 @@ public class FlatRootPaneUI
|
||||
titlePane.titleBarColorsChanged();
|
||||
break;
|
||||
|
||||
case FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_BOUNDS:
|
||||
FullWindowContentSupport.revalidatePlaceholders( rootPane );
|
||||
break;
|
||||
|
||||
case FlatClientProperties.GLASS_PANE_FULL_HEIGHT:
|
||||
rootPane.revalidate();
|
||||
break;
|
||||
@@ -371,26 +384,30 @@ public class FlatRootPaneUI
|
||||
case FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE:
|
||||
case "ancestor":
|
||||
if( SystemInfo.isMacFullWindowContentSupported &&
|
||||
SystemInfo.isJava_17_orLater &&
|
||||
rootPane.isDisplayable() &&
|
||||
FlatClientProperties.clientPropertyBoolean( rootPane, "apple.awt.fullWindowContent", false ) &&
|
||||
FlatNativeMacLibrary.isLoaded() )
|
||||
FlatClientProperties.clientPropertyBoolean( rootPane, "apple.awt.fullWindowContent", false ) )
|
||||
{
|
||||
int buttonStyle = FlatNativeMacLibrary.BUTTON_STYLE_DEFAULT;
|
||||
Object value = rootPane.getClientProperty( FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE );
|
||||
switch( String.valueOf( value ) ) {
|
||||
case FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE_MEDIUM:
|
||||
buttonStyle = FlatNativeMacLibrary.BUTTON_STYLE_MEDIUM;
|
||||
break;
|
||||
// set window button style
|
||||
if( SystemInfo.isJava_17_orLater && FlatNativeMacLibrary.isLoaded() ) {
|
||||
int buttonStyle = FlatNativeMacLibrary.BUTTON_STYLE_DEFAULT;
|
||||
Object value = rootPane.getClientProperty( FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE );
|
||||
switch( String.valueOf( value ) ) {
|
||||
case FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE_MEDIUM:
|
||||
buttonStyle = FlatNativeMacLibrary.BUTTON_STYLE_MEDIUM;
|
||||
break;
|
||||
|
||||
case "true":
|
||||
case FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE_LARGE:
|
||||
buttonStyle = FlatNativeMacLibrary.BUTTON_STYLE_LARGE;
|
||||
break;
|
||||
case "true":
|
||||
case FlatClientProperties.MACOS_WINDOW_BUTTON_STYLE_LARGE:
|
||||
buttonStyle = FlatNativeMacLibrary.BUTTON_STYLE_LARGE;
|
||||
break;
|
||||
}
|
||||
|
||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
||||
FlatNativeMacLibrary.setWindowButtonStyle( window, buttonStyle );
|
||||
}
|
||||
|
||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
||||
FlatNativeMacLibrary.setWindowButtonStyle( window, buttonStyle );
|
||||
// update buttons bounds client property
|
||||
FullWindowContentSupport.macUpdateFullWindowContentButtonsBoundsProperty( rootPane );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.awt.Rectangle;
|
||||
import java.util.function.Function;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.ToolBarUI;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
@@ -115,18 +114,6 @@ public class FlatToolBarBorder
|
||||
insets.top += gripInset;
|
||||
}
|
||||
|
||||
// on macOS, add some extra space to left side for close/minimize/zoom buttons (if necessary)
|
||||
if( c instanceof JToolBar && FlatToolBarUI.isMacOSMainToolbar( (JToolBar) c ) ) {
|
||||
// get button area width from macOS
|
||||
int buttonBarWidth = FlatNativeMacLibrary.isLoaded()
|
||||
? FlatNativeMacLibrary.getWindowButtonAreaWidth( SwingUtilities.windowForComponent( c ) )
|
||||
: -1;
|
||||
if( buttonBarWidth < 0 )
|
||||
buttonBarWidth = 68; // default width if NSWindow does not have a toolbar
|
||||
|
||||
insets.left += buttonBarWidth;
|
||||
}
|
||||
|
||||
return insets;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,45 +19,35 @@ package com.formdev.flatlaf.ui;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FocusTraversalPolicy;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.LayoutManager2;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ContainerEvent;
|
||||
import java.awt.event.ContainerListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.ButtonModel;
|
||||
import javax.swing.DefaultButtonModel;
|
||||
import javax.swing.InputMap;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.LayoutFocusTraversalPolicy;
|
||||
import javax.swing.RootPaneContainer;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicToolBarUI;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||
import com.formdev.flatlaf.util.LoggingFacade;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
import com.formdev.flatlaf.util.UIScale;
|
||||
|
||||
/**
|
||||
@@ -158,12 +148,6 @@ public class FlatToolBarUI
|
||||
toolBar.setFloatable( false );
|
||||
} else
|
||||
oldFloatable = null;
|
||||
|
||||
// layout manager
|
||||
LayoutManager layout = createLayout();
|
||||
toolBar.setLayout( layout );
|
||||
if( layout instanceof PropertyChangeListener )
|
||||
toolBar.addPropertyChangeListener( (PropertyChangeListener) layout );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -176,8 +160,6 @@ public class FlatToolBarUI
|
||||
toolBar.setFloatable( oldFloatable );
|
||||
oldFloatable = null;
|
||||
}
|
||||
|
||||
toolBar.setLayout( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -471,137 +453,6 @@ public class FlatToolBarUI
|
||||
: null;
|
||||
}
|
||||
|
||||
/** @since 3.3 */
|
||||
protected LayoutManager createLayout() {
|
||||
return new FlatToolBarLayoutManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given toolbar is used in window titlebar on macOS.
|
||||
* <p>
|
||||
* Returns {@code true} if:
|
||||
* <ul>
|
||||
* <li>running on macOS
|
||||
* <li>Java supports "full window content"
|
||||
* <li>"full window content" is enabled for window
|
||||
* <li>toolbar orientation is horizontal
|
||||
* <li>toolbar is located at {@code 0,0} in window
|
||||
* </ul>
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
public static boolean isMacOSMainToolbar( JToolBar toolBar ) {
|
||||
if( !SystemInfo.isMacFullWindowContentSupported ||
|
||||
toolBar.getOrientation() != JToolBar.HORIZONTAL ||
|
||||
toolBar.getX() != 0 ||
|
||||
toolBar.getY() != 0 )
|
||||
return false;
|
||||
|
||||
JRootPane rootPane = SwingUtilities.getRootPane( toolBar );
|
||||
if( rootPane == null )
|
||||
return false;
|
||||
|
||||
if( !FlatClientProperties.clientPropertyBoolean( rootPane, "apple.awt.fullWindowContent", false ) )
|
||||
return false;
|
||||
|
||||
for( Component p = toolBar.getParent(); p != null && !(p instanceof Window); p = p.getParent() ) {
|
||||
if( p.getX() != 0 || p.getY() != 0 )
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//---- class FlatToolBarLayoutManager -------------------------------------
|
||||
|
||||
/**
|
||||
* @since 3.3
|
||||
*/
|
||||
protected class FlatToolBarLayoutManager
|
||||
implements LayoutManager2, PropertyChangeListener, UIResource
|
||||
{
|
||||
private BoxLayout delegate;
|
||||
|
||||
FlatToolBarLayoutManager() {
|
||||
initBoxLayout();
|
||||
}
|
||||
|
||||
private void initBoxLayout() {
|
||||
delegate = new BoxLayout( toolBar, (toolBar.getOrientation() == JToolBar.HORIZONTAL)
|
||||
? BoxLayout.LINE_AXIS : BoxLayout.PAGE_AXIS );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutComponent( Component comp, Object constraints ) {
|
||||
delegate.addLayoutComponent( comp, constraints );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutComponent( String name, Component comp ) {
|
||||
delegate.addLayoutComponent( name, comp );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutComponent( Component comp ) {
|
||||
delegate.removeLayoutComponent( comp );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension preferredLayoutSize( Container parent ) {
|
||||
return minimumHeightOnMacOS( delegate.preferredLayoutSize( parent ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension minimumLayoutSize( Container parent ) {
|
||||
return minimumHeightOnMacOS( delegate.minimumLayoutSize( parent ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension maximumLayoutSize( Container target ) {
|
||||
return minimumHeightOnMacOS( delegate.maximumLayoutSize( target ) );
|
||||
}
|
||||
|
||||
private Dimension minimumHeightOnMacOS( Dimension size ) {
|
||||
if( isMacOSMainToolbar( toolBar ) ) {
|
||||
// get title bar height from macOS
|
||||
int titleBarHeight = FlatNativeMacLibrary.isLoaded()
|
||||
? FlatNativeMacLibrary.getWindowTitleBarHeight( SwingUtilities.windowForComponent( toolBar ) )
|
||||
: -1;
|
||||
if( titleBarHeight < 0 )
|
||||
titleBarHeight = 28; // default height if NSWindow does not have a toolbar
|
||||
|
||||
size.height = Math.max( size.height, titleBarHeight );
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layoutContainer( Container parent ) {
|
||||
delegate.layoutContainer( parent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateLayout( Container target ) {
|
||||
delegate.invalidateLayout( target );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLayoutAlignmentX( Container target ) {
|
||||
return delegate.getLayoutAlignmentX( target );
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLayoutAlignmentY( Container target ) {
|
||||
return delegate.getLayoutAlignmentY( target );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChange( PropertyChangeEvent e ) {
|
||||
if( "orientation".equals( e.getPropertyName() ) )
|
||||
initBoxLayout();
|
||||
}
|
||||
}
|
||||
|
||||
//---- class FlatToolBarFocusTraversalPolicy ------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright 2024 FormDev Software GmbH
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import com.formdev.flatlaf.util.SystemInfo;
|
||||
|
||||
/**
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
class FullWindowContentSupport
|
||||
{
|
||||
private static final String KEY_DEBUG_SHOW_PLACEHOLDERS = "FlatLaf.debug.panel.showPlaceholders";
|
||||
|
||||
private static ArrayList<WeakReference<JComponent>> placeholders = new ArrayList<>();
|
||||
|
||||
static Dimension getPlaceholderPreferredSize( JComponent c, String options ) {
|
||||
JRootPane rootPane;
|
||||
Rectangle bounds;
|
||||
|
||||
if( options.startsWith( SystemInfo.isMacOS ? "mac" : "win" ) &&
|
||||
c.isDisplayable() &&
|
||||
(rootPane = SwingUtilities.getRootPane( c )) != null &&
|
||||
(bounds = (Rectangle) rootPane.getClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_BOUNDS )) != null )
|
||||
{
|
||||
// On macOS, the client property is updated very late when toggling full screen,
|
||||
// which results in "jumping" layout after full screen toggle finished.
|
||||
// To avoid that, get up-to-date buttons bounds from macOS.
|
||||
if( SystemInfo.isMacFullWindowContentSupported && FlatNativeMacLibrary.isLoaded() ) {
|
||||
Rectangle r = FlatNativeMacLibrary.getWindowButtonsBounds( SwingUtilities.windowForComponent( c ) );
|
||||
if( r != null )
|
||||
bounds = r;
|
||||
}
|
||||
|
||||
if( options.length() > 3 ) {
|
||||
if( options.contains( "horizontal" ) )
|
||||
return new Dimension( bounds.width, 0 );
|
||||
if( options.contains( "vertical" ) )
|
||||
return new Dimension( 0, bounds.height );
|
||||
}
|
||||
|
||||
return bounds.getSize();
|
||||
}
|
||||
|
||||
// default to 0,0
|
||||
return new Dimension();
|
||||
}
|
||||
|
||||
static void registerPlaceholder( JComponent c ) {
|
||||
synchronized( placeholders ) {
|
||||
if( indexOfPlaceholder( c ) < 0 )
|
||||
placeholders.add( new WeakReference<>( c ) );
|
||||
}
|
||||
}
|
||||
|
||||
static void unregisterPlaceholder( JComponent c ) {
|
||||
synchronized( placeholders ) {
|
||||
int index = indexOfPlaceholder( c );
|
||||
if( index >= 0 )
|
||||
placeholders.remove( index );
|
||||
}
|
||||
}
|
||||
|
||||
private static int indexOfPlaceholder( JComponent c ) {
|
||||
int size = placeholders.size();
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
if( placeholders.get( i ).get() == c )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void revalidatePlaceholders( Component container ) {
|
||||
synchronized( placeholders ) {
|
||||
if( placeholders.isEmpty() )
|
||||
return;
|
||||
|
||||
for( Iterator<WeakReference<JComponent>> it = placeholders.iterator(); it.hasNext(); ) {
|
||||
WeakReference<JComponent> ref = it.next();
|
||||
JComponent c = ref.get();
|
||||
|
||||
// remove already released placeholder
|
||||
if( c == null ) {
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
// revalidate placeholder if is in given container
|
||||
if( SwingUtilities.isDescendingFrom( c, container ) )
|
||||
c.revalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ComponentListener macInstallListeners( JRootPane rootPane ) {
|
||||
ComponentListener l = new ComponentAdapter() {
|
||||
boolean lastFullScreen;
|
||||
|
||||
@Override
|
||||
public void componentResized( ComponentEvent e ) {
|
||||
Window window = SwingUtilities.windowForComponent( rootPane );
|
||||
if( window == null )
|
||||
return;
|
||||
|
||||
boolean fullScreen = FlatNativeMacLibrary.isLoaded() && FlatNativeMacLibrary.isWindowFullScreen( window );
|
||||
if( fullScreen == lastFullScreen )
|
||||
return;
|
||||
|
||||
lastFullScreen = fullScreen;
|
||||
macUpdateFullWindowContentButtonsBoundsProperty( rootPane );
|
||||
}
|
||||
};
|
||||
|
||||
rootPane.addComponentListener( l );
|
||||
return l;
|
||||
}
|
||||
|
||||
static void macUninstallListeners( JRootPane rootPane, ComponentListener l ) {
|
||||
if( l != null )
|
||||
rootPane.removeComponentListener( l );
|
||||
}
|
||||
|
||||
static void macUpdateFullWindowContentButtonsBoundsProperty( JRootPane rootPane ) {
|
||||
if( !SystemInfo.isMacFullWindowContentSupported ||
|
||||
!rootPane.isDisplayable() ||
|
||||
!FlatClientProperties.clientPropertyBoolean( rootPane, "apple.awt.fullWindowContent", false ) )
|
||||
return;
|
||||
|
||||
Rectangle bounds = FlatNativeMacLibrary.isLoaded()
|
||||
? FlatNativeMacLibrary.getWindowButtonsBounds( SwingUtilities.windowForComponent( rootPane ) )
|
||||
: new Rectangle( 68, 28 ); // default size
|
||||
rootPane.putClientProperty( FlatClientProperties.FULL_WINDOW_CONTENT_BUTTONS_BOUNDS, bounds );
|
||||
}
|
||||
|
||||
static void debugPaint( Graphics g, JComponent c ) {
|
||||
if( !UIManager.getBoolean( KEY_DEBUG_SHOW_PLACEHOLDERS ) )
|
||||
return;
|
||||
|
||||
int width = c.getWidth() - 1;
|
||||
int height = c.getHeight() - 1;
|
||||
if( width <= 0 || height <= 0 )
|
||||
return;
|
||||
|
||||
g.setColor( Color.red );
|
||||
g.drawRect( 0, 0, width, height );
|
||||
|
||||
// draw diagonal cross
|
||||
Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g );
|
||||
g.drawLine( 0, 0, width, height );
|
||||
g.drawLine( 0, height, width, 0 );
|
||||
FlatUIUtils.resetRenderingHints( g, oldRenderingHints );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user