Skip to content

Commit 65dec50

Browse files
committed
App: add about(), prefs() and quit() methods
These methods were previously part of the AppEventService, but make more sense as App-specific methods. That way, each app can control the way it handles these functions. Another important consequence of this change is that we no longer need multiple AppEventService implementations competing to define the behavior of these three operations. This avoids a cascade/domino problem where AppEventService is a SciJavaService, but individual apps like ImageJ2 override behavior with e.g. LegacyAppEventService which pulls in lots of IJ2 dependencies into a "SciJava-only" context. By making it handled at the plugin level, we avoid the issue because those plugins simply fail to initialize as desired when the required services are unavailable to the context.
1 parent c3c5897 commit 65dec50

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/main/java/org/scijava/app/AbstractApp.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333

3434
import java.io.File;
3535

36+
import org.scijava.log.LogService;
3637
import org.scijava.plugin.AbstractRichPlugin;
38+
import org.scijava.plugin.Parameter;
3739
import org.scijava.util.AppUtils;
3840
import org.scijava.util.Manifest;
3941
import org.scijava.util.POM;
@@ -45,6 +47,9 @@
4547
*/
4648
public abstract class AbstractApp extends AbstractRichPlugin implements App {
4749

50+
@Parameter(required = false)
51+
private LogService log;
52+
4853
/** Maven POM with metadata about the application. */
4954
private POM pom;
5055

@@ -108,4 +113,19 @@ public File getBaseDirectory() {
108113
return AppUtils.getBaseDirectory(getSystemProperty(), getClass(), null);
109114
}
110115

116+
@Override
117+
public void about() {
118+
if (log != null) log.info(getInfo(false));
119+
}
120+
121+
@Override
122+
public void prefs() {
123+
// NB: Do nothing.
124+
}
125+
126+
@Override
127+
public void quit() {
128+
getContext().dispose();
129+
}
130+
111131
}

src/main/java/org/scijava/app/App.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ public interface App extends RichPlugin, SingletonPlugin, Versioned {
9696
*/
9797
File getBaseDirectory();
9898

99+
/**
100+
* Displays information about the application. Typically this action
101+
* takes the form as About dialog in the UI, and/or a message on the console.
102+
*/
103+
void about();
104+
105+
/**
106+
* Displays application preferences. The behavior is application-specific, but
107+
* typically a preferences dialog will be shown onscreen.
108+
*/
109+
void prefs();
110+
111+
/**
112+
* Quits the application. Typically this action will prompt the user about any
113+
* unsaved work first.
114+
*/
115+
void quit();
116+
99117
// -- Versioned methods --
100118

101119
/**

0 commit comments

Comments
 (0)