diff --git a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java index f1cf9213..5e04984d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java +++ b/core/src/main/java/com/github/weisj/darklaf/DarkLaf.java @@ -28,6 +28,7 @@ import com.github.weisj.darklaf.platform.JNIDecorations; import com.github.weisj.darklaf.platform.SystemInfo; import com.github.weisj.darklaf.theme.Theme; import com.github.weisj.darklaf.ui.popupmenu.DarkPopupMenuUI; +import com.github.weisj.darklaf.util.ReflectiveWarningSuppressor; import sun.awt.AppContext; import javax.swing.*; @@ -65,8 +66,10 @@ public class DarkLaf extends BasicLookAndFeel implements PropertyChangeListener if (SystemInfo.isWindows || SystemInfo.isLinux) { base = new MetalLookAndFeel(); } else { - final String name = UIManager.getSystemLookAndFeelClassName(); - base = (BasicLookAndFeel) Class.forName(name).getDeclaredConstructor().newInstance(); + try (ReflectiveWarningSuppressor sup = new ReflectiveWarningSuppressor()) { + final String name = UIManager.getSystemLookAndFeelClassName(); + base = (BasicLookAndFeel) Class.forName(name).getDeclaredConstructor().newInstance(); + } } } catch (final Exception e) { LOGGER.log(Level.SEVERE, e.getMessage(), e.getStackTrace()); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java index bdfc6958..14b7528c 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java @@ -54,8 +54,8 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { public void installComponents(final JFileChooser fc) { FileSystemView fsv = fc.getFileSystemView(); - fc.setBorder(new EmptyBorder(12, 12, 11, 11)); - fc.setLayout(new BorderLayout(0, 11)); + fc.setBorder(new EmptyBorder(10, 10, 10, 10)); + fc.setLayout(new BorderLayout(0, 10)); filePane = new DarkFilePane(new MetalFileChooserUIAccessor()); fc.addPropertyChangeListener(filePane); @@ -65,7 +65,7 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { // ********************************* // // Directory manipulation buttons - JPanel topPanel = new JPanel(new BorderLayout(11, 0)); + JPanel topPanel = new JPanel(new BorderLayout(10, 0)); JPanel topButtonPanel = new JPanel(); topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS)); topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS); @@ -278,7 +278,7 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { filesOfTypePanel.add(filterComboBox); // buttons - getButtonPanel().setLayout(new ButtonAreaLayout()); + getButtonPanel().setLayout(new DarkButtonAreaLayout()); approveButton = new TooltipAwareButton(getApproveButtonText(fc)); // Note: Metal does not use mnemonics for approve and cancel @@ -297,4 +297,11 @@ public class DarkFileChooserUI extends DarkFileChooserUIBridge { groupLabels(new AlignedLabel[]{fileNameLabel, filesOfTypeLabel}); } + + protected static class DarkButtonAreaLayout extends ButtonAreaLayout { + + protected DarkButtonAreaLayout() { + topMargin = 10; + } + } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java index c2a37ef1..3716d112 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java @@ -23,7 +23,7 @@ */ package com.github.weisj.darklaf.ui.popupmenu; -import com.github.weisj.darklaf.util.ReflectionUtil; +import com.github.weisj.darklaf.util.ReflectiveWarningSuppressor; import sun.awt.AppContext; import sun.awt.SunToolkit; @@ -34,12 +34,7 @@ import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicPopupMenuUI; import java.applet.Applet; import java.awt.*; -import java.awt.event.AWTEventListener; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.MouseEvent; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; +import java.awt.event.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -100,9 +95,8 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { * implementation for it that is a bit more generous with closing the popup. */ private void removeOldMouseGrabber() { - Object oldLogger = ReflectionUtil.changeIllegalAccessLogger(null); AppContext context = AppContext.getAppContext(); - try { + try (ReflectiveWarningSuppressor sup = new ReflectiveWarningSuppressor()) { Field field = BasicPopupMenuUI.class.getDeclaredField("MOUSE_GRABBER_KEY"); field.setAccessible(true); Object value = field.get(null); @@ -115,8 +109,6 @@ public class DarkPopupMenuUI extends BasicPopupMenuUI { context.put(value, null); } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { e.printStackTrace(); - } finally { - ReflectionUtil.changeIllegalAccessLogger(oldLogger); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java b/core/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java index 4e05519d..659e5e3b 100644 --- a/core/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java @@ -53,4 +53,5 @@ public final class ReflectionUtil { } return null; } + } diff --git a/core/src/main/java/com/github/weisj/darklaf/util/ReflectiveWarningSuppressor.java b/core/src/main/java/com/github/weisj/darklaf/util/ReflectiveWarningSuppressor.java new file mode 100644 index 00000000..60760c64 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/util/ReflectiveWarningSuppressor.java @@ -0,0 +1,38 @@ +/* + * 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.util; + +public class ReflectiveWarningSuppressor implements AutoCloseable { + + private final Object oldLogger; + + public ReflectiveWarningSuppressor() { + oldLogger = ReflectionUtil.changeIllegalAccessLogger(null); + } + + @Override + public void close() { + ReflectionUtil.changeIllegalAccessLogger(oldLogger); + } +}