Ticket #380 (closed enhancement: fixed)

Opened 8 years ago

Last modified 7 years ago

Add support for interdependent parameters

Reported by: curtis Owned by: curtis
Priority: major Milestone:
Component: Plugin Framework Version:
Severity: non-issue Keywords:
Cc: bene.schmid@… Blocked By:
Blocking: #11


The plugin framework needs a way for changes to one parameter value to automatically affect other parameter values. For example, a "constrain aspect ratio" checkbox might cause the two numerical parameters "width" and "height" to stay at a particular ratio.

We can achieve this feature by adding a new "String callback" attribute to @Parameter, which specifies a callback method for that parameter. Whenever the parameter changes, the indicated callback method is called. In this way, plugins can completely customize what happens in response to any given parameter change.

After invoking the callback, the plugin infrastructure updates all dialog fields to the latest values (and this update does not itself trigger any additional callbacks).

Here is an sample implementation for the aspect ratio use case:

public int width;

public int height;

@Parameter(label="Maintain aspect ratio", callback="aspectRatioToggled")
public boolean aspectRatio;

/** The plugin must populate these with the image's initial width and height. */
private int originalWidth, originalHeight;

/** Invoked when width text field changes. */
public void widthChanged() {
  if (aspectRatio) constrainHeight();

/** Invoked when height text field changes. */
public void heightChanged() {
  if (aspectRatio) constrainWidth();

public void aspectRatioToggled() {
  if (aspectRatio) constrainHeight(); // arbitrarily change height, rather than width

/** Adjusts width to match original aspect ratio. */
private void constrainWidth() {
  width = originalWidth * height / originalHeight;

/** Adjusts height to match original aspect ratio. */
private void constrainHeight() {
  height = originalHeight * width / originalWidth;

Change History

comment:1 Changed 8 years ago by curtis

  • Status changed from new to closed
  • Resolution set to fixed

Initial implementation of callback methods in b4cd642b6b63b7bb3c83992d02421a53820912ba. See source:trunk/core/core-plugins/src/main/java/imagej/core/plugins/GradientImage.java for an example.

comment:2 Changed 7 years ago by curtis

  • Blocking 11 added
Note: See TracTickets for help on using tickets.