Browse Source

Allow hiding the title of a window using a rootPane property

titlebar_button_bounds
Jannis Weis 3 years ago
parent
commit
f2ea6571d0
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 12
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java
  2. 14
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java
  3. 1
      platform-base/src/main/java/com/github/weisj/darklaf/platform/DecorationsConstants.java
  4. 9
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

12
macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java

@ -58,7 +58,7 @@ public final class MacOSDecorationsUtil {
setFullSizeContent(windowHandle, useColoredTitleBar); setFullSizeContent(windowHandle, useColoredTitleBar);
boolean titleVisible = SystemInfo.isMacOSMojave && !UIManager.getBoolean("Theme.macos.useSwingTitleLabel"); boolean titleVisible = SystemInfo.isMacOSMojave && !UIManager.getBoolean("Theme.macos.useSwingTitleLabel");
JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible); setTitleVisible(windowHandle, titleVisible);
if (titleVisible) { if (titleVisible) {
boolean isDarkTheme = UIManager.getBoolean("Theme.dark"); boolean isDarkTheme = UIManager.getBoolean("Theme.dark");
JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme); JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme);
@ -88,7 +88,7 @@ public final class MacOSDecorationsUtil {
isTransparentTitleBarEnabled(information.rootPane)); isTransparentTitleBarEnabled(information.rootPane));
window.setBounds(bounds); window.setBounds(bounds);
} }
JNIDecorationsMacOS.setTitleEnabled(information.windowHandle, true); setTitleVisible(information, true);
JNIDecorationsMacOS.releaseWindow(information.windowHandle); JNIDecorationsMacOS.releaseWindow(information.windowHandle);
} }
@ -99,4 +99,12 @@ public final class MacOSDecorationsUtil {
static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) { static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) {
return PropertyUtil.getBooleanProperty(rootPane, TRANSPARENT_TITLE_BAR_KEY); return PropertyUtil.getBooleanProperty(rootPane, TRANSPARENT_TITLE_BAR_KEY);
} }
static void setTitleVisible(final DecorationInformation decorationInformation, final boolean visible) {
setTitleVisible(decorationInformation.windowHandle, visible);
}
private static void setTitleVisible(final long windowHandle, boolean visible) {
JNIDecorationsMacOS.setTitleEnabled(windowHandle, visible);
}
} }

14
macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java

@ -61,6 +61,7 @@ public class MacOSTitlePane extends CustomTitlePane {
this.window = window; this.window = window;
determineColors(); determineColors();
updateTitleBarVisibility(); updateTitleBarVisibility();
updateTitleVisibility();
updateOpacity(); updateOpacity();
} }
@ -209,6 +210,8 @@ public class MacOSTitlePane extends CustomTitlePane {
} else if (MacOSDecorationsUtil.TRANSPARENT_TITLE_BAR_KEY.equals(evt.getPropertyName())) { } else if (MacOSDecorationsUtil.TRANSPARENT_TITLE_BAR_KEY.equals(evt.getPropertyName())) {
updateOpacity(); updateOpacity();
repaint(); repaint();
} else if (DecorationsConstants.KEY_HIDE_TITLE.equals(evt.getPropertyName())) {
updateTitleVisibility();
} }
} }
} }
@ -258,6 +261,17 @@ public class MacOSTitlePane extends CustomTitlePane {
rootPane.repaint(); rootPane.repaint();
} }
private void updateTitleVisibility() {
boolean visible = PropertyUtil.getBooleanProperty(rootPane, DecorationsConstants.KEY_HIDE_TITLE);
if (titleLabel != null) {
titleLabel.setVisible(visible);
doLayout();
repaint();
} else {
MacOSDecorationsUtil.setTitleVisible(decorationInformation, visible);
}
}
private void updateOpacity() { private void updateOpacity() {
setOpaque(!PropertyUtil.getBooleanProperty(rootPane, MacOSDecorationsUtil.TRANSPARENT_TITLE_BAR_KEY)); setOpaque(!PropertyUtil.getBooleanProperty(rootPane, MacOSDecorationsUtil.TRANSPARENT_TITLE_BAR_KEY));
} }

1
platform-base/src/main/java/com/github/weisj/darklaf/platform/DecorationsConstants.java

@ -27,4 +27,5 @@ public interface DecorationsConstants {
String KEY_NO_DECORATIONS = "JRootPane.noDecorations"; String KEY_NO_DECORATIONS = "JRootPane.noDecorations";
String KEY_UNIFIED_MENUBAR = "JRootPane.unifiedMenuBar"; String KEY_UNIFIED_MENUBAR = "JRootPane.unifiedMenuBar";
String KEY_COLORED_TITLE_BAR = "JRootPane.coloredTitleBar"; String KEY_COLORED_TITLE_BAR = "JRootPane.coloredTitleBar";
String KEY_HIDE_TITLE = "JRootPane.hideTitle";
} }

9
windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

@ -124,6 +124,7 @@ public class WindowsTitlePane extends CustomTitlePane {
installSubcomponents(); installSubcomponents();
menuBarStealer.install(); menuBarStealer.install();
updateTitleBarVisibility(); updateTitleBarVisibility();
updateTitleVisibility();
installDefaults(); installDefaults();
setLayout(createLayout()); setLayout(createLayout());
setOpaque(true); setOpaque(true);
@ -135,6 +136,12 @@ public class WindowsTitlePane extends CustomTitlePane {
rootPane.repaint(); rootPane.repaint();
} }
private void updateTitleVisibility() {
titleLabel.setVisible(!PropertyUtil.getBooleanProperty(rootPane, DecorationsConstants.KEY_HIDE_TITLE));
doLayout();
repaint();
}
private TitleBarButton createButton(final Icon icon, final Action action) { private TitleBarButton createButton(final Icon icon, final Action action) {
return createButton(icon, action, false); return createButton(icon, action, false);
} }
@ -953,6 +960,8 @@ public class WindowsTitlePane extends CustomTitlePane {
menuBarStealer.updateMenuBar(true); menuBarStealer.updateMenuBar(true);
} else if (DecorationsConstants.KEY_HIDE_TITLEBAR.equals(evt.getPropertyName())) { } else if (DecorationsConstants.KEY_HIDE_TITLEBAR.equals(evt.getPropertyName())) {
updateTitleBarVisibility(); updateTitleBarVisibility();
} else if (DecorationsConstants.KEY_HIDE_TITLE.equals(evt.getPropertyName())) {
updateTitleVisibility();
} }
} }
} }

Loading…
Cancel
Save