mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 13:59:49 -04:00
* fixed visual issues with SeasonSpinnerEditor
This commit is contained in:
parent
4afc701ff7
commit
912bf0464f
@ -1,57 +1,63 @@
|
|||||||
|
|
||||||
package net.sourceforge.filebot.ui.panel.episodelist;
|
package net.sourceforge.filebot.ui.panel.episodelist;
|
||||||
|
|
||||||
|
|
||||||
import static net.sourceforge.filebot.ui.panel.episodelist.SeasonSpinnerModel.ALL_SEASONS;
|
import static net.sourceforge.filebot.ui.panel.episodelist.SeasonSpinnerModel.ALL_SEASONS;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JSpinner;
|
import javax.swing.JSpinner;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.JSpinner.DefaultEditor;
|
import javax.swing.JSpinner.DefaultEditor;
|
||||||
import javax.swing.text.DefaultFormatter;
|
import javax.swing.text.DefaultFormatter;
|
||||||
import javax.swing.text.DefaultFormatterFactory;
|
import javax.swing.text.DefaultFormatterFactory;
|
||||||
|
|
||||||
class SeasonSpinnerEditor extends DefaultEditor {
|
|
||||||
|
|
||||||
|
class SeasonSpinnerEditor extends DefaultEditor {
|
||||||
|
|
||||||
public SeasonSpinnerEditor(JSpinner spinner) {
|
public SeasonSpinnerEditor(JSpinner spinner) {
|
||||||
super(spinner);
|
super(spinner);
|
||||||
|
|
||||||
getTextField().setFormatterFactory(new DefaultFormatterFactory(new DefaultFormatter() {
|
getTextField().setFormatterFactory(new DefaultFormatterFactory(new DefaultFormatter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object stringToValue(String string) throws ParseException {
|
public Object stringToValue(String string) throws ParseException {
|
||||||
if ("All Seasons".equals(string)) {
|
if ("All Seasons".equals(string)) {
|
||||||
return ALL_SEASONS;
|
return ALL_SEASONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher matcher = Pattern.compile("Season (\\d+)").matcher(string);
|
Matcher matcher = Pattern.compile("Season (\\d+)").matcher(string);
|
||||||
|
|
||||||
if (matcher.matches()) {
|
if (matcher.matches()) {
|
||||||
return Integer.valueOf(matcher.group(1));
|
return Integer.valueOf(matcher.group(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// negative season number
|
// negative season number
|
||||||
throw new ParseException("Illegal season number", 0);
|
throw new ParseException("Illegal season number", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String valueToString(Object value) throws ParseException {
|
public String valueToString(Object value) throws ParseException {
|
||||||
int season = ((Number) value).intValue();
|
int season = ((Number) value).intValue();
|
||||||
|
|
||||||
if (season == ALL_SEASONS)
|
if (season == ALL_SEASONS)
|
||||||
return "All Seasons";
|
return "All Seasons";
|
||||||
else if (season >= 1)
|
else if (season >= 1)
|
||||||
return String.format("Season %d", season);
|
return String.format("Season %d", season);
|
||||||
|
|
||||||
// negative season number
|
// negative season number
|
||||||
throw new ParseException("Illegal season number", 0);
|
throw new ParseException("Illegal season number", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
getTextField().setBorder(BorderFactory.createEmptyBorder(1, 3, 1, 1));
|
||||||
getTextField().setHorizontalAlignment(SwingConstants.RIGHT);
|
getTextField().setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
|
getTextField().setBackground(Color.white);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user