mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Merge pull request #5420 from hitch17/load-deck-content-from-clipboard
Prepopulate DeckImportFromClipboardDialog content with string content…
This commit is contained in:
commit
6fa014d1a9
3 changed files with 40 additions and 5 deletions
|
@ -3,15 +3,28 @@ 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 {
|
||||
|
||||
private static final String FORMAT_TEXT =
|
||||
"// Example:\n" +
|
||||
"//1 Library of Congress\n" +
|
||||
"//1 Cryptic Gateway\n" +
|
||||
"//1 Azami, Lady of Scrolls\n" +
|
||||
"// NB: This is slow as, and will lock your screen :)\n" +
|
||||
"\n" +
|
||||
"// Your current clipboard:\n";
|
||||
|
||||
private JPanel contentPane;
|
||||
private JButton buttonOK;
|
||||
private JButton buttonCancel;
|
||||
|
@ -21,6 +34,9 @@ public class DeckImportFromClipboardDialog extends JDialog {
|
|||
|
||||
public DeckImportFromClipboardDialog() {
|
||||
initComponents();
|
||||
|
||||
onRefreshClipboard();
|
||||
|
||||
setContentPane(contentPane);
|
||||
setModal(true);
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
|
@ -40,6 +56,15 @@ public class DeckImportFromClipboardDialog extends JDialog {
|
|||
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
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() {
|
||||
BufferedWriter bw = null;
|
||||
try {
|
||||
|
@ -60,6 +85,10 @@ public class DeckImportFromClipboardDialog extends JDialog {
|
|||
dispose();
|
||||
}
|
||||
|
||||
private void onRefreshClipboard() {
|
||||
txtDeckList.setText(FORMAT_TEXT + getClipboardStringData().orElse(""));
|
||||
}
|
||||
|
||||
public String getTmpPath() {
|
||||
return tmpPath;
|
||||
}
|
||||
|
@ -143,7 +172,7 @@ public class DeckImportFromClipboardDialog extends JDialog {
|
|||
|
||||
txtDeckList.setMinimumSize(new Dimension(250, 400));
|
||||
txtDeckList.setPreferredSize(new Dimension(550, 400));
|
||||
txtDeckList.setText("// Example:\n//1 Library of Congress\n//1 Cryptic Gateway\n//1 Azami, Lady of Scrolls\n// NB: This is slow as, and will lock your screen :)");
|
||||
txtDeckList.setText(FORMAT_TEXT);
|
||||
JScrollPane txtScrollableDeckList = new JScrollPane(txtDeckList);
|
||||
panel3.add(txtScrollableDeckList, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0,
|
||||
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
|
||||
|
|
|
@ -26,6 +26,8 @@ import mage.view.CardView;
|
|||
import mage.view.PermanentView;
|
||||
import net.xeoh.plugins.base.PluginManager;
|
||||
import net.xeoh.plugins.base.impl.PluginManagerFactory;
|
||||
import net.xeoh.plugins.base.util.uri.ClassURI;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.plugins.card.CardPluginImpl;
|
||||
import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
|
||||
|
@ -46,13 +48,15 @@ public enum Plugins implements MagePlugins {
|
|||
|
||||
@Override
|
||||
public void loadPlugins() {
|
||||
|
||||
LOGGER.info("Loading plugins...");
|
||||
pm = PluginManagerFactory.createPluginManager();
|
||||
pm.addPluginsFrom(new File(PLUGINS_DIRECTORY + File.separator).toURI());
|
||||
this.cardPlugin = new CardPluginImpl();
|
||||
pm.addPluginsFrom(new ClassURI(CardPluginImpl.class).toURI());
|
||||
pm.addPluginsFrom(new ClassURI(ThemePluginImpl.class).toURI());
|
||||
|
||||
this.cardPlugin = pm.getPlugin(CardPlugin.class);
|
||||
this.counterPlugin = pm.getPlugin(CounterPlugin.class);
|
||||
this.themePlugin = new ThemePluginImpl();
|
||||
this.themePlugin = pm.getPlugin(ThemePlugin.class);
|
||||
LOGGER.info("Done.");
|
||||
}
|
||||
|
||||
|
|
|
@ -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