From cd7fa8cb3629c13e7d111337ce18c5e150795f07 Mon Sep 17 00:00:00 2001 From: RumbleBBU Date: Thu, 20 Sep 2012 07:41:16 +0000 Subject: [PATCH] Added a checkbox for not automatically choosing the latest card version when importing decks (useful in some cases). --- src/main/java/forge/deck/DeckRecognizer.java | 13 ++++++++----- src/main/java/forge/gui/deckeditor/DeckImport.java | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/forge/deck/DeckRecognizer.java b/src/main/java/forge/deck/DeckRecognizer.java index b441ffbd245..6b236800db7 100644 --- a/src/main/java/forge/deck/DeckRecognizer.java +++ b/src/main/java/forge/deck/DeckRecognizer.java @@ -164,9 +164,12 @@ public class DeckRecognizer { * * @param rawLine * the raw_line + * @param newestEdition + * get the newest available edition? + * * @return the token */ - public static Token recognizeLine(final String rawLine) { + public static Token recognizeLine(final String rawLine, final boolean newestEdition) { if (StringUtils.isBlank(rawLine)) { return new Token(TokenType.Comment, 0, rawLine); } @@ -178,7 +181,7 @@ public class DeckRecognizer { if (foundNumbersInFront.matches()) { final String cardName = foundNumbersInFront.group(2); 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 = * foundNumbersInBack.group(1); int amount = @@ -187,16 +190,16 @@ public class DeckRecognizer { */ else { 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); } 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)) { - 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 diff --git a/src/main/java/forge/gui/deckeditor/DeckImport.java b/src/main/java/forge/gui/deckeditor/DeckImport.java index a5d9880caf5..a01056e2792 100644 --- a/src/main/java/forge/gui/deckeditor/DeckImport.java +++ b/src/main/java/forge/gui/deckeditor/DeckImport.java @@ -32,6 +32,7 @@ import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JScrollPane; import javax.swing.JTextArea; +import javax.swing.JCheckBox; import javax.swing.border.TitledBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -86,7 +87,8 @@ public class DeckImport ex private final JLabel summarySide = new JLabel("This is second line"); private final JButton cmdAccept = new JButton("Import Deck"); private final JButton cmdCancel = new JButton("Cancel"); - + private final JCheckBox newEditionCheck = new JCheckBox("Import latest version of card", true); + /** The tokens. */ private final List tokens = new ArrayList(); @@ -126,15 +128,16 @@ public class DeckImport ex this.scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder()); 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.summaryMain, "cell 1 1, 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.cmdCancel, "w 100"); + this.cmdCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { @@ -174,7 +177,7 @@ public class DeckImport ex final int rangeEnd = e.getEndOffset(); try { 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) { } }