Skip to content

Commit 6d18d84

Browse files
committed
Migrate handling of AppEvents to AppService
This deprecates the AppEventService, moving the event handlers into the DefaultAppService. Each event handler method simply invokes the respective method of the highest priority app.
1 parent 65dec50 commit 6d18d84

File tree

3 files changed

+48
-31
lines changed

3 files changed

+48
-31
lines changed

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)