Skip to content

Commit 13626d1

Browse files
committed
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.
1 parent 3f0e32f commit 13626d1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.scijava.ui;
2+
3+
import java.util.function.Consumer;
4+
5+
/**
6+
* Representation of an outcome after opening some input, be it a file on a drive, URL,
7+
* object from a drag-and-drop event or alike. The outcome is represented with an object
8+
* with the data itself, and a method that knows how to present (that means read and display)
9+
* this data. The class is primarily intended for opening inputs which ImageJ2 is not normally
10+
* able to open. Example of such opening outcomes are opening of a specific/proprietary data file
11+
* for GUI-based applications such as BigDataViewer or Mastodon.
12+
*
13+
* @param <T> The particular type for the particular data.
14+
*
15+
* @author Curtis Rueden, Vladimir Ulman
16+
*/
17+
public class SelfShowableContent<T> {
18+
private T content;
19+
private Consumer<T> showAction;
20+
21+
/**
22+
* Binds together a particular piece of data and a method that knows how to open it.
23+
* @param content
24+
* @param showAction
25+
*/
26+
public SelfShowableContent(T content, Consumer<T> showAction) {
27+
this.content = content;
28+
this.showAction = showAction;
29+
}
30+
31+
/** Getter of the stored data. */
32+
public T content() {
33+
return content;
34+
}
35+
36+
/**
37+
* This starts the actual opening/consuming of the stored data.
38+
*/
39+
public void show() {
40+
showAction.accept(content());
41+
}
42+
}

0 commit comments

Comments
 (0)