Refactor TextColorizer

This commit is contained in:
Reinhard Pointner 2016-04-13 12:34:01 +00:00
parent 4d87f4c456
commit af3c60eeef
3 changed files with 19 additions and 18 deletions

View File

@ -305,18 +305,14 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
if (header != null) {
html.append(escapeHTML(header)).append("<br>");
}
for (File file : sortByUniquePath(selection)) {
html.append("<nobr>");
html.append("");
TextColorizer colorizer = new TextColorizer("<nobr>• ", "</nobr><br>");
for (File file : sortByUniquePath(selection)) {
File path = getStructurePathTail(file);
if (path == null) {
path = getRelativePathTail(file, 3);
}
new TextColorizer().colorizePath(html, path, true);
html.append("</nobr>");
html.append("<br>");
colorizer.colorizePath(html, path, true);
}
if (selection.size() < files.size()) {
html.append("").append("").append("<br>");

View File

@ -256,17 +256,12 @@ class MovieMatcher implements AutoCompleteMatcher {
html.append(escapeHTML(header)).append("<br>");
}
html.append("<nobr>");
html.append("");
File path = getStructurePathTail(file);
if (path == null) {
path = getRelativePathTail(file, 3);
}
new TextColorizer().colorizePath(html, path, file.isFile());
html.append("</nobr>");
html.append("<br>");
TextColorizer colorizer = new TextColorizer("<nobr>• ", "</nobr><br>");
colorizer.colorizePath(html, path, file.isFile());
html.append("<br>");
if (message != null) {

View File

@ -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("<html><nobr>", "</nobr></html>");
}
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<File> path = listPath(file);
html.append(before);
// colorize parent path
List<File> 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);
}
}