Browse Source

Adjusted spacing in FileChooser.

Suppressed reflective warning on loadup.

Signed-off-by: weisj <weisj@arcor.de>
pull/60/head
weisj 5 years ago
parent
commit
691d9aec96
  1. 7
      core/src/main/java/com/github/weisj/darklaf/DarkLaf.java
  2. 15
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUI.java
  3. 14
      core/src/main/java/com/github/weisj/darklaf/ui/popupmenu/DarkPopupMenuUI.java
  4. 1
      core/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java
  5. 38
      core/src/main/java/com/github/weisj/darklaf/util/ReflectiveWarningSuppressor.java

7
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());

15
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;
}
}
}

14
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);
}
}

1
core/src/main/java/com/github/weisj/darklaf/util/ReflectionUtil.java

@ -53,4 +53,5 @@ public final class ReflectionUtil {
}
return null;
}
}

38
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);
}
}
Loading…
Cancel
Save