Browse Source

Fixed window background not changing when theme is swapped on windows.

Added borders for root pane. Allows for high contrast borders.
pull/139/head
weisj 5 years ago
parent
commit
eb73afdc30
  1. 36
      core/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java
  2. 43
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneBorder.java
  3. 24
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  4. 20
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/rootPane.properties
  5. 1
      theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_dark/high_contrast_dark_ui.properties
  6. 1
      theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_light/high_contrast_light_ui.properties
  7. 3
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/ui/WindowsTitlePane.java

36
core/src/main/java/com/github/weisj/darklaf/components/border/MutableLineBorder.java

@ -37,6 +37,9 @@ public class MutableLineBorder extends AbstractBorder {
protected int right; protected int right;
protected int bottom; protected int bottom;
public MutableLineBorder(final Insets insets, final Color color) {
this(insets.top, insets.left, insets.bottom, insets.right, color);
}
public MutableLineBorder( public MutableLineBorder(
final int top, final int left, final int bottom, final int right, final Color color) { final int top, final int left, final int bottom, final int right, final Color color) {
@ -51,10 +54,10 @@ public class MutableLineBorder extends AbstractBorder {
public void paintBorder(final Component c, final Graphics g, final int x, final int y, public void paintBorder(final Component c, final Graphics g, final int x, final int y,
final int width, final int height) { final int width, final int height) {
g.setColor(getColor()); g.setColor(getColor());
g.fillRect(x, y, width - right, top); g.fillRect(x, y, width - getRight(), getTop());
g.fillRect(x, y + top, left, height - top); g.fillRect(x, y + getTop(), getLeft(), height - getTop());
g.fillRect(x + left, y + height - bottom, width - left, bottom); g.fillRect(x + getLeft(), y + height - getBottom(), width - getLeft(), getBottom());
g.fillRect(x + width - right, y, right, height - bottom); g.fillRect(x + width - getRight(), y, getRight(), height - getBottom());
} }
@Override @Override
@ -79,17 +82,32 @@ public class MutableLineBorder extends AbstractBorder {
@Override @Override
public Insets getBorderInsets(final Component c, final Insets insets) { public Insets getBorderInsets(final Component c, final Insets insets) {
insets.left = left; insets.left = getRight();
insets.top = top; insets.top = getTop();
insets.right = right; insets.right = getRight();
insets.bottom = bottom; insets.bottom = getBottom();
return insets; return insets;
} }
public Insets getBorderInsets() { public Insets getBorderInsets() {
return new Insets(top, left, bottom, right); return getBorderInsets(null, new Insets(0, 0, 0, 0));
}
public int getTop() {
return top;
}
public int getBottom() {
return bottom;
}
public int getLeft() {
return left;
} }
public int getRight() {
return right;
}
public void setTop(final int top) { public void setTop(final int top) {
this.top = top; this.top = top;

43
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneBorder.java

@ -0,0 +1,43 @@
/*
* MIT License
*
* Copyright (c) 2020 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.ui.rootpane;
import com.github.weisj.darklaf.components.border.MutableLineBorder;
import com.github.weisj.darklaf.platform.DecorationsHandler;
import javax.swing.*;
import javax.swing.plaf.UIResource;
public class DarkRootPaneBorder extends MutableLineBorder implements UIResource {
public DarkRootPaneBorder() {
super(UIManager.getInsets("RootPane.borderInsets"), UIManager.getColor("RootPane.borderColor"));
}
@Override
public int getTop() {
return DecorationsHandler.getSharedInstance().isCustomDecorationSupported()
? super.getTop() : 0;
}
}

24
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java

@ -49,6 +49,14 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
protected static final String KEY_PREFIX = "JRootPane."; protected static final String KEY_PREFIX = "JRootPane.";
public static final String KEY_NO_DECORATIONS_UPDATE = KEY_PREFIX + "noDecorationsUpdate"; public static final String KEY_NO_DECORATIONS_UPDATE = KEY_PREFIX + "noDecorationsUpdate";
public static final String KEY_NO_DECORATIONS = KEY_PREFIX + "noDecorations"; public static final String KEY_NO_DECORATIONS = KEY_PREFIX + "noDecorations";
protected static final String[] borderKeys = new String[]{
"RootPane.border", "RootPane.frameBorder", "RootPane.plainDialogBorder",
"RootPane.informationDialogBorder",
"RootPane.errorDialogBorder", "RootPane.colorChooserDialogBorder",
"RootPane.fileChooserDialogBorder", "RootPane.questionDialogBorder",
"RootPane.warningDialogBorder"
};
private Window window; private Window window;
private CustomTitlePane titlePane; private CustomTitlePane titlePane;
private LayoutManager layoutManager; private LayoutManager layoutManager;
@ -69,17 +77,28 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
super.installUI(c); super.installUI(c);
rootPane = (JRootPane) c; rootPane = (JRootPane) c;
windowDecorationsStyle = rootPane.getWindowDecorationStyle(); windowDecorationsStyle = rootPane.getWindowDecorationStyle();
LookAndFeel.installColors(rootPane, "RootPane.background", "RootPane.foreground");
updateClientDecoration(); updateClientDecoration();
installBorder(rootPane);
}
protected void installBorder(final JRootPane root) {
LookAndFeel.installBorder(root, borderKeys[windowDecorationsStyle]);
} }
@Override @Override
public void uninstallUI(final JComponent c) { public void uninstallUI(final JComponent c) {
super.uninstallUI(c); super.uninstallUI(c);
uninstallClientDecorations(rootPane); uninstallClientDecorations(rootPane);
uninstallBorder(rootPane);
layoutManager = null; layoutManager = null;
rootPane = null; rootPane = null;
} }
private static void uninstallBorder(final JRootPane root) {
LookAndFeel.uninstallBorder(root);
}
@Override @Override
public void propertyChange(final PropertyChangeEvent e) { public void propertyChange(final PropertyChangeEvent e) {
super.propertyChange(e); super.propertyChange(e);
@ -89,6 +108,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
windowDecorationsStyle = decorationsStyleFromWindow(window, rootPane.getWindowDecorationStyle()); windowDecorationsStyle = decorationsStyleFromWindow(window, rootPane.getWindowDecorationStyle());
if (window instanceof JDialog) updateClientDecoration(); if (window instanceof JDialog) updateClientDecoration();
if (titlePane != null) titlePane.setDecorationsStyle(windowDecorationsStyle); if (titlePane != null) titlePane.setDecorationsStyle(windowDecorationsStyle);
installBorder(rootPane);
if (windowDecorationsStyle == JRootPane.PLAIN_DIALOG) { if (windowDecorationsStyle == JRootPane.PLAIN_DIALOG) {
/* /*
* Otherwise, the property change doesn't get fired when the dialog is a plain dialog. * Otherwise, the property change doesn't get fired when the dialog is a plain dialog.
@ -133,10 +153,6 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
window = null; window = null;
} }
private static void uninstallBorder(final JRootPane root) {
LookAndFeel.uninstallBorder(root);
}
private void uninstallLayout(final JRootPane root) { private void uninstallLayout(final JRootPane root) {
if (oldLayout != null) { if (oldLayout != null) {
root.setLayout(oldLayout); root.setLayout(oldLayout);

20
core/src/main/resources/com/github/weisj/darklaf/properties/ui/rootPane.properties

@ -23,14 +23,16 @@
# SOFTWARE. # SOFTWARE.
# #
RootPaneUI = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneUI RootPaneUI = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneUI
RootPane.background = %backgroundContainer
RootPane.frameBorder = null RootPane.borderInsets = 0,0,0,0
RootPane.informationDialogBorder = null RootPane.borderColor = %border
RootPane.plainDialogBorder = null RootPane.border = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.warningDialogBorder = null RootPane.frameBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.colorChooserDialogBorder = null RootPane.informationDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.fileChooserDialogBorder = null RootPane.plainDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.questionDialogBorder = null RootPane.warningDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.errorDialogBorder = null RootPane.colorChooserDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.fileChooserDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.questionDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder
RootPane.errorDialogBorder = com.github.weisj.darklaf.ui.rootpane.DarkRootPaneBorder

1
theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_dark/high_contrast_dark_ui.properties

@ -27,3 +27,4 @@ Button.borderless.drawOutline = true
TabbedPane.selectedHoverBackground = %backgroundHover TabbedPane.selectedHoverBackground = %backgroundHover
ToolTip.paintShadow = false ToolTip.paintShadow = false
ScrollBar.fadeEndColor = %ScrollBar.fadeStartColor ScrollBar.fadeEndColor = %ScrollBar.fadeStartColor
RootPane.borderInsets = 1,1,1,1

1
theme/src/main/resources/com/github/weisj/darklaf/theme/high_contrast_light/high_contrast_light_ui.properties

@ -30,3 +30,4 @@ TabbedPane.selectedHoverBackground = %backgroundHover
TabFrameTab.selectedForeground = %textSelectionForeground TabFrameTab.selectedForeground = %textSelectionForeground
TabFrameTab.hoverForeground = %textSelectionForeground TabFrameTab.hoverForeground = %textSelectionForeground
ScrollBar.fadeEndColor = %ScrollBar.fadeStartColor ScrollBar.fadeEndColor = %ScrollBar.fadeStartColor
RootPane.borderInsets = 1,1,1,1

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

@ -228,7 +228,7 @@ public class WindowsTitlePane extends CustomTitlePane {
if (windowHandle != 0) { if (windowHandle != 0) {
JNIDecorationsWindows.installDecorations(windowHandle); JNIDecorationsWindows.installDecorations(windowHandle);
updateResizeBehaviour(); updateResizeBehaviour();
Color color = window.getBackground(); Color color = rootPane.getBackground();
JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue()); JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
} else { } else {
uninstall(); uninstall();
@ -794,6 +794,7 @@ public class WindowsTitlePane extends CustomTitlePane {
repaint(); repaint();
} else if (PropertyKey.BACKGROUND.equals(name) && pce.getNewValue() instanceof Color) { } else if (PropertyKey.BACKGROUND.equals(name) && pce.getNewValue() instanceof Color) {
Color color = (Color) pce.getNewValue(); Color color = (Color) pce.getNewValue();
System.out.println(color);
if (color == null) return; if (color == null) return;
JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue()); JNIDecorationsWindows.setBackground(windowHandle, color.getRed(), color.getGreen(), color.getBlue());
} }

Loading…
Cancel
Save