Browse Source

Use MetalLookAndFeel to get labels in FileChooser

fixes #98
pull/97/head
Vladimir Sitnikov 5 years ago
parent
commit
11247747a8
  1. 52
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFileChooserUIBridge.java
  2. 13
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/DarkFilePaneUIBridge.java
  3. 32
      core/src/main/java/com/github/weisj/darklaf/ui/filechooser/MetalUIDefaults.java

52
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 com.github.weisj.darklaf.util.PropertyKey;
import sun.awt.shell.ShellFolder; import sun.awt.shell.ShellFolder;
import sun.swing.FilePane; import sun.swing.FilePane;
import sun.swing.SwingUtilities2;
import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleContext;
import javax.swing.*; import javax.swing.*;
@ -406,36 +405,45 @@ public class DarkFileChooserUIBridge extends BasicFileChooserUI {
Locale l = fc.getLocale(); Locale l = fc.getLocale();
lookInLabelMnemonic = getMnemonic("FileChooser.lookInLabelMnemonic", l); UIDefaults defaults = MetalUIDefaults.DEFAULTS;
lookInLabelText = UIManager.getString("FileChooser.lookInLabelText", l);
saveInLabelText = UIManager.getString("FileChooser.saveInLabelText", l);
fileNameLabelMnemonic = getMnemonic("FileChooser.fileNameLabelMnemonic", l); lookInLabelMnemonic = getMnemonic(defaults, "FileChooser.lookInLabelMnemonic", l);
fileNameLabelText = UIManager.getString("FileChooser.fileNameLabelText", l); lookInLabelText = defaults.getString("FileChooser.lookInLabelText", l);
folderNameLabelMnemonic = getMnemonic("FileChooser.folderNameLabelMnemonic", l); saveInLabelText = defaults.getString("FileChooser.saveInLabelText", l);
folderNameLabelText = UIManager.getString("FileChooser.folderNameLabelText", l);
filesOfTypeLabelMnemonic = getMnemonic("FileChooser.filesOfTypeLabelMnemonic", l); fileNameLabelMnemonic = getMnemonic(defaults, "FileChooser.fileNameLabelMnemonic", l);
filesOfTypeLabelText = UIManager.getString("FileChooser.filesOfTypeLabelText", 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); filesOfTypeLabelMnemonic = getMnemonic(defaults, "FileChooser.filesOfTypeLabelMnemonic", l);
upFolderAccessibleName = UIManager.getString("FileChooser.upFolderAccessibleName", l); filesOfTypeLabelText = defaults.getString("FileChooser.filesOfTypeLabelText", l);
homeFolderToolTipText = UIManager.getString("FileChooser.homeFolderToolTipText", l); upFolderToolTipText = defaults.getString("FileChooser.upFolderToolTipText", l);
homeFolderAccessibleName = UIManager.getString("FileChooser.homeFolderAccessibleName", l); upFolderAccessibleName = defaults.getString("FileChooser.upFolderAccessibleName", l);
newFolderToolTipText = UIManager.getString("FileChooser.newFolderToolTipText", l); homeFolderToolTipText = defaults.getString("FileChooser.homeFolderToolTipText", l);
newFolderAccessibleName = UIManager.getString("FileChooser.newFolderAccessibleName", l); homeFolderAccessibleName = defaults.getString("FileChooser.homeFolderAccessibleName", l);
listViewButtonToolTipText = UIManager.getString("FileChooser.listViewButtonToolTipText", l); newFolderToolTipText = defaults.getString("FileChooser.newFolderToolTipText", l);
listViewButtonAccessibleName = UIManager.getString("FileChooser.listViewButtonAccessibleName", l); newFolderAccessibleName = defaults.getString("FileChooser.newFolderAccessibleName", l);
detailsViewButtonToolTipText = UIManager.getString("FileChooser.detailsViewButtonToolTipText", l); listViewButtonToolTipText = defaults.getString("FileChooser.listViewButtonToolTipText", l);
detailsViewButtonAccessibleName = UIManager.getString("FileChooser.detailsViewButtonAccessibleName", 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) { protected Integer getMnemonic(UIDefaults defaults, final String key, final Locale l) {
return SwingUtilities2.getUIDefaultsInt(key, 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;
} }
/* /*

13
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"); readOnly = UIManager.getBoolean("FileChooser.readOnly");
// TUDU: On windows, get the following localized strings from the OS // TUDU: On windows, get the following localized strings from the OS
UIDefaults metal = MetalUIDefaults.DEFAULTS;
viewMenuLabelText = viewMenuLabelText =
UIManager.getString("FileChooser.viewMenuLabelText", l); metal.getString("FileChooser.viewMenuLabelText", l);
refreshActionLabelText = refreshActionLabelText =
UIManager.getString("FileChooser.refreshActionLabelText", l); metal.getString("FileChooser.refreshActionLabelText", l);
newFolderActionLabelText = newFolderActionLabelText =
UIManager.getString("FileChooser.newFolderActionLabelText", l); metal.getString("FileChooser.newFolderActionLabelText", l);
viewTypeActionNames = new String[VIEWTYPE_COUNT]; viewTypeActionNames = new String[VIEWTYPE_COUNT];
viewTypeActionNames[VIEWTYPE_LIST] = viewTypeActionNames[VIEWTYPE_LIST] =
UIManager.getString("FileChooser.listViewActionLabelText", l); metal.getString("FileChooser.listViewActionLabelText", l);
viewTypeActionNames[VIEWTYPE_DETAILS] = viewTypeActionNames[VIEWTYPE_DETAILS] =
UIManager.getString("FileChooser.detailsViewActionLabelText", l); metal.getString("FileChooser.detailsViewActionLabelText", l);
kiloByteString = UIManager.getString("FileChooser.fileSizeKiloBytes", l); kiloByteString = UIManager.getString("FileChooser.fileSizeKiloBytes", l);
megaByteString = UIManager.getString("FileChooser.fileSizeMegaBytes", l); megaByteString = UIManager.getString("FileChooser.fileSizeMegaBytes", l);
@ -682,7 +683,7 @@ public class DarkFilePaneUIBridge extends JPanel implements PropertyChangeListen
String title = dataItem.getTitle(); String title = dataItem.getTitle();
if (title != null && title.startsWith("FileChooser.") && title.endsWith("HeaderText")) { if (title != null && title.startsWith("FileChooser.") && title.endsWith("HeaderText")) {
// the column must have a string resource that we try to get // 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) { if (uiTitle != null) {
title = uiTitle; title = uiTitle;
} }

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