Allow Season Year values in the Season spinner

This commit is contained in:
Reinhard Pointner 2016-01-26 16:23:01 +00:00
parent db9dc0f9e9
commit 52d82489cb
2 changed files with 34 additions and 38 deletions

View File

@ -3,6 +3,7 @@ package net.filebot.ui.episodelist;
import static net.filebot.ui.episodelist.SeasonSpinnerModel.*; import static net.filebot.ui.episodelist.SeasonSpinnerModel.*;
import static net.filebot.web.EpisodeUtilities.*; import static net.filebot.web.EpisodeUtilities.*;
import java.awt.Dimension;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
@ -66,7 +67,9 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, E
seasonSpinner.setEditor(new SeasonSpinnerEditor(seasonSpinner)); seasonSpinner.setEditor(new SeasonSpinnerEditor(seasonSpinner));
// set minimum size to "All Seasons" preferred size // set minimum size to "All Seasons" preferred size
seasonSpinner.setMinimumSize(seasonSpinner.getPreferredSize()); Dimension d = seasonSpinner.getPreferredSize();
d.width += 12;
seasonSpinner.setMinimumSize(d);
// add after text field // add after text field
add(seasonSpinner, "sgy button, gap indent", 1); add(seasonSpinner, "sgy button, gap indent", 1);

View File

@ -1,68 +1,61 @@
package net.filebot.ui.episodelist; package net.filebot.ui.episodelist;
import static java.lang.Math.*;
import static java.util.Collections.*;
import javax.swing.SpinnerNumberModel; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.swing.SpinnerListModel;
class SeasonSpinnerModel extends SpinnerNumberModel { class SeasonSpinnerModel extends SpinnerListModel {
public static final int ALL_SEASONS = 0; public static final int ALL_SEASONS = 0;
public static final int MAX_VALUE = 99; public static final int YEAR_SEASON_MIN_VALUE = 1990;
public static final int YEAR_SEASON_MAX_VALUE = 2100;
private Number valueBeforeLock = null; public static final int SEASON_MIN_VALUE = 1;
public static final int SEASON_MAX_VALUE = 50;
public static List<Integer> getSeasonValues() {
IntStream values = IntStream.of(ALL_SEASONS);
values = IntStream.concat(values, IntStream.range(SEASON_MIN_VALUE, SEASON_MAX_VALUE));
values = IntStream.concat(values, IntStream.range(YEAR_SEASON_MIN_VALUE, YEAR_SEASON_MAX_VALUE));
return values.boxed().collect(Collectors.toList());
}
public SeasonSpinnerModel() { public SeasonSpinnerModel() {
super(ALL_SEASONS, ALL_SEASONS, MAX_VALUE, 1); super(getSeasonValues());
} }
public int getSeason() { public int getSeason() {
return getNumber().intValue(); return ((Integer) getValue()).intValue();
} }
@Override
public Integer getMinimum() {
return (Integer) super.getMinimum();
}
@Override
public Integer getMaximum() {
return (Integer) super.getMaximum();
}
public void spin(int steps) { public void spin(int steps) {
int next = getSeason() + steps; for (int i = 0; i < abs(steps); i++) {
setValue(i < 0 ? getPreviousValue() : getNextValue());
if (next < getMinimum()) }
next = getMinimum();
else if (next > getMaximum())
next = getMaximum();
setValue(next);
} }
private Object valueBeforeLock = null;
public void lock(int value) { public void lock(int value) {
valueBeforeLock = getNumber(); valueBeforeLock = getValue();
setMinimum(value);
setMaximum(value); setList(singletonList(ALL_SEASONS));
setValue(value); setValue(ALL_SEASONS);
} }
public void unlock() { public void unlock() {
setMinimum(ALL_SEASONS); setList(getSeasonValues());
setMaximum(MAX_VALUE);
if (valueBeforeLock != null) { if (valueBeforeLock != null) {
setValue(valueBeforeLock); setValue(valueBeforeLock);
}
valueBeforeLock = null; valueBeforeLock = null;
} }
}
} }