Fix various Dark Mode issues

This commit is contained in:
Reinhard Pointner 2019-02-28 15:18:37 +07:00
parent 8aa798318a
commit 9dd8044097
15 changed files with 69 additions and 79 deletions

View File

@ -1,6 +1,7 @@
package net.filebot.ui;
import static net.filebot.ui.ThemeSupport.*;
import java.awt.Dimension;
@ -16,17 +17,15 @@ import net.filebot.util.ui.ProgressIndicator;
import net.filebot.util.ui.SwingUI;
import net.miginfocom.swing.MigLayout;
public class FileBotTabComponent extends JComponent {
private ProgressIndicator progressIndicator = new ProgressIndicator();
private ProgressIndicator progressIndicator = getProgressIndicator();
private JLabel textLabel = new JLabel();
private JLabel iconLabel = new JLabel();
private AbstractButton closeButton = createCloseButton();
private boolean loading = false;
public FileBotTabComponent() {
iconLabel.setHorizontalAlignment(SwingConstants.CENTER);
textLabel.setHorizontalAlignment(SwingConstants.LEFT);
@ -42,45 +41,37 @@ public class FileBotTabComponent extends JComponent {
add(closeButton, "gap unrel:push, hidemode 3, align center 45%");
}
public void setLoading(boolean loading) {
this.loading = loading;
progressIndicator.setVisible(loading);
iconLabel.setVisible(!loading);
}
public boolean isLoading() {
return loading;
}
public void setIcon(Icon icon) {
iconLabel.setIcon(icon);
progressIndicator.setPreferredSize(icon != null ? SwingUI.getDimension(icon) : progressIndicator.getMinimumSize());
}
public Icon getIcon() {
return iconLabel.getIcon();
}
public void setText(String text) {
textLabel.setText(text);
}
public String getText() {
return textLabel.getText();
}
public AbstractButton getCloseButton() {
return closeButton;
}
protected AbstractButton createCloseButton() {
Icon icon = ResourceManager.getIcon("tab.close");
Icon rolloverIcon = ResourceManager.getIcon("tab.close.hover");

View File

@ -11,7 +11,6 @@ import static net.filebot.Settings.*;
import static net.filebot.ui.ThemeSupport.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dialog.ModalExclusionType;
import java.awt.Dimension;
@ -253,7 +252,7 @@ public class MainFrame extends JFrame {
private static class PanelCellRenderer extends DefaultFancyListCellRenderer {
public PanelCellRenderer() {
super(10, 0, new Color(0x163264));
super(10, 0, getPanelSelectionBorderColor());
// center labels in list
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));

View File

@ -5,6 +5,7 @@ import static javax.swing.BorderFactory.*;
import static net.filebot.Logging.*;
import java.awt.Color;
import java.awt.Insets;
import java.awt.LinearGradientPaint;
import java.util.logging.Level;
@ -18,6 +19,8 @@ import com.bulenkov.iconloader.util.ColorUtil;
import net.filebot.util.SystemProperty;
import net.filebot.util.ui.GradientStyle;
import net.filebot.util.ui.ProgressIndicator;
import net.filebot.util.ui.RoundBorder;
import net.filebot.util.ui.SelectionPainter;
import net.filebot.util.ui.notification.SeparatorBorder;
import net.filebot.util.ui.notification.SeparatorBorder.Position;
@ -67,6 +70,22 @@ public class ThemeSupport {
return theme.getLinkSelectionForeground();
}
public static Color getActiveColor() {
return new Color(0x6495ED);// CornflowerBlue
}
public static Color getPassiveColor() {
return Color.gray;
}
public static Color getVerificationColor() {
return new Color(0x009900);
}
public static Color getPanelSelectionBorderColor() {
return new Color(0x163264);
}
public static LinearGradientPaint getPanelBackgroundGradient(int x, int y, int w, int h) {
float[] gradientFractions = { 0.0f, 0.5f, 1.0f };
Color[] gradientColors = { getColor(0xF6F6F6), getColor(0xF8F8F8), getColor(0xF3F3F3) };
@ -74,10 +93,26 @@ public class ThemeSupport {
return new LinearGradientPaint(x, y, w, h, gradientFractions, gradientColors);
}
public static SeparatorBorder getSeparatorBorder(Position position) {
public static Border getRoundBorder() {
return new RoundBorder(getColor(0xACACAC), 12, new Insets(1, 1, 1, 1));
}
public static Border getSeparatorBorder(Position position) {
return new SeparatorBorder(1, getColor(0xB4B4B4), getColor(0xACACAC), GradientStyle.LEFT_TO_RIGHT, position);
}
public static Border getHorizontalRule() {
return new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM);
}
public static ProgressIndicator getProgressIndicator() {
return new ProgressIndicator(Color.orange, withAlpha(getColor(0x000000), 0.25f));
}
public static Color withAlpha(Color color, float alpha) {
return new Color(((int) ((alpha * 255)) << 24) | (color.getRGB() & 0x00FFFFFF), true);
}
public enum Theme {
System {
@ -154,8 +189,8 @@ public class ThemeSupport {
}
};
public Color getColor(int rgba) {
return new Color(rgba);
public Color getColor(int rgb) {
return new Color(rgb);
}
public boolean isDark() {

View File

@ -6,7 +6,6 @@ import static net.filebot.ui.ThemeSupport.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.Color;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
@ -34,11 +33,9 @@ import net.filebot.archive.Archive;
import net.filebot.archive.FileMapper;
import net.filebot.cli.ConflictAction;
import net.filebot.util.FileUtilities;
import net.filebot.util.ui.GradientStyle;
import net.filebot.util.ui.LoadingOverlayPane;
import net.filebot.util.ui.ProgressMonitor;
import net.filebot.util.ui.ProgressMonitor.ProgressWorker;
import net.filebot.util.ui.notification.SeparatorBorder;
import net.filebot.vfs.FileInfo;
import net.filebot.vfs.SimpleFileInfo;
import net.miginfocom.swing.MigLayout;
@ -62,7 +59,7 @@ class ExtractTool extends Tool<TableModel> {
table.setRowHeight(25);
JScrollPane tableScrollPane = new JScrollPane(table);
tableScrollPane.setBorder(new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM));
tableScrollPane.setBorder(getHorizontalRule());
setLayout(new MigLayout("insets 0, nogrid, fill", "align center", "[fill][pref!]"));
add(new LoadingOverlayPane(tableScrollPane, this, "25px", "30px"), "grow, wrap");

View File

@ -1,9 +1,9 @@
package net.filebot.ui.filter;
import static java.util.Collections.*;
import static net.filebot.ui.ThemeSupport.*;
import static net.filebot.util.FileUtilities.*;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@ -19,9 +19,7 @@ import javax.swing.tree.TreeNode;
import net.filebot.ui.filter.FileTree.FolderNode;
import net.filebot.ui.transfer.DefaultTransferHandler;
import net.filebot.util.ui.GradientStyle;
import net.filebot.util.ui.LoadingOverlayPane;
import net.filebot.util.ui.notification.SeparatorBorder;
import net.miginfocom.swing.MigLayout;
class SplitTool extends Tool<TreeModel> {
@ -34,7 +32,7 @@ class SplitTool extends Tool<TreeModel> {
super("Parts");
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setBorder(new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM));
treeScrollPane.setBorder(getHorizontalRule());
JSpinner spinner = new JSpinner(spinnerModel);
spinner.setEditor(new JSpinner.NumberEditor(spinner, "#"));

View File

@ -10,7 +10,6 @@ import static net.filebot.util.JsonUtilities.*;
import static net.filebot.util.RegularExpressions.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Window;
import java.awt.event.ActionEvent;
@ -145,7 +144,7 @@ class BindingDialog extends JDialog {
// highlight cell
if (!isSelected) {
setForeground(new Color(0x6495ED)); // CornflowerBlue
setForeground(getActiveColor());
}
} catch (Exception e) {
// could not evaluate expression
@ -153,7 +152,7 @@ class BindingDialog extends JDialog {
// highlight cell
if (!isSelected) {
setForeground(Color.gray);
setForeground(getPassiveColor());
}
}

View File

@ -101,7 +101,7 @@ public class FormatDialog extends JDialog {
private JLabel status = new JLabel();
private FormatExpressionTextArea editor = new FormatExpressionTextArea();
private ProgressIndicator progressIndicator = new ProgressIndicator();
private ProgressIndicator progressIndicator = getProgressIndicator();
private JLabel title = new JLabel();
private JPanel help = new JPanel(new MigLayout("insets 0, nogrid, novisualpadding, fillx"));

View File

@ -1,7 +1,7 @@
package net.filebot.ui.rename;
import static net.filebot.ui.ThemeSupport.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.AlphaComposite;
import java.awt.Color;
@ -137,7 +137,7 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
if (renameModel.hasComplement(index)) {
setOpaque(true); // enable paint background
setBackground(derive(warningGradientBeginColor, (1 - matchProbablity) * 0.5f)); // alpha indicates match probability
setBackground(withAlpha(warningGradientBeginColor, (1 - matchProbablity) * 0.5f)); // alpha indicates match probability
if (matchProbablity < 1) {
if (isSelected) {

View File

@ -1,9 +1,9 @@
package net.filebot.ui.sfv;
import static java.awt.Font.*;
import static net.filebot.util.ui.SwingUI.*;
import static net.filebot.ui.ThemeSupport.*;
import static net.filebot.util.ExceptionUtilities.*;
import java.awt.Color;
import java.awt.Component;
@ -14,15 +14,11 @@ import javax.swing.SwingWorker;
import javax.swing.SwingWorker.StateValue;
import javax.swing.table.DefaultTableCellRenderer;
import net.filebot.util.ExceptionUtilities;
public class ChecksumCellRenderer extends DefaultTableCellRenderer {
private final SwingWorkerCellRenderer progressRenderer = new SwingWorkerCellRenderer();
private final Color verificationForeground = new Color(0x009900);
private final Color verificationForeground = getVerificationColor();
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
@ -52,17 +48,16 @@ public class ChecksumCellRenderer extends DefaultTableCellRenderer {
if (pendingWorker) {
setText("Pending...");
} else if (value == null && !isSelected) {
setBackground(derive(table.getGridColor(), 0.1f));
setBackground(withAlpha(table.getGridColor(), 0.1f));
} else if (value instanceof FileNotFoundException) {
setText("File not found");
} else if (value instanceof Throwable) {
setText(ExceptionUtilities.getRootCauseMessage((Throwable) value));
setText(getRootCauseMessage((Throwable) value));
}
return this;
}
private boolean isVerificationColumn(JTable table, int column) {
ChecksumTableModel model = (ChecksumTableModel) table.getModel();
int modelColumn = table.getColumnModel().getColumn(column).getModelIndex();

View File

@ -69,7 +69,6 @@ import net.filebot.util.ui.AbstractBean;
import net.filebot.util.ui.DashedSeparator;
import net.filebot.util.ui.EmptySelectionModel;
import net.filebot.util.ui.LinkButton;
import net.filebot.util.ui.RoundBorder;
import net.filebot.vfs.MemoryFile;
import net.filebot.web.SubtitleDescriptor;
import net.filebot.web.SubtitleProvider;
@ -80,6 +79,7 @@ class SubtitleAutoMatchDialog extends JDialog {
private static final Color hashMatchColor = new Color(0xFAFAD2); // LightGoldenRodYellow
private static final Color nameMatchColor = new Color(0xFFEBCD); // BlanchedAlmond
private final JPanel hashMatcherServicePanel = createServicePanel(hashMatchColor);
private final JPanel nameMatcherServicePanel = createServicePanel(nameMatchColor);
@ -112,7 +112,7 @@ class SubtitleAutoMatchDialog extends JDialog {
protected JPanel createServicePanel(Color color) {
JPanel panel = new JPanel(new MigLayout("hidemode 3, novisualpadding"));
panel.setBorder(new RoundBorder());
panel.setBorder(getRoundBorder());
panel.setOpaque(false);
panel.setBackground(color);
panel.setVisible(false);
@ -452,7 +452,7 @@ class SubtitleAutoMatchDialog extends JDialog {
}
if (f < 0.9f) {
setOpaque(true);
setBackground(derive(Color.RED, (1 - f) * 0.5f));
setBackground(withAlpha(Color.RED, (1 - f) * 0.5f));
}
}
}

View File

@ -1,6 +1,8 @@
package net.filebot.util.ui;
import static net.filebot.ui.ThemeSupport.*;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
@ -69,7 +71,7 @@ public class ListView extends JList {
}
protected void paintBlockSelection(Graphics2D g2d, Rectangle selection) {
g2d.setPaint(SwingUI.derive(getSelectionBackground(), 0.3f));
g2d.setPaint(withAlpha(getSelectionBackground(), 0.3f));
g2d.fill(selection);
g2d.setPaint(getSelectionBackground());

View File

@ -1,6 +1,8 @@
package net.filebot.util.ui;
import static net.filebot.ui.ThemeSupport.*;
import javax.swing.JComponent;
import net.miginfocom.swing.MigLayout;
@ -22,7 +24,7 @@ public class LoadingOverlayPane extends JComponent {
public LoadingOverlayPane(JComponent component, JComponent propertyChangeSource, String offsetX, String offsetY) {
setLayout(new MigLayout("insets 0, fill"));
animationComponent = new ProgressIndicator();
animationComponent = getProgressIndicator();
animationComponent.setVisible(false);
add(animationComponent, String.format("pos n %s 100%%-%s n", offsetY != null ? offsetY : "8px", offsetX != null ? offsetX : "20px"));

View File

@ -1,7 +1,6 @@
package net.filebot.util.ui;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
@ -20,7 +19,6 @@ import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
import javax.swing.Timer;
public class ProgressIndicator extends JComponent {
private float radius = 4.0f;
@ -29,9 +27,6 @@ public class ProgressIndicator extends JComponent {
private float strokeWidth = 2f;
private Stroke stroke = new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
private Color progressShapeColor = Color.orange;
private Color backgroundShapeColor = new Color(0f, 0f, 0f, 0.25f);
private final Rectangle2D frame = new Rectangle2D.Double();
private final Ellipse2D circle = new Ellipse2D.Double();
private final Dimension baseSize = new Dimension(32, 32);
@ -41,8 +36,13 @@ public class ProgressIndicator extends JComponent {
private Timer updateTimer;
private final Color progressShapeColor;
private final Color backgroundShapeColor;
public ProgressIndicator(Color progressShapeColor, Color backgroundShapeColor) {
this.progressShapeColor = progressShapeColor;
this.backgroundShapeColor = backgroundShapeColor;
public ProgressIndicator() {
setPreferredSize(baseSize);
addComponentListener(new ComponentAdapter() {
@ -52,7 +52,6 @@ public class ProgressIndicator extends JComponent {
startAnimation();
}
@Override
public void componentHidden(ComponentEvent e) {
stopAnimation();
@ -60,14 +59,12 @@ public class ProgressIndicator extends JComponent {
});
}
public void animateOnce() {
if ((alpha += (speed / 1000)) >= 1) {
alpha -= Math.floor(alpha);
}
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
@ -83,7 +80,6 @@ public class ProgressIndicator extends JComponent {
paintShapes(g2d);
}
private void paintShapes(Graphics2D g2d) {
circle.setFrame(frame);
@ -110,12 +106,10 @@ public class ProgressIndicator extends JComponent {
}
}
private double getTheta(double value, double max) {
return (value / max) * 2 * Math.PI;
}
public void startAnimation() {
if (updateTimer == null) {
updateTimer = new Timer(20, new ActionListener() {
@ -131,7 +125,6 @@ public class ProgressIndicator extends JComponent {
}
}
public void stopAnimation() {
if (updateTimer != null) {
updateTimer.stop();
@ -139,17 +132,14 @@ public class ProgressIndicator extends JComponent {
}
}
public void setShapeCount(int indeterminateShapeCount) {
this.shapeCount = indeterminateShapeCount;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public double getSpeed() {
return speed;
}

View File

@ -1,7 +1,6 @@
package net.filebot.util.ui;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
@ -11,34 +10,23 @@ import java.awt.RenderingHints;
import javax.swing.border.AbstractBorder;
public class RoundBorder extends AbstractBorder {
private final Color color;
private final Insets insets;
private final int arc;
public RoundBorder() {
this.color = new Color(0xACACAC);
this.arc = 12;
this.insets = new Insets(1, 1, 1, 1);
}
public RoundBorder(Color color, int arc, Insets insets) {
this.color = color;
this.arc = arc;
this.insets = insets;
}
@Override
public boolean isBorderOpaque() {
return false;
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D) g.create();
@ -53,13 +41,11 @@ public class RoundBorder extends AbstractBorder {
g2d.dispose();
}
@Override
public Insets getBorderInsets(Component c) {
return new Insets(insets.top, insets.left, insets.bottom, insets.right);
}
@Override
public Insets getBorderInsets(Component c, Insets insets) {
insets.top = this.insets.top;

View File

@ -126,10 +126,6 @@ public final class SwingUI {
return s;
}
public static Color derive(Color color, float alpha) {
return new Color(((int) ((alpha * 255)) << 24) | (color.getRGB() & 0x00FFFFFF), true);
}
public static String toHex(Color c) {
return c == null ? "inherit" : String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue());
}