From baeb9d8b0089d733cea0b941a02e9aa6e6707476 Mon Sep 17 00:00:00 2001 From: John Hitchings Date: Thu, 8 Nov 2018 09:25:03 -0800 Subject: [PATCH 1/2] Prepopulate DeckImportFromClipboardDialog content with string contents of clipboard. --- .../deckeditor/DeckImportFromClipboardDialog.java | 15 +++++++++++++++ .../cards/decks/importer/DeckImporterUtil.java | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java index eef1987dfa..6c89063217 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java @@ -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 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() { diff --git a/Mage/src/main/java/mage/cards/decks/importer/DeckImporterUtil.java b/Mage/src/main/java/mage/cards/decks/importer/DeckImporterUtil.java index a0e90dc526..0384a17f44 100644 --- a/Mage/src/main/java/mage/cards/decks/importer/DeckImporterUtil.java +++ b/Mage/src/main/java/mage/cards/decks/importer/DeckImporterUtil.java @@ -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(); From b1df464e8fa2777b3bfb956e1e3f88a5bf92ea37 Mon Sep 17 00:00:00 2001 From: John Hitchings Date: Fri, 16 Nov 2018 21:57:25 -0800 Subject: [PATCH 2/2] refactor deck import content to include hints --- .../DeckImportFromClipboardDialog.java | 20 ++++++++++++++++--- .../mage/client/plugins/impl/Plugins.java | 10 +++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java index 6c89063217..4b370eee77 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckImportFromClipboardDialog.java @@ -16,6 +16,15 @@ 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; @@ -25,6 +34,9 @@ public class DeckImportFromClipboardDialog extends JDialog { public DeckImportFromClipboardDialog() { initComponents(); + + onRefreshClipboard(); + setContentPane(contentPane); setModal(true); getRootPane().setDefaultButton(buttonOK); @@ -42,8 +54,6 @@ 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 getClipboardStringData() { @@ -75,6 +85,10 @@ public class DeckImportFromClipboardDialog extends JDialog { dispose(); } + private void onRefreshClipboard() { + txtDeckList.setText(FORMAT_TEXT + getClipboardStringData().orElse("")); + } + public String getTmpPath() { return tmpPath; } @@ -158,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, diff --git a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java index d9f1fef14f..1731b0b656 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java +++ b/Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java @@ -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."); }