diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java index aa36b132..159d9290 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java @@ -26,7 +26,6 @@ package com.github.weisj.darklaf.ui.filechooser; import com.github.weisj.darklaf.util.PropertyKey; import sun.awt.shell.ShellFolder; import sun.swing.FilePane; -import sun.swing.SwingUtilities2; import javax.accessibility.AccessibleContext; import javax.swing.*; @@ -406,36 +405,45 @@ public class DarkFileChooserUIBridge extends BasicFileChooserUI { Locale l = fc.getLocale(); - lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l); - lookInLabelText = UIManager.getString("FileChooser.lookInLabelText", l); - saveInLabelText = UIManager.getString("FileChooser.saveInLabelText", l); + UIDefaults defaults = MetalUIDefaults.DEFAULTS; - fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l); - fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText", l); - folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l); - folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText", l); + lookInLabelMnemonic = getMnemonic(defaults, "FileChooser.lookInLabelMnemonic", l); + lookInLabelText = defaults.getString("FileChooser.lookInLabelText", l); + saveInLabelText = defaults.getString("FileChooser.saveInLabelText", l); - filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l); - filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText", l); + fileNameLabelMnemonic = getMnemonic(defaults, "FileChooser.fileNameLabelMnemonic", l); + fileNameLabelText = defaults.getString("FileChooser.fileNameLabelText", l); + folderNameLabelMnemonic = getMnemonic(defaults, "FileChooser.folderNameLabelMnemonic", l); + folderNameLabelText = defaults.getString("FileChooser.folderNameLabelText", l); - upFolderToolTipText = UIManager.getString("FileChooser.upFolderToolTipText", l); - upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName", l); + filesOfTypeLabelMnemonic = getMnemonic(defaults, "FileChooser.filesOfTypeLabelMnemonic", l); + filesOfTypeLabelText = defaults.getString("FileChooser.filesOfTypeLabelText", l); - homeFolderToolTipText = UIManager.getString("FileChooser.homeFolderToolTipText", l); - homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName", l); + upFolderToolTipText = defaults.getString("FileChooser.upFolderToolTipText", l); + upFolderAccessibleName = defaults.getString("FileChooser.upFolderAccessibleName", l); - newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText", l); - newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName", l); + homeFolderToolTipText = defaults.getString("FileChooser.homeFolderToolTipText", l); + homeFolderAccessibleName = defaults.getString("FileChooser.homeFolderAccessibleName", l); - listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText", l); - listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName", l); + newFolderToolTipText = defaults.getString("FileChooser.newFolderToolTipText", l); + newFolderAccessibleName = defaults.getString("FileChooser.newFolderAccessibleName", l); - detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText", l); - detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName", l); + listViewButtonToolTipText = defaults.getString("FileChooser.listViewButtonToolTipText", l); + listViewButtonAccessibleName = defaults.getString("FileChooser.listViewButtonAccessibleName", l); + + detailsViewButtonToolTipText = defaults.getString("FileChooser.detailsViewButtonToolTipText", l); + detailsViewButtonAccessibleName = defaults.getString("FileChooser.detailsViewButtonAccessibleName", l); } - protected Integer getMnemonic(final String key, final Locale l) { - return SwingUtilities2.getUIDefaultsInt(key, l); + protected Integer getMnemonic(UIDefaults defaults, final String key, final Locale l) { + Object value = defaults.get(key, l); + if (value instanceof Integer) { + return (Integer) value; + } + if (value instanceof String) { + return Integer.parseInt((String) value); + } + return 0; } /* diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java index a2ccdff5..277483fc 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java @@ -459,19 +459,20 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen readOnly = UIManager.getBoolean("FileChooser.readOnly"); // TUDU: On windows, get the following localized strings from the OS + UIDefaults metal = MetalUIDefaults.DEFAULTS; viewMenuLabelText = - UIManager.getString("FileChooser.viewMenuLabelText", l); + metal.getString("FileChooser.viewMenuLabelText", l); refreshActionLabelText = - UIManager.getString("FileChooser.refreshActionLabelText", l); + metal.getString("FileChooser.refreshActionLabelText", l); newFolderActionLabelText = - UIManager.getString("FileChooser.newFolderActionLabelText", l); + metal.getString("FileChooser.newFolderActionLabelText", l); viewTypeActionNames = new String[VIEWTYPE_COUNT]; viewTypeActionNames[VIEWTYPE_LIST] = - UIManager.getString("FileChooser.listViewActionLabelText", l); + metal.getString("FileChooser.listViewActionLabelText", l); viewTypeActionNames[VIEWTYPE_DETAILS] = - UIManager.getString("FileChooser.detailsViewActionLabelText", l); + metal.getString("FileChooser.detailsViewActionLabelText", l); kiloByteString = UIManager.getString("FileChooser.fileSizeKiloBytes", l); megaByteString = UIManager.getString("FileChooser.fileSizeMegaBytes", l); @@ -682,7 +683,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen String title = dataItem.getTitle(); if (title != null && title.startsWith("FileChooser.") && title.endsWith("HeaderText")) { // the column must have a string resource that we try to get - String uiTitle = UIManager.getString(title, table.getLocale()); + String uiTitle = MetalUIDefaults.DEFAULTS.getString(title, table.getLocale()); if (uiTitle != null) { title = uiTitle; } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/MetalUIDefaults.java b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/MetalUIDefaults.java new file mode 100644 index 00000000..d15a03aa --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/filechooser/MetalUIDefaults.java @@ -0,0 +1,32 @@ +/* + * 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.filechooser; + +import javax.swing.*; +import javax.swing.plaf.metal.MetalLookAndFeel; + +// Extra class is for lazy initialization +class MetalUIDefaults { + static final UIDefaults DEFAULTS = new MetalLookAndFeel().getDefaults(); +}