Reformat javadoc & methods

MYC-Refactor
Hammy 3 years ago
parent 1b4e0af716
commit 061e2502c3

@ -7,19 +7,22 @@ import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import me.goudham.listener.ClipboardEventListener;
import static me.goudham.domain.Contents.IMAGE;
import static me.goudham.domain.Contents.STRING;
abstract class ClipboardListener {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
List<ClipboardEventListener> eventsListener = new ArrayList<>();
private EventManager eventManager = new EventManager();
private boolean imagesMonitored = true;
private boolean textMonitored = true;
/**
* Try to unmarshal {@link Transferable} into {@link String}
*
* @param clipboardContents The {@link Transferable} to be converted into {@link String}
* @return {@link String} representation of {@code clipboardContents}
*/
String getStringContent(Transferable clipboardContents) {
String newContent = null;
@ -32,6 +35,12 @@ abstract class ClipboardListener {
return newContent;
}
/**
* Try to unmarshal {@link Transferable} into {@link BufferedImage}
*
* @param clipboardContents The {@link Transferable} to be converted into {@link BufferedImage}
* @return {@link BufferedImage} representation of {@code clipboardContents}
*/
BufferedImage getImageContent(Transferable clipboardContents) {
BufferedImage bufferedImage = null;
@ -44,28 +53,6 @@ abstract class ClipboardListener {
return bufferedImage;
}
void notifyStringEvent(String stringContent) {
for (ClipboardEventListener clipboardEventListener : eventsListener) {
clipboardEventListener.onCopyString(stringContent);
}
}
void notifyImageEvent(BufferedImage imageContent) {
for (ClipboardEventListener clipboardEventListener : eventsListener) {
clipboardEventListener.onCopyImage(imageContent);
}
}
void addEventListener(ClipboardEventListener clipboardEventListener) {
if (!eventsListener.contains(clipboardEventListener)) {
eventsListener.add(clipboardEventListener);
}
}
void removeEventListener(ClipboardEventListener clipboardEventListener) {
eventsListener.remove(clipboardEventListener);
}
void toggleTextMonitored() {
this.textMonitored = !textMonitored;
}
@ -90,5 +77,19 @@ abstract class ClipboardListener {
this.textMonitored = textMonitored;
}
EventManager getEventManager() {
return eventManager;
}
void setEventManager(EventManager eventManager) {
this.eventManager = eventManager;
}
/**
* Main entry point of execution for both {@link MacClipboardListener} and {@link WindowsOrUnixClipboardListener}
*
* @see MacClipboardListener
* @see WindowsOrUnixClipboardListener
*/
abstract void execute();
}

@ -1,7 +1,7 @@
package me.goudham;
import me.goudham.exception.UnsupportedSystemException;
import me.goudham.listener.ClipboardEventListener;
import me.goudham.event.ClipboardEvent;
import org.apache.commons.lang3.SystemUtils;
import org.jetbrains.annotations.NotNull;
@ -45,23 +45,26 @@ public class MyClipboard {
}
/**
* Adds a {@link ClipboardEventListener} to the underlying {@link ClipboardListener}
* Adds a {@link ClipboardEvent} to the underlying {@link ClipboardListener}
*
* @param clipboardEventListener The {@link ClipboardEventListener} to be added
* @param clipboardEvent The {@link ClipboardEvent} to be added
* @see EventManager
*/
public void addEventListener(ClipboardEventListener clipboardEventListener) {
clipboardListener.addEventListener(clipboardEventListener);
public void subscribe(ClipboardEvent clipboardEvent) {
clipboardListener.getEventManager().subscribe(clipboardEvent);
}
/**
* Removes a {@link ClipboardEventListener} from the underlying {@link ClipboardListener}
* Removes a {@link ClipboardEvent} from the underlying {@link ClipboardListener#}
*
* @param clipboardEventListener The {@link ClipboardEventListener} to be removed
* @param clipboardEvent The {@link ClipboardEvent} to be removed
* @see EventManager
*/
public void removeEventListener(ClipboardEventListener clipboardEventListener) {
clipboardListener.removeEventListener(clipboardEventListener);
public void unsubscribe(ClipboardEvent clipboardEvent) {
clipboardListener.getEventManager().unsubscribe(clipboardEvent);
}
public void toggleTextMonitored() {
clipboardListener.toggleTextMonitored();
}

Loading…
Cancel
Save