Prepopulate DeckImportFromClipboardDialog content with string contents of clipboard.

This commit is contained in:
John Hitchings 2018-11-08 09:25:03 -08:00
parent a3206785ab
commit baeb9d8b00
2 changed files with 18 additions and 1 deletions

View file

@ -3,11 +3,15 @@ package mage.client.deckeditor;
import mage.util.StreamUtils;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Optional;
import javax.swing.*;
public class DeckImportFromClipboardDialog extends JDialog {
@ -38,6 +42,17 @@ public class DeckImportFromClipboardDialog extends JDialog {
// Close on "ESC"
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
getClipboardStringData().ifPresent(content -> txtDeckList.setText(content));
}
private Optional<String> getClipboardStringData() {
try {
return Optional.of((String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor));
} catch (HeadlessException | UnsupportedFlavorException | IOException e) {
e.printStackTrace();
}
return Optional.empty();
}
private void onOK() {

View file

@ -39,7 +39,9 @@ public final class DeckImporterUtil {
}
public static DeckImporter getDeckImporter(String file) {
if (file.toLowerCase(Locale.ENGLISH).endsWith("dec")) {
if (file == null) {
return null;
} if (file.toLowerCase(Locale.ENGLISH).endsWith("dec")) {
return new DecDeckImporter();
} else if (file.toLowerCase(Locale.ENGLISH).endsWith("mwdeck")) {
return new MWSDeckImporter();