mirror of
https://github.com/correl/mage.git
synced 2025-01-12 03:00:13 +00:00
Prepopulate DeckImportFromClipboardDialog content with string contents of clipboard.
This commit is contained in:
parent
a3206785ab
commit
baeb9d8b00
2 changed files with 18 additions and 1 deletions
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue