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.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; 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.IMAGE;
import static me.goudham.domain.Contents.STRING; import static me.goudham.domain.Contents.STRING;
abstract class ClipboardListener { abstract class ClipboardListener {
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
List<ClipboardEventListener> eventsListener = new ArrayList<>(); private EventManager eventManager = new EventManager();
private boolean imagesMonitored = true; private boolean imagesMonitored = true;
private boolean textMonitored = 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 getStringContent(Transferable clipboardContents) {
String newContent = null; String newContent = null;
@ -32,6 +35,12 @@ abstract class ClipboardListener {
return newContent; 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 getImageContent(Transferable clipboardContents) {
BufferedImage bufferedImage = null; BufferedImage bufferedImage = null;
@ -44,28 +53,6 @@ abstract class ClipboardListener {
return bufferedImage; 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() { void toggleTextMonitored() {
this.textMonitored = !textMonitored; this.textMonitored = !textMonitored;
} }
@ -90,5 +77,19 @@ abstract class ClipboardListener {
this.textMonitored = textMonitored; 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(); abstract void execute();
} }

@ -1,7 +1,7 @@
package me.goudham; package me.goudham;
import me.goudham.exception.UnsupportedSystemException; import me.goudham.exception.UnsupportedSystemException;
import me.goudham.listener.ClipboardEventListener; import me.goudham.event.ClipboardEvent;
import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.SystemUtils;
import org.jetbrains.annotations.NotNull; 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) { public void subscribe(ClipboardEvent clipboardEvent) {
clipboardListener.addEventListener(clipboardEventListener); 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) { public void unsubscribe(ClipboardEvent clipboardEvent) {
clipboardListener.removeEventListener(clipboardEventListener); clipboardListener.getEventManager().unsubscribe(clipboardEvent);
} }
public void toggleTextMonitored() { public void toggleTextMonitored() {
clipboardListener.toggleTextMonitored(); clipboardListener.toggleTextMonitored();
} }

Loading…
Cancel
Save