filebot/source/net/filebot/ui/episodelist/SeasonSpinnerModel.java

69 lines
1.1 KiB
Java
Raw Normal View History

2014-04-19 02:30:29 -04:00
package net.filebot.ui.episodelist;
import javax.swing.SpinnerNumberModel;
class SeasonSpinnerModel extends SpinnerNumberModel {
2015-07-25 18:47:19 -04:00
public static final int ALL_SEASONS = 0;
2015-07-25 18:47:19 -04:00
public static final int MAX_VALUE = 99;
2015-07-25 18:47:19 -04:00
private Number valueBeforeLock = null;
2015-07-25 18:47:19 -04:00
public SeasonSpinnerModel() {
super(ALL_SEASONS, ALL_SEASONS, MAX_VALUE, 1);
}
2015-07-25 18:47:19 -04:00
public int getSeason() {
return getNumber().intValue();
}
2015-07-25 18:47:19 -04:00
@Override
public Integer getMinimum() {
return (Integer) super.getMinimum();
}
2015-07-25 18:47:19 -04:00
@Override
public Integer getMaximum() {
return (Integer) super.getMaximum();
}
2015-07-25 18:47:19 -04:00
public void spin(int steps) {
int next = getSeason() + steps;
2015-07-25 18:47:19 -04:00
if (next < getMinimum())
next = getMinimum();
else if (next > getMaximum())
next = getMaximum();
2015-07-25 18:47:19 -04:00
setValue(next);
}
2015-07-25 18:47:19 -04:00
public void lock(int value) {
valueBeforeLock = getNumber();
setMinimum(value);
setMaximum(value);
setValue(value);
}
2015-07-25 18:47:19 -04:00
public void unlock() {
setMinimum(ALL_SEASONS);
setMaximum(MAX_VALUE);
2015-07-25 18:47:19 -04:00
if (valueBeforeLock != null) {
setValue(valueBeforeLock);
valueBeforeLock = null;
}
}
}