Interface ParameterBundle<TargetT>

Type Parameters:
TargetT - the target class to be parameterized
All Known Implementing Classes:
BernsenThresholder.Parameters, BilateralF.Parameters, CannyEdgeDetector.Parameters, Circle_Make_Random.Parameters, Ellipse_Make_Random.Parameters, EllipseGeometricFitCoord.Parameters, EllipseGeometricFitDist.Parameters, GradientCornerDetector.Parameters, HoughTransformLines.Parameters, KuwaharaF.Parameters, Line_Make_Random.Parameters, LucasKanadeMatcher.Parameters, MserParameters, MultiGradientEdgeDetector.Parameters, NagaoMatsuyamaF.Parameters, NiblackThresholder.Parameters, PdfExporter.Parameters, PeronaMalikF.Parameters, RansacCircleDetector.Parameters, RansacDetector.RansacParameters, RansacEllipseDetector.Parameters, RansacLineDetector.Parameters, SauvolaThresholder.Parameters, ScalarMedianFilter.Parameters, SiftParameters, TschumperleDericheF.Parameters, VectorMedianFilter.Parameters, VectorMedianFilterSharpen.Parameters

public interface ParameterBundle<TargetT>

Interface to be implemented by local 'Parameters' classes. This is part of the 'simple parameter object' scheme, working with public fields. Only non-static, non-final, public fields are accepted as parameters. Current features include:
(a) Makes parameter bundles printable by listing all eligible fields.
(b) Parameter bundles can be added/modified as a whole by ImageJ's GenericDialog, supported by specific annotations (use methods DialogUtils.addToDialog(ParameterBundle, GenericDialog) and DialogUtils.getFromDialog(ParameterBundle, GenericDialog)).
See the example in DemoParameters below. Other functionality may be added in the future.

 public class ClassToBeParameterized {
        enum MyEnum {  // local enum type
                A, B, Cee
    };
        // Sample parameter bundle class:
        static class DemoParameters implements ParameterBundle<ClassToBeParameterized> {
                public static int staticInt = 44; // currently static members are listed too!
                @DialogLabel("Make a decision:")
                public boolean someBool = true;
                public int someInt = 39;
                public float someFloat = 1.99f;
                @DialogLabel("Math.PI")
                @DialogDigits(10)
                public double someDouble = Math.PI;
                public String someString = "SHOW ME";
                @DialogHide
                public String hiddenString = "HIDE ME";
                public MyEnum someEnum = MyEnum.B;
    }
        public static void main(String[] args) {
                ParameterBundle params = new DemoParameters();
                System.out.println("p1 = \n" + params.printToString());
                GenericDialog gd = new GenericDialog(ParameterBundle.class.getSimpleName());
                gd.addNumericField("some single int", 123, 0);
                params.addToDialog(gd);
                gd.showDialog();
                if (gd.wasCanceled())
                        return;
                int singleInt = (int) gd.getNextNumber();
                boolean success = params.getFromDialog(gd);
                System.out.println("success = " + success);
                System.out.println("p2 = \n" + params.printToString());
    }
 }
 
Version:
2022/11/23 added generic target type
See Also:
  • Method Details

    • getValidParameterFields

      Returns the valid parameter fields as an array.
      Returns:
      the valid parameter fields
    • printToString

      default String printToString()
      Substitute for Object.toString(), which cannot be overridden by an interface's default method.
      Returns:
      as string representation of theis parameter bundle
    • printToStream

      default void printToStream(PrintStream strm)
      Sends a string representation of this parameter bundle to the specified stream.
      Parameters:
      strm - the output stream
    • validate

      default boolean validate()
      Validates the correctness and compatibility of the parameters in this bundle. Does nothing by default, implementing classes should override this method.
      Returns:
      true if all parameters are OK, false otherwise
    • isValidParameterField

      static boolean isValidParameterField(Field f)
      Returns true iff the specified field is a valid parameter item. This applies if the field is neither private nor final or static.
      Parameters:
      f - the field
      Returns:
      true if a valid parameter field
    • duplicate

      static <T extends ParameterBundle<?>> T duplicate(T params)
      Returns a shallow copy of the specified ParameterBundle instance.
      Type Parameters:
      T - generic type
      Parameters:
      params - a ParameterBundle instance
      Returns:
      a copy with the same type, fields and values as the original instance