Skip to content

Commit 8fc8dee

Browse files
committed
DisplayViewer: add view(UserInterface, Display)
This method allow DisplayViewer implementations to customize exactly how they work for each supported UserInterface. The default implementation tells the UserInterface to create its usual flavor of DisplayWindow around the Display, invokes view(DisplayWindow, Display), then DisplayWindow#showDisplay(Display), and finally Display#update(), as AbstractUserInterface was previously doing. DisplayViewer implementations needing more control (e.g., if a window already exists, and we don't want the SwingUI to create another one) may now override view(UserInterface, Display) to customize this process. This will be useful in particular for SciView (https://github.com/scenerygraphics/SciView).
1 parent f0cc7f4 commit 8fc8dee

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>scijava-common</artifactId>
13-
<version>2.71.2-SNAPSHOT</version>
13+
<version>2.72.0-SNAPSHOT</version>
1414

1515
<name>SciJava Common</name>
1616
<description>SciJava Common is a shared library for SciJava software. It provides a plugin framework, with an extensible mechanism for service discovery, backed by its own annotation processor, so that plugins can be loaded dynamically. It is used by downstream projects in the SciJava ecosystem, such as ImageJ and SCIFIO.</description>

src/main/java/org/scijava/ui/AbstractUserInterface.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.scijava.prefs.PrefService;
4545
import org.scijava.thread.ThreadService;
4646
import org.scijava.ui.viewer.DisplayViewer;
47-
import org.scijava.ui.viewer.DisplayWindow;
4847

4948
/**
5049
* Abstract superclass for {@link UserInterface} implementations.
@@ -138,12 +137,8 @@ public void show(final Display<?> display) {
138137
threadService.queue(new Runnable() {
139138
@Override
140139
public void run() {
141-
final DisplayWindow displayWindow = createDisplayWindow(display);
142-
finalViewer.view(displayWindow, display);
143-
displayWindow.setTitle(display.getName());
140+
finalViewer.view(AbstractUserInterface.this, display);
144141
uiService.addDisplayViewer(finalViewer);
145-
displayWindow.showDisplay(true);
146-
display.update();
147142
}
148143
});
149144
}

src/main/java/org/scijava/ui/viewer/DisplayViewer.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ public interface DisplayViewer<T> extends RichPlugin, Disposable {
6767
*/
6868
boolean canView(Display<?> d);
6969

70+
/**
71+
* Begins viewing the given display.
72+
* <p>
73+
* The default behavior of this method is to ask the given
74+
* {@link UserInterface} to create a {@link DisplayWindow} via
75+
* {@link UserInterface#createDisplayWindow(Display)} and then pass it to
76+
* {@link #view(DisplayWindow, Display)}. Viewers needing to customize details
77+
* of the {@link DisplayWindow} creation can do so via this method.
78+
* </p>
79+
*
80+
* @param ui The user interface with which the viewer will be associated.
81+
* @param d the model for the display to show.
82+
*/
83+
default void view(final UserInterface ui, final Display<?> d) {
84+
final DisplayWindow w = ui.createDisplayWindow(d);
85+
w.setTitle(d.getName());
86+
view(w, d);
87+
w.showDisplay(true);
88+
d.update();
89+
}
90+
7091
/**
7192
* Begins viewing the given display.
7293
*

0 commit comments

Comments
 (0)