Skip to content

Commit e8f7b66

Browse files
committed
Merge branch 'app-cascade'
This branch reworks how the AppAbout, AppPrefs and AppQuit events are handled, such that a dedicated service is no longer necessary. Instead, each App plugin now defines its own implementation of these methods.
2 parents 2c10b85 + 6d18d84 commit e8f7b66

File tree

5 files changed

+86
-31
lines changed

5 files changed

+86
-31
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
/**

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
import java.util.List;
3737
import java.util.Map;
3838

39+
import org.scijava.event.EventHandler;
3940
import org.scijava.log.LogService;
41+
import org.scijava.platform.event.AppAboutEvent;
42+
import org.scijava.platform.event.AppPreferencesEvent;
43+
import org.scijava.platform.event.AppQuitEvent;
4044
import org.scijava.plugin.AbstractSingletonService;
4145
import org.scijava.plugin.Parameter;
4246
import org.scijava.plugin.Plugin;
@@ -86,6 +90,26 @@ public Class<App> getPluginType() {
8690
return App.class;
8791
}
8892

93+
// -- Event handlers --
94+
95+
@EventHandler(key = "org.scijava.app.AppService#about")
96+
protected void onEvent(@SuppressWarnings("unused") final AppAboutEvent event)
97+
{
98+
getApp().about();
99+
}
100+
101+
@EventHandler(key = "org.scijava.app.AppService#prefs")
102+
protected void onEvent(
103+
@SuppressWarnings("unused") final AppPreferencesEvent event)
104+
{
105+
getApp().prefs();
106+
}
107+
108+
@EventHandler(key = "org.scijava.app.AppService#quit")
109+
protected void onEvent(@SuppressWarnings("unused") final AppQuitEvent event) {
110+
getApp().quit();
111+
}
112+
89113
// -- Helper methods - lazy initialization --
90114

91115
/** Gets {@link #apps}, initializing if necessary. */

src/main/java/org/scijava/platform/AppEventService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@
3333

3434
import java.util.List;
3535

36+
import org.scijava.app.App;
37+
import org.scijava.app.AppService;
3638
import org.scijava.command.Command;
3739
import org.scijava.service.SciJavaService;
3840

39-
/**
40-
* Interface for service that handles application-level events.
41-
*
42-
* @author Curtis Rueden
43-
*/
41+
/** @deprecated Use {@link AppService} and {@link App} instead. */
42+
@Deprecated
4443
public interface AppEventService extends SciJavaService {
4544

46-
/** Displays an About ImageJ dialog. */
45+
/** @deprecated Use {@link App#about()} instead. */
46+
@Deprecated
4747
void about();
4848

49-
/** Displays the ImageJ preferences dialog. */
49+
/** @deprecated Use {@link App#prefs()} instead. */
50+
@Deprecated
5051
void prefs();
5152

52-
/** Quits ImageJ, prompting the user about any unsaved work first. */
53+
/** @deprecated Use {@link App#quit()} instead. */
54+
@Deprecated
5355
void quit();
5456

5557
/**
56-
* Gets the commands associated with this service.
57-
*
5858
* @deprecated Tag relevant commands instead:
5959
* <code>attrs = { @Attr(name = "app-command") }</code>
6060
*/

src/main/java/org/scijava/platform/DefaultAppEventService.java

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,70 +35,63 @@
3535
import java.util.List;
3636

3737
import org.scijava.Priority;
38+
import org.scijava.app.App;
39+
import org.scijava.app.AppService;
3840
import org.scijava.command.Command;
39-
import org.scijava.event.EventHandler;
4041
import org.scijava.platform.event.AppAboutEvent;
4142
import org.scijava.platform.event.AppPreferencesEvent;
4243
import org.scijava.platform.event.AppQuitEvent;
44+
import org.scijava.plugin.Parameter;
4345
import org.scijava.plugin.Plugin;
4446
import org.scijava.service.AbstractService;
4547
import org.scijava.service.Service;
4648

47-
/**
48-
* Default service for handling application-level events.
49-
* <p>
50-
* An {@link AppAboutEvent} triggers a callback to {@link #about()}. An
51-
* {@link AppPreferencesEvent} triggers a callback to {@link #prefs()}. Finally,
52-
* an {@link AppQuitEvent} triggers a callback to {@link #quit()}. Note that
53-
* this class's implementations of the former two methods do nothing, and the
54-
* latter simply disposes the application context with no user checks.
55-
* </p>
56-
*
57-
* @author Curtis Rueden
58-
*/
49+
/** @deprecated Use {@link AppService} and {@link App} instead. */
50+
@Deprecated
5951
@Plugin(type = Service.class, priority = Priority.LOW_PRIORITY)
6052
public class DefaultAppEventService extends AbstractService implements
6153
AppEventService
6254
{
6355

56+
@Parameter
57+
private AppService appService;
58+
6459
// -- AppService methods --
6560

6661
@Override
6762
public void about() {
68-
// NB: Do nothing.
63+
appService.getApp().about();
6964
}
7065

7166
@Override
7267
public void prefs() {
73-
// NB: Do nothing.
68+
appService.getApp().prefs();
7469
}
7570

7671
@Override
7772
public void quit() {
78-
getContext().dispose();
73+
appService.getApp().quit();
7974
}
8075

8176
@Override
8277
public List<Class<? extends Command>> getCommands() {
8378
return Collections.emptyList();
8479
}
8580

86-
// -- Event handlers --
87-
88-
@EventHandler(key = "org.scijava.platform.AppEventService#about")
81+
@Deprecated
8982
protected void onEvent(@SuppressWarnings("unused") final AppAboutEvent event)
9083
{
9184
about();
9285
}
9386

94-
@EventHandler(key = "org.scijava.platform.AppEventService#prefs")
87+
@Deprecated
9588
protected void onEvent(
9689
@SuppressWarnings("unused") final AppPreferencesEvent event)
9790
{
9891
prefs();
9992
}
10093

101-
@EventHandler(key = "org.scijava.platform.AppEventService#quit")
94+
@Deprecated
10295
protected void onEvent(@SuppressWarnings("unused") final AppQuitEvent event) {
10396
quit();
10497
}

0 commit comments

Comments
 (0)