From e3fbd3825f302e5e34e24c1ea1fc2871baf0b3cd Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 9 Oct 2016 00:28:40 +0800 Subject: [PATCH] SwingUI.copyToClipboard(String text) --- source/net/filebot/ui/rename/RenamePanel.java | 4 +--- source/net/filebot/util/ui/SwingUI.java | 6 ++++++ .../filebot/util/ui/notification/MessageNotification.java | 4 +--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index d1230081..0f50e648 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -16,9 +16,7 @@ import static net.filebot.util.ui.SwingUI.*; import java.awt.Component; import java.awt.Cursor; import java.awt.Insets; -import java.awt.Toolkit; import java.awt.Window; -import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.event.ActionEvent; import java.io.File; @@ -364,7 +362,7 @@ public class RenamePanel extends JComponent { installAction(this, WHEN_IN_FOCUSED_WINDOW, getKeyStroke(VK_F7, 0), newAction("Copy Debug Information", evt -> { try { withWaitCursor(evt.getSource(), () -> { - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(getDebugInfo()), null); + copyToClipboard(getDebugInfo()); log.info("Match model has been copied to clipboard"); }); } catch (Exception e) { diff --git a/source/net/filebot/util/ui/SwingUI.java b/source/net/filebot/util/ui/SwingUI.java index 765f7d6e..86ac8efd 100644 --- a/source/net/filebot/util/ui/SwingUI.java +++ b/source/net/filebot/util/ui/SwingUI.java @@ -13,7 +13,9 @@ import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; +import java.awt.Toolkit; import java.awt.Window; +import java.awt.datatransfer.StringSelection; import java.awt.dnd.DnDConstants; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; @@ -62,6 +64,10 @@ public final class SwingUI { } } + public static void copyToClipboard(String text) { + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null); + } + public static void checkEventDispatchThread() { if (!SwingUtilities.isEventDispatchThread()) { throw new IllegalStateException("Method must be accessed from the Swing Event Dispatch Thread, but was called on Thread \"" + Thread.currentThread().getName() + "\""); diff --git a/source/net/filebot/util/ui/notification/MessageNotification.java b/source/net/filebot/util/ui/notification/MessageNotification.java index bb76b205..048605a8 100644 --- a/source/net/filebot/util/ui/notification/MessageNotification.java +++ b/source/net/filebot/util/ui/notification/MessageNotification.java @@ -10,9 +10,7 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Cursor; import java.awt.Font; -import java.awt.Toolkit; import java.awt.Window; -import java.awt.datatransfer.StringSelection; import javax.swing.BorderFactory; import javax.swing.Icon; @@ -75,7 +73,7 @@ public class MessageNotification extends NotificationWindow { // copy message to clipboard getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - getGlassPane().addMouseListener(mouseClicked(evt -> Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), null))); + getGlassPane().addMouseListener(mouseClicked(evt -> copyToClipboard(text))); } }