Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacroRecorder: Improve handling of org.scijava.widget.Button #239

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.imagej.legacy.convert;

import org.scijava.Priority;
import org.scijava.convert.AbstractConverter;
import org.scijava.convert.ConversionRequest;
import org.scijava.convert.Converter;
import org.scijava.plugin.Plugin;
import org.scijava.widget.Button;

@Plugin(type = Converter.class, priority = Priority.LOW)
public class StringToButtonConverter extends AbstractConverter<String, Button> {
@Override
public <T> T convert(Object src, Class<T> dest) {
return null;
}

@Override
public Class<Button> getOutputType() {
return Button.class;
}

@Override
public Class<String> getInputType() {
return String.class;
}

@Override
public boolean supports(ConversionRequest request) {
return super.supports(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.scijava.module.process.PostprocessorPlugin;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.widget.Button;
import org.scijava.widget.TextWidget;

/**
Expand Down Expand Up @@ -73,13 +74,18 @@ public void process(final Module module) {
final String name = input.getName();
if (excludedInputs != null && excludedInputs.contains(name)) continue;
if (excludedFromRecording(input)) continue;
if (isButton(input)) ij1Helper.recordOption(name, "0");
final Object value = module.getInput(name);
if (value != null) ij1Helper.recordOption(name, toString(value));
}

ij1Helper.finishRecording();
}

private boolean isButton(ModuleItem<?> input) {
return input.getType().equals(Button.class);
}

// -- Helper methods --

private boolean excludedFromRecording(final ModuleItem<?> input) {
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/net/imagej/legacy/ExploreCommandRecording.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.imagej.legacy;

import ij.plugin.frame.Recorder;
import org.scijava.command.Command;
import org.scijava.command.DefaultCommandService;
import org.scijava.plugin.Parameter;
import org.scijava.widget.Button;

public class ExploreCommandRecording implements Command
{
@Parameter
String string = "Hello";

@Parameter( callback = "callback" )
Button button;

@Override
public void run()
{

}

public void callback()
{
System.out.println("Button pressed.");
}

public static void main( String[] args )
{
// turn on recorder
new Recorder();

// execute above command (does not work)
final DefaultCommandService cs = new DefaultCommandService();
cs.run( ExploreCommandRecording.class, true );
}
}