Skip to content

Commit 786a58b

Browse files
authored
Merge pull request #307 from imagej/macro-recorder-postprocessor
Closes #305
2 parents 915bec8 + ba93c4e commit 786a58b

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>net.imagej</groupId>
1313
<artifactId>imagej-legacy</artifactId>
14-
<version>1.2.3-SNAPSHOT</version>
14+
<version>2.0.0-SNAPSHOT</version>
1515

1616
<name>ImageJ Legacy Bridge</name>
1717
<description>The legacy component enables backward compatibility with the original version of ImageJ (1.x). It contains the code necessary to translate between ImageJ and ImageJ2 images, so that ImageJ plugins can be executed faithfully.</description>

src/main/java/net/imagej/legacy/DefaultLegacyHooks.java

+17-10
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
public class DefaultLegacyHooks extends LegacyHooks {
8686

8787
private final LegacyService legacyService;
88-
private final IJ1Helper helper;
8988

9089
private LogService log;
9190
private LegacyEditor editor;
@@ -97,14 +96,7 @@ public class DefaultLegacyHooks extends LegacyHooks {
9796
private BufferedWriter logFileWriter;
9897

9998
public DefaultLegacyHooks(final LegacyService legacyService) {
100-
this(legacyService, legacyService.getIJ1Helper());
101-
}
102-
103-
public DefaultLegacyHooks(final LegacyService legacyService,
104-
final IJ1Helper helper)
105-
{
10699
this.legacyService = legacyService;
107-
this.helper = helper;
108100
}
109101

110102
@Override
@@ -147,6 +139,8 @@ public Object interceptRunPlugIn(final String className, final String arg) {
147139
return legacyService == null ? null : legacyService.getContext();
148140
}
149141

142+
IJ1Helper helper = helper();
143+
150144
// Intercept IJ1 commands
151145
if (helper != null) {
152146
// intercept ij.plugins.Commands
@@ -341,6 +335,7 @@ public void addMenuItem(final String menuPath, final String command) {
341335
final Pattern pattern = Pattern.compile(
342336
"^\\s*([^,]*),\\s*\"([^\"]*)\",\\s*([^\\s]*(\\(.*\\))?)\\s*");
343337
final ClassLoader cl = Context.getClassLoader();
338+
final IJ1Helper helper = helper();
344339
try {
345340
final Enumeration<URL> pluginsConfigs = cl.getResources("plugins.config");
346341
while (pluginsConfigs.hasMoreElements()) {
@@ -501,7 +496,7 @@ public boolean interceptCloseAllWindows() {
501496
final Window win = windows[w];
502497

503498
// Skip the ImageJ 1.x main window
504-
if (win == null || win == helper.getIJ()) {
499+
if (win == null || win == helper().getIJ()) {
505500
continue;
506501
}
507502

@@ -550,6 +545,7 @@ public boolean interceptCloseAllWindows() {
550545
@Override
551546
public void interceptImageWindowClose(final Object window) {
552547
final Frame w = (Frame)window;
548+
final IJ1Helper helper = helper();
553549
// When quitting, IJ1 doesn't dispose closing ImageWindows.
554550
// If the quit is later canceled this would leave orphaned windows.
555551
// Thus we queue any closed windows for disposal.
@@ -569,7 +565,7 @@ public boolean disposing() {
569565
// within its ij.ImageJ#run() method, which is typically, but not always,
570566
// called on a separate thread by ij.ImageJ#quit(). The question is: did
571567
// the shutdown originate from an IJ1 code path, or a SciJava one?
572-
if (helper.isDisposing()) {
568+
if (helper().isDisposing()) {
573569
// NB: ImageJ1 is in the process of a hard shutdown via an API call on
574570
// the SciJava level. It was probably either LegacyService#dispose() or
575571
// LegacyUI#dispose(), either of which triggers IJ1Helper#dispose().
@@ -586,6 +582,17 @@ public boolean disposing() {
586582

587583
// -- Helper methods --
588584

585+
/**
586+
* Convenience method for accessing the attached {@link LegacyService}'s
587+
* {@link IJ1Helper}.
588+
*/
589+
private IJ1Helper helper() {
590+
// NB: although there is a setter for the IJ1Helper, it is documented as
591+
// "non-API" and thus the helper should never be null. If this changes at
592+
// some point we should do null checking here.
593+
return legacyService.getIJ1Helper();
594+
}
595+
589596
/**
590597
* Determines whether a file is binary or text.
591598
* <p>

src/main/java/net/imagej/legacy/LegacyService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public void initialize() {
457457
final ClassLoader loader = Context.getClassLoader();
458458
ij1Helper = new IJ1Helper(this);
459459
LegacyInjector.installHooks(loader, //
460-
new DefaultLegacyHooks(this, ij1Helper));
460+
new DefaultLegacyHooks(this));
461461
instance = this;
462462

463463
// Initialize ImageJ 1.x, if needed.

src/test/java/net/imagej/legacy/plugin/MacroRecorderPostprocessorTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.scijava.Context;
4545
import org.scijava.module.Module;
4646
import org.scijava.module.process.AbstractPreprocessorPlugin;
47+
import org.scijava.module.process.PostprocessorPlugin;
4748
import org.scijava.module.process.PreprocessorPlugin;
4849
import org.scijava.plugin.PluginInfo;
4950
import org.scijava.plugin.PluginService;
@@ -86,6 +87,9 @@ public void testParametersRecorded() throws InterruptedException,
8687
context.service(PluginService.class).addPlugin(new PluginInfo<>(
8788
MockInputHarvester.class, PreprocessorPlugin.class));
8889

90+
context.service(PluginService.class).addPlugin(new PluginInfo<>(
91+
MacroRecorderPostprocessor.class, PostprocessorPlugin.class));
92+
8993
// NB: Override the IJ1Helper to remember which parameters get recorded.
9094
final EideticIJ1Helper ij1Helper = new EideticIJ1Helper();
9195
legacyService.setIJ1Helper(ij1Helper);

0 commit comments

Comments
 (0)