Add getContents() method

pull/2/head
Hammy 3 years ago
parent 6a77a5da56
commit 09dc01ea84

@ -3,8 +3,10 @@ package me.goudham;
import java.awt.Image; import java.awt.Image;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import me.goudham.domain.ClipboardContent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -109,6 +111,16 @@ abstract class ClipboardListener {
*/ */
abstract void insertAndNotify(List<File> fileContent); abstract void insertAndNotify(List<File> fileContent);
/**
* Returns the current clipboard contents, {@code null} if clipboard has no contents
*
* @return {@link ClipboardContent} containing either {@code String}, {@code BufferedImage} or {@code List<File>}
*/
ClipboardContent getContents() {
Transferable clipboardContents = clipboard.getContents(null);
return clipboardContents == null ? null : clipboardUtils.getOldClipboardContent(clipboardContents);
}
/** /**
* Toggles the current value of text monitoring, the default value is set to {@code True} * Toggles the current value of text monitoring, the default value is set to {@code True}
*/ */

@ -3,6 +3,7 @@ package me.goudham;
import java.awt.Image; import java.awt.Image;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import me.goudham.domain.ClipboardContent;
import me.goudham.event.FileEvent; import me.goudham.event.FileEvent;
import me.goudham.event.ImageEvent; import me.goudham.event.ImageEvent;
import me.goudham.event.TextEvent; import me.goudham.event.TextEvent;
@ -146,6 +147,16 @@ public class MyClipboard {
clipboardListener.insertAndNotify(fileContent); clipboardListener.insertAndNotify(fileContent);
} }
/**
* Returns the current clipboard contents, {@code null} if clipboard has no contents
*
* @return {@link ClipboardContent} containing either {@code String}, {@code BufferedImage} or {@code List<File>}
* @see ClipboardListener#getContents()
*/
public ClipboardContent getContents() {
return clipboardListener.getContents();
}
/** /**
* Adds a {@link TextEvent} to the underlying {@link ClipboardListener} * Adds a {@link TextEvent} to the underlying {@link ClipboardListener}
* *

Loading…
Cancel
Save