Add blank thumbnail if poster is not available

This commit is contained in:
Reinhard Pointner 2019-05-05 04:47:13 +07:00
parent b73c634645
commit 27095c51d0
2 changed files with 67 additions and 7 deletions

View File

@ -0,0 +1,60 @@
package net.filebot.ui.rename;
import static net.filebot.ui.ThemeSupport.*;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import javax.swing.Icon;
public class BlankThumbnail implements Icon {
public static final BlankThumbnail BLANK_POSTER = new BlankThumbnail(48, 48, getColor(0xF8F8FF), getPanelSelectionBorderColor(), 0.68f, 1f);
private int width;
private int height;
private Paint fill;
private Paint draw;
private float squeezeX;
private float squeezeY;
public BlankThumbnail(int width, int height, Paint fill, Paint draw, float squeezeX, float squeezeY) {
this.width = width;
this.height = height;
this.fill = fill;
this.draw = draw;
this.squeezeX = squeezeX;
this.squeezeY = squeezeY;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g;
int w = (int) (width * squeezeX);
int h = (int) (height * squeezeY);
x = (int) (x + (width - w) / 2);
y = (int) (y + (width - h) / 2);
g2d.setPaint(fill);
g2d.fillRect(x, y, w, h);
g2d.setPaint(draw);
g2d.drawRect(x, y, w, h);
}
@Override
public int getIconWidth() {
return width;
}
@Override
public int getIconHeight() {
return height;
}
}

View File

@ -4,6 +4,7 @@ import static java.util.Collections.*;
import static java.util.Comparator.*;
import static java.util.stream.Collectors.*;
import static javax.swing.BorderFactory.*;
import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.Settings.*;
import static net.filebot.WebServices.*;
@ -31,6 +32,7 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.prefs.Preferences;
import java.util.regex.Pattern;
@ -39,9 +41,6 @@ import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import com.bulenkov.iconloader.util.CenteredIcon;
import com.bulenkov.iconloader.util.EmptyIcon;
import net.filebot.Cache;
import net.filebot.Cache.TypedCache;
import net.filebot.CacheType;
@ -302,17 +301,18 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
Map<SearchResult, Icon> icons = new HashMap<>(ids.length);
for (int i = 0; i < ids.length; i++) {
if (thumbnails[i].length > 0) {
icons.put(options.get(i), new CenteredIcon(new ImageIcon(thumbnails[i]), 48, 48, false));
if (thumbnails[i] != null && thumbnails[i].length > 0) {
icons.put(options.get(i), new ImageIcon(thumbnails[i]));
} else {
icons.put(options.get(i), new EmptyIcon(48, 48));
icons.put(options.get(i), BlankThumbnail.BLANK_POSTER);
}
}
if (icons.size() > 0) {
return icons;
}
} catch (Exception e) {
e.printStackTrace();
debug.log(Level.SEVERE, e, e::toString);
}
}
return null;