Add support for file events

MYC-Refactor
Hammy 3 years ago
parent cdc08f4d6d
commit 96dac0ad5f

@ -6,16 +6,20 @@ import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import static me.goudham.domain.Contents.FILELIST;
import static me.goudham.domain.Contents.IMAGE; import static me.goudham.domain.Contents.IMAGE;
import static me.goudham.domain.Contents.STRING; import static me.goudham.domain.Contents.TEXT;
abstract class ClipboardListener { abstract class ClipboardListener {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
private EventManager eventManager = new EventManager(); private EventManager eventManager = new EventManager();
private boolean imagesMonitored = true; private boolean imageMonitored = true;
private boolean textMonitored = true; private boolean textMonitored = true;
private boolean fileListMonitored = true;
/** /**
* Try to unmarshal {@link Transferable} into {@link String} * Try to unmarshal {@link Transferable} into {@link String}
@ -27,7 +31,7 @@ abstract class ClipboardListener {
String newContent = null; String newContent = null;
try { try {
newContent = (String) clipboardContents.getTransferData(STRING.getDataFlavor()); newContent = (String) clipboardContents.getTransferData(TEXT.getDataFlavor());
} catch (UnsupportedFlavorException | IOException exp) { } catch (UnsupportedFlavorException | IOException exp) {
exp.printStackTrace(); exp.printStackTrace();
} }
@ -53,26 +57,46 @@ abstract class ClipboardListener {
return bufferedImage; return bufferedImage;
} }
List<File> getFileContent(Transferable clipboardContents) {
List<File> fileList = null;
try {
fileList = (List<File>) clipboardContents.getTransferData(FILELIST.getDataFlavor());
} catch (UnsupportedFlavorException | IOException exp) {
exp.printStackTrace();
}
return fileList;
}
void toggleTextMonitored() { void toggleTextMonitored() {
this.textMonitored = !textMonitored; this.textMonitored = !textMonitored;
} }
void toggleImagesMonitored() { void toggleImagesMonitored() {
this.imagesMonitored = !imagesMonitored; this.imageMonitored = !imageMonitored;
} }
boolean isImagesMonitored() { boolean isImageMonitored() {
return imagesMonitored; return imageMonitored;
} }
void setImagesMonitored(boolean imagesMonitored) { void setImageMonitored(boolean imageMonitored) {
this.imagesMonitored = imagesMonitored; this.imageMonitored = imageMonitored;
} }
boolean isTextMonitored() { boolean isTextMonitored() {
return textMonitored; return textMonitored;
} }
public boolean isFileListMonitored() {
return fileListMonitored;
}
public void setFileListMonitored(boolean fileListMonitored) {
this.fileListMonitored = fileListMonitored;
}
void setTextMonitored(boolean textMonitored) { void setTextMonitored(boolean textMonitored) {
this.textMonitored = textMonitored; this.textMonitored = textMonitored;
} }

@ -1,10 +1,13 @@
package me.goudham.domain; package me.goudham.domain;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
public class OldClipboardContent { public class OldClipboardContent {
private String oldText; private String oldText;
private BufferedImage oldImage; private BufferedImage oldImage;
private List<File> oldFiles;
public OldClipboardContent(String oldText) { public OldClipboardContent(String oldText) {
this.oldText = oldText; this.oldText = oldText;
@ -14,6 +17,10 @@ public class OldClipboardContent {
this.oldImage = oldImage; this.oldImage = oldImage;
} }
public OldClipboardContent(List<File> oldFiles) {
this.oldFiles = oldFiles;
}
public BufferedImage getOldImage() { public BufferedImage getOldImage() {
return oldImage; return oldImage;
} }
@ -21,4 +28,8 @@ public class OldClipboardContent {
public String getOldText() { public String getOldText() {
return oldText; return oldText;
} }
public List<File> getOldFiles() {
return oldFiles;
}
} }

@ -1,9 +1,12 @@
package me.goudham.event; package me.goudham.event;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.OldClipboardContent;
public interface ClipboardEvent { public interface ClipboardEvent {
void onCopyString(OldClipboardContent oldContent, String newContent); void onCopyString(OldClipboardContent oldContent, String newContent);
void onCopyImage(OldClipboardContent oldContent, BufferedImage newContent); void onCopyImage(OldClipboardContent oldContent, BufferedImage newContent);
void onCopyFiles(OldClipboardContent oldContent, List<File> newContent);
} }

Loading…
Cancel
Save