diff --git a/source/net/filebot/ui/FileBotTabComponent.java b/source/net/filebot/ui/FileBotTabComponent.java index 2987d522..1fe10b7e 100644 --- a/source/net/filebot/ui/FileBotTabComponent.java +++ b/source/net/filebot/ui/FileBotTabComponent.java @@ -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"); diff --git a/source/net/filebot/ui/MainFrame.java b/source/net/filebot/ui/MainFrame.java index 5f274e80..4e1e33f5 100644 --- a/source/net/filebot/ui/MainFrame.java +++ b/source/net/filebot/ui/MainFrame.java @@ -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)); diff --git a/source/net/filebot/ui/ThemeSupport.java b/source/net/filebot/ui/ThemeSupport.java index fc590cb0..d18ad24a 100644 --- a/source/net/filebot/ui/ThemeSupport.java +++ b/source/net/filebot/ui/ThemeSupport.java @@ -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() { diff --git a/source/net/filebot/ui/filter/ExtractTool.java b/source/net/filebot/ui/filter/ExtractTool.java index 0e03d296..17e7557d 100644 --- a/source/net/filebot/ui/filter/ExtractTool.java +++ b/source/net/filebot/ui/filter/ExtractTool.java @@ -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 { 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"); diff --git a/source/net/filebot/ui/filter/SplitTool.java b/source/net/filebot/ui/filter/SplitTool.java index 1944995e..6daf5f01 100644 --- a/source/net/filebot/ui/filter/SplitTool.java +++ b/source/net/filebot/ui/filter/SplitTool.java @@ -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 { @@ -34,7 +32,7 @@ class SplitTool extends Tool { 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, "#")); diff --git a/source/net/filebot/ui/rename/BindingDialog.java b/source/net/filebot/ui/rename/BindingDialog.java index 14885323..6e712bae 100644 --- a/source/net/filebot/ui/rename/BindingDialog.java +++ b/source/net/filebot/ui/rename/BindingDialog.java @@ -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()); } } diff --git a/source/net/filebot/ui/rename/FormatDialog.java b/source/net/filebot/ui/rename/FormatDialog.java index 98723c11..b10b952b 100644 --- a/source/net/filebot/ui/rename/FormatDialog.java +++ b/source/net/filebot/ui/rename/FormatDialog.java @@ -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")); diff --git a/source/net/filebot/ui/rename/RenameListCellRenderer.java b/source/net/filebot/ui/rename/RenameListCellRenderer.java index 401fb08c..1ea0ce5e 100644 --- a/source/net/filebot/ui/rename/RenameListCellRenderer.java +++ b/source/net/filebot/ui/rename/RenameListCellRenderer.java @@ -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) { diff --git a/source/net/filebot/ui/sfv/ChecksumCellRenderer.java b/source/net/filebot/ui/sfv/ChecksumCellRenderer.java index 6bcd4791..9e194df1 100644 --- a/source/net/filebot/ui/sfv/ChecksumCellRenderer.java +++ b/source/net/filebot/ui/sfv/ChecksumCellRenderer.java @@ -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(); diff --git a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java index b637de8f..690804ed 100644 --- a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java @@ -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)); } } } diff --git a/source/net/filebot/util/ui/ListView.java b/source/net/filebot/util/ui/ListView.java index cbd822eb..b65b7d2c 100644 --- a/source/net/filebot/util/ui/ListView.java +++ b/source/net/filebot/util/ui/ListView.java @@ -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()); diff --git a/source/net/filebot/util/ui/LoadingOverlayPane.java b/source/net/filebot/util/ui/LoadingOverlayPane.java index 694b27a7..9ed682d4 100644 --- a/source/net/filebot/util/ui/LoadingOverlayPane.java +++ b/source/net/filebot/util/ui/LoadingOverlayPane.java @@ -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")); diff --git a/source/net/filebot/util/ui/ProgressIndicator.java b/source/net/filebot/util/ui/ProgressIndicator.java index 78595ddb..8ef336ee 100644 --- a/source/net/filebot/util/ui/ProgressIndicator.java +++ b/source/net/filebot/util/ui/ProgressIndicator.java @@ -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; } diff --git a/source/net/filebot/util/ui/RoundBorder.java b/source/net/filebot/util/ui/RoundBorder.java index 0edf9922..eb2cb2a8 100644 --- a/source/net/filebot/util/ui/RoundBorder.java +++ b/source/net/filebot/util/ui/RoundBorder.java @@ -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; diff --git a/source/net/filebot/util/ui/SwingUI.java b/source/net/filebot/util/ui/SwingUI.java index b73ad882..951b97f0 100644 --- a/source/net/filebot/util/ui/SwingUI.java +++ b/source/net/filebot/util/ui/SwingUI.java @@ -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()); }