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

Adapt to code changes introduced in 1.52q through 1.53b #47

Merged
merged 4 commits into from
Jun 12, 2020
Merged
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
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>27.0.1</version>
<version>28.0.0</version>
<relativePath />
</parent>

<groupId>net.imagej</groupId>
<artifactId>ij1-patcher</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>

<name>ImageJ 1.x Patcher</name>
<description>A runtime patcher to introduce extension points into ImageJ 1.x. This project offers extension points for use with ImageJ2 and it also offers (limited) support for headless operations.</description>
Expand Down Expand Up @@ -92,6 +92,8 @@ Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
Institute of Molecular Cell Biology and Genetics.</license.copyrightOwners>
<license.projectName>ImageJ software for multidimensional image processing and analysis.</license.projectName>
<ij1-patcher.jar>${project.build.directory}/${project.build.finalName}.jar</ij1-patcher.jar>

<imagej1.version>1.53b</imagej1.version>
</properties>

<dependencies>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/imagej/patcher/CodeHacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,18 @@ private void skipAWTInstantiations(final CtClass clazz)
{
clazz.instrument(new ExprEditor() {

@Override
public void edit(final ConstructorCall call) throws CannotCompileException {
try {
if (call.getConstructor().getLongName().equals("ij.gui.GenericDialog(java.lang.String,java.awt.Frame)")) {
call.replace("super();");
}
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
public void edit(final NewExpr expr) throws CannotCompileException {
final String name = expr.getClassName();
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/net/imagej/patcher/HeadlessGenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Panel;
import java.awt.TextArea;
Expand Down Expand Up @@ -124,12 +125,16 @@ public void addChoice(String label, String[] items, String defaultItem) {
choices.add(items[index]);
}

public void addNumericField(String label, double defaultValue, int digits) {
public void addNumericField(String label, double defaultValue) {
numbers.add(getMacroParameter(label, defaultValue));
}

public void addNumericField(String label, double defaultValue, int digits) {
addNumericField(label, defaultValue);
}

public void addNumericField(String label, double defaultValue, int digits, int columns, String units) {
addNumericField(label, defaultValue, digits);
addNumericField(label, defaultValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the digits parameter value be passed down the line here?

Copy link
Member Author

@imagejan imagejan Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

digits, as well as columns and units in the other signature, only make sense in a non-headless environment, as they define details of how the dialog is displayed.
All that addNumericField in HeadlessGenericDialog does is calling:

numbers.add(getMacroParameter(label, defaultValue));

i.e. only label and defaultValue are actually used.

I essentially kept this pattern from the two pre-existing signatures (addNumericField(String, double, int, int, String) was calling addNumericField(String, double, int) before, dropping the last two arguments).

}

public void addSlider(String label, double minValue, double maxValue, double defaultValue) {
Expand Down Expand Up @@ -222,7 +227,7 @@ public void showDialog() {
/**
* Resets the counters before reading the dialog parameters.
*/
private void resetCounters() {
void resetCounters() {
numberfieldIndex = 0;
stringfieldIndex = 0;
checkboxIndex = 0;
Expand Down Expand Up @@ -257,6 +262,7 @@ public void centerDialog(boolean b) {}
public void setSmartRecording(boolean smartRecording) {}
public void enableYesNoCancel() {}
public void enableYesNoCancel(String yesLabel, String noLabel) {}
public void finalizeRecording() {}
public void focusGained(FocusEvent e) {}
public void focusLost(FocusEvent e) {}
public Button[] getButtons() { return null; }
Expand All @@ -279,6 +285,7 @@ public void setInsets(int top, int left, int bottom) {}
public void setOKLabel(String label) {}
protected void setup() {}
public void accessTextFields() {}
public void show() {}
public void showHelp() {}
public void setLocation(int x, int y) {}
public void setDefaultString(int index, String str) {}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/imagej/patcher/LegacyHeadless.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void patch() {
return;
}
hacker.commitClass(HeadlessGenericDialog.class);
hacker.replaceWithStubMethods("ij.gui.GenericDialog", "paint", "getInsets", "repaint", "showHelp");
hacker.replaceWithStubMethods("ij.gui.GenericDialog", "paint", "getInsets", "getParentFrame", "repaint", "showHelp");
hacker.replaceSuperclassAndStubifyAWTMethods("ij.gui.GenericDialog", HeadlessGenericDialog.class.getName());
hacker.skipAWTInstantiations("ij.gui.GenericDialog");

Expand All @@ -96,6 +96,8 @@ public void patch() {

hacker.skipAWTInstantiations("ij.plugin.Duplicator");

hacker.skipAWTInstantiations("ij.gui.GUI");

hacker.insertAtTopOfMethod("ij.plugin.filter.ScaleDialog",
"java.awt.Panel makeButtonPanel(ij.plugin.filter.SetScaleDialog gd)",
"return null;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public void missingGenericDialogMethods() throws Exception {
"adjustmentValueChanged(java.awt.event.AdjustmentEvent)", //
"getInsets(int,int,int,int)", //
"getInstance()", //
"getLabel()", //
"getValue(java.lang.String)", //
"isMacro()", //
"isMatch(java.lang.String,java.lang.String)", //
Expand Down