Browse Source

Fixed too large windows when custom decorations are enabled.

Signed-off-by: weisj <weisj@arcor.de>
pull/44/head
weisj 5 years ago
parent
commit
99d6ec07e2
  1. 40
      core/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneBorder.java
  2. 12
      core/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneUI.java
  3. 15
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  4. 14
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java
  5. 2
      core/src/main/resources/com/github/weisj/darklaf/properties/ui/optionPane.properties

40
core/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneBorder.java

@ -0,0 +1,40 @@
/*
* 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.optionpane;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
public class DarkOptionPaneBorder extends EmptyBorder {
public DarkOptionPaneBorder() {
super(0, 0, 0, 0);
Insets insets = UIManager.getInsets("OptionPane.borderInsets");
left = insets.left;
right = insets.right;
top = insets.top;
bottom = insets.bottom;
}
}

12
core/src/main/java/com/github/weisj/darklaf/ui/optionpane/DarkOptionPaneUI.java

@ -39,8 +39,8 @@ public class DarkOptionPaneUI extends BasicOptionPaneUI {
} }
@Override @Override
protected void installDefaults() { protected LayoutManager createLayoutManager() {
super.installDefaults(); return super.createLayoutManager();
} }
@Override @Override
@ -52,10 +52,10 @@ public class DarkOptionPaneUI extends BasicOptionPaneUI {
bottom.setBorder(border); bottom.setBorder(border);
} }
bottom.setLayout(new DarkButtonAreaLayout( bottom.setLayout(new DarkButtonAreaLayout(
DefaultLookup.getBoolean(optionPane, this, "OptionPane.sameSizeButtons", false), DefaultLookup.getBoolean(optionPane, this, "OptionPane.sameSizeButtons", false),
DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding", 6), DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding", 6),
DefaultLookup.getInt(optionPane, this, "OptionPane.buttonOrientation", SwingConstants.CENTER), DefaultLookup.getInt(optionPane, this, "OptionPane.buttonOrientation", SwingConstants.CENTER),
DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast", false))); DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast", false)));
addButtonComponents(bottom, getButtons(), getInitialValueIndex()); addButtonComponents(bottom, getButtons(), getInitialValueIndex());
return bottom; return bottom;
} }

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

@ -139,7 +139,6 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
} }
private void installClientDecorations(final JRootPane root) { private void installClientDecorations(final JRootPane root) {
installBorder(root);
DarkTitlePane titlePane = createTitlePane(root); DarkTitlePane titlePane = createTitlePane(root);
setTitlePane(root, titlePane); setTitlePane(root, titlePane);
updateWindow(root.getParent()); updateWindow(root.getParent());
@ -155,15 +154,6 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
} }
} }
public void installBorder(final JRootPane root) {
int style = root.getWindowDecorationStyle();
if (style == JRootPane.NONE) {
LookAndFeel.uninstallBorder(root);
} else {
LookAndFeel.uninstallBorder(root);
}
}
protected DarkTitlePane createTitlePane(final JRootPane root) { protected DarkTitlePane createTitlePane(final JRootPane root) {
return new DarkTitlePane(root); return new DarkTitlePane(root);
} }
@ -198,13 +188,12 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
root.setLayout(layoutManager); root.setLayout(layoutManager);
} }
protected JComponent getTitlePane() { protected JComponent getTitlePane() {
return titlePane; return titlePane;
} }
protected LayoutManager createLayoutManager() { protected LayoutManager createLayoutManager() {
return new SubstanceRootLayout(); return new DarkSubstanceRootLayout();
} }
@Override @Override
@ -245,4 +234,4 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
uninstallClientDecorations(rootPane); uninstallClientDecorations(rootPane);
installClientDecorations(rootPane); installClientDecorations(rootPane);
} }
} }

14
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/SubstanceRootLayout.java → core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java

@ -23,6 +23,8 @@
*/ */
package com.github.weisj.darklaf.ui.rootpane; package com.github.weisj.darklaf.ui.rootpane;
import com.github.weisj.darklaf.util.DarkUIUtil;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -31,7 +33,7 @@ import java.awt.*;
* @author Konstantin Bulenkov * @author Konstantin Bulenkov
* @author Jannis Weis * @author Jannis Weis
*/ */
class SubstanceRootLayout implements LayoutManager2 { class DarkSubstanceRootLayout implements LayoutManager2 {
public void addLayoutComponent(final String name, final Component comp) { public void addLayoutComponent(final String name, final Component comp) {
} }
@ -47,6 +49,13 @@ class SubstanceRootLayout implements LayoutManager2 {
int tpWidth = 0; int tpWidth = 0;
int tpHeight = 0; int tpHeight = 0;
Insets i = parent.getInsets(); Insets i = parent.getInsets();
//Compensate for the insets of the native window peer that include the decorations.
Window window = DarkUIUtil.getWindow(parent);
Insets peerInsets = window != null ? window.getInsets() : new Insets(0, 0, 0, 0);
i.set(i.top - peerInsets.top, i.left - peerInsets.left,
i.bottom - peerInsets.bottom, i.right - peerInsets.right);
JRootPane root = (JRootPane) parent; JRootPane root = (JRootPane) parent;
if (root.getContentPane() != null) { if (root.getContentPane() != null) {
@ -79,8 +88,7 @@ class SubstanceRootLayout implements LayoutManager2 {
} }
} }
return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
+ i.left + i.right,
cpHeight + mbHeight + tpHeight + i.top + i.bottom); cpHeight + mbHeight + tpHeight + i.top + i.bottom);
} }

2
core/src/main/resources/com/github/weisj/darklaf/properties/ui/optionPane.properties

@ -23,11 +23,13 @@
# SOFTWARE. # SOFTWARE.
# #
OptionPaneUI = com.github.weisj.darklaf.ui.optionpane.DarkOptionPaneUI OptionPaneUI = com.github.weisj.darklaf.ui.optionpane.DarkOptionPaneUI
OptionPane.border = com.github.weisj.darklaf.ui.optionpane.DarkOptionPaneBorder
OptionPane.messageForeground = %textForeground OptionPane.messageForeground = %textForeground
OptionPane.buttonPadding = 5 OptionPane.buttonPadding = 5
#SwingConstants.CENTER #SwingConstants.CENTER
OptionPane.buttonOrientation = 0 OptionPane.buttonOrientation = 0
OptionPane.sameSizeButtons = false OptionPane.sameSizeButtons = false
OptionPane.borderInsets = 5,5,5,5
#Icons #Icons
OptionPane.informationIcon = dialog/informationDialog.svg[themed](32,32) OptionPane.informationIcon = dialog/informationDialog.svg[themed](32,32)

Loading…
Cancel
Save