Refactor
This commit is contained in:
parent
ef71e2fff8
commit
4d6f4032b8
|
@ -1,6 +1,5 @@
|
||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static java.util.regex.Pattern.*;
|
import static java.util.regex.Pattern.*;
|
||||||
|
@ -161,7 +160,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1:SxE && Title, 2:SxE
|
// 1:SxE && Title, 2:SxE
|
||||||
return (float) ((max(sxe, 0) * title) + (floor(sxe) / 10));
|
return (float) ((Math.max(sxe, 0) * title) + (Math.floor(sxe) / 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getTitle(Object o) {
|
public Object getTitle(Object o) {
|
||||||
|
@ -191,7 +190,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
sum /= f1.length * f2.length;
|
sum /= f1.length * f2.length;
|
||||||
|
|
||||||
// normalize into 3 similarity levels
|
// normalize into 3 similarity levels
|
||||||
return (float) (ceil(sum * 3) / 3);
|
return (float) (Math.ceil(sum * 3) / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String[] normalize(Object[] objects) {
|
protected String[] normalize(Object[] objects) {
|
||||||
|
@ -244,13 +243,13 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
float max = 0;
|
float max = 0;
|
||||||
for (String s1 : f1) {
|
for (String s1 : f1) {
|
||||||
for (String s2 : f2) {
|
for (String s2 : f2) {
|
||||||
max = max(super.getSimilarity(s1, s2), max);
|
max = Math.max(super.getSimilarity(s1, s2), max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize absolute similarity to similarity rank (4 ranks in total),
|
// normalize absolute similarity to similarity rank (4 ranks in total),
|
||||||
// so we are less likely to fall for false positives in this pass, and move on to the next one
|
// so we are less likely to fall for false positives in this pass, and move on to the next one
|
||||||
return (float) (floor(max * 4) / 4);
|
return (float) (Math.floor(max * 4) / 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -287,7 +286,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
public float getSimilarity(Object o1, Object o2) {
|
public float getSimilarity(Object o1, Object o2) {
|
||||||
// normalize absolute similarity to similarity rank (4 ranks in total),
|
// normalize absolute similarity to similarity rank (4 ranks in total),
|
||||||
// so we are less likely to fall for false positives in this pass, and move on to the next one
|
// so we are less likely to fall for false positives in this pass, and move on to the next one
|
||||||
return (float) (floor(super.getSimilarity(o1, o2) * 4) / 4);
|
return (float) (Math.floor(super.getSimilarity(o1, o2) * 4) / 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -311,13 +310,13 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
float max = 0;
|
float max = 0;
|
||||||
for (String s1 : f1) {
|
for (String s1 : f1) {
|
||||||
for (String s2 : f2) {
|
for (String s2 : f2) {
|
||||||
max = max(super.getSimilarity(s1, s2), max);
|
max = Math.max(super.getSimilarity(s1, s2), max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalize absolute similarity to similarity rank (4 ranks in total),
|
// normalize absolute similarity to similarity rank (4 ranks in total),
|
||||||
// so we are less likely to fall for false positives in this pass, and move on to the next one
|
// so we are less likely to fall for false positives in this pass, and move on to the next one
|
||||||
return (float) (floor(max * 4) / 4);
|
return (float) (Math.floor(max * 4) / 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -395,11 +394,11 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
s1 = stripReleaseInfo(s1, false);
|
s1 = stripReleaseInfo(s1, false);
|
||||||
s2 = stripReleaseInfo(s2, false);
|
s2 = stripReleaseInfo(s2, false);
|
||||||
|
|
||||||
int length = min(s1.length(), s2.length());
|
int length = Math.min(s1.length(), s2.length());
|
||||||
s1 = s1.substring(0, length);
|
s1 = s1.substring(0, length);
|
||||||
s2 = s2.substring(0, length);
|
s2 = s2.substring(0, length);
|
||||||
|
|
||||||
return (float) (floor(super.getSimilarity(s1, s2) * 4) / 4);
|
return (float) (Math.floor(super.getSimilarity(s1, s2) * 4) / 4);
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -415,7 +414,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
float lowerBound = super.getSimilarity(normalize(o1, true), normalize(o2, true));
|
float lowerBound = super.getSimilarity(normalize(o1, true), normalize(o2, true));
|
||||||
float upperBound = super.getSimilarity(normalize(o1, false), normalize(o2, false));
|
float upperBound = super.getSimilarity(normalize(o1, false), normalize(o2, false));
|
||||||
|
|
||||||
return max(lowerBound, upperBound);
|
return Math.max(lowerBound, upperBound);
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -459,7 +458,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
for (String s1 : f1) {
|
for (String s1 : f1) {
|
||||||
for (String s2 : f2) {
|
for (String s2 : f2) {
|
||||||
if (s1 != null && s2 != null) {
|
if (s1 != null && s2 != null) {
|
||||||
max = max(super.getSimilarity(s1, s2), max);
|
max = Math.max(super.getSimilarity(s1, s2), max);
|
||||||
if (max >= 1) {
|
if (max >= 1) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
@ -578,7 +577,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
if (r1 < 0 || r2 < 0)
|
if (r1 < 0 || r2 < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return max(r1, r2);
|
return Math.max(r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScore(Object object) {
|
public float getScore(Object object) {
|
||||||
|
@ -586,7 +585,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
SeriesInfo seriesInfo = ((Episode) object).getSeriesInfo();
|
SeriesInfo seriesInfo = ((Episode) object).getSeriesInfo();
|
||||||
if (seriesInfo != null && seriesInfo.getRating() != null && seriesInfo.getRatingCount() != null) {
|
if (seriesInfo != null && seriesInfo.getRating() != null && seriesInfo.getRatingCount() != null) {
|
||||||
if (seriesInfo.getRatingCount() >= 20) {
|
if (seriesInfo.getRatingCount() >= 20) {
|
||||||
return (float) floor(seriesInfo.getRating() / 3); // BOOST POPULAR SHOWS and PUT INTO 3 GROUPS
|
return (float) Math.floor(seriesInfo.getRating() / 3); // BOOST POPULAR SHOWS and PUT INTO 3 GROUPS
|
||||||
}
|
}
|
||||||
if (seriesInfo.getRatingCount() >= 1) {
|
if (seriesInfo.getRatingCount() >= 1) {
|
||||||
return 0; // PENALIZE SHOWS WITH FEW RATINGS
|
return 0; // PENALIZE SHOWS WITH FEW RATINGS
|
||||||
|
@ -605,7 +604,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||||
float r1 = getScore(o1);
|
float r1 = getScore(o1);
|
||||||
float r2 = getScore(o2);
|
float r2 = getScore(o2);
|
||||||
|
|
||||||
return max(r1, r2) >= 0.1 ? 1 : 0;
|
return Math.max(r1, r2) >= 0.1 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getScore(Object object) {
|
public float getScore(Object object) {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
|
|
||||||
public class MetricCascade implements SimilarityMetric {
|
public class MetricCascade implements SimilarityMetric {
|
||||||
|
|
||||||
private final SimilarityMetric[] cascade;
|
private final SimilarityMetric[] cascade;
|
||||||
|
@ -15,7 +13,7 @@ public class MetricCascade implements SimilarityMetric {
|
||||||
float f = 0;
|
float f = 0;
|
||||||
for (SimilarityMetric metric : cascade) {
|
for (SimilarityMetric metric : cascade) {
|
||||||
float similarity = metric.getSimilarity(o1, o2);
|
float similarity = metric.getSimilarity(o1, o2);
|
||||||
if (abs(similarity) >= abs(f)) {
|
if (Math.abs(similarity) >= Math.abs(f)) {
|
||||||
// perfect match, ignore remaining metrics
|
// perfect match, ignore remaining metrics
|
||||||
if (similarity >= 1) {
|
if (similarity >= 1) {
|
||||||
return similarity;
|
return similarity;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
import static net.filebot.similarity.CommonSequenceMatcher.*;
|
import static net.filebot.similarity.CommonSequenceMatcher.*;
|
||||||
import static net.filebot.similarity.Normalization.*;
|
import static net.filebot.similarity.Normalization.*;
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ public class SequenceMatchSimilarity implements SimilarityMetric {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float similarity(String match, String s1, String s2) {
|
protected float similarity(String match, String s1, String s2) {
|
||||||
return (float) match.length() / min(s1.length(), s2.length());
|
return (float) match.length() / Math.min(s1.length(), s2.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String normalize(Object object) {
|
protected String normalize(Object object) {
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
|
|
||||||
package net.filebot.similarity;
|
package net.filebot.similarity;
|
||||||
|
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
|
|
||||||
public class TimeStampMetric implements SimilarityMetric {
|
public class TimeStampMetric implements SimilarityMetric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,13 +15,12 @@ public class TimeStampMetric implements SimilarityMetric {
|
||||||
if (t1 <= 0 || t2 <= 0)
|
if (t1 <= 0 || t2 <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
float min = min(t1, t2);
|
float min = Math.min(t1, t2);
|
||||||
float max = max(t1, t2);
|
float max = Math.max(t1, t2);
|
||||||
|
|
||||||
return min / max;
|
return min / max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getTimeStamp(Object obj) {
|
public long getTimeStamp(Object obj) {
|
||||||
if (obj instanceof File) {
|
if (obj instanceof File) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.filebot.subtitle;
|
package net.filebot.subtitle;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.media.MediaDetection.*;
|
import static net.filebot.media.MediaDetection.*;
|
||||||
|
@ -122,7 +121,7 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float similarity(String match, String s1, String s2) {
|
protected float similarity(String match, String s1, String s2) {
|
||||||
return (float) match.length() / max(s1.length(), s2.length()) > 0.8 ? 1 : 0;
|
return (float) match.length() / Math.max(s1.length(), s2.length()) > 0.8 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<File, String> xattrCache = new WeakHashMap<File, String>(64);
|
private final Map<File, String> xattrCache = new WeakHashMap<File, String>(64);
|
||||||
|
@ -171,11 +170,11 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||||
private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) {
|
private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) {
|
||||||
try {
|
try {
|
||||||
Map<String, Object> props = new HashMap<String, Object>();
|
Map<String, Object> props = new HashMap<String, Object>();
|
||||||
float fps = round(subtitle.getMovieFPS()); // round because most FPS values in the database are bad anyway
|
float fps = Math.round(subtitle.getMovieFPS()); // round because most FPS values in the database are bad anyway
|
||||||
if (fps > 0) {
|
if (fps > 0) {
|
||||||
props.put(FPS, fps);
|
props.put(FPS, fps);
|
||||||
}
|
}
|
||||||
long seconds = (long) floor(subtitle.getMovieTimeMS() / (double) 1000);
|
long seconds = (long) Math.floor(subtitle.getMovieTimeMS() / (double) 1000);
|
||||||
if (seconds > 0) {
|
if (seconds > 0) {
|
||||||
props.put(SECONDS, seconds);
|
props.put(SECONDS, seconds);
|
||||||
}
|
}
|
||||||
|
@ -195,11 +194,11 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||||
Map<String, Object> props = new HashMap<String, Object>();
|
Map<String, Object> props = new HashMap<String, Object>();
|
||||||
MediaInfo mediaInfo = new MediaInfo().open(file);
|
MediaInfo mediaInfo = new MediaInfo().open(file);
|
||||||
|
|
||||||
float fps = round(Float.parseFloat(mediaInfo.get(StreamKind.Video, 0, "FrameRate")));
|
float fps = Math.round(Float.parseFloat(mediaInfo.get(StreamKind.Video, 0, "FrameRate")));
|
||||||
if (fps > 0) {
|
if (fps > 0) {
|
||||||
props.put(FPS, fps);
|
props.put(FPS, fps);
|
||||||
}
|
}
|
||||||
long seconds = (long) floor(Long.parseLong(mediaInfo.get(StreamKind.Video, 0, "Duration")) / (double) 1000);
|
long seconds = (long) Math.floor(Long.parseLong(mediaInfo.get(StreamKind.Video, 0, "Duration")) / (double) 1000);
|
||||||
if (seconds > 0) {
|
if (seconds > 0) {
|
||||||
props.put(SECONDS, seconds);
|
props.put(SECONDS, seconds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.filebot.subtitle;
|
package net.filebot.subtitle;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static java.util.stream.Collectors.*;
|
import static java.util.stream.Collectors.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
|
@ -359,7 +358,7 @@ public final class SubtitleUtilities {
|
||||||
try (SubRipWriter out = new SubRipWriter(buffer)) {
|
try (SubRipWriter out = new SubRipWriter(buffer)) {
|
||||||
for (SubtitleElement it : decodeSubtitles(data)) {
|
for (SubtitleElement it : decodeSubtitles(data)) {
|
||||||
if (outputTimingOffset != 0) {
|
if (outputTimingOffset != 0) {
|
||||||
it = new SubtitleElement(max(0, it.getStart() + outputTimingOffset), max(0, it.getEnd() + outputTimingOffset), it.getText());
|
it = new SubtitleElement(Math.max(0, it.getStart() + outputTimingOffset), Math.max(0, it.getEnd() + outputTimingOffset), it.getText());
|
||||||
}
|
}
|
||||||
out.write(it);
|
out.write(it);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.filebot.ui.episodelist;
|
package net.filebot.ui.episodelist;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -35,7 +34,7 @@ class SeasonSpinnerModel extends SpinnerListModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spin(int steps) {
|
public void spin(int steps) {
|
||||||
for (int i = 0; i < abs(steps); i++) {
|
for (int i = 0; i < Math.abs(steps); i++) {
|
||||||
setValue(i < 0 ? getPreviousValue() : getNextValue());
|
setValue(i < 0 ? getPreviousValue() : getNextValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.filebot.ui.list;
|
package net.filebot.ui.list;
|
||||||
|
|
||||||
import static net.filebot.util.FileUtilities.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
|
|
||||||
package net.filebot.ui.sfv;
|
package net.filebot.ui.sfv;
|
||||||
|
|
||||||
|
|
||||||
import static java.awt.Color.*;
|
import static java.awt.Color.*;
|
||||||
import static java.awt.Cursor.*;
|
import static java.awt.Cursor.*;
|
||||||
import static java.awt.Font.*;
|
import static java.awt.Font.*;
|
||||||
import static java.awt.RenderingHints.*;
|
import static java.awt.RenderingHints.*;
|
||||||
import static java.lang.Math.*;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
@ -20,17 +18,15 @@ import javax.swing.JToggleButton;
|
||||||
|
|
||||||
import net.filebot.ResourceManager;
|
import net.filebot.ResourceManager;
|
||||||
|
|
||||||
|
|
||||||
public class ChecksumButton extends JToggleButton {
|
public class ChecksumButton extends JToggleButton {
|
||||||
|
|
||||||
private static final Icon contentArea = ResourceManager.getIcon("button.checksum");
|
private static final Icon contentArea = ResourceManager.getIcon("button.checksum");
|
||||||
private static final Icon contentAreaSelected = ResourceManager.getIcon("button.checksum.selected");
|
private static final Icon contentAreaSelected = ResourceManager.getIcon("button.checksum.selected");
|
||||||
|
|
||||||
|
|
||||||
public ChecksumButton(Action action) {
|
public ChecksumButton(Action action) {
|
||||||
super(action);
|
super(action);
|
||||||
|
|
||||||
setPreferredSize(new Dimension(max(contentAreaSelected.getIconWidth(), contentArea.getIconWidth()), max(contentAreaSelected.getIconHeight(), contentArea.getIconHeight())));
|
setPreferredSize(new Dimension(Math.max(contentAreaSelected.getIconWidth(), contentArea.getIconWidth()), Math.max(contentAreaSelected.getIconHeight(), contentArea.getIconHeight())));
|
||||||
setMinimumSize(getPreferredSize());
|
setMinimumSize(getPreferredSize());
|
||||||
setMaximumSize(getPreferredSize());
|
setMaximumSize(getPreferredSize());
|
||||||
|
|
||||||
|
@ -45,7 +41,6 @@ public class ChecksumButton extends JToggleButton {
|
||||||
setEnabled(true);
|
setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
|
@ -54,7 +49,6 @@ public class ChecksumButton extends JToggleButton {
|
||||||
setCursor(getPredefinedCursor(enabled ? HAND_CURSOR : DEFAULT_CURSOR));
|
setCursor(getPredefinedCursor(enabled ? HAND_CURSOR : DEFAULT_CURSOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
@ -64,14 +58,14 @@ public class ChecksumButton extends JToggleButton {
|
||||||
|
|
||||||
// paint background image in the center
|
// paint background image in the center
|
||||||
if (isSelected()) {
|
if (isSelected()) {
|
||||||
contentAreaSelected.paintIcon(this, g2d, (int) round((getWidth() - contentAreaSelected.getIconWidth()) / (double) 2), (int) round((getHeight() - contentAreaSelected.getIconHeight()) / (double) 2));
|
contentAreaSelected.paintIcon(this, g2d, (int) Math.round((getWidth() - contentAreaSelected.getIconWidth()) / (double) 2), (int) Math.round((getHeight() - contentAreaSelected.getIconHeight()) / (double) 2));
|
||||||
} else {
|
} else {
|
||||||
contentArea.paintIcon(this, g2d, (int) round((getWidth() - contentArea.getIconWidth()) / (double) 2), (int) round((getHeight() - contentArea.getIconHeight()) / (double) 2));
|
contentArea.paintIcon(this, g2d, (int) Math.round((getWidth() - contentArea.getIconWidth()) / (double) 2), (int) Math.round((getHeight() - contentArea.getIconHeight()) / (double) 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle2D textBounds = g2d.getFontMetrics().getStringBounds(getText(), g2d);
|
Rectangle2D textBounds = g2d.getFontMetrics().getStringBounds(getText(), g2d);
|
||||||
|
|
||||||
// draw text in the center
|
// draw text in the center
|
||||||
g2d.drawString(getText(), round((getWidth() - textBounds.getWidth()) / 2) + 1, round(getHeight() / 2 - textBounds.getY() - textBounds.getHeight() / 2));
|
g2d.drawString(getText(), Math.round((getWidth() - textBounds.getWidth()) / 2) + 1, Math.round(getHeight() / 2 - textBounds.getY() - textBounds.getHeight() / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package net.filebot.ui.sfv;
|
package net.filebot.ui.sfv;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
|
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyChangeSupport;
|
import java.beans.PropertyChangeSupport;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -103,7 +101,7 @@ class ChecksumComputationService {
|
||||||
// for a few files, use one thread
|
// for a few files, use one thread
|
||||||
// for lots of files, use multiple threads
|
// for lots of files, use multiple threads
|
||||||
// e.g 50 files ~ 1 thread, 200 files ~ 2 threads, 1000 files ~ 3 threads, 40000 files ~ 5 threads
|
// e.g 50 files ~ 1 thread, 200 files ~ 2 threads, 1000 files ~ 3 threads, 40000 files ~ 5 threads
|
||||||
return (int) max(1, round(sqrt(threadPoolSize) + log10(getQueue().size()) - 1));
|
return (int) Math.max(1, Math.round(Math.sqrt(threadPoolSize) + Math.log10(getQueue().size()) - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.filebot.ui.sfv;
|
package net.filebot.ui.sfv;
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
import static net.filebot.ui.sfv.ChecksumTableModel.*;
|
import static net.filebot.ui.sfv.ChecksumTableModel.*;
|
||||||
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
|
import static net.filebot.ui.transfer.BackgroundFileTransferablePolicy.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
@ -184,7 +183,7 @@ public class SfvPanel extends JComponent {
|
||||||
computationService.purge();
|
computationService.purge();
|
||||||
|
|
||||||
// auto select next row
|
// auto select next row
|
||||||
selectedRow = min(selectedRow, table.getRowCount() - 1);
|
selectedRow = Math.min(selectedRow, table.getRowCount() - 1);
|
||||||
|
|
||||||
table.getSelectionModel().setSelectionInterval(selectedRow, selectedRow);
|
table.getSelectionModel().setSelectionInterval(selectedRow, selectedRow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
|
|
||||||
package net.filebot.util.ui;
|
package net.filebot.util.ui;
|
||||||
|
|
||||||
|
|
||||||
import static java.lang.Math.*;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
@ -23,12 +20,10 @@ import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.event.MouseInputAdapter;
|
import javax.swing.event.MouseInputAdapter;
|
||||||
|
|
||||||
|
|
||||||
public class ListView extends JList {
|
public class ListView extends JList {
|
||||||
|
|
||||||
protected final BlockSelectionHandler blockSelectionHandler = new BlockSelectionHandler();
|
protected final BlockSelectionHandler blockSelectionHandler = new BlockSelectionHandler();
|
||||||
|
|
||||||
|
|
||||||
public ListView(ListModel dataModel) {
|
public ListView(ListModel dataModel) {
|
||||||
super(dataModel);
|
super(dataModel);
|
||||||
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||||
|
@ -45,7 +40,6 @@ public class ListView extends JList {
|
||||||
addMouseMotionListener(blockSelectionHandler);
|
addMouseMotionListener(blockSelectionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addSelectionInterval(Rectangle selection) {
|
public void addSelectionInterval(Rectangle selection) {
|
||||||
Point p1 = selection.getLocation();
|
Point p1 = selection.getLocation();
|
||||||
Point p2 = new Point(p1.x + selection.width, p1.y + selection.height);
|
Point p2 = new Point(p1.x + selection.width, p1.y + selection.height);
|
||||||
|
@ -62,7 +56,6 @@ public class ListView extends JList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
@ -75,7 +68,6 @@ public class ListView extends JList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void paintBlockSelection(Graphics2D g2d, Rectangle selection) {
|
protected void paintBlockSelection(Graphics2D g2d, Rectangle selection) {
|
||||||
g2d.setPaint(SwingUI.derive(getSelectionBackground(), 0.3f));
|
g2d.setPaint(SwingUI.derive(getSelectionBackground(), 0.3f));
|
||||||
g2d.fill(selection);
|
g2d.fill(selection);
|
||||||
|
@ -84,24 +76,20 @@ public class ListView extends JList {
|
||||||
g2d.draw(selection);
|
g2d.draw(selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String convertValueToText(Object value) {
|
protected String convertValueToText(Object value) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Icon convertValueToIcon(Object value) {
|
protected Icon convertValueToIcon(Object value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected class ListViewRenderer extends DefaultListCellRenderer {
|
protected class ListViewRenderer extends DefaultListCellRenderer {
|
||||||
|
|
||||||
public ListViewRenderer() {
|
public ListViewRenderer() {
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
Icon icon = convertValueToIcon(value);
|
Icon icon = convertValueToIcon(value);
|
||||||
|
@ -125,7 +113,6 @@ public class ListView extends JList {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
// paint selection background for the text area only, not the whole cell
|
// paint selection background for the text area only, not the whole cell
|
||||||
|
@ -140,14 +127,12 @@ public class ListView extends JList {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
protected class BlockSelectionHandler extends MouseInputAdapter {
|
protected class BlockSelectionHandler extends MouseInputAdapter {
|
||||||
|
|
||||||
private Rectangle selection;
|
private Rectangle selection;
|
||||||
|
|
||||||
private Point origin;
|
private Point origin;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if (SwingUtilities.isLeftMouseButton(e) && !isSelectedIndex(locationToIndex(e.getPoint()))) {
|
if (SwingUtilities.isLeftMouseButton(e) && !isSelectedIndex(locationToIndex(e.getPoint()))) {
|
||||||
|
@ -155,7 +140,6 @@ public class ListView extends JList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
if (origin == null)
|
if (origin == null)
|
||||||
|
@ -167,8 +151,8 @@ public class ListView extends JList {
|
||||||
|
|
||||||
// keep point within component bounds
|
// keep point within component bounds
|
||||||
Point p2 = e.getPoint();
|
Point p2 = e.getPoint();
|
||||||
p2.x = max(0, min(getWidth() - 1, p2.x));
|
p2.x = Math.max(0, Math.min(getWidth() - 1, p2.x));
|
||||||
p2.y = max(0, min(getHeight() - 1, p2.y));
|
p2.y = Math.max(0, Math.min(getHeight() - 1, p2.y));
|
||||||
|
|
||||||
// update selection bounds
|
// update selection bounds
|
||||||
selection.setFrameFromDiagonal(origin, p2);
|
selection.setFrameFromDiagonal(origin, p2);
|
||||||
|
@ -184,7 +168,6 @@ public class ListView extends JList {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
origin = null;
|
origin = null;
|
||||||
|
@ -196,7 +179,6 @@ public class ListView extends JList {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Rectangle getSelection() {
|
public Rectangle getSelection() {
|
||||||
return selection;
|
return selection;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue