From 2cb1997d95c5cd3530c9255c3352aa16c69a4d36 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Wed, 21 Jul 2021 01:35:39 +0100 Subject: [PATCH] Add enum class for different DataFlavors --- src/main/java/me/goudham/util/Contents.java | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/me/goudham/util/Contents.java diff --git a/src/main/java/me/goudham/util/Contents.java b/src/main/java/me/goudham/util/Contents.java new file mode 100644 index 0000000..79b94ab --- /dev/null +++ b/src/main/java/me/goudham/util/Contents.java @@ -0,0 +1,37 @@ +package me.goudham.util; + +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; + +public enum Contents { + STRING(DataFlavor.stringFlavor) { + @Override + public boolean isAvailable(Clipboard clipboard) { + return clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor); + } + }, + IMAGE(DataFlavor.imageFlavor) { + @Override + public boolean isAvailable(Clipboard clipboard) { + return clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor); + } + }, + FILELIST(DataFlavor.javaFileListFlavor) { + @Override + public boolean isAvailable(Clipboard clipboard) { + return clipboard.isDataFlavorAvailable(DataFlavor.javaFileListFlavor); + } + }; + + private final DataFlavor dataFlavor; + + Contents(DataFlavor dataFlavor) { + this.dataFlavor = dataFlavor; + } + + public DataFlavor getDataFlavor() { + return dataFlavor; + } + + public abstract boolean isAvailable(Clipboard clipboard); +}