From af3c60eeef5e99ad531d49772478df4484e54b45 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 13 Apr 2016 12:34:01 +0000 Subject: [PATCH] Refactor TextColorizer --- .../filebot/ui/rename/EpisodeListMatcher.java | 10 +++------- source/net/filebot/ui/rename/MovieMatcher.java | 9 ++------- .../net/filebot/ui/rename/TextColorizer.java | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/source/net/filebot/ui/rename/EpisodeListMatcher.java b/source/net/filebot/ui/rename/EpisodeListMatcher.java index ca683343..a3d7ae7e 100644 --- a/source/net/filebot/ui/rename/EpisodeListMatcher.java +++ b/source/net/filebot/ui/rename/EpisodeListMatcher.java @@ -305,18 +305,14 @@ class EpisodeListMatcher implements AutoCompleteMatcher { if (header != null) { html.append(escapeHTML(header)).append("
"); } - for (File file : sortByUniquePath(selection)) { - html.append(""); - html.append("• "); + TextColorizer colorizer = new TextColorizer("• ", "
"); + for (File file : sortByUniquePath(selection)) { File path = getStructurePathTail(file); if (path == null) { path = getRelativePathTail(file, 3); } - - new TextColorizer().colorizePath(html, path, true); - html.append(""); - html.append("
"); + colorizer.colorizePath(html, path, true); } if (selection.size() < files.size()) { html.append("• ").append("…").append("
"); diff --git a/source/net/filebot/ui/rename/MovieMatcher.java b/source/net/filebot/ui/rename/MovieMatcher.java index 18880012..b6f5783b 100644 --- a/source/net/filebot/ui/rename/MovieMatcher.java +++ b/source/net/filebot/ui/rename/MovieMatcher.java @@ -256,17 +256,12 @@ class MovieMatcher implements AutoCompleteMatcher { html.append(escapeHTML(header)).append("
"); } - html.append(""); - html.append("• "); - File path = getStructurePathTail(file); if (path == null) { path = getRelativePathTail(file, 3); } - - new TextColorizer().colorizePath(html, path, file.isFile()); - html.append(""); - html.append("
"); + TextColorizer colorizer = new TextColorizer("• ", "
"); + colorizer.colorizePath(html, path, file.isFile()); html.append("
"); if (message != null) { diff --git a/source/net/filebot/ui/rename/TextColorizer.java b/source/net/filebot/ui/rename/TextColorizer.java index bdccd253..dceb5ab5 100644 --- a/source/net/filebot/ui/rename/TextColorizer.java +++ b/source/net/filebot/ui/rename/TextColorizer.java @@ -14,19 +14,29 @@ public class TextColorizer { private Color pathRainbowBeginColor; private Color pathRainbowEndColor; + private String before; + private String after; + public TextColorizer() { - this(new Color(0xCC3300), new Color(0x008080)); + this("", ""); } - public TextColorizer(Color pathRainbowBeginColor, Color pathRainbowEndColor) { + public TextColorizer(String before, String after) { + this(before, after, new Color(0xCC3300), new Color(0x008080)); + } + + public TextColorizer(String before, String after, Color pathRainbowBeginColor, Color pathRainbowEndColor) { + this.before = before; + this.after = after; this.pathRainbowBeginColor = pathRainbowBeginColor; this.pathRainbowEndColor = pathRainbowEndColor; } public StringBuilder colorizePath(StringBuilder html, File file, boolean hasExtension) { - List path = listPath(file); + html.append(before); // colorize parent path + List path = listPath(file); for (int i = 0; i < path.size() - 1; i++) { float f = (path.size() <= 2) ? 1 : (float) i / (path.size() - 2); Color c = interpolateHSB(pathRainbowBeginColor, pathRainbowEndColor, f); @@ -44,7 +54,7 @@ public class TextColorizer { html.append(file.getName()); } - return html; + return html.append(after); } }