From 8854b6707df85a90c4753d473ecc7fc3186df787 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 28 Feb 2019 01:42:26 +0700 Subject: [PATCH] Fix various Dark Mode issues --- .../net/filebot/ui/AbstractSearchPanel.java | 2 +- source/net/filebot/ui/HistoryPanel.java | 5 +-- .../net/filebot/ui/SelectButtonTextField.java | 16 ++++++--- source/net/filebot/ui/ThemeSupport.java | 7 ++++ source/net/filebot/ui/list/ListPanel.java | 4 +-- source/net/filebot/ui/sfv/SfvPanel.java | 2 +- .../filebot/ui/subtitle/SimpleComboBox.java | 8 ++--- .../ui/subtitle/SubtitleAutoMatchDialog.java | 5 +-- .../ui/subtitle/SubtitleDropTarget.java | 15 +++++---- .../subtitle/SubtitlePackageCellRenderer.java | 5 +-- .../filebot/ui/subtitle/SubtitlePanel.java | 4 +-- .../filebot/ui/subtitle/SubtitleViewer.java | 2 +- .../subtitle/upload/SubtitleUploadDialog.java | 4 +-- .../util/ui/FancyTreeCellRenderer.java | 17 ++-------- source/net/filebot/util/ui/SelectButton.java | 9 ++--- .../net/filebot/util/ui/SelectionPainter.java | 33 +++++++++++++++++++ .../ui/notification/MessageNotification.java | 6 ++-- 17 files changed, 90 insertions(+), 54 deletions(-) create mode 100644 source/net/filebot/util/ui/SelectionPainter.java diff --git a/source/net/filebot/ui/AbstractSearchPanel.java b/source/net/filebot/ui/AbstractSearchPanel.java index b4567abf..3382f7a8 100644 --- a/source/net/filebot/ui/AbstractSearchPanel.java +++ b/source/net/filebot/ui/AbstractSearchPanel.java @@ -63,7 +63,7 @@ public abstract class AbstractSearchPanel extends JComponent { tabbedPaneGroup.setBorder(createTitledBorder("Search Results")); tabbedPaneGroup.add(tabbedPane, "grow, wrap"); - setLayout(new MigLayout("nogrid, novisualpadding, fill, insets 10px 10px 15px 10px", "align 45%", "[pref!]10px[fill]")); + setLayout(new MigLayout("nogrid, novisualpadding, fill, insets 10px 10px 15px 10px", "align 45%", "[center, pref!]10px[fill]")); add(searchTextField, "gap 0px:push"); add(new JButton(searchAction), "gap 16px, gap after 0px:push, h 2+pref!, id search, sgy button"); diff --git a/source/net/filebot/ui/HistoryPanel.java b/source/net/filebot/ui/HistoryPanel.java index af2362e2..2a68e5b8 100644 --- a/source/net/filebot/ui/HistoryPanel.java +++ b/source/net/filebot/ui/HistoryPanel.java @@ -1,6 +1,7 @@ package net.filebot.ui; -import java.awt.Color; +import static net.filebot.ui.ThemeSupport.*; + import java.awt.Font; import java.net.URI; import java.util.ArrayList; @@ -22,7 +23,7 @@ public class HistoryPanel extends JPanel { public HistoryPanel() { super(new MigLayout("fillx, insets 10 30 10 50, wrap 3")); - setBackground(Color.WHITE); + setBackground(getPanelBackground()); setOpaque(true); setupHeader(); diff --git a/source/net/filebot/ui/SelectButtonTextField.java b/source/net/filebot/ui/SelectButtonTextField.java index 1e670886..747c6570 100644 --- a/source/net/filebot/ui/SelectButtonTextField.java +++ b/source/net/filebot/ui/SelectButtonTextField.java @@ -1,8 +1,9 @@ package net.filebot.ui; import static javax.swing.BorderFactory.*; +import static net.filebot.Settings.*; +import static net.filebot.ui.ThemeSupport.*; -import java.awt.Color; import java.awt.Component; import java.awt.Rectangle; import java.awt.event.ActionEvent; @@ -24,13 +25,13 @@ import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import javax.swing.plaf.basic.BasicButtonUI; import javax.swing.plaf.basic.BasicComboBoxUI; import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.ComboPopup; import javax.swing.text.JTextComponent; import net.filebot.ResourceManager; -import net.filebot.Settings; import net.filebot.util.ui.SelectButton; import net.filebot.util.ui.SwingUI; import net.miginfocom.swing.MigLayout; @@ -141,15 +142,20 @@ public class SelectButtonTextField extends JComponent { public void configureArrowButton() { super.configureArrowButton(); - arrowButton.setBackground(Color.white); - arrowButton.setOpaque(true); + arrowButton.setUI(new BasicButtonUI()); + arrowButton.setBackground(getPanelBackground()); + arrowButton.setOpaque(false); arrowButton.setBorder(createEmptyBorder()); arrowButton.setContentAreaFilled(false); arrowButton.setFocusPainted(false); arrowButton.setFocusable(false); + if (getTheme().isDark()) { + arrowButton.setBorder(createEmptyBorder(0, 1, 0, 2)); + } + // fix Aqua UI - if (Settings.isMacApp()) { + if (isMacApp()) { arrowButton.setContentAreaFilled(true); } } diff --git a/source/net/filebot/ui/ThemeSupport.java b/source/net/filebot/ui/ThemeSupport.java index 4603958e..fc590cb0 100644 --- a/source/net/filebot/ui/ThemeSupport.java +++ b/source/net/filebot/ui/ThemeSupport.java @@ -18,6 +18,7 @@ import com.bulenkov.iconloader.util.ColorUtil; import net.filebot.util.SystemProperty; import net.filebot.util.ui.GradientStyle; +import net.filebot.util.ui.SelectionPainter; import net.filebot.util.ui.notification.SeparatorBorder; import net.filebot.util.ui.notification.SeparatorBorder.Position; @@ -107,6 +108,12 @@ public class ThemeSupport { UIManager.put("List.selectionBackground", selectionBackground); UIManager.put("ComboBox.selectionBackground", selectionBackground); UIManager.put("Table.selectionBackground", selectionBackground); + UIManager.put("Menu.selectionBackground", selectionBackground); + UIManager.put("MenuItem.selectionBackground", selectionBackground); + UIManager.put("MenuItem.selectedBackgroundPainter", new SelectionPainter(selectionBackground)); + UIManager.put("PopupMenu.selectionBackground", selectionBackground); + UIManager.put("Tree.selectionBackground", selectionBackground); + UIManager.put("Tree.selectionInactiveBackground", selectionBackground); UIManager.put("Table.background", componentBackground); UIManager.put("TabbedPane.selected", componentBackground); } diff --git a/source/net/filebot/ui/list/ListPanel.java b/source/net/filebot/ui/list/ListPanel.java index 339f8183..e000c72d 100644 --- a/source/net/filebot/ui/list/ListPanel.java +++ b/source/net/filebot/ui/list/ListPanel.java @@ -29,8 +29,6 @@ import javax.swing.SpinnerNumberModel; import javax.swing.TransferHandler; import javax.swing.border.Border; -import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; -import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rtextarea.RTextScrollPane; import com.google.common.eventbus.Subscribe; @@ -56,7 +54,7 @@ public class ListPanel extends JComponent { public static final String DEFAULT_FILE_FORMAT = "{fn}"; public static final String DEFAULT_EPISODE_FORMAT = "{n} - {s00e00} - [{absolute}] - [{airdate}] - {t}"; - private FormatExpressionTextArea editor = new FormatExpressionTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_GROOVY)); + private FormatExpressionTextArea editor = new FormatExpressionTextArea(); private SpinnerNumberModel fromSpinnerModel = new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1); private SpinnerNumberModel toSpinnerModel = new SpinnerNumberModel(20, 0, Integer.MAX_VALUE, 1); diff --git a/source/net/filebot/ui/sfv/SfvPanel.java b/source/net/filebot/ui/sfv/SfvPanel.java index 2c518a66..f64a96fa 100644 --- a/source/net/filebot/ui/sfv/SfvPanel.java +++ b/source/net/filebot/ui/sfv/SfvPanel.java @@ -54,7 +54,7 @@ public class SfvPanel extends JComponent { public SfvPanel() { table.setTransferHandler(new DefaultTransferHandler(transferablePolicy, exportHandler)); - JPanel contentPane = new JPanel(new MigLayout("insets 0, nogrid, novisualpadding, fill", "", "[fill]10px[bottom, pref!]4px")); + JPanel contentPane = new JPanel(new MigLayout("insets 0, nogrid, novisualpadding, fill", "", "[fill]10px[center, pref!]4px")); contentPane.setBorder(new TitledBorder("SFV")); setLayout(new MigLayout("insets dialog, fill")); diff --git a/source/net/filebot/ui/subtitle/SimpleComboBox.java b/source/net/filebot/ui/subtitle/SimpleComboBox.java index 20e5c1a8..19861ef5 100644 --- a/source/net/filebot/ui/subtitle/SimpleComboBox.java +++ b/source/net/filebot/ui/subtitle/SimpleComboBox.java @@ -1,8 +1,8 @@ package net.filebot.ui.subtitle; import static javax.swing.BorderFactory.*; +import static net.filebot.ui.ThemeSupport.*; -import java.awt.Color; import java.awt.Rectangle; import javax.swing.Icon; @@ -57,11 +57,11 @@ public class SimpleComboBox extends JComboBox { super.configurePopup(); setOpaque(true); - list.setBackground(Color.white); - setBackground(Color.white); + setBackground(getPanelBackground()); + list.setBackground(getBackground()); // use gray instead of black border for combobox popup - setBorder(createCompoundBorder(createLineBorder(Color.gray, 1), createEmptyBorder(1, 1, 1, 1))); + setBorder(createCompoundBorder(createLineBorder(getColor(0xEEEEEE), 1), createEmptyBorder(1, 1, 1, 1))); } }; } diff --git a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java index 3aba4876..b637de8f 100644 --- a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java @@ -5,6 +5,7 @@ import static javax.swing.JOptionPane.*; import static net.filebot.Logging.*; import static net.filebot.Settings.*; import static net.filebot.subtitle.SubtitleUtilities.*; +import static net.filebot.ui.ThemeSupport.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.ui.SwingUI.*; @@ -125,7 +126,7 @@ class SubtitleAutoMatchDialog extends JDialog { table.setRowHeight(24); table.setIntercellSpacing(new Dimension(5, 5)); - table.setBackground(Color.white); + table.setBackground(getPanelBackground()); table.setAutoCreateRowSorter(true); table.setFillsViewportHeight(true); @@ -359,7 +360,7 @@ class SubtitleAutoMatchDialog extends JDialog { private final JComboBox optionComboBox = new SimpleComboBox(ResourceManager.getIcon("action.select")); public SubtitleMappingOptionRenderer() { - optionComboBox.setBackground(Color.white); + optionComboBox.setBackground(getPanelBackground()); optionComboBox.setRenderer(new SubtitleOptionRenderer(false)); } diff --git a/source/net/filebot/ui/subtitle/SubtitleDropTarget.java b/source/net/filebot/ui/subtitle/SubtitleDropTarget.java index ab432a81..cee2e5f1 100644 --- a/source/net/filebot/ui/subtitle/SubtitleDropTarget.java +++ b/source/net/filebot/ui/subtitle/SubtitleDropTarget.java @@ -4,6 +4,7 @@ import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import static net.filebot.Settings.*; import static net.filebot.UserFiles.*; +import static net.filebot.ui.ThemeSupport.*; import static net.filebot.ui.transfer.FileTransferable.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.ui.SwingUI.*; @@ -56,12 +57,16 @@ abstract class SubtitleDropTarget extends JButton { public SubtitleDropTarget() { setHorizontalAlignment(CENTER); + setHorizontalTextPosition(CENTER); + setVerticalAlignment(CENTER); + setVerticalTextPosition(TOP); + setIconTextGap(0); setHideActionText(true); setContentAreaFilled(false); setFocusPainted(false); setBorderPainted(false); - setBackground(Color.white); + setBackground(getPanelBackground()); // initialize with default mode setDropAction(DropAction.Accept); @@ -74,18 +79,14 @@ abstract class SubtitleDropTarget extends JButton { new DropTarget(this, dropHandler); } - private Color lineColor = new Color(0xD7D7D7); + private Color lineColor = getColor(0xD7D7D7); @Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - float w = getWidth(); - float h = getHeight(); - float d = Math.min(w, h) - 1f; - - Shape shape = new Ellipse2D.Float((w - d) / 2, (h - d) / 2, d - 1, d - 1); + Shape shape = new Ellipse2D.Float(0, 0, getWidth() - 1, getHeight() - 1); g2d.setColor(getBackground()); g2d.fill(shape); diff --git a/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java b/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java index 86f4ac1d..dcaf70cc 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java +++ b/source/net/filebot/ui/subtitle/SubtitlePackageCellRenderer.java @@ -1,7 +1,8 @@ package net.filebot.ui.subtitle; -import java.awt.Color; +import static net.filebot.ui.ThemeSupport.*; + import java.awt.Insets; import javax.swing.Icon; @@ -29,7 +30,7 @@ class SubtitlePackageCellRenderer extends AbstractFancyListCellRenderer { add(languageLabel, "hidemode 3, w 85px!"); add(titleLabel); - setBorder(new CompoundBorder(new DashedSeparator(2, 4, Color.lightGray, Color.white), getBorder())); + setBorder(new CompoundBorder(new DashedSeparator(2, 4, getColor(0xEEEEEE), getPanelBackground()), getBorder())); } @Override diff --git a/source/net/filebot/ui/subtitle/SubtitlePanel.java b/source/net/filebot/ui/subtitle/SubtitlePanel.java index 76959fef..952baa02 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePanel.java +++ b/source/net/filebot/ui/subtitle/SubtitlePanel.java @@ -67,11 +67,11 @@ public class SubtitlePanel extends AbstractSearchPanel extends JButton { public static final String SELECTED_VALUE = "selected value"; - private final Color beginColor = new Color(0xF0EEE4); - private final Color endColor = new Color(0xE0DED4); + private final Color beginColor = getColor(0xF0EEE4); + private final Color endColor = getColor(0xE0DED4); private final Color beginColorHover = beginColor; - private final Color endColorHover = new Color(0xD8D7CD); + private final Color endColorHover = getColor(0xD8D7CD); private final SelectIcon selectIcon = new SelectIcon(); @@ -56,7 +57,7 @@ public class SelectButton extends JButton { setHorizontalAlignment(SwingConstants.CENTER); setVerticalAlignment(SwingConstants.CENTER); - setBorder(createLineBorder(new Color(0xA4A4A4), 1)); + setBorder(createLineBorder(getColor(0xA4A4A4), 1)); setPreferredSize(new Dimension(32, 22)); addActionListener(new OpenPopupOnClick()); diff --git a/source/net/filebot/util/ui/SelectionPainter.java b/source/net/filebot/util/ui/SelectionPainter.java new file mode 100644 index 00000000..2d4f725c --- /dev/null +++ b/source/net/filebot/util/ui/SelectionPainter.java @@ -0,0 +1,33 @@ +package net.filebot.util.ui; + +import java.awt.Color; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Insets; + +import javax.swing.border.Border; + +public class SelectionPainter implements Border { + + private Color color; + + public SelectionPainter(Color color) { + this.color = color; + } + + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + g.setColor(color); + g.fillRect(x, y, width, height); + } + + @Override + public boolean isBorderOpaque() { + return true; + } + + @Override + public Insets getBorderInsets(Component c) { + return new Insets(0, 0, 0, 0); + } +} \ No newline at end of file diff --git a/source/net/filebot/util/ui/notification/MessageNotification.java b/source/net/filebot/util/ui/notification/MessageNotification.java index e4a35766..c4dd51dd 100644 --- a/source/net/filebot/util/ui/notification/MessageNotification.java +++ b/source/net/filebot/util/ui/notification/MessageNotification.java @@ -5,10 +5,10 @@ package net.filebot.util.ui.notification; import static javax.swing.BorderFactory.*; +import static net.filebot.ui.ThemeSupport.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Cursor; import java.awt.Font; import java.awt.Window; @@ -34,7 +34,7 @@ public class MessageNotification extends NotificationWindow { private int margin = 10; private Border marginBorder = createEmptyBorder(margin, margin, margin, margin); - private Border border = createCompoundBorder(createEtchedBorder(new Color(245, 155, 15), Color.WHITE), marginBorder); + private Border border = createCompoundBorder(createEtchedBorder(getColor(0xF59B0F), getPanelBackground()), marginBorder); private JLabel headLabel; private JTextPane textArea; @@ -46,7 +46,7 @@ public class MessageNotification extends NotificationWindow { JComponent c = (JComponent) getContentPane(); c.setLayout(new BorderLayout(5, 2)); - c.setBackground(Color.WHITE); + c.setBackground(getPanelBackground()); c.setBorder(border); JPanel textPanel = new JPanel(new BorderLayout());