Browse Source

Extract decorations related constants into interface

decorations
Jannis Weis 3 years ago
parent
commit
a1a55db222
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 2
      core/src/test/java/com/github/weisj/darklaf/core/test/CustomTitleBarTest.java
  2. 8
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java
  3. 30
      platform-base/src/main/java/com/github/weisj/darklaf/platform/DecorationsConstants.java
  4. 6
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/MenuBarStealer.java
  5. 38
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

2
core/src/test/java/com/github/weisj/darklaf/core/test/CustomTitleBarTest.java

@ -233,7 +233,7 @@ class CustomTitleBarTest extends AbstractImageTest implements NonThreadSafeTest
checkImage("title_bar_hidden_" + SystemInfo.getOsName(),
frame -> {
JRootPane rootPane = frame.getRootPane();
rootPane.putClientProperty(DarkRootPaneUI.HIDE_TITLEBAR, true);
rootPane.putClientProperty(DarkRootPaneUI.KEY_HIDE_TITLEBAR, true);
},
img -> assertScreenColorEquals(CONTENT_COLOR, new Color(img.getRGB(img.getWidth() / 2, TITLE_BAR_Y)),
"Titlebar isn't hidden"));

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

@ -138,7 +138,7 @@ public class MacOSTitlePane extends CustomTitlePane {
}
private boolean isUseColoredTitleBar(final JRootPane rootPane) {
return PropertyUtil.getBooleanProperty(rootPane, "JRootPane.coloredTitleBar", true);
return PropertyUtil.getBooleanProperty(rootPane, DecorationsConstants.KEY_COLORED_TITLE_BAR, true);
}
private String getTitle() {
@ -197,9 +197,9 @@ public class MacOSTitlePane extends CustomTitlePane {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if ("JRootPane.hideTitleBar".equals(evt.getPropertyName())) {
if (DecorationsConstants.KEY_HIDE_TITLEBAR.equals(evt.getPropertyName())) {
updateTitleBarVisibility();
} else if ("JRootPane.coloredTitleBar".equals(evt.getPropertyName())) {
} else if (DecorationsConstants.KEY_COLORED_TITLE_BAR.equals(evt.getPropertyName())) {
uninstall(false);
install();
}
@ -247,7 +247,7 @@ public class MacOSTitlePane extends CustomTitlePane {
private void updateTitleBarVisibility() {
titleBarHidden = PropertyUtil.getBooleanProperty(rootPane, "JRootPane.hideTitleBar");
titleBarHidden = PropertyUtil.getBooleanProperty(rootPane, DecorationsConstants.KEY_HIDE_TITLEBAR);
rootPane.doLayout();
rootPane.repaint();
}

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

@ -0,0 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2022 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.github.weisj.darklaf.platform;
public interface DecorationsConstants {
String KEY_HIDE_TITLEBAR = "JRootPane.hideTitleBar";
String KEY_NO_DECORATIONS_UPDATE = "JRootPane.noDecorationsUpdate";
String KEY_NO_DECORATIONS = "JRootPane.noDecorations";
String KEY_UNIFIED_MENUBAR = "JRootPane.unifiedMenuBar";
String KEY_COLORED_TITLE_BAR = "JRootPane.coloredTitleBar";
}

6
windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/MenuBarStealer.java

@ -20,8 +20,6 @@
*/
package com.github.weisj.darklaf.platform.windows.ui;
import com.github.weisj.darklaf.platform.DecorationsConstants;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.HierarchyEvent;
@ -32,6 +30,8 @@ import javax.swing.JLayeredPane;
import javax.swing.JMenuBar;
import javax.swing.JRootPane;
import com.github.weisj.darklaf.platform.DecorationsConstants;
public class MenuBarStealer {
private final JRootPane rootPane;
@ -93,7 +93,7 @@ public class MenuBarStealer {
}
private boolean isUnifiedMenuBarEnabled(final JComponent c) {
Object obj = c.getClientProperty("JRootPane.unifiedMenuBar");
Object obj = c.getClientProperty(DecorationsConstants.KEY_UNIFIED_MENUBAR);
if (!(obj instanceof Boolean) && obj != null) {
obj = Boolean.parseBoolean(obj.toString());
}

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

@ -33,7 +33,8 @@ import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import com.github.weisj.darklaf.platform.decorations.CustomTitlePane;
import com.github.weisj.darklaf.platform.CustomTitlePane;
import com.github.weisj.darklaf.platform.DecorationsConstants;
import com.github.weisj.darklaf.platform.windows.JNIDecorationsWindows;
import com.github.weisj.darklaf.platform.windows.PointerUtil;
import com.github.weisj.darklaf.util.LogUtil;
@ -117,7 +118,7 @@ public class WindowsTitlePane extends CustomTitlePane {
}
private void updateTitleBarVisibility() {
titleBarHidden = PropertyUtil.getBooleanProperty(rootPane, "JRootPane.hideTitleBar");
titleBarHidden = PropertyUtil.getBooleanProperty(rootPane, DecorationsConstants.KEY_HIDE_TITLEBAR);
rootPane.doLayout();
rootPane.repaint();
}
@ -656,9 +657,22 @@ public class WindowsTitlePane extends CustomTitlePane {
}
}
private class CloseAction extends AbstractAction {
private abstract class TitlePaneAction extends AbstractAction {
private TitlePaneAction(Icon icon, String... resourceNames) {
super("", icon);
for (String key : resourceNames) {
String value = UIManager.getString(key, getLocale());
if (value != null) {
putValue(AbstractAction.NAME, value);
return;
}
}
}
}
private class CloseAction extends TitlePaneAction {
public CloseAction() {
super(UIManager.getString("Actions.close", getLocale()), closeIcon);
super(closeIcon, "Actions.close", "InternalFrame.closeButtonToolTip");
}
@Override
@ -667,9 +681,9 @@ public class WindowsTitlePane extends CustomTitlePane {
}
}
private class MinimizeAction extends AbstractAction {
private class MinimizeAction extends TitlePaneAction {
public MinimizeAction() {
super(UIManager.getString("Actions.minimize", getLocale()), minimizeIcon);
super(minimizeIcon, "Actions.minimize", "InternalFrame.iconButtonToolTip");
}
@Override
@ -678,9 +692,9 @@ public class WindowsTitlePane extends CustomTitlePane {
}
}
private class MaximizeAction extends AbstractAction {
private class MaximizeAction extends TitlePaneAction {
public MaximizeAction() {
super(UIManager.getString("Actions.maximize", getLocale()), maximizeIcon);
super(maximizeIcon, "Actions.maximize", "InternalFrame.maxButtonToolTip");
}
@Override
@ -689,9 +703,9 @@ public class WindowsTitlePane extends CustomTitlePane {
}
}
private class RestoreAction extends AbstractAction {
private class RestoreAction extends TitlePaneAction {
public RestoreAction() {
super(UIManager.getString("Actions.restore", getLocale()), restoreIcon);
super(restoreIcon, "Actions.restore", "InternalFrame.restoreButtonToolTip");
}
@Override
@ -910,9 +924,9 @@ public class WindowsTitlePane extends CustomTitlePane {
@Override
public void propertyChange(final PropertyChangeEvent evt) {
if ("JRootPane.unifiedMenuBar".equals(evt.getPropertyName())) {
if (DecorationsConstants.KEY_UNIFIED_MENUBAR.equals(evt.getPropertyName())) {
menuBarStealer.updateMenuBar(true);
} else if ("JRootPane.hideTitleBar".equals(evt.getPropertyName())) {
} else if (DecorationsConstants.KEY_HIDE_TITLEBAR.equals(evt.getPropertyName())) {
updateTitleBarVisibility();
}
}

Loading…
Cancel
Save