From 13626d130d511339ce65086a22e07fd2468d0735 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Ulman?= Date: Wed, 14 Jun 2023 23:41:35 +0200 Subject: [PATCH] ADD: SelfShowableContent - a new kind of opening outcome It is often used in conjuction with openers that do load-and-show on their own, as opposite to load-only-and-have-Fiji-to-show pattern. --- .../org/scijava/ui/SelfShowableContent.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/org/scijava/ui/SelfShowableContent.java diff --git a/src/main/java/org/scijava/ui/SelfShowableContent.java b/src/main/java/org/scijava/ui/SelfShowableContent.java new file mode 100644 index 000000000..0f11b5b6f --- /dev/null +++ b/src/main/java/org/scijava/ui/SelfShowableContent.java @@ -0,0 +1,42 @@ +package org.scijava.ui; + +import java.util.function.Consumer; + +/** + * Representation of an outcome after opening some input, be it a file on a drive, URL, + * object from a drag-and-drop event or alike. The outcome is represented with an object + * with the data itself, and a method that knows how to present (that means read and display) + * this data. The class is primarily intended for opening inputs which ImageJ2 is not normally + * able to open. Example of such opening outcomes are opening of a specific/proprietary data file + * for GUI-based applications such as BigDataViewer or Mastodon. + * + * @param The particular type for the particular data. + * + * @author Curtis Rueden, Vladimir Ulman + */ +public class SelfShowableContent { + private T content; + private Consumer showAction; + + /** + * Binds together a particular piece of data and a method that knows how to open it. + * @param content + * @param showAction + */ + public SelfShowableContent(T content, Consumer showAction) { + this.content = content; + this.showAction = showAction; + } + + /** Getter of the stored data. */ + public T content() { + return content; + } + + /** + * This starts the actual opening/consuming of the stored data. + */ + public void show() { + showAction.accept(content()); + } +} \ No newline at end of file