Class DialogUtils

java.lang.Object
imagingbook.common.ij.DialogUtils

public abstract class DialogUtils extends Object
Utility methods and annotations related to ImageJ's GenericDialog class.
Version:
2022/09/14
  • Method Details

    • splitTextToLines

      public static String[] splitTextToLines(int columns, String input)
      Splits a long string into multiple lines of the specified maximum length. The result is returned as a String[] with one element per text line. Multiple input strings are first joined into a single string using blank spaces as separators. Inspired by: https://stackoverflow.com/a/21002193
      Parameters:
      columns - the maximum number of characters per line
      input - the input text to be decomposed
      Returns:
      a String[] with one element per text line
    • formatText

      public static String formatText(int columns, String... textChunks)
      Splits a long string into multiple lines of the specified maximum length and builds a new string with newline (\n) characters separating successive lines. Multiple input strings are first joined into a single string using blank spaces as separators. Intended mainly to format message texts of plugin dialogs.
      Parameters:
      columns - the maximum number of characters per line
      textChunks - one or more strings which are joined
      Returns:
      a new string with newline characters separating successive lines
    • makeLineSeparatedString

      public static String makeLineSeparatedString(String... lines)
      Creates a string by formatting the supplied strings as individual text lines separated by newline. Mainly to be used with GenericDialog.addMessage(String).
      Parameters:
      lines - a sequence of strings interpreted as text lines
      Returns:
      a newline-separated string
    • makeHtmlString

      public static String makeHtmlString(String... textLines)
      Creates a HTML string by formatting the supplied string(s) as individual text lines separated by <br>. The complete text is wrapped by <html>...</html>. Mainly used to format HTML-texts before being passed to GenericDialog.addHelp(String), which requires text lines to be separated by <br>. The supplied text lines may contain any text (including HTML formatting code), they are not processed or split.
      Parameters:
      textLines - a sequence of strings interpreted as text lines
      Returns:
      a HTML string with input lines separated by <br>
    • addToDialog

      public static void addToDialog(ParameterBundle<?> params, GenericDialog gd)
      Adds all qualified fields of the given ParameterBundle to the specified GenericDialog instance, in the exact order of their definition. Qualified means that the field is of suitable type and no DialogUtils.DialogHide annotation is present. Allowed field types are boolean, int, long, float, double, enum, and String.
      Parameters:
      params - a ParameterBundle instance
      gd - a generic dialog
    • getFromDialog

      public static boolean getFromDialog(ParameterBundle<?> params, GenericDialog gd)
      Retrieves the field values of the specified ParameterBundle from the GenericDialog instance. The ParameterBundle is modified. Throws an exception if anything goes wrong.
      Parameters:
      params - a ParameterBundle instance
      gd - a generic dialog
      Returns:
      true if successful
    • askYesOrCancel

      @Deprecated public static boolean askYesOrCancel(String title, String message)
      Deprecated.
      Opens a simple dialog with the specified title and message that allows only a "Yes" or "Cancel" response.
      Parameters:
      title - the text displayed in the dialog's title bar
      message - the dialog message (may be multiple lines separated by newlines)
      Returns:
      true if "yes" was selected, false otherwise
    • askForSampleImage

      public static boolean askForSampleImage(ImageResource suggested)
      Opens a very specific dialog asking if the suggested sample image (resource) should be opened and made the active image. If the answer is YES, the suggested image is opened, otherwise not. This if typically used in the (otherwise empty) constructor of demo plugins when no (or no suitable) image is currently open. Does nothing and returns false if invoked from outside ImageJ (e.g., during testing) and in IJ batch mode.
      Parameters:
      suggested - a sample image (ImageResource)
      Returns:
      true if user accepted, false otherwise
    • askForSampleImage

      public static boolean askForSampleImage()