Added a checkbox for not automatically choosing the latest card version when importing decks (useful in some cases).

This commit is contained in:
RumbleBBU
2012-09-20 07:41:16 +00:00
parent 26bf7ea313
commit cd7fa8cb36
2 changed files with 15 additions and 9 deletions

View File

@@ -164,9 +164,12 @@ public class DeckRecognizer {
* *
* @param rawLine * @param rawLine
* the raw_line * the raw_line
* @param newestEdition
* get the newest available edition?
*
* @return the token * @return the token
*/ */
public static Token recognizeLine(final String rawLine) { public static Token recognizeLine(final String rawLine, final boolean newestEdition) {
if (StringUtils.isBlank(rawLine)) { if (StringUtils.isBlank(rawLine)) {
return new Token(TokenType.Comment, 0, rawLine); return new Token(TokenType.Comment, 0, rawLine);
} }
@@ -178,7 +181,7 @@ public class DeckRecognizer {
if (foundNumbersInFront.matches()) { if (foundNumbersInFront.matches()) {
final String cardName = foundNumbersInFront.group(2); final String cardName = foundNumbersInFront.group(2);
final int amount = Integer.parseInt(foundNumbersInFront.group(1)); final int amount = Integer.parseInt(foundNumbersInFront.group(1));
result = DeckRecognizer.recognizePossibleNameAndNumber(cardName, amount); result = DeckRecognizer.recognizePossibleNameAndNumber(cardName, amount, newestEdition);
} /* } /*
* else if (foundNumbersInBack.matches()) { String cardName = * else if (foundNumbersInBack.matches()) { String cardName =
* foundNumbersInBack.group(1); int amount = * foundNumbersInBack.group(1); int amount =
@@ -187,16 +190,16 @@ public class DeckRecognizer {
*/ */
else { else {
if (CardDb.instance().isCardSupported(line)) { if (CardDb.instance().isCardSupported(line)) {
return Token.knownCard(CardDb.instance().getCard(line, true), 1); return Token.knownCard(CardDb.instance().getCard(line, newestEdition), 1);
} }
result = DeckRecognizer.recognizeNonCard(line, 1); result = DeckRecognizer.recognizeNonCard(line, 1);
} }
return result != null ? result : new Token(TokenType.UnknownText, 0, line); return result != null ? result : new Token(TokenType.UnknownText, 0, line);
} }
private static Token recognizePossibleNameAndNumber(final String name, final int n) { private static Token recognizePossibleNameAndNumber(final String name, final int n, final boolean newestEdition) {
if (CardDb.instance().isCardSupported(name)) { if (CardDb.instance().isCardSupported(name)) {
return Token.knownCard(CardDb.instance().getCard(name, true), n); return Token.knownCard(CardDb.instance().getCard(name, newestEdition), n);
} }
// TODO: recognize format: http://topdeck.ru/forum/index.php?showtopic=12711 // TODO: recognize format: http://topdeck.ru/forum/index.php?showtopic=12711

View File

@@ -32,6 +32,7 @@ import javax.swing.JLabel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.JCheckBox;
import javax.swing.border.TitledBorder; import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
@@ -86,6 +87,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
private final JLabel summarySide = new JLabel("This is second line"); private final JLabel summarySide = new JLabel("This is second line");
private final JButton cmdAccept = new JButton("Import Deck"); private final JButton cmdAccept = new JButton("Import Deck");
private final JButton cmdCancel = new JButton("Cancel"); private final JButton cmdCancel = new JButton("Cancel");
private final JCheckBox newEditionCheck = new JCheckBox("Import latest version of card", true);
/** The tokens. */ /** The tokens. */
private final List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>(); private final List<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
@@ -126,15 +128,16 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
this.scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder()); this.scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
this.getContentPane().setLayout(new MigLayout("fill")); this.getContentPane().setLayout(new MigLayout("fill"));
this.getContentPane().add(this.scrollInput, "cell 0 0, w 50%, sy 4, growy, pushy"); this.getContentPane().add(this.scrollInput, "cell 0 0, w 50%, growy, pushy");
this.getContentPane().add(this.newEditionCheck, "cell 0 1, w 50%, align c");
this.getContentPane().add(this.scrollOutput, "cell 1 0, w 50%, growy, pushy"); this.getContentPane().add(this.scrollOutput, "cell 1 0, w 50%, growy, pushy");
this.getContentPane().add(this.summaryMain, "cell 1 1, label"); this.getContentPane().add(this.summaryMain, "cell 1 1, label");
this.getContentPane().add(this.summarySide, "cell 1 2, label"); this.getContentPane().add(this.summarySide, "cell 1 2, label");
this.getContentPane().add(this.cmdAccept, "cell 1 3, split 2, w 100, align c"); this.getContentPane().add(this.cmdAccept, "cell 1 3, split 2, w 100, align c");
this.getContentPane().add(this.cmdCancel, "w 100"); this.getContentPane().add(this.cmdCancel, "w 100");
this.cmdCancel.addActionListener(new ActionListener() { this.cmdCancel.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
@@ -174,7 +177,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
final int rangeEnd = e.getEndOffset(); final int rangeEnd = e.getEndOffset();
try { try {
final String line = this.txtInput.getText(rangeStart, rangeEnd - rangeStart); final String line = this.txtInput.getText(rangeStart, rangeEnd - rangeStart);
this.tokens.add(DeckRecognizer.recognizeLine(line)); this.tokens.add(DeckRecognizer.recognizeLine(line, newEditionCheck.isSelected()));
} catch (final BadLocationException ex) { } catch (final BadLocationException ex) {
} }
} }